-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
directive-on-window.spec.ts
65 lines (51 loc) · 1.84 KB
/
directive-on-window.spec.ts
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
/**
* Internal dependencies
*/
import { test, expect } from './fixtures';
test.describe( 'data-wp-on-window', () => {
test.beforeAll( async ( { interactivityUtils: utils } ) => {
await utils.activatePlugins();
await utils.addPostWithBlock( 'test/directive-on-window' );
} );
test.beforeEach( async ( { interactivityUtils: utils, page } ) => {
await page.goto( utils.getLink( 'test/directive-on-window' ) );
} );
test.afterAll( async ( { interactivityUtils: utils } ) => {
await utils.deactivatePlugins();
await utils.deleteAllPosts();
} );
test( 'the event listener is attached when the element is added', async ( {
page,
} ) => {
const counter = page.getByTestId( 'counter' );
const visibilityButton = page.getByTestId( 'visibility' );
// Initial value.
await expect( counter ).toHaveText( '0' );
// Make sure the event listener is attached.
await page.waitForSelector(
'[data-testid="isEventAttached"]:has-text("yes")'
);
// Change the viewport size.
await page.setViewportSize( { width: 600, height: 600 } );
await expect( counter ).toHaveText( '1' );
// Remove the element.
await visibilityButton.click();
// Make sure the event listener is not attached.
await page.waitForSelector(
'[data-testid="isEventAttached"]:has-text("no")'
);
// This resize should not increase the counter.
await page.setViewportSize( { width: 300, height: 600 } );
// Add the element back.
await visibilityButton.click();
// The counter should have the same value as before.
await expect( counter ).toHaveText( '1' );
// Make sure the event listener is re-attached.
await page.waitForSelector(
'[data-testid="isEventAttached"]:has-text("yes")'
);
// This resize should increase the counter.
await page.setViewportSize( { width: 200, height: 600 } );
await expect( counter ).toHaveText( '2' );
} );
} );