-
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.
Use Duotone presets in block duotone attributes (#48318)
* Naive implementation * Refactor to named functions * Fix order of hooks * Utilise existing duotone presets on front of site * Improve self documenting code * Refactor away redundant color prop of filter_preset * Satisfy master yoda… * More commenting * Remove count() check for duotone color array Duotone color arrays can be more than 2 colors, and the code doesn't seem to handle 2 colors differently than 3 or more, so the count() === 2 was unnecessary. Since we've already defined the $is_duotone_colors_array, we can use it later instead of redoing another is_array() check. * Improve comments and linting * Allow Duotone to be cleared using UI * Add initial tests for getColorsFromDuotonePreset * Be explicit about handling presets vs colors Previously the decision about how to handle values were deferred to the utility. Instead the consuming code should decide whether to look for a preset. * Complete tests for getColorsFromDuotonePreset * Add tests and fix implementation of getDuotonePresetFromColors * Fix bug with selecting custom colors introduced during test refactor * Fix custom colors Duotone on front end rendering --------- Co-authored-by: Jerry Jones <jones.jeremydavid@gmail.com>
- Loading branch information
Showing
3 changed files
with
194 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
getColorsFromDuotonePreset, | ||
getDuotonePresetFromColors, | ||
} from '../duotone'; | ||
|
||
describe( 'Duotone utilities', () => { | ||
const duotonePalette = [ | ||
{ | ||
name: 'Dark grayscale', | ||
colors: [ '#000000', '#7f7f7f' ], | ||
slug: 'dark-grayscale', | ||
}, | ||
{ | ||
name: 'Grayscale', | ||
colors: [ '#000000', '#ffffff' ], | ||
slug: 'grayscale', | ||
}, | ||
{ | ||
name: 'Purple and yellow', | ||
colors: [ '#8c00b7', '#fcff41' ], | ||
slug: 'purple-yellow', | ||
}, | ||
]; | ||
describe( 'getColorsFromDuotonePreset', () => { | ||
it( 'should return undefined if no arguments are provided', () => { | ||
expect( getColorsFromDuotonePreset() ).toBeUndefined(); | ||
} ); | ||
|
||
it( 'should return undefined if no duotone preset is provided', () => { | ||
expect( | ||
getColorsFromDuotonePreset( undefined, duotonePalette ) | ||
).toBeUndefined(); | ||
} ); | ||
|
||
it( 'should return undefined if a non-existent preset is provided', () => { | ||
expect( | ||
getColorsFromDuotonePreset( 'does-not-exist', duotonePalette ) | ||
).toBeUndefined(); | ||
} ); | ||
|
||
it( 'should return the colors from the preset if found', () => { | ||
expect( | ||
getColorsFromDuotonePreset( | ||
duotonePalette[ 2 ].slug, | ||
duotonePalette | ||
) | ||
).toEqual( duotonePalette[ 2 ].colors ); | ||
} ); | ||
} ); | ||
|
||
describe( 'getDuotonePresetFromColors', () => { | ||
it( 'should return undefined if no arguments are provided', () => { | ||
expect( getDuotonePresetFromColors() ).toBeUndefined(); | ||
} ); | ||
|
||
it( 'should return undefined if no colors are provided', () => { | ||
expect( | ||
getDuotonePresetFromColors( undefined, duotonePalette ) | ||
).toBeUndefined(); | ||
} ); | ||
|
||
it( 'should return undefined if provided colors is not of valid type', () => { | ||
const notAnArrayOfColorStrings = 'purple-yellow'; | ||
expect( | ||
getDuotonePresetFromColors( | ||
notAnArrayOfColorStrings, | ||
duotonePalette | ||
) | ||
).toBeUndefined(); | ||
} ); | ||
|
||
it( 'should return undefined if no duotone palette is provided', () => { | ||
expect( | ||
getDuotonePresetFromColors( [ '#8c00b7', '#fcff41' ] ) | ||
).toBeUndefined(); | ||
} ); | ||
|
||
it( 'should return undefined if the provided colors do not match any preset', () => { | ||
expect( | ||
getDuotonePresetFromColors( | ||
[ '#000000', '#000000' ], | ||
duotonePalette | ||
) | ||
).toBeUndefined(); | ||
} ); | ||
|
||
it( 'should return the slug of the preset if found', () => { | ||
expect( | ||
getDuotonePresetFromColors( | ||
duotonePalette[ 2 ].colors, | ||
duotonePalette | ||
) | ||
).toEqual( duotonePalette[ 2 ].slug ); | ||
} ); | ||
} ); | ||
} ); |
c74672c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in c74672c.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4252077524
📝 Reported issues:
specs/editor/various/multi-block-selection.test.js