gristlabs_grist-core/test/nbrowser/Boot.playwright.ts

65 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-07-15 17:06:17 +00:00
import { assert } from 'mocha-webdriver';
2024-06-15 03:52:04 +00:00
import * as gu from 'test/nbrowser/playwrightGristUtils';
2024-07-15 17:06:17 +00:00
import { server, setupTestSuite } from 'test/nbrowser/playwrightTestUtils';
2024-06-15 03:52:04 +00:00
import * as testUtils from 'test/server/testUtils';
2024-07-15 17:06:17 +00:00
import { expect, Page, test } from '@playwright/test';
2024-06-15 03:52:04 +00:00
/**
* The boot page functionality has been merged with the Admin Panel.
* Check that it behaves as a boot page did now.
*/
test.describe('Boot', () => {
setupTestSuite();
let oldEnv: testUtils.EnvironmentSnapshot;
test.afterEach(({ page }) => gu.checkForErrors(page));
async function hasPrompt(page: Page) {
// There is some glitchiness to when the text appears.
const text = await page.getByText(/GRIST_BOOT_KEY/).textContent();
expect(text).toContain('GRIST_BOOT_KEY=example-');
}
2024-07-15 17:06:17 +00:00
test('tells user about /admin', async function({ page }) {
await page.goto(`${server.getHost()}/boot`);
assert.match(await page.content(), /\/admin/);
2024-06-15 03:52:04 +00:00
// Switch to a regular place to that gu.checkForErrors won't panic -
// it needs a Grist page.
2024-07-15 17:06:17 +00:00
await page.goto(`${server.getHost()}`);
2024-06-15 03:52:04 +00:00
});
test('gives prompt about how to enable boot page', async function({ page }) {
2024-07-15 17:06:17 +00:00
await page.goto(`${server.getHost()}/admin`);
2024-06-15 03:52:04 +00:00
await hasPrompt(page);
});
test.describe('with a GRIST_BOOT_KEY', function() {
test.beforeAll(async function() {
oldEnv = new testUtils.EnvironmentSnapshot();
process.env.GRIST_BOOT_KEY = 'lala';
await server.restart();
});
test.afterAll(async function() {
oldEnv.restore();
await server.restart();
});
test('gives prompt when key is missing', async function({ page }) {
2024-07-15 17:06:17 +00:00
await page.goto(`${server.getHost()}/admin`);
2024-06-15 03:52:04 +00:00
await hasPrompt(page);
});
test('gives prompt when key is wrong', async function({ page }) {
2024-07-15 17:06:17 +00:00
await page.goto(`${server.getHost()}/admin?boot-key=bilbo`);
2024-06-15 03:52:04 +00:00
await hasPrompt(page);
});
2024-07-15 17:06:17 +00:00
test('gives page when key is right', async function({ page }) {
await page.goto(`${server.getHost()}/admin?boot-key=lala`);
await expect(page.getByText(/Is home page available/)).toBeVisible();
2024-06-15 03:52:04 +00:00
});
});
});