-
Notifications
You must be signed in to change notification settings - Fork 4k
/
undo.test.js
67 lines (51 loc) · 1.99 KB
/
undo.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
/**
* Internal dependencies
*/
import {
clickBlockAppender,
getEditedPostContent,
newPost,
pressWithModifier,
META_KEY,
} from '../support/utils';
describe( 'undo', () => {
beforeEach( async () => {
await newPost();
} );
it( 'should undo typing after a pause', async () => {
await clickBlockAppender();
await page.keyboard.type( 'before pause' );
await new Promise( ( resolve ) => setTimeout( resolve, 1000 ) );
await page.keyboard.type( ' after pause' );
expect( await getEditedPostContent() ).toMatchSnapshot();
await pressWithModifier( META_KEY, 'z' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should undo typing after non input change', async () => {
await clickBlockAppender();
await page.keyboard.type( 'before keyboard ' );
await pressWithModifier( META_KEY, 'b' );
await page.keyboard.type( 'after keyboard' );
expect( await getEditedPostContent() ).toMatchSnapshot();
await pressWithModifier( META_KEY, 'z' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'Should undo to expected level intervals', async () => {
await clickBlockAppender();
await page.keyboard.type( 'This' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'is' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'test' );
expect( await getEditedPostContent() ).toMatchSnapshot();
await pressWithModifier( META_KEY, 'z' ); // Undo 3rd paragraph text.
await pressWithModifier( META_KEY, 'z' ); // Undo 3rd block.
await pressWithModifier( META_KEY, 'z' ); // Undo 2nd paragraph text.
await pressWithModifier( META_KEY, 'z' ); // Undo 2nd block.
await pressWithModifier( META_KEY, 'z' ); // Undo 1st paragraph text.
await pressWithModifier( META_KEY, 'z' ); // Undo 1st block.
expect( await getEditedPostContent() ).toBe( '' );
// After undoing every action, there should be no more undo history.
expect( await page.$( '.editor-history__undo[aria-disabled="true"]' ) ).not.toBeNull();
} );
} );