-
Notifications
You must be signed in to change notification settings - Fork 60
/
column-block.spec.js
155 lines (122 loc) · 5.46 KB
/
column-block.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* WordPress dependencies
*/
import {
createNewPost,
getEditedPostContent,
searchForBlock,
selectBlockByClientId,
} from '@wordpress/e2e-test-utils';
import {
insertRowBlock,
} from '../row/row-helper';
import {
getColumnBlocks,
} from './column-helper';
import {
clickElementByText,
getCheckboxValueByLabel,
getDataValuesOfElement,
inputIsDisabledByLabel,
getInputValueByLabel,
openSidebarPanelWithTitle,
selectOption,
} from '../helper';
describe( 'column block', () => {
beforeEach( async () => {
await createNewPost();
} );
it( 'Column block should not be available in block inserter', async () => {
expect( console ).toHaveWarned();
await searchForBlock( 'Bootstrap Column' );
expect( await page.$( '.block-editor-inserter__no-results' ) ).not.toBeNull();
} );
it( 'Column block should be initialized with default attributes', async () => {
expect( console ).toHaveWarned();
await insertRowBlock();
// Check attributes of first column block
const columnBlocks = await getColumnBlocks();
const firstColumnBlockClientId = columnBlocks[ 0 ].clientId;
const columnData = await getDataValuesOfElement( `#block-${ firstColumnBlockClientId }` );
// Check if default values are set in data attributes
expect( columnData.sizeXs ).toMatch( '12' );
expect( columnData.sizeSm ).toMatch( '0' );
expect( columnData.sizeMd ).toMatch( '6' );
expect( columnData.sizeLg ).toMatch( '0' );
expect( columnData.sizeXl ).toMatch( '0' );
// Select first column block
await selectBlockByClientId( firstColumnBlockClientId );
// Check if default values are set in inspector controls
await openSidebarPanelWithTitle( 'Column size' );
expect( await getInputValueByLabel( 'Xs Column count' ) ).toMatch( '12' );
expect( await getInputValueByLabel( 'Sm Column count' ) ).toMatch( '0' );
expect( await getInputValueByLabel( 'Md Column count' ) ).toMatch( '6' );
expect( await getInputValueByLabel( 'Lg Column count' ) ).toMatch( '0' );
expect( await getInputValueByLabel( 'Xl Column count' ) ).toMatch( '0' );
expect( await getCheckboxValueByLabel( 'Xs equal-width' ) ).toBe( false );
expect( await getCheckboxValueByLabel( 'Sm equal-width' ) ).toBe( false );
expect( await getCheckboxValueByLabel( 'Md equal-width' ) ).toBe( false );
expect( await getCheckboxValueByLabel( 'Lg equal-width' ) ).toBe( false );
expect( await getCheckboxValueByLabel( 'Xl equal-width' ) ).toBe( false );
} );
it( 'Should be possible to change column size', async () => {
expect( console ).toHaveWarned();
await insertRowBlock();
// Select first column block
const columnBlocks = await getColumnBlocks();
const firstColumnBlockClientId = columnBlocks[ 0 ].clientId;
await selectBlockByClientId( firstColumnBlockClientId );
await openSidebarPanelWithTitle( 'Column size' );
// Change column size attributes
await clickElementByText( 'label', 'Lg equal-width' );
let columnData = await getDataValuesOfElement( `#block-${ firstColumnBlockClientId }` );
// Check if default values are set in data attributes
expect( columnData.sizeXs ).toMatch( '0' );
expect( columnData.sizeSm ).toMatch( '0' );
expect( columnData.sizeMd ).toMatch( '0' );
expect( columnData.sizeLg ).toMatch( '0' );
expect( columnData.sizeXl ).toMatch( '0' );
expect( await getCheckboxValueByLabel( 'Lg equal-width' ) ).toBe( true );
// Column size should be disabled if equal-width checkbox is checked
expect( await inputIsDisabledByLabel( 'Lg Column count' ) ).toBe( true );
expect( await getEditedPostContent() ).toMatchSnapshot();
await page.type( '[aria-label="Xl Column count"]', '2' );
columnData = await getDataValuesOfElement( `#block-${ firstColumnBlockClientId }` );
expect( columnData.sizeXl ).toMatch( '2' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'Should be possible to select background color', async () => {
expect( console ).toHaveWarned();
await insertRowBlock();
// Select first column block
const columnBlocks = await getColumnBlocks();
const firstColumnBlockClientId = columnBlocks[ 0 ].clientId;
await selectBlockByClientId( firstColumnBlockClientId );
await openSidebarPanelWithTitle( 'Background color' );
// Select background color
await page.click( 'button[aria-label="Color: secondary"]' );
// Check if selected background is set in data attribute
let columnData = await getDataValuesOfElement( `#block-${ firstColumnBlockClientId }` );
expect( columnData.bgColor ).toMatch( 'secondary' );
expect( await getEditedPostContent() ).toMatchSnapshot();
// Select center content vertically
await clickElementByText( 'label', 'Center content vertically in row' );
columnData = await getDataValuesOfElement( `#block-${ firstColumnBlockClientId }` );
expect( columnData.centerContent ).toMatch( 'true' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'Should be possible to select padding', async () => {
expect( console ).toHaveWarned();
await insertRowBlock();
// Select first column block
const columnBlocks = await getColumnBlocks();
const firstColumnBlockClientId = columnBlocks[ 0 ].clientId;
await selectBlockByClientId( firstColumnBlockClientId );
// Select padding
await openSidebarPanelWithTitle( 'Padding (inside column)' );
await selectOption( 'Size', 'p-2' );
const columnData = await getDataValuesOfElement( `#block-${ firstColumnBlockClientId }` );
expect( columnData.padding ).toMatch( 'p-2' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );