-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create dataset style, tooltips, text
- Loading branch information
1 parent
6f6cd13
commit 80e0518
Showing
9 changed files
with
231 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,3 +91,11 @@ | |
.text-input-container { | ||
width: 100% | ||
} | ||
|
||
.text-input-tooltip { | ||
svg { | ||
path { | ||
fill: #c1c1c1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,50 @@ | ||
type ValidationError = string | null | ||
|
||
export const ERR_INVALID_USERNAME_CHARACTERS: ValidationError = 'Usernames may only include a-z, 0-9, _ , and -' | ||
export const ERR_INVALID_USERNAME_LENGTH: ValidationError = 'Username must be 50 characters or fewer' | ||
|
||
// validators return an error message or null | ||
export const validateUsername = (username: string): ValidationError => { | ||
if (username) { | ||
const invalidCharacters = !(/^[a-z0-9_-]+$/.test(username)) | ||
if (invalidCharacters) return 'Usernames may only include a-z, 0-9, _ , and -' | ||
if (invalidCharacters) return ERR_INVALID_USERNAME_CHARACTERS | ||
|
||
const tooLong = username.length > 50 | ||
if (tooLong) return 'Username must be 50 characters or less' | ||
if (tooLong) return ERR_INVALID_USERNAME_LENGTH | ||
} | ||
return null | ||
} | ||
|
||
export const ERR_INVALID_EMAIL: ValidationError = 'Enter a valid email address' | ||
|
||
export const validateEmail = (email: string): ValidationError => { | ||
if (email) { | ||
const invalidEmail = !(/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) | ||
if (invalidEmail) return 'Enter a valid email address' | ||
if (invalidEmail) return ERR_INVALID_EMAIL | ||
} | ||
return null | ||
} | ||
|
||
export const ERR_INVALID_PASSWORD_LENGTH: ValidationError = 'Password must be at least 8 characters' | ||
|
||
export const validatePassword = (password: string) => { | ||
if (password) { | ||
const tooShort = password && password.length < 8 | ||
if (tooShort) return 'Password must be at least 8 characters' | ||
if (tooShort) return ERR_INVALID_PASSWORD_LENGTH | ||
} | ||
return null | ||
} | ||
|
||
export const ERR_INVALID_DATASETNAME_CHARACTERS: ValidationError = 'Dataset names may only include a-z, 0-9, and _' | ||
export const ERR_INVALID_DATASETNAME_LENGTH: ValidationError = 'Username must be 100 characters or fewer' | ||
|
||
export const validateDatasetName = (name: string): ValidationError => { | ||
if (name) { | ||
const invalidCharacters = !(/^[a-z0-9_]+$/.test(name)) | ||
if (invalidCharacters) return 'Dataset names may only include a-z, 0-9, and _' | ||
if (invalidCharacters) return ERR_INVALID_DATASETNAME_CHARACTERS | ||
|
||
const tooLong = name.length > 100 | ||
if (tooLong) return 'Username must be 100 characters or fewer' | ||
if (tooLong) return ERR_INVALID_DATASETNAME_LENGTH | ||
} | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { | ||
validateUsername, | ||
validateEmail, | ||
validatePassword, | ||
validateDatasetName, | ||
ERR_INVALID_USERNAME_CHARACTERS, | ||
ERR_INVALID_USERNAME_LENGTH, | ||
ERR_INVALID_EMAIL, | ||
ERR_INVALID_PASSWORD_LENGTH, | ||
ERR_INVALID_DATASETNAME_CHARACTERS, | ||
ERR_INVALID_DATASETNAME_LENGTH | ||
} from '../../../app/utils/formValidation' | ||
|
||
describe('formValidation', () => { | ||
const usernameGoodCases = [ | ||
'foo_bar', | ||
'foo27', | ||
'foo-bar', | ||
'sp4vsihuof65kgyhcmv0agbjgcwljfufkjidk5wmqhl0mxg61n' | ||
] | ||
|
||
usernameGoodCases.forEach((string) => { | ||
it(`validateUsername accepts ${string}`, () => { | ||
const got = validateUsername(string) | ||
expect(got).toBe(null) | ||
}) | ||
}) | ||
|
||
const userNameBadCases = [ | ||
{ | ||
string: 'foo👋bar', | ||
err: ERR_INVALID_USERNAME_CHARACTERS | ||
}, | ||
{ | ||
string: 'iceman@34', | ||
err: ERR_INVALID_USERNAME_CHARACTERS | ||
}, | ||
{ | ||
string: 'sp4vsihuof65kgyhcmv0agbjgcwljfufkjidk5wmqhl0mxg61n182', | ||
err: ERR_INVALID_USERNAME_LENGTH | ||
} | ||
] | ||
|
||
userNameBadCases.forEach(({ string, err }) => { | ||
it(`validateUsername rejects ${string}`, () => { | ||
const got = validateUsername(string) | ||
expect(got).toBe(err) | ||
}) | ||
}) | ||
|
||
const emailGoodCases = [ | ||
'foo@bar.com' | ||
] | ||
|
||
emailGoodCases.forEach((string) => { | ||
it(`validateEmail accepts ${string}`, () => { | ||
const got = validateEmail(string) | ||
expect(got).toBe(null) | ||
}) | ||
}) | ||
|
||
const emailBadCases = [ | ||
{ | ||
string: 'foobar', | ||
err: ERR_INVALID_EMAIL | ||
}, | ||
{ | ||
string: 'foo+bar', | ||
err: ERR_INVALID_EMAIL | ||
} | ||
] | ||
|
||
emailBadCases.forEach(({ string, err }) => { | ||
it(`validateEmail rejects ${string}`, () => { | ||
const got = validateEmail(string) | ||
expect(got).toBe(err) | ||
}) | ||
}) | ||
|
||
const passwordGoodCases = [ | ||
'someLongPassword' | ||
] | ||
|
||
passwordGoodCases.forEach((string) => { | ||
it(`validatePassword accepts ${string}`, () => { | ||
const got = validatePassword(string) | ||
expect(got).toBe(null) | ||
}) | ||
}) | ||
|
||
const passwordBadCases = [ | ||
{ | ||
string: 'imShort', | ||
err: ERR_INVALID_PASSWORD_LENGTH | ||
} | ||
] | ||
|
||
passwordBadCases.forEach(({ string, err }) => { | ||
it(`validatePassword rejects ${string}`, () => { | ||
const got = validatePassword(string) | ||
expect(got).toBe(err) | ||
}) | ||
}) | ||
|
||
const datasetNameGoodCases = [ | ||
'a', | ||
'hello_world', | ||
'pmfqbx5bhe7w4nbonqj6zu2abb15txq7vc5yfgysawjbdiqaxghvt4iy3rdyhvxg2v52mcsqeh1yymxe6ciz1lsxwmfsqyzdkh' | ||
] | ||
|
||
datasetNameGoodCases.forEach((string) => { | ||
it(`validateDatasetName accepts ${string}`, () => { | ||
const got = validateDatasetName(string) | ||
expect(got).toBe(null) | ||
}) | ||
}) | ||
|
||
const datasetNameBadCases = [ | ||
{ | ||
string: 'hello-world', | ||
err: ERR_INVALID_DATASETNAME_CHARACTERS | ||
}, | ||
{ | ||
string: '👋🏻', | ||
err: ERR_INVALID_DATASETNAME_CHARACTERS | ||
}, | ||
{ | ||
string: 'pmfqbx5bhe7w4nbonqj6zu2abb15txq7vc5yfgysawjbdiqaxghvt4iy3rdyhvxg2v52mcsqeh1yymxe6ciz1lsxwmfsqyzdkhsdf3182', | ||
err: ERR_INVALID_DATASETNAME_LENGTH | ||
} | ||
] | ||
|
||
datasetNameBadCases.forEach(({ string, err }) => { | ||
it(`validateDatasetName rejects ${string}`, () => { | ||
const got = validateDatasetName(string) | ||
expect(got).toBe(err) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
const spawn = require('cross-spawn'); | ||
const path = require('path'); | ||
const spawn = require('cross-spawn') | ||
const path = require('path') | ||
|
||
const s = `\\${path.sep}`; | ||
const s = `\\${path.sep}` | ||
const pattern = process.argv[2] === 'e2e' | ||
? `test${s}e2e${s}.+\\.spec\\.tsx?` | ||
: `test${s}(?!e2e${s})[^${s}]+${s}.+\\.spec\\.tsx?$`; | ||
: `test${s}(?!e2e${s})[^${s}]+${s}.+\\.test\\.ts?$` | ||
|
||
const result = spawn.sync(path.normalize('./node_modules/.bin/jest'), [pattern], { stdio: 'inherit' }); | ||
const result = spawn.sync(path.normalize('./node_modules/.bin/jest'), [pattern], { stdio: 'inherit' }) | ||
|
||
process.exit(result.status); | ||
process.exit(result.status) |
Oops, something went wrong.