summaryrefslogtreecommitdiffstats
path: root/tests/e2e/repo-code.test.e2e.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-12-12 23:57:56 +0100
commite68b9d00a6e05b3a941f63ffb696f91e554ac5ec (patch)
tree97775d6c13b0f416af55314eb6a89ef792474615 /tests/e2e/repo-code.test.e2e.js
parentInitial commit. (diff)
downloadforgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.tar.xz
forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.zip
Adding upstream version 9.0.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'tests/e2e/repo-code.test.e2e.js')
-rw-r--r--tests/e2e/repo-code.test.e2e.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/e2e/repo-code.test.e2e.js b/tests/e2e/repo-code.test.e2e.js
new file mode 100644
index 0000000..62c4f55
--- /dev/null
+++ b/tests/e2e/repo-code.test.e2e.js
@@ -0,0 +1,86 @@
+// @ts-check
+import {expect} from '@playwright/test';
+import {test, login_user, load_logged_in_context} from './utils_e2e.js';
+
+test.beforeAll(async ({browser}, workerInfo) => {
+ await login_user(browser, workerInfo, 'user2');
+});
+
+async function assertSelectedLines(page, nums) {
+ const pageAssertions = async () => {
+ expect(
+ await Promise.all((await page.locator('tr.active [data-line-number]').all()).map((line) => line.getAttribute('data-line-number'))),
+ )
+ .toStrictEqual(nums);
+
+ // the first line selected has an action button
+ if (nums.length > 0) await expect(page.locator(`#L${nums[0]} .code-line-button`)).toBeVisible();
+ };
+
+ await pageAssertions();
+
+ // URL has the expected state
+ expect(new URL(page.url()).hash)
+ .toEqual(nums.length === 0 ? '' : nums.length === 1 ? `#L${nums[0]}` : `#L${nums[0]}-L${nums.at(-1)}`);
+
+ // test selection restored from URL hash
+ await page.reload();
+ return pageAssertions();
+}
+
+test('Line Range Selection', async ({browser}, workerInfo) => {
+ const context = await load_logged_in_context(browser, workerInfo, 'user2');
+ const page = await context.newPage();
+
+ const filePath = '/user2/repo1/src/branch/master/README.md?display=source';
+
+ const response = await page.goto(filePath);
+ await expect(response?.status()).toBe(200);
+
+ await assertSelectedLines(page, []);
+ await page.locator('span#L1').click();
+ await assertSelectedLines(page, ['1']);
+ await page.locator('span#L3').click({modifiers: ['Shift']});
+ await assertSelectedLines(page, ['1', '2', '3']);
+ await page.locator('span#L2').click();
+ await assertSelectedLines(page, ['2']);
+ await page.locator('span#L1').click({modifiers: ['Shift']});
+ await assertSelectedLines(page, ['1', '2']);
+
+ // out-of-bounds end line
+ await page.goto(`${filePath}#L1-L100`);
+ await assertSelectedLines(page, ['1', '2', '3']);
+});
+
+test('Readable diff', async ({page}, workerInfo) => {
+ // remove this when the test covers more (e.g. accessibility scans or interactive behaviour)
+ test.skip(workerInfo.project.name !== 'firefox', 'This currently only tests the backend-generated HTML code and it is not necessary to test with multiple browsers.');
+ const expectedDiffs = [
+ {id: 'testfile-2', removed: 'e', added: 'a'},
+ {id: 'testfile-3', removed: 'allo', added: 'ola'},
+ {id: 'testfile-4', removed: 'hola', added: 'native'},
+ {id: 'testfile-5', removed: 'native', added: 'ubuntu-latest'},
+ {id: 'testfile-6', added: '- runs-on: '},
+ {id: 'testfile-7', removed: 'ubuntu', added: 'debian'},
+ ];
+ for (const thisDiff of expectedDiffs) {
+ const response = await page.goto('/user2/diff-test/commits/branch/main');
+ await expect(response?.status()).toBe(200); // Status OK
+ await page.getByText(`Patch: ${thisDiff.id}`).click();
+ if (thisDiff.removed) {
+ await expect(page.getByText(thisDiff.removed, {exact: true})).toHaveClass(/removed-code/);
+ await expect(page.getByText(thisDiff.removed, {exact: true})).toHaveCSS('background-color', 'rgb(252, 165, 165)');
+ }
+ if (thisDiff.added) {
+ await expect(page.getByText(thisDiff.added, {exact: true})).toHaveClass(/added-code/);
+ await expect(page.getByText(thisDiff.added, {exact: true})).toHaveCSS('background-color', 'rgb(134, 239, 172)');
+ }
+ }
+});
+
+test('Commit graph overflow', async ({page}) => {
+ await page.goto('/user2/diff-test/graph');
+ await expect(page.getByRole('button', {name: 'Mono'})).toBeInViewport({ratio: 1});
+ await expect(page.getByRole('button', {name: 'Color'})).toBeInViewport({ratio: 1});
+ await expect(page.locator('.selection.search.dropdown')).toBeInViewport({ratio: 1});
+});