From 5bf0af1aaf0e8ffc521b0992bb6560da6739c658 Mon Sep 17 00:00:00 2001 From: Otto Richter Date: Wed, 11 Sep 2024 20:45:14 +0200 Subject: [PATCH] tests(e2e): Refactor branch protection test - ensuring the afterEach hook runs should reduce flakiness and allow retries - the hook cleans up a rule if it exists or does nothing if not --- tests/e2e/repo-settings.test.e2e.js | 45 +++++++++++++++++------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/tests/e2e/repo-settings.test.e2e.js b/tests/e2e/repo-settings.test.e2e.js index b7b0884b26..3ec57a8a3c 100644 --- a/tests/e2e/repo-settings.test.e2e.js +++ b/tests/e2e/repo-settings.test.e2e.js @@ -25,24 +25,33 @@ test('repo webhook settings', async ({browser}, workerInfo) => { await expect(page.locator('.hide-unless-checked')).toBeHidden(); }); -test('repo branch protection settings', async ({browser}, workerInfo) => { - test.skip(workerInfo.project.name === 'Mobile Safari', 'Cannot get it to work - as usual'); - const page = await login({browser}, workerInfo); - const response = await page.goto('/user2/repo1/settings/branches/edit'); - await expect(response?.status()).toBe(200); +test.describe('repo branch protection settings', () => { + test('form', async ({browser}, workerInfo) => { + test.skip(workerInfo.project.name === 'Mobile Safari', 'Cannot get it to work - as usual'); + const page = await login({browser}, workerInfo); + const response = await page.goto('/user2/repo1/settings/branches/edit'); + await expect(response?.status()).toBe(200); - await validate_form({page}, 'fieldset'); + await validate_form({page}, 'fieldset'); - // verify header is new - await expect(page.locator('h4')).toContainText('new'); - await page.locator('input[name="rule_name"]').fill('testrule'); - await page.getByText('Save rule').click(); - // verify header is in edit mode - await page.waitForLoadState('networkidle'); - await page.getByText('Edit').click(); - await expect(page.locator('h4')).toContainText('Protection rules for branch'); - // delete the rule for the next test - await page.goBack(); - await page.getByText('Delete rule').click(); - await page.getByText('Yes').click(); + // verify header is new + await expect(page.locator('h4')).toContainText('new'); + await page.locator('input[name="rule_name"]').fill('testrule'); + await page.getByText('Save rule').click(); + // verify header is in edit mode + await page.waitForLoadState('domcontentloaded'); + await page.getByText('Edit').click(); + await expect(page.locator('h4')).toContainText('Protection rules for branch'); + }); + + test.afterEach(async ({browser}, workerInfo) => { + const page = await login({browser}, workerInfo); + // delete the rule for the next test + await page.goto('/user2/repo1/settings/branches/'); + await page.waitForLoadState('domcontentloaded'); + test.skip(await page.getByText('Delete rule').isHidden(), 'Nothing to delete at this time'); + await page.getByText('Delete rule').click(); + await page.getByText('Yes').click(); + await page.waitForLoadState('load'); + }); });