Files
makelore/tests/e2e/settings-proxy.spec.ts

65 lines
2.6 KiB
TypeScript

import type { Locator, Page } from '@playwright/test';
import { completeSetup, expect, test } from './fixtures/electron';
async function ensureSwitchState(toggle: Locator, checked: boolean): Promise<void> {
const currentState = await toggle.getAttribute('data-state');
const isChecked = currentState === 'checked';
if (isChecked !== checked) {
await toggle.click();
}
}
async function readProxyEnabled(page: Page): Promise<boolean> {
return await page.evaluate(async () => {
const settings = await window.electron.ipcRenderer.invoke('settings:getAll');
return Boolean(settings?.proxyEnabled);
});
}
async function openSettingsFromSidebarAccountMenu(page: Page): Promise<void> {
await page.getByTestId('sidebar-member-menu-trigger').click();
await page.getByTestId('sidebar-nav-settings').click();
}
async function unlockDeveloperSettings(page: Page): Promise<void> {
const dialog = page.getByTestId('settings-admin-password-dialog');
if (!(await dialog.isVisible().catch(() => false))) {
await page.getByTestId('settings-reveal-additional').click();
}
await page.getByTestId('settings-admin-password-input').fill('zhiniankeji666');
await page.getByTestId('settings-admin-unlock-button').click();
await expect(page.getByTestId('settings-proxy-section')).toBeVisible();
}
test.describe('Makelore administrator-protected proxy settings', () => {
test('keeps proxy save available after administrator unlock', async ({ page }) => {
await completeSetup(page);
await openSettingsFromSidebarAccountMenu(page);
await expect(page.getByTestId('settings-page')).toBeVisible();
await page.getByTestId('settings-reveal-additional').click();
await expect(page.getByTestId('settings-proxy-section')).not.toBeVisible();
await unlockDeveloperSettings(page);
const proxySection = page.getByTestId('settings-proxy-section');
const proxyToggle = page.getByTestId('settings-proxy-toggle');
const proxySaveButton = page.getByTestId('settings-proxy-save-button');
await expect(proxySection).toBeVisible();
await expect(proxyToggle).toBeVisible();
await expect(proxySaveButton).toBeVisible();
await ensureSwitchState(proxyToggle, true);
await expect(proxySaveButton).toBeEnabled();
await proxySaveButton.click();
await expect.poll(async () => await readProxyEnabled(page)).toBe(true);
await ensureSwitchState(proxyToggle, false);
await expect(proxySaveButton).toBeVisible();
await expect(proxySaveButton).toBeEnabled();
await proxySaveButton.click();
await expect.poll(async () => await readProxyEnabled(page)).toBe(false);
});
});