|
| 1 | +/** |
| 2 | + * @format |
| 3 | + * */ |
| 4 | + |
| 5 | +/** |
| 6 | + * Internal dependencies |
| 7 | + */ |
| 8 | +import EditorPage from './pages/editor-page'; |
| 9 | +import { |
| 10 | + setupDriver, |
| 11 | + isLocalEnvironment, |
| 12 | + stopDriver, |
| 13 | + isAndroid, |
| 14 | + clickMiddleOfElement, |
| 15 | +} from './helpers/utils'; |
| 16 | +import testData from './helpers/test-data'; |
| 17 | + |
| 18 | +jasmine.DEFAULT_TIMEOUT_INTERVAL = 300000; |
| 19 | + |
| 20 | +describe( 'Gutenberg Editor tests for Block insertion', () => { |
| 21 | + let driver; |
| 22 | + let editorPage; |
| 23 | + let allPassed = true; |
| 24 | + |
| 25 | + // Use reporter for setting status for saucelabs Job |
| 26 | + if ( ! isLocalEnvironment() ) { |
| 27 | + const reporter = { |
| 28 | + specDone: async ( result ) => { |
| 29 | + allPassed = allPassed && result.status !== 'failed'; |
| 30 | + }, |
| 31 | + }; |
| 32 | + |
| 33 | + jasmine.getEnv().addReporter( reporter ); |
| 34 | + } |
| 35 | + |
| 36 | + beforeAll( async () => { |
| 37 | + driver = await setupDriver(); |
| 38 | + editorPage = new EditorPage( driver ); |
| 39 | + } ); |
| 40 | + |
| 41 | + it( 'should be able to see visual editor', async () => { |
| 42 | + await expect( editorPage.getBlockList() ).resolves.toBe( true ); |
| 43 | + } ); |
| 44 | + |
| 45 | + it( 'should be able to insert block into post', async () => { |
| 46 | + await editorPage.addNewParagraphBlock(); |
| 47 | + let paragraphBlockElement = await editorPage.getParagraphBlockAtPosition( 1 ); |
| 48 | + if ( isAndroid() ) { |
| 49 | + await paragraphBlockElement.click(); |
| 50 | + } |
| 51 | + await editorPage.sendTextToParagraphBlockAtPosition( 1, testData.longText ); |
| 52 | + // Should have 3 paragraph blocks at this point |
| 53 | + |
| 54 | + paragraphBlockElement = await editorPage.getParagraphBlockAtPosition( 2 ); |
| 55 | + await paragraphBlockElement.click(); |
| 56 | + |
| 57 | + await editorPage.addNewParagraphBlock(); |
| 58 | + paragraphBlockElement = await editorPage.getParagraphBlockAtPosition( 3 ); |
| 59 | + await paragraphBlockElement.click(); |
| 60 | + await editorPage.sendTextToParagraphBlockAtPosition( 3, testData.mediumText ); |
| 61 | + |
| 62 | + await editorPage.verifyHtmlContent( testData.blockInsertionHtml ); |
| 63 | + |
| 64 | + // Workaround for now since deleting the first element causes a crash on CI for Android |
| 65 | + if ( isAndroid() ) { |
| 66 | + paragraphBlockElement = await editorPage.getParagraphBlockAtPosition( 3 ); |
| 67 | + await paragraphBlockElement.click(); |
| 68 | + await editorPage.removeParagraphBlockAtPosition( 3 ); |
| 69 | + for ( let i = 3; i > 0; i-- ) { |
| 70 | + paragraphBlockElement = await editorPage.getParagraphBlockAtPosition( i ); |
| 71 | + await paragraphBlockElement.click(); |
| 72 | + await editorPage.removeParagraphBlockAtPosition( i ); |
| 73 | + } |
| 74 | + } else { |
| 75 | + for ( let i = 4; i > 0; i-- ) { |
| 76 | + paragraphBlockElement = await editorPage.getParagraphBlockAtPosition( 1 ); |
| 77 | + await clickMiddleOfElement( driver, paragraphBlockElement ); |
| 78 | + await editorPage.removeParagraphBlockAtPosition( 1 ); |
| 79 | + } |
| 80 | + } |
| 81 | + } ); |
| 82 | + |
| 83 | + it( 'should be able to insert block at the beginning of post from the title', async () => { |
| 84 | + await editorPage.addNewParagraphBlock(); |
| 85 | + let paragraphBlockElement = await editorPage.getParagraphBlockAtPosition( 1 ); |
| 86 | + if ( isAndroid() ) { |
| 87 | + await paragraphBlockElement.click(); |
| 88 | + } |
| 89 | + await editorPage.sendTextToParagraphBlockAtPosition( 1, testData.longText ); |
| 90 | + // Should have 3 paragraph blocks at this point |
| 91 | + |
| 92 | + if ( isAndroid() ) { |
| 93 | + await driver.hideDeviceKeyboard(); |
| 94 | + } |
| 95 | + |
| 96 | + const titleElement = await editorPage.getTitleElement(); |
| 97 | + await titleElement.click(); |
| 98 | + await titleElement.click(); |
| 99 | + |
| 100 | + await editorPage.addNewParagraphBlock(); |
| 101 | + paragraphBlockElement = await editorPage.getParagraphBlockAtPosition( 1 ); |
| 102 | + await clickMiddleOfElement( driver, paragraphBlockElement ); |
| 103 | + await editorPage.sendTextToParagraphBlockAtPosition( 1, testData.mediumText ); |
| 104 | + await paragraphBlockElement.click(); |
| 105 | + await editorPage.verifyHtmlContent( testData.blockInsertionHtmlFromTitle ); |
| 106 | + } ); |
| 107 | + |
| 108 | + afterAll( async () => { |
| 109 | + if ( ! isLocalEnvironment() ) { |
| 110 | + driver.sauceJobStatus( allPassed ); |
| 111 | + } |
| 112 | + await stopDriver( driver ); |
| 113 | + } ); |
| 114 | +} ); |
0 commit comments