Skip to content

Commit

Permalink
e2e: add site settings tests
Browse files Browse the repository at this point in the history
  • Loading branch information
634750802 committed Aug 19, 2024
1 parent 31f8f1b commit e72ce08
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion e2e/tests/datasource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test';
import { loginViaApi } from '../utils/login';

test.describe('Datasource', () => {
test.only('Web Single Page', async ({ page }) => {
test('Web Single Page', async ({ page }) => {
test.slow();

await test.step('Login and visit page', async () => {
Expand Down
46 changes: 46 additions & 0 deletions e2e/tests/site-settings.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { expect, test } from '@playwright/test';
import { loginViaApi } from '../utils/login';

test.describe('Site Sittings', () => {
test('Basic Settings', async ({ page, browser, baseURL }) => {
const homePage = await test.step('Visit Settings Page', async () => {
await loginViaApi(page);
await page.goto('/site-settings');
const homePage = await browser.newPage({
baseURL,
});
await homePage.goto('/');
return homePage;
});

await test.step('Title and Description', async () => {
await page.getByLabel('Title', { exact: true }).fill('FooBar.AI');
await submitAndWaitSavedByLabel('Title');

await page.getByLabel('Description', { exact: true }).fill('FooBar AI Description');
await submitAndWaitSavedByLabel('Description');

await page.getByLabel('Homepage Title', { exact: true }).fill('Ask anything about FooBar');
await submitAndWaitSavedByLabel('Homepage Title');

await page.reload();

await homePage.waitForTimeout(11000); // wait for settings cache
await homePage.reload();
expect(await homePage.title()).toBe('FooBar.AI');
await expect(homePage.locator('h1')).toHaveText('Ask anything about FooBar');
await expect(homePage.locator('h1 + p')).toHaveText('FooBar AI Description');
await expect(homePage.locator('meta[name=description]')).toHaveAttribute('content', 'FooBar AI Description');
});

async function submitAndWaitSavedByLabel (label: string) {
const button = page.getByText(label, { exact: true }).locator('..').locator('..').getByRole('button', { name: 'Save', exact: true });

// Click the save button in the field form
await button.click();

// Wait the save button to be vanished. (Saved)
await button.waitFor({ state: 'hidden' });
}
});
});

0 comments on commit e72ce08

Please sign in to comment.