loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

test: issue sidebar testing using playwright (#4319)

Conclusion of https://codeberg.org/forgejo/forgejo/issues/3499

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4319
Co-authored-by: Otto Richter <git@otto.splvs.net>
Co-committed-by: Otto Richter <git@otto.splvs.net>

authored by

Otto Richter
Otto Richter
and committed by
Earl Warren
fafc4f6a 3c7a830f

+112
+26
tests/e2e/README.md
··· 19 19 npx playwright install-deps 20 20 ``` 21 21 22 + ## Interactive testing 23 + 24 + You can make use of Playwright's integrated UI mode to run individual tests, 25 + get feedback and visually trace what your browser is doing. 26 + 27 + To do so, launch the debugserver using: 28 + 29 + ``` 30 + make test-e2e-debugserver 31 + ``` 32 + 33 + Then launch the Playwright UI: 34 + 35 + ``` 36 + npx playwright test --ui 37 + ``` 38 + 39 + You can also run individual tests while the debugserver using: 40 + 41 + ``` 42 + npx playwright test actions.test.e2e.js:9 43 + ``` 44 + 45 + First, specify the complete test filename, 46 + and after the colon you can put the linenumber where the test is defined. 47 + 22 48 23 49 ## Run all tests via local act_runner 24 50 ```
+86
tests/e2e/issue-sidebar.test.e2e.js
··· 1 + // @ts-check 2 + import {test, expect} from '@playwright/test'; 3 + import {login_user, load_logged_in_context} from './utils_e2e.js'; 4 + 5 + test.beforeAll(async ({browser}, workerInfo) => { 6 + await login_user(browser, workerInfo, 'user2'); 7 + }); 8 + 9 + async function login({browser}, workerInfo) { 10 + const context = await load_logged_in_context(browser, workerInfo, 'user2'); 11 + return await context.newPage(); 12 + } 13 + 14 + // belongs to test: Pull: Toggle WIP 15 + const prTitle = 'pull5'; 16 + 17 + async function click_toggle_wip({page}) { 18 + await page.locator('.toggle-wip>a').click(); 19 + await page.waitForLoadState('networkidle'); 20 + } 21 + 22 + async function check_wip({page}, is) { 23 + const elemTitle = '#issue-title-display'; 24 + const stateLabel = '.issue-state-label'; 25 + await expect(page.locator(elemTitle)).toContainText(prTitle); 26 + await expect(page.locator(elemTitle)).toContainText('#5'); 27 + if (is) { 28 + await expect(page.locator(elemTitle)).toContainText('WIP'); 29 + await expect(page.locator(stateLabel)).toContainText('Draft'); 30 + } else { 31 + await expect(page.locator(elemTitle)).not.toContainText('WIP'); 32 + await expect(page.locator(stateLabel)).toContainText('Open'); 33 + } 34 + } 35 + 36 + test('Pull: Toggle WIP', async ({browser}, workerInfo) => { 37 + test.skip(workerInfo.project.name === 'Mobile Safari', 'Unable to get tests working on Safari Mobile, see https://codeberg.org/forgejo/forgejo/pulls/3445#issuecomment-1789636'); 38 + const page = await login({browser}, workerInfo); 39 + const response = await page.goto('/user2/repo1/pulls/5'); 40 + await expect(response?.status()).toBe(200); // Status OK 41 + // initial state 42 + await check_wip({page}, false); 43 + // toggle to WIP 44 + await click_toggle_wip({page}); 45 + await check_wip({page}, true); 46 + // remove WIP 47 + await click_toggle_wip({page}); 48 + await check_wip({page}, false); 49 + 50 + // manually edit title to another prefix 51 + await page.locator('#issue-title-edit-show').click(); 52 + await page.locator('#issue-title-editor input').fill(`[WIP] ${prTitle}`); 53 + await page.getByText('Save').click(); 54 + await page.waitForLoadState('networkidle'); 55 + await check_wip({page}, true); 56 + // remove again 57 + await click_toggle_wip({page}); 58 + await check_wip({page}, false); 59 + }); 60 + 61 + test('Issue: Labels', async ({browser}, workerInfo) => { 62 + test.skip(workerInfo.project.name === 'Mobile Safari', 'Unable to get tests working on Safari Mobile, see https://codeberg.org/forgejo/forgejo/pulls/3445#issuecomment-1789636'); 63 + const page = await login({browser}, workerInfo); 64 + // select label list in sidebar only 65 + const labelList = page.locator('.issue-content-right .labels-list a'); 66 + const response = await page.goto('/user2/repo1/issues/1'); 67 + await expect(response?.status()).toBe(200); 68 + // preconditions 69 + await expect(labelList.filter({hasText: 'label1'})).toBeVisible(); 70 + await expect(labelList.filter({hasText: 'label2'})).not.toBeVisible(); 71 + // add label2 72 + await page.locator('.select-label').click(); 73 + // label search could be tested this way: 74 + // await page.locator('.select-label input').fill('label2'); 75 + await page.locator('.select-label .item').filter({hasText: 'label2'}).click(); 76 + await page.locator('.select-label').click(); 77 + await page.waitForLoadState('networkidle'); 78 + await expect(labelList.filter({hasText: 'label2'})).toBeVisible(); 79 + // test removing label again 80 + await page.locator('.select-label').click(); 81 + await page.locator('.select-label .item').filter({hasText: 'label2'}).click(); 82 + await page.locator('.select-label').click(); 83 + await page.waitForLoadState('networkidle'); 84 + await expect(labelList.filter({hasText: 'label2'})).not.toBeVisible(); 85 + await expect(labelList.filter({hasText: 'label1'})).toBeVisible(); 86 + });