-
Notifications
You must be signed in to change notification settings - Fork 890
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lin Wang <[email protected]>
- Loading branch information
Showing
9 changed files
with
149 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { validateWorkspaceColor } from '../utils'; | ||
|
||
describe('validateWorkspaceColor', () => { | ||
it('should return true for a valid 6-digit hex color code', () => { | ||
expect(validateWorkspaceColor('#ABCDEF')).toBe(true); | ||
expect(validateWorkspaceColor('#123456')).toBe(true); | ||
}); | ||
|
||
it('should return true for a valid 3-digit hex color code', () => { | ||
expect(validateWorkspaceColor('#ABC')).toBe(true); | ||
expect(validateWorkspaceColor('#DEF')).toBe(true); | ||
}); | ||
|
||
it('should return false for an invalid color code', () => { | ||
expect(validateWorkspaceColor('#GHI')).toBe(false); | ||
expect(validateWorkspaceColor('#12345')).toBe(false); | ||
expect(validateWorkspaceColor('#ABCDEFG')).toBe(false); | ||
expect(validateWorkspaceColor('ABCDEF')).toBe(false); | ||
}); | ||
|
||
it('should return false for an empty string', () => { | ||
expect(validateWorkspaceColor('')).toBe(false); | ||
}); | ||
|
||
it('should return false for undefined', () => { | ||
expect(validateWorkspaceColor()).toBe(false); | ||
}); | ||
|
||
it('should be case-insensitive', () => { | ||
expect(validateWorkspaceColor('#abcdef')).toBe(true); | ||
expect(validateWorkspaceColor('#ABC')).toBe(true); | ||
}); | ||
}); |
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,8 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// Reference https://github.com/opensearch-project/oui/blob/main/src/services/color/is_valid_hex.ts | ||
export const validateWorkspaceColor = (color?: string) => | ||
!!color && /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color); |
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
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