Skip to content

Commit 34ec6a1

Browse files
Add some rough tests for Global Styles output
Plan is to refactor both the JS and PHP processing of global styles/theme.json to see if we can make that any easier to grok, more efficient or flexible etc.
1 parent 144c52e commit 34ec6a1

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

packages/block-editor/src/components/global-styles/test/use-global-styles-output.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,35 @@ describe( 'global styles renderer', () => {
2828
text: 'red',
2929
},
3030
blocks: {
31+
'core/group': {
32+
color: {
33+
background: 'linen',
34+
},
35+
variations: {
36+
foo: {
37+
color: 'aliceblue',
38+
blocks: {
39+
'core/heading': {
40+
typography: {
41+
fontSize: '3em',
42+
},
43+
},
44+
},
45+
elements: {
46+
link: {
47+
color: {
48+
text: 'darkcyan',
49+
},
50+
':hover': {
51+
color: {
52+
text: 'darkturqoise',
53+
},
54+
},
55+
},
56+
},
57+
},
58+
},
59+
},
3160
'core/heading': {
3261
color: {
3362
background: 'blue',
@@ -89,6 +118,12 @@ describe( 'global styles renderer', () => {
89118
},
90119
};
91120
const blockSelectors = {
121+
'core/group': {
122+
selector: '.my-group',
123+
styleVariationSelectors: {
124+
foo: '.is-style-foo.my-group',
125+
},
126+
},
92127
'core/heading': {
93128
selector: '.my-heading1, .my-heading2',
94129
},
@@ -129,6 +164,44 @@ describe( 'global styles renderer', () => {
129164
},
130165
selector: ELEMENTS.link,
131166
},
167+
{
168+
selector:
169+
'.is-style-foo.my-group .my-heading1, .is-style-foo.my-group .my-heading2',
170+
styles: {
171+
typography: {
172+
fontSize: '3em',
173+
},
174+
},
175+
},
176+
{
177+
selector: '.is-style-foo.my-group a',
178+
styles: {
179+
color: {
180+
text: 'darkcyan',
181+
},
182+
':hover': {
183+
color: {
184+
text: 'darkturqoise',
185+
},
186+
},
187+
},
188+
},
189+
{
190+
selector: '.my-group',
191+
styles: {
192+
color: {
193+
background: 'linen',
194+
},
195+
variations: {
196+
foo: {
197+
color: 'aliceblue',
198+
},
199+
},
200+
},
201+
styleVariationSelectors: {
202+
foo: '.is-style-foo.my-group',
203+
},
204+
},
132205
{
133206
styles: {
134207
color: {
@@ -549,6 +622,44 @@ describe( 'global styles renderer', () => {
549622
},
550623
},
551624
},
625+
'core/group': {
626+
variations: {
627+
bar: {
628+
color: {
629+
background: 'midnightblue',
630+
text: 'lightskyblue',
631+
},
632+
blocks: {
633+
'core/heading': {
634+
color: {
635+
text: 'royalblue',
636+
},
637+
},
638+
'core/image': {
639+
border: {
640+
color: 'darkcyan',
641+
style: 'dashed',
642+
width: '5px',
643+
},
644+
},
645+
},
646+
elements: {
647+
h2: {
648+
color: {
649+
text: 'turquoise',
650+
},
651+
},
652+
button: {
653+
color: {
654+
background: 'midnightblue',
655+
text: 'powderblue',
656+
},
657+
':hover': {},
658+
},
659+
},
660+
},
661+
},
662+
},
552663
},
553664
},
554665
};
@@ -567,11 +678,21 @@ describe( 'global styles renderer', () => {
567678
foo: '.is-style-foo.wp-image',
568679
},
569680
},
681+
'core/group': {
682+
selector: '.wp-group',
683+
styleVariationSelectors: {
684+
bar: '.is-style-bar.wp-group',
685+
},
686+
},
687+
'core/heading': {
688+
selector: '.wp-heading',
689+
},
570690
};
571691

572692
expect( toStyles( Object.freeze( tree ), blockSelectors ) ).toEqual(
573693
'body {margin: 0;}body .is-layout-flow > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }body .is-layout-flow > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }body .is-layout-flow > .aligncenter { margin-left: auto !important; margin-right: auto !important; }body .is-layout-constrained > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }body .is-layout-constrained > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }body .is-layout-constrained > .aligncenter { margin-left: auto !important; margin-right: auto !important; }body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)) { max-width: var(--wp--style--global--content-size); margin-left: auto !important; margin-right: auto !important; }body .is-layout-constrained > .alignwide { max-width: var(--wp--style--global--wide-size); }body .is-layout-flex { display:flex; }body .is-layout-flex { flex-wrap: wrap; align-items: center; }body .is-layout-flex > * { margin: 0; }body .is-layout-grid { display:grid; }body .is-layout-grid > * { margin: 0; }' +
574694
'.is-style-foo.wp-image.wp-image-spacing{padding-top: 2px;}.is-style-foo.wp-image.wp-image-border-color{border-color: blue;}.is-style-foo.wp-image{color: blue;}' +
695+
'.is-style-bar.wp-group .wp-heading{color: royalblue;}.is-style-bar.wp-group .wp-image-border-color{border-color: darkcyan;}.is-style-bar.wp-group .wp-image-border{border-style: dashed;border-width: 5px;}.is-style-bar.wp-group h2{color: turquoise;}.is-style-bar.wp-group .wp-element-button, .is-style-bar.wp-group .wp-block-button__link{color: powderblue;background-color: midnightblue;}.is-style-bar.wp-group{color: lightskyblue;background-color: midnightblue;}' +
575696
'.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }'
576697
);
577698
} );

0 commit comments

Comments
 (0)