From 8a4e81fadd37c82962f80fa2735bb8f508f82d1b Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Mon, 9 Oct 2023 10:07:34 +0200 Subject: [PATCH] Fixed splitting string into characters (#18480) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - quite funny because it's such a sneaky thing to discover - this code actually results in looping over `'xxxxx<,t,e,s,t,f,o,o,t,>'` and not an array of characters - adding brackets fixes that --- ### 🤖 Generated by Copilot at 584ab6c Fix a bug in the code injection test case for the admin settings app. Ensure that the test code is properly padded and split by using parentheses in the string concatenations. --------- Co-authored-by: Jono Mingard --- .../acceptance/advanced/codeInjection.test.ts | 18 +++++++++++------- .../test/acceptance/general/facebook.test.ts | 2 +- .../test/acceptance/general/twitter.test.ts | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/admin-x-settings/test/acceptance/advanced/codeInjection.test.ts b/apps/admin-x-settings/test/acceptance/advanced/codeInjection.test.ts index bd544a9193..5f0fba842c 100644 --- a/apps/admin-x-settings/test/acceptance/advanced/codeInjection.test.ts +++ b/apps/admin-x-settings/test/acceptance/advanced/codeInjection.test.ts @@ -11,8 +11,8 @@ test.describe('Code injection settings', async () => { const {lastApiRequests} = await mockApi({page, requests: { ...globalDataRequests, editSettings: {method: 'PUT', path: '/settings/', response: updatedSettingsResponse([ - {key: 'codeinjection_head', value: ''}, - {key: 'codeinjection_foot', value: ''} + {key: 'codeinjection_head', value: 'testhead'}, + {key: 'codeinjection_foot', value: 'testfoot'} ])} }}); @@ -21,24 +21,27 @@ test.describe('Code injection settings', async () => { const section = page.getByTestId('code-injection'); await section.getByRole('button', {name: 'Edit'}).click(); + // Click on the CodeMirror content to make sure it's loaded + await section.getByTestId('header-code').locator('.cm-content').click(); - for (const character of PADDING + ''.split('')) { + for (const character of (PADDING + 'testhead').split('')) { await page.keyboard.press(character); } await section.getByRole('tab', {name: 'Site footer'}).click(); - await section.getByTestId('footer-code').click(); + await section.getByTestId('footer-code').locator('.cm-content').click(); - for (const character of PADDING + ''.split('')) { + for (const character of (PADDING + 'testfoot').split('')) { await page.keyboard.press(character); } await section.getByRole('button', {name: 'Save'}).click(); + await expect(section.getByRole('button', {name: 'Save'})).toBeHidden(); expect(lastApiRequests.editSettings?.body).toMatchObject({ settings: [ - {key: 'codeinjection_head', value: /$/}, - {key: 'codeinjection_foot', value: /$/} + {key: 'codeinjection_head', value: /testhead$/}, + {key: 'codeinjection_foot', value: /testfoot$/} ] }); }); @@ -80,6 +83,7 @@ test.describe('Code injection settings', async () => { } await section.getByRole('button', {name: 'Save'}).click(); + await expect(section.getByRole('button', {name: 'Save'})).toBeHidden(); expect(lastApiRequests.editSettings?.body).toMatchObject({ settings: [ diff --git a/apps/admin-x-settings/test/acceptance/general/facebook.test.ts b/apps/admin-x-settings/test/acceptance/general/facebook.test.ts index 0d4f5bdc53..7673afde94 100644 --- a/apps/admin-x-settings/test/acceptance/general/facebook.test.ts +++ b/apps/admin-x-settings/test/acceptance/general/facebook.test.ts @@ -22,7 +22,7 @@ test.describe('Facebook settings', async () => { const fileChooser = await fileChooserPromise; await fileChooser.setFiles(`${__dirname}/../../utils/images/image.png`); - await expect(section.getByRole('img')).toBeVisible(); + await expect(section.locator('img[src="http://example.com/image.png"]')).toBeVisible(); await section.getByLabel('Facebook title').fill('Facetitle'); await section.getByLabel('Facebook description').fill('Facescription'); diff --git a/apps/admin-x-settings/test/acceptance/general/twitter.test.ts b/apps/admin-x-settings/test/acceptance/general/twitter.test.ts index 804d20eebb..b4425726d2 100644 --- a/apps/admin-x-settings/test/acceptance/general/twitter.test.ts +++ b/apps/admin-x-settings/test/acceptance/general/twitter.test.ts @@ -22,7 +22,7 @@ test.describe('Twitter settings', async () => { const fileChooser = await fileChooserPromise; await fileChooser.setFiles(`${__dirname}/../../utils/images/image.png`); - await expect(section.getByRole('img')).toBeVisible(); + await expect(section.locator('img[src="http://example.com/image.png"]')).toBeVisible(); await section.getByLabel('X title').fill('Twititle'); await section.getByLabel('X description').fill('Twitscription');