-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Site editor: preset custom color duplicates (#40837)
* Initial commit Check the slugs for the highest id number and add one. * Ensure that color option keys are unique, even where colors are the same * Updating test snapshots Adding tests for getNameForPosition() * Roll back unique keys test * Update packages/components/src/palette-edit/index.js Update doc comments Co-authored-by: Glen Davies <glendaviesnz@users.noreply.github.com> * Extra tests Co-authored-by: Glen Davies <glendaviesnz@users.noreply.github.com>
- Loading branch information
1 parent
49c80fb
commit bcc497b
Showing
2 changed files
with
98 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { getNameForPosition } from '../'; | ||
|
||
describe( 'getNameForPosition', () => { | ||
test( 'should return 1 by default', () => { | ||
const slugPrefix = 'test-'; | ||
const elements = []; | ||
|
||
expect( getNameForPosition( elements, slugPrefix ) ).toEqual( | ||
'Color 1' | ||
); | ||
} ); | ||
|
||
test( 'should return a new color name with an incremented slug id', () => { | ||
const slugPrefix = 'test-'; | ||
const elements = [ | ||
{ | ||
slug: 'test-color-1', | ||
}, | ||
]; | ||
|
||
expect( getNameForPosition( elements, slugPrefix ) ).toEqual( | ||
'Color 2' | ||
); | ||
} ); | ||
|
||
test( 'should ignore user-defined color names', () => { | ||
const slugPrefix = 'test-'; | ||
const elements = [ | ||
{ | ||
slug: 'a-sweet-color-2', | ||
}, | ||
]; | ||
|
||
expect( getNameForPosition( elements, slugPrefix ) ).toEqual( | ||
'Color 1' | ||
); | ||
} ); | ||
|
||
test( 'should return a new color name with an incremented slug id one higher than the current highest', () => { | ||
const slugPrefix = 'test-'; | ||
const elements = [ | ||
{ | ||
slug: 'test-color-1', | ||
}, | ||
{ | ||
slug: 'test-color-2', | ||
}, | ||
{ | ||
slug: 'test-color-150', | ||
}, | ||
{ | ||
slug: 'a-sweet-color-100', | ||
}, | ||
]; | ||
|
||
expect( getNameForPosition( elements, slugPrefix ) ).toEqual( | ||
'Color 151' | ||
); | ||
} ); | ||
} ); |