diff --git a/tests/e2e/articles.spec.js b/tests/e2e/articles.spec.js new file mode 100644 index 000000000..8f5a02df0 --- /dev/null +++ b/tests/e2e/articles.spec.js @@ -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); +}); +