Add initial playwright test

This commit is contained in:
Matthias 2023-11-19 15:34:57 +01:00
parent 24b1192312
commit e5de9e5d9e
2 changed files with 75 additions and 0 deletions

46
e2e/helpers.ts Normal file
View File

@ -0,0 +1,46 @@
import { Page } from '@playwright/test';
export async function setLoginInfo(page) {
await page.goto('/');
await page.evaluate(() => {
localStorage.setItem(
'ftAuthLoginInfo',
JSON.stringify({
'ftbot.0': {
botName: 'TestBot',
apiUrl: 'http://localhost:3000',
accessToken: 'access_token_tesst',
refreshToken: 'refresh_test',
autoRefresh: true,
},
}),
);
localStorage.setItem('ftSelectedBot', 'ftbot.0');
});
}
export async function defaultMocks(page: Page) {
page.route('**/api/v1/**', (route) => {
route.fulfill({
headers: { 'access-control-allow-origin': '*' },
json: {},
});
});
await page.route('**/api/v1/ping', (route) => {
return route.fulfill({ path: './cypress/fixtures/ping.json' });
});
}
export function getWaitForResponse(page: Page, url: string) {
const urlMapping = {
'@Ping': '**/api/v1/ping',
'@ShowConf': '**/api/v1/show_config',
'@PairCandles': '**/api/v1/pair_candles',
'@Logs': '**/api/v1/logs',
};
const urlMap = urlMapping[url] ?? url;
console.log(urlMap);
return page.waitForResponse(urlMap);
}

29
e2e/logs.spec.ts Normal file
View File

@ -0,0 +1,29 @@
import { test, expect } from '@playwright/test';
import { setLoginInfo, defaultMocks, getWaitForResponse } from './helpers';
test.describe('Logs', () => {
test('Displays and reloads logs', async ({ page }) => {
///
await defaultMocks(page);
await setLoginInfo(page);
// const pingPromise = page.route('**/*ping*',
// const logsPromise = page.waitForResponse('**/api/v1/logs');
await page.route('**/api/v1/logs', (route) => {
return route.fulfill({ path: './cypress/fixtures/logs.json' });
});
const logs = getWaitForResponse(page, '@Logs');
const ping = getWaitForResponse(page, '@ShowConf');
await page.goto('/logs', { waitUntil: 'networkidle' });
await Promise.all([logs, ping]);
await expect(page.locator('textarea')).toBeVisible();
await expect(page.locator('textarea')).toHaveValue(/Checking exchange.../, {});
// const logsPromise = page.waitForResponse('**/api/v1/logs');
const logsPromise = getWaitForResponse(page, '@Logs');
await page.getByRole('button', { name: 'Reload Logs' }).click();
await logsPromise;
});
});