-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Site Editor: Add e2e tests for templates export (#28324)
Add end-to-end tests for site editor templates export functionality.
- Loading branch information
1 parent
502f79a
commit 37e1579
Showing
6 changed files
with
105 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/e2e-tests/specs/experiments/site-editor-export.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import os from 'os'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { trashAllPosts, activateTheme } from '@wordpress/e2e-test-utils'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { siteEditor } from '../../experimental-features'; | ||
|
||
async function waitForFileExists( filePath, timeout = 10000 ) { | ||
const start = Date.now(); | ||
while ( ! fs.existsSync( filePath ) ) { | ||
// Puppeteer doesn't have an API for managing file downloads. | ||
// We are using `waitForTimeout` to add delays between check of file existence. | ||
// eslint-disable-next-line no-restricted-syntax | ||
await page.waitForTimeout( 1000 ); | ||
if ( Date.now() - start > timeout ) { | ||
throw Error( 'waitForFileExists timeout' ); | ||
} | ||
} | ||
} | ||
|
||
describe( 'Site Editor Templates Export', () => { | ||
beforeAll( async () => { | ||
await activateTheme( 'tt1-blocks' ); | ||
await trashAllPosts( 'wp_template' ); | ||
await trashAllPosts( 'wp_template_part' ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await activateTheme( 'twentytwentyone' ); | ||
} ); | ||
|
||
beforeEach( async () => { | ||
await siteEditor.visit(); | ||
} ); | ||
|
||
it( 'clicking export should download edit-site-export.zip file', async () => { | ||
const directory = fs.mkdtempSync( | ||
path.join( os.tmpdir(), 'test-edit-site-export-' ) | ||
); | ||
await page._client.send( 'Page.setDownloadBehavior', { | ||
behavior: 'allow', | ||
downloadPath: directory, | ||
} ); | ||
|
||
await siteEditor.clickOnMoreMenuItem( 'Export' ); | ||
const filePath = path.join( directory, 'edit-site-export.zip' ); | ||
await waitForFileExists( filePath ); | ||
expect( fs.existsSync( filePath ) ).toBe( true ); | ||
fs.unlinkSync( filePath ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters