forgejo/tests/e2e/login.test.e2e.ts
Otto Richter f87b76160e e2e: Selective screenshots (#9499)
* Add some test that only snapshot relevant content
* Allow adding marging around the element in case the environment is relevant (e.g. the location of an element relative to the parent, but excluding the environment of the parent)

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9499
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Otto Richter <git@otto.splvs.net>
Co-committed-by: Otto Richter <git@otto.splvs.net>
2025-10-03 13:45:08 +02:00

35 lines
1.4 KiB
TypeScript

// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
// @watch start
// templates/user/auth/**
// web_src/js/features/user-**
// web_src/js/features/common-global.js
// @watch end
import {expect} from '@playwright/test';
import {test, test_context} from './utils_e2e.ts';
import {screenshot} from './shared/screenshots.ts';
test('Mismatched ROOT_URL', async ({browser}, workerInfo) => {
test.skip(['Mobile Safari', 'webkit'].includes(workerInfo.project.name), 'init script gets randomly ignored');
const context = await test_context(browser);
const page = await context.newPage();
// Ugly hack to override the appUrl of `window.config`.
await page.addInitScript(() => {
setInterval(() => {
if (window.config) {
window.config.appUrl = 'https://example.com';
}
}, 1);
});
const response = await page.goto('/user/login');
expect(response?.status()).toBe(200);
await screenshot(page);
const globalError = page.locator('.js-global-error');
await expect(globalError).toContainText('This Forgejo instance is configured to be served on ');
await expect(globalError).toContainText('You are currently viewing Forgejo through a different URL, which may cause parts of the application to break. The canonical URL is controlled by Forgejo admins via the ROOT_URL setting in the app.ini.');
});