mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-05-20 03:01:44 +02:00
Playwright testing
Learned: Restore initial state after test so that followup tests don't fail
This commit is contained in:
parent
5bc72998e0
commit
099a35c52a
67
tests/e2e/issue_sidebar.test.e2e.js
Normal file
67
tests/e2e/issue_sidebar.test.e2e.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
// @ts-check
|
||||
import {test, expect} from '@playwright/test';
|
||||
import {login_user, load_logged_in_context} from './utils_e2e.js';
|
||||
|
||||
test.beforeAll(async ({browser}, workerInfo) => {
|
||||
await login_user(browser, workerInfo, 'user2');
|
||||
});
|
||||
|
||||
async function login({browser}, workerInfo) {
|
||||
const context = await load_logged_in_context(browser, workerInfo, 'user2');
|
||||
return await context.newPage();
|
||||
}
|
||||
|
||||
async function click_toggle_wip({page}) {
|
||||
await page.locator('.toggle-wip>a').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
}
|
||||
|
||||
test('Pull: Toggle WIP', async ({browser}, workerInfo) => {
|
||||
const elemTitle = '#issue-title';
|
||||
const prTitle = 'pull5';
|
||||
const prTitleWithSuffix = `${prTitle} #5`;
|
||||
const page = await login({browser}, workerInfo);
|
||||
const response = await page.goto('/user2/repo1/pulls/5');
|
||||
await expect(response?.status()).toBe(200); // Status OK
|
||||
await expect(page.locator(elemTitle)).toHaveText(prTitleWithSuffix);
|
||||
await click_toggle_wip({page});
|
||||
await expect(page.locator(elemTitle)).toHaveText(`WIP: ${prTitleWithSuffix}`);
|
||||
await click_toggle_wip({page});
|
||||
await expect(page.locator(elemTitle)).toHaveText(prTitleWithSuffix);
|
||||
|
||||
// manually edit title to another prefix
|
||||
await page.locator('#edit-title').click();
|
||||
await page.locator('#edit-title-input > input').fill(`[WIP] ${prTitle}`);
|
||||
await page.locator('#save-edit-title').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
// and test if it is removed correctly
|
||||
await expect(page.locator(elemTitle)).toHaveText(`[WIP] ${prTitleWithSuffix}`);
|
||||
await click_toggle_wip({page});
|
||||
await expect(page.locator(elemTitle)).toHaveText(prTitleWithSuffix);
|
||||
});
|
||||
|
||||
test('Issue: Labels', async ({browser}, workerInfo) => {
|
||||
const page = await login({browser}, workerInfo);
|
||||
// select label list in sidebar only
|
||||
const labelList = page.locator('.issue-content-right .labels-list a');
|
||||
const response = await page.goto('/user2/repo1/issues/1');
|
||||
await expect(response?.status()).toBe(200);
|
||||
// preconditions
|
||||
await expect(labelList.filter({hasText: 'label1'})).toBeVisible();
|
||||
await expect(labelList.filter({hasText: 'label2'})).not.toBeVisible();
|
||||
// add label2
|
||||
await page.locator('.select-label').click();
|
||||
// label search could be tested this way:
|
||||
// await page.locator('.select-label input').fill('label2');
|
||||
await page.locator('.select-label .item').filter({hasText: 'label2'}).click();
|
||||
await page.locator('.select-label').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(labelList.filter({hasText: 'label2'})).toBeVisible();
|
||||
// test removing label again
|
||||
await page.locator('.select-label').click();
|
||||
await page.locator('.select-label .item').filter({hasText: 'label2'}).click();
|
||||
await page.locator('.select-label').click();
|
||||
await page.waitForLoadState('networkidle');
|
||||
await expect(labelList.filter({hasText: 'label2'})).not.toBeVisible();
|
||||
await expect(labelList.filter({hasText: 'label1'})).toBeVisible();
|
||||
});
|
Loading…
Reference in a new issue