Skip to content

Commit

Permalink
chore: add E2E test with empty content feed field
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed May 24, 2024
1 parent d4bb631 commit 26021b1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
16 changes: 11 additions & 5 deletions tests/e2e/specs/feed.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
import {tryCloseTourModal, deleteAllFeedImports, addFeeds, runFeedImport} from '../utils';
import {tryCloseTourModal, deleteAllFeedImports, addFeeds, runFeedImport, addContentMapping} from '../utils';

test.describe( 'Feed Settings', () => {

Expand Down Expand Up @@ -69,7 +69,8 @@ test.describe( 'Feed Settings', () => {
await expect( page.locator('#ui-id-1').locator('li a').count() ).resolves.toBe(3);
});

test( 'changing Map Content', async({ editor, page }) => {
test( 'changing Map Content', async({ editor, page, admin }) => {
await admin.createNewPost();

const importName = 'Test Title: changing General Feed Settings';

Expand All @@ -81,12 +82,17 @@ test.describe( 'Feed Settings', () => {

await page.getByRole('button', { name: 'Step 3 Map content' }).click({ force: true });

await page.waitForTimeout(1000);

// await page.waitForTimeout(1000); // Wait for the feed to be added.
// Do not import feed content.
await addContentMapping( page, '' );

await page.getByRole('button', { name: 'Save & Activate importing' }).click({ force: true });

await runFeedImport( page );

// Select the first post created by feeds import. We should have no feed content imported (which is usually saved in `core/html` block).
await page.getByRole('link', { name: 'Posts', exact: true }).click({ force: true });
await page.locator('#the-list tr').first().locator('a.row-title').click({ force: true });
const blocks = await editor.getBlocks();
expect(blocks).toHaveLength(0); // No content.
});
});
15 changes: 14 additions & 1 deletion tests/e2e/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ export async function addFeeds( page, feedURLs ) {
}, feedURLs );
}

/**
* Add content mapping to the import on Feed Edit page.
* @param page The page object.
* @param mapping The content mapping to add.
* @returns {Promise<void>}
*/
export async function addContentMapping( page, mapping ) {
await page.evaluate( ( mapping ) => {
document.querySelector( 'textarea[name="feedzy_meta_data[import_post_content]"]' ).value = mapping;
}, mapping );
}

/**
* Run the feed import.
*
Expand All @@ -41,7 +53,7 @@ export async function runFeedImport( page ) {

await page.getByRole('button', { name: 'Run Now' }).click();

await expect( page.getByRole('cell', { name: 'Successfully run! (Refresh this page for the updated status)', exact: true }) ).toBeVisible();
await expect( page.getByRole('cell', { name: 'Successfully run! (Refresh this page for the updated status)', exact: true }) ).toBeVisible({ timeout: 10000 });

// Reload the page to check the status.
await page.reload();
Expand All @@ -54,6 +66,7 @@ export async function runFeedImport( page ) {
// Open the dialog with the imported feeds.
await page.locator('.feedzy-items a').click();
await expect( page.locator('#ui-id-1').locator('li a').count() ).resolves.toBeGreaterThan(0);
await page.getByRole('button', { name: 'Ok' }).click();
}

/**
Expand Down

0 comments on commit 26021b1

Please sign in to comment.