-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLANET-5419 Add Playwright test for Articles block
This is to increase our test coverage
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 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
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); | ||
}); | ||
|