Skip to content

Commit

Permalink
PLANET-5419 Add Playwright test for Articles block
Browse files Browse the repository at this point in the history
This is to increase our test coverage
  • Loading branch information
mleray committed Jul 18, 2023
1 parent 4d5d610 commit 6d35446
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/e2e/articles.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {test, expect} from './tools/lib/test-utils.js';
import {publishPostAndVisit} from './tools/lib/post.js';

const TEST_TITLE = 'All Articles';
const TEST_DESCRIPTION = 'All articles in date order';
const TEST_BUTTON_TEXT = 'Load';

test.useAdminLoggedIn();

test('Test Articles block', async ({page, admin, editor}) => {
await admin.createNewPost({postType: 'page', title:'Test Articles', legacyCanvas: true});

// Add Articles block.
await editor.canvas.getByRole('button', {name: 'Add default block'}).click();
await page.keyboard.type('/articles');
await page.getByRole('option', {name: 'Articles'}).click();

// Check that the default texts for the title and button are applied.
const editorTitle = page.getByRole('textbox', {name: 'Enter title'});
const editorDescription = page.getByRole('textbox', {name: 'Enter description'});
const editorButton = page.getByRole('textbox', {name: 'Enter text'});
await expect(editorTitle).toHaveText('Related Articles');
await expect(editorButton).toHaveText('Load more');

// Change title, description and button text.
await editorTitle.click();
await editorTitle.fill(TEST_TITLE);
await editorDescription.click();
await editorDescription.fill(TEST_DESCRIPTION);
await editorButton.click();
await editorButton.fill(TEST_BUTTON_TEXT);

// Change amount of articles from 3 to 4.
await page.getByLabel('Articles count').fill('4');

// Publish page.
await publishPostAndVisit({page, editor});

// Test that the block is displayed as expected in the frontend.
const frontendTitle = await page.innerHTML('.page-section-header');
const frontendDescription = await page.innerHTML('.page-section-description');
const frontendButton = await page.innerHTML('.article-load-more');
expect(frontendTitle).toBe(TEST_TITLE);
expect(frontendDescription).toBe(TEST_DESCRIPTION);
expect(frontendButton).toBe(TEST_BUTTON_TEXT);
await expect(page.locator('.article-list-item')).toHaveCount(4);
});

0 comments on commit 6d35446

Please sign in to comment.