-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathclassic.test.js
More file actions
73 lines (61 loc) · 2.22 KB
/
classic.test.js
File metadata and controls
73 lines (61 loc) · 2.22 KB
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
/**
* External dependencies
*/
import path from 'path';
import fs from 'fs';
import os from 'os';
import uuid from 'uuid/v4';
/**
* Internal dependencies
*/
import {
getEditedPostContent,
createNewPost,
insertBlock,
pressKeyWithModifier,
} from '../../support/utils';
describe( 'Classic', () => {
beforeEach( async () => {
await createNewPost();
} );
it( 'should be inserted', async () => {
await insertBlock( 'Classic' );
// Wait for TinyMCE to initialise.
await page.waitForSelector( '.mce-content-body' );
// Ensure there is focus.
await page.focus( '.mce-content-body' );
await page.keyboard.type( 'test' );
// Move focus away.
await pressKeyWithModifier( 'shift', 'Tab' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
it( 'should insert media', async () => {
await insertBlock( 'Classic' );
// Wait for TinyMCE to initialise.
await page.waitForSelector( '.mce-content-body' );
// Ensure there is focus.
await page.focus( '.mce-content-body' );
await page.keyboard.type( 'test' );
// Click the image button.
await page.waitForSelector( 'div[aria-label="Add Media"]' );
await page.click( 'div[aria-label="Add Media"]' );
// Wait for media modal to appear and upload image.
await page.waitForSelector( '.media-modal input[type=file]' );
const inputElement = await page.$( '.media-modal input[type=file]' );
const testImagePath = path.join( __dirname, '..', '..', 'assets', '10x10_e2e_test_image_z9T8jK.png' );
const filename = uuid();
const tmpFileName = path.join( os.tmpdir(), filename + '.png' );
fs.copyFileSync( testImagePath, tmpFileName );
await inputElement.uploadFile( tmpFileName );
// Wait for upload.
await page.waitForSelector( `.media-modal li[aria-label="${ filename }"]` );
// Insert the uploaded image.
await page.click( '.media-modal button.media-button-insert' );
// Wait for image to be inserted.
await page.waitForSelector( '.mce-content-body img' );
// Move focus away.
await pressKeyWithModifier( 'shift', 'Tab' );
const regExp = new RegExp( `test<img class="alignnone size-full wp-image-\\d+" src="[^"]+\\/${ filename }\\.png" alt="" width="10" height="10" \\/>` );
expect( await getEditedPostContent() ).toMatch( regExp );
} );
} );