test(e2e): add test suite for guest dashboard

This commit is contained in:
Nicolas Meienberger 2023-11-02 07:59:11 +01:00 committed by Nicolas Meienberger
parent ab3dcabbf9
commit 3ddcf3732e
2 changed files with 62 additions and 0 deletions

View file

@ -0,0 +1,54 @@
import { test, expect } from '@playwright/test';
import { appTable } from '@/server/db/schema';
import { setSettings } from './helpers/settings';
import { loginUser } from './fixtures/fixtures';
import { clearDatabase, db } from './helpers/db';
test.beforeEach(async () => {
await clearDatabase();
await setSettings({});
});
test('user can activate the guest dashboard and see it when logged out', async ({ page }) => {
await loginUser(page);
await page.goto('/settings');
await page.getByRole('tab', { name: 'Settings' }).click();
await page.getByLabel('guestDashboard').setChecked(true);
await page.getByRole('button', { name: 'Save' }).click();
await page.getByTestId('logout-button').click();
await expect(page.getByText('No apps to display')).toBeVisible();
});
test('logged out users can see the apps on the guest dashboard', async ({ page, context }) => {
await setSettings({ guestDashboard: true });
await db.insert(appTable).values({ config: {}, isVisibleOnGuestDashboard: true, id: 'hello-world', exposed: true, domain: 'duckduckgo.com', status: 'running' });
await db.insert(appTable).values({ config: {}, isVisibleOnGuestDashboard: false, id: 'actual-budget', exposed: false, status: 'running' });
await page.goto('/');
await expect(page.getByText(/Hello World web server/)).toBeVisible();
const locator = page.locator('text=Actual Budget');
expect(locator).not.toBeVisible();
const [newPage] = await Promise.all([context.waitForEvent('page'), await page.getByRole('link', { name: /Hello World/ }).click()]);
await newPage.waitForLoadState();
expect(newPage.url()).toBe('https://duckduckgo.com/');
await newPage.close();
});
test('user can deactivate the guest dashboard and not see it when logged out', async ({ page }) => {
await loginUser(page);
await page.goto('/settings');
await page.getByRole('tab', { name: 'Settings' }).click();
await page.getByLabel('guestDashboard').setChecked(false);
await page.getByRole('button', { name: 'Save' }).click();
await page.getByTestId('logout-button').click();
await page.goto('/');
// We should be redirected to the login page
await expect(page.getByRole('heading', { name: 'Login' })).toBeVisible();
});

8
e2e/helpers/settings.ts Normal file
View file

@ -0,0 +1,8 @@
import { promises } from 'fs';
import path from 'path';
import { z } from 'zod';
import { settingsSchema } from '@runtipi/shared';
export const setSettings = async (settings: z.infer<typeof settingsSchema>) => {
await promises.writeFile(path.join(__dirname, '../../state/settings.json'), JSON.stringify(settings));
};