-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(login): better indicators to input project subdomain (#728)
* fix(login): better indicators to input project subdomain * refactor: rename helper function/file * refactor: separate validator function, add tests * chore: rename another file * fix: lint * chore: this was bugging me
- Loading branch information
1 parent
b8090fd
commit 0318093
Showing
7 changed files
with
78 additions
and
41 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,55 @@ | ||
import fs from 'fs'; | ||
|
||
import { validateFilePath, validateSubdomain } from '../../src/lib/validatePromptInput'; | ||
|
||
describe('#validateFilePath', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return error for empty path value', () => { | ||
return expect(validateFilePath('')).toBe('An output path must be supplied.'); | ||
}); | ||
|
||
it('should return error if path already exists', () => { | ||
expect.assertions(2); | ||
const testPath = 'path-that-already-exists'; | ||
|
||
fs.existsSync = jest.fn(() => true); | ||
|
||
expect(validateFilePath(testPath)).toBe('Specified output path already exists.'); | ||
expect(fs.existsSync).toHaveBeenCalledWith(testPath); | ||
}); | ||
|
||
it("should return true if the path doesn't exist", () => { | ||
expect.assertions(2); | ||
const testPath = 'path-that-does-not-exist'; | ||
|
||
fs.existsSync = jest.fn(() => false); | ||
|
||
expect(validateFilePath(testPath)).toBe(true); | ||
expect(fs.existsSync).toHaveBeenCalledWith(testPath); | ||
}); | ||
}); | ||
|
||
describe('#validateSubdomain', () => { | ||
it('should validate basic subdomain', () => { | ||
expect(validateSubdomain('subdomain')).toBe(true); | ||
}); | ||
|
||
it('should validate subdomain with other characters', () => { | ||
expect(validateSubdomain('test-Subdomain123')).toBe(true); | ||
}); | ||
|
||
it('should reject subdomain with spaces', () => { | ||
expect(validateSubdomain('test subdomain')).toBe( | ||
'Project subdomain must contain only letters, numbers and dashes.' | ||
); | ||
}); | ||
|
||
it('should reject subdomain with special characters', () => { | ||
expect(validateSubdomain('test-subdomain!')).toBe( | ||
'Project subdomain must contain only letters, numbers and dashes.' | ||
); | ||
}); | ||
}); |
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