Skip to content

Commit

Permalink
chore: test for featured image
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed Jun 4, 2024
1 parent 8244834 commit 9aee59a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 47 deletions.
3 changes: 3 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"plugins": [ "." ],
"env": {
"tests": {
"config": {
"CYPRESS_TESTING": true
},
"mappings": {
"wp-content/themes/gutenberg-test-themes/twentytwentyone": "https://downloads.wordpress.org/theme/twentytwentyone.2.1.zip",
"wp-content/themes/gutenberg-test-themes/twentytwentyfour": "https://downloads.wordpress.org/theme/twentytwentyfour.1.0.zip"
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ To fix automatically fixable issues, run `composer format`.
To run PHPUnit, run `phpunit` or `./vendor/bin/phpunit` if it is not configured globally.

### E2E Tests
If the folder `e2e-tests` is present, you can run the E2E tests by following the instructions in the [E2E testing](./e2e-tests/README.md).

Run `npm run wp-env start` to start the WordPress environment for the E2E tests (it use Docker).
Then run `npm run test:e2e` to run the E2E tests. When debugging or making a test, use `npm run test:e2e:debug` to lunch the UI mode.

### Next Steps

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 0 additions & 29 deletions tests/e2e/specs/feed.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,41 +67,12 @@ test.describe( 'Feed Settings', () => {
await page.locator('#feedzy_item_limit').fill('3');
await expect( page.locator('#feedzy_item_limit').inputValue() ).resolves.toBe('3');

// await page.waitForTimeout(1000); // Wait for the feed to be added.

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

await runFeedImport( page );
await expect( page.locator('#ui-id-1').locator('li a').count() ).resolves.toBe(3);
});

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

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

await page.goto('/wp-admin/post-new.php?post_type=feedzy_imports');
await tryCloseTourModal( page );

await page.getByPlaceholder('Add a name for your import').fill(importName);
await addFeeds( page, [FEED_URL] );

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

// 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.
});

test( 'chained actions for feed content', async({ editor, page, admin }) => {
const importName = 'Test Title: changing General Feed Settings';

Expand Down
52 changes: 37 additions & 15 deletions tests/e2e/specs/import.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, addFeaturedImage} from '../utils';

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

Expand All @@ -13,20 +13,6 @@ test.describe( 'Feed Import', () => {
await requestUtils.deleteAllPosts();
} );

test( 'importing feed from URL', async({ editor, page }) => {

const importName = 'Test Title: importing feed from URL';

await page.goto('/wp-admin/post-new.php?post_type=feedzy_imports');
await tryCloseTourModal( page );

await page.getByPlaceholder('Add a name for your import').fill(importName);
await addFeeds( page, [FEED_URL] );
await page.getByRole('button', { name: 'Save & Activate importing' }).click({ force: true });

await runFeedImport( page );
});

test( 'import feeds with shortcode', async({ editor, page, admin }) => {
const shortcode = "[feedzy-rss feeds='https://s3.amazonaws.com/verti-utils/sample-feed.xml' max='11' offset='1' feed_title='yes' refresh='1_hours' meta='yes' multiple_meta='yes' summary='yes' price='yes' mapping='price=im:price' thumb='yes' keywords_title='God, Mendes, Cyrus, Taylor' keywords_ban='Cyrus' template='style1']";

Expand Down Expand Up @@ -110,4 +96,40 @@ test.describe( 'Feed Import', () => {
await expect( page.locator('.feedzy-rss .rss_image').count() ).resolves.toBeGreaterThan(0);
await expect( page.locator('.feedzy-rss .rss_content').count() ).resolves.toBeGreaterThan(0);
});

test( 'importing feed from URL', async({ editor, page }) => {

const importName = 'Test Title: importing feed from URL';

await page.goto('/wp-admin/post-new.php?post_type=feedzy_imports');
await tryCloseTourModal( page );

await page.getByPlaceholder('Add a name for your import').fill(importName);
await addFeeds( page, [FEED_URL] );
await page.getByRole('button', { name: 'Save & Activate importing' }).click({ force: true });

await runFeedImport( page );
});

test( 'importing feed from URL with featured image', async({ admin, page }) => {
await admin.createNewPost();

const importName = 'Test Title: importing feed from URL with featured image';

await page.goto('/wp-admin/post-new.php?post_type=feedzy_imports');
await tryCloseTourModal( page );

await page.getByPlaceholder('Add a name for your import').fill(importName);
await addFeeds( page, [FEED_URL] );
await addFeaturedImage( page, '[#item_image]' );
await page.getByRole('button', { name: 'Save & Activate importing' }).click({ force: true });

await runFeedImport( page );

// Select the first post created by feeds import. Check the featured image.
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 });
await page.getByRole('button', { name: 'Featured image' }).click({ force: true });

Check failure on line 132 in tests/e2e/specs/import.spec.js

View workflow job for this annotation

GitHub Actions / E2E

[chromium] › import.spec.js:114:6 › Feed Import › importing feed from URL with featured image

3) [chromium] › import.spec.js:114:6 › Feed Import › importing feed from URL with featured image ─ TimeoutError: locator.click: Timeout 10000ms exceeded. Call log: - waiting for getByRole('button', { name: 'Featured image' }) 130 | await page.getByRole('link', { name: 'Posts', exact: true }).click({ force: true }); 131 | await page.locator('#the-list tr').first().locator('a.row-title').click({ force: true }); > 132 | await page.getByRole('button', { name: 'Featured image' }).click({ force: true }); | ^ 133 | await expect( page.getByLabel('Edit or replace the image') ).toBeVisible(); // Featured image is added. 134 | }); 135 | }); at /home/runner/work/feedzy-rss-feeds/feedzy-rss-feeds/tests/e2e/specs/import.spec.js:132:62

Check failure on line 132 in tests/e2e/specs/import.spec.js

View workflow job for this annotation

GitHub Actions / E2E

[chromium] › import.spec.js:114:6 › Feed Import › importing feed from URL with featured image

3) [chromium] › import.spec.js:114:6 › Feed Import › importing feed from URL with featured image ─ Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: locator.click: Timeout 10000ms exceeded. Call log: - waiting for getByRole('button', { name: 'Featured image' }) 130 | await page.getByRole('link', { name: 'Posts', exact: true }).click({ force: true }); 131 | await page.locator('#the-list tr').first().locator('a.row-title').click({ force: true }); > 132 | await page.getByRole('button', { name: 'Featured image' }).click({ force: true }); | ^ 133 | await expect( page.getByLabel('Edit or replace the image') ).toBeVisible(); // Featured image is added. 134 | }); 135 | }); at /home/runner/work/feedzy-rss-feeds/feedzy-rss-feeds/tests/e2e/specs/import.spec.js:132:62

Check failure on line 132 in tests/e2e/specs/import.spec.js

View workflow job for this annotation

GitHub Actions / E2E

[chromium] › import.spec.js:114:6 › Feed Import › importing feed from URL with featured image

3) [chromium] › import.spec.js:114:6 › Feed Import › importing feed from URL with featured image ─ Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── TimeoutError: locator.click: Timeout 10000ms exceeded. Call log: - waiting for getByRole('button', { name: 'Featured image' }) 130 | await page.getByRole('link', { name: 'Posts', exact: true }).click({ force: true }); 131 | await page.locator('#the-list tr').first().locator('a.row-title').click({ force: true }); > 132 | await page.getByRole('button', { name: 'Featured image' }).click({ force: true }); | ^ 133 | await expect( page.getByLabel('Edit or replace the image') ).toBeVisible(); // Featured image is added. 134 | }); 135 | }); at /home/runner/work/feedzy-rss-feeds/feedzy-rss-feeds/tests/e2e/specs/import.spec.js:132:62
await expect( page.getByLabel('Edit or replace the image') ).toBeVisible(); // Featured image is added.
});
});
14 changes: 14 additions & 0 deletions tests/e2e/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ export async function addFeeds( page, feedURLs ) {
}, feedURLs );
}

/**
* Add tags to the Featured Image on Feed Edit page.
*
* @param {import('playwright').Page} page The page object.
* @param {string} feedTag The tag that import the image from the feed.
* @returns {Promise<void>} The promise that resolves when the tags are added.
*/
export async function addFeaturedImage( page, feedTag ) {
await page.evaluate( ( feedTag ) => {
document.querySelector( 'input[name="feedzy_meta_data[import_post_featured_img]"]' ).value = feedTag;
}, feedTag );
}

/**
* Add content mapping to the import on Feed Edit page.
* @param page The page object.
Expand All @@ -49,6 +62,7 @@ export async function addContentMapping( page, mapping ) {
* @returns {Promise<void>} The promise that resolves when the feed is imported.
*/
export async function runFeedImport( page ) {
await page.goto('/wp-admin/edit.php?post_type=feedzy_imports');
await page.waitForSelector('.feedzy-import-status-row');

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

0 comments on commit 9aee59a

Please sign in to comment.