-
Notifications
You must be signed in to change notification settings - Fork 4k
/
settings-sidebar.test.js
122 lines (108 loc) · 3.22 KB
/
settings-sidebar.test.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
/**
* WordPress dependencies
*/
import {
trashAllPosts,
activateTheme,
getAllBlocks,
selectBlockByClientId,
insertBlock,
} from '@wordpress/e2e-test-utils';
/**
* Internal dependencies
*/
import { siteEditor } from './utils';
async function toggleSidebar() {
await page.click(
'.edit-site-header__actions button[aria-label="Settings"]'
);
}
async function getActiveTabLabel() {
return await page.$eval(
'.edit-site-sidebar__panel-tab.is-active',
( element ) => element.getAttribute( 'aria-label' )
);
}
async function getTemplateCard() {
return {
title: await page.$eval(
'.edit-site-template-card__title',
( element ) => element.innerText
),
description: await page.$eval(
'.edit-site-template-card__description',
( element ) => element.innerText
),
};
}
describe( 'Settings sidebar', () => {
beforeAll( async () => {
await activateTheme( 'tt1-blocks' );
await trashAllPosts( 'wp_template' );
await trashAllPosts( 'wp_template_part' );
} );
afterAll( async () => {
await trashAllPosts( 'wp_template' );
await trashAllPosts( 'wp_template_part' );
await activateTheme( 'twentytwentyone' );
} );
beforeEach( async () => {
await siteEditor.visit();
await siteEditor.disableWelcomeGuide();
} );
describe( 'Template tab', () => {
it( 'should open template tab by default if no block is selected', async () => {
await toggleSidebar();
expect( await getActiveTabLabel() ).toEqual(
'Template (selected)'
);
} );
it( "should show the currently selected template's title and description", async () => {
await toggleSidebar();
const templateCardBeforeNavigation = await getTemplateCard();
await siteEditor.visit( {
postId: 'tt1-blocks//404',
postType: 'wp_template',
} );
const templateCardAfterNavigation = await getTemplateCard();
expect( templateCardBeforeNavigation ).toMatchObject( {
title: 'Index',
description: 'Displays posts.',
} );
expect( templateCardAfterNavigation ).toMatchObject( {
title: '404',
description: 'Displays when no content is found.',
} );
} );
} );
describe( 'Block tab', () => {
it( 'should open block tab by default if a block is selected', async () => {
const allBlocks = await getAllBlocks();
await selectBlockByClientId( allBlocks[ 0 ].clientId );
await toggleSidebar();
expect( await getActiveTabLabel() ).toEqual( 'Block (selected)' );
} );
} );
describe( 'Tab switch based on selection', () => {
it( 'should switch to block tab if we select a block, when Template is selected', async () => {
await toggleSidebar();
expect( await getActiveTabLabel() ).toEqual(
'Template (selected)'
);
// By inserting the block is also selected.
await insertBlock( 'Heading' );
expect( await getActiveTabLabel() ).toEqual( 'Block (selected)' );
} );
it( 'should switch to Template tab when a block was selected and we select the Template', async () => {
await insertBlock( 'Heading' );
await toggleSidebar();
expect( await getActiveTabLabel() ).toEqual( 'Block (selected)' );
await page.evaluate( () => {
wp.data.dispatch( 'core/block-editor' ).clearSelectedBlock();
} );
expect( await getActiveTabLabel() ).toEqual(
'Template (selected)'
);
} );
} );
} );