frequi_origin/e2e/trade.spec.ts

135 lines
5.0 KiB
TypeScript
Raw Normal View History

2024-04-07 17:53:32 +00:00
import { test, expect } from '@playwright/test';
2024-04-08 18:53:15 +00:00
import { setLoginInfo, defaultMocks, tradeMocks } from './helpers';
2024-04-07 17:53:32 +00:00
2024-04-08 05:33:42 +00:00
test.describe('Trade', () => {
test.beforeEach(async ({ page }) => {
await defaultMocks(page);
await setLoginInfo(page);
await tradeMocks(page);
});
test('Trade page', async ({ page }) => {
2024-04-08 15:58:33 +00:00
await Promise.all([
2024-04-08 16:14:10 +00:00
page.goto('/trade'),
2024-04-08 15:58:33 +00:00
// Wait for network requests
2024-04-08 16:14:10 +00:00
// page.waitForResponse('**/ping'),
page.waitForResponse('**/status'),
page.waitForResponse('**/profit'),
page.waitForResponse('**/balance'),
// page.waitForResponse('**/trades'),
page.waitForResponse('**/whitelist'),
page.waitForResponse('**/blacklist'),
page.waitForResponse('**/locks'),
2024-04-08 15:58:33 +00:00
]);
2024-04-08 05:33:42 +00:00
// // Check visibility of elements
await expect(page.locator('.drag-header', { hasText: 'Multi Pane' })).toBeInViewport();
2024-04-08 15:51:43 +00:00
await expect(page.locator('.drag-header', { hasText: 'Chart' })).toBeInViewport();
2024-04-08 05:33:42 +00:00
// Pairlist elements
2024-04-08 15:51:43 +00:00
await expect(page.locator('button', { hasText: 'BTC/USDT' })).toBeInViewport();
await expect(page.locator('button', { hasText: 'ETH/USDT' })).toBeInViewport();
2024-04-08 05:33:42 +00:00
// // Click on Performance button and wait for response
await Promise.all([
page.waitForResponse('**/performance'),
page.click('button:has-text("Performance")'),
]);
// // Check visibility of Profit USDT
await expect(page.locator('th:has-text("Profit USDT")')).toBeInViewport();
// // Test messageBox behavior
const dialogModal = page.getByRole('dialog');
const modalButton = page.locator(
'#MsgBoxModal .modal-dialog > .modal-content > .modal-footer > .btn-secondary:has-text("Cancel")',
);
await expect(dialogModal).not.toBeVisible();
await expect(dialogModal).not.toBeInViewport();
await expect(modalButton).not.toBeVisible();
await page.getByRole('button', { name: 'Stop Trading - Also stops' }).click();
// Modal open
await expect(dialogModal).toBeVisible();
await expect(dialogModal).toBeInViewport();
await expect(modalButton).toBeInViewport();
// // Close modal
await modalButton.click();
// // Modal closed
await expect(modalButton).not.toBeVisible();
await expect(modalButton).not.toBeInViewport();
// // Click on General tab
const performancePair = page.locator('td:has-text("XRP/USDT")');
await expect(performancePair).toBeInViewport();
await page.click('button[role="tab"]:has-text("General")');
// // Check visibility of elements
await expect(performancePair).not.toBeInViewport();
const openTrades = page.locator('.drag-header:has-text("Open Trades")');
openTrades.scrollIntoViewIfNeeded();
await expect(openTrades).toBeInViewport();
const closedTrades = page.locator('.drag-header:has-text("Closed Trades")');
closedTrades.scrollIntoViewIfNeeded();
await expect(closedTrades).toBeInViewport();
await expect(page.locator('span:has-text("TRX/USDT")')).toBeInViewport();
await expect(page.locator('td:has-text("8070.5")')).toBeInViewport();
// Scroll to top
const multiPane = page.locator('.drag-header', { hasText: 'Multi Pane' });
await expect(multiPane).toBeVisible();
await multiPane.scrollIntoViewIfNeeded();
await expect(multiPane).toBeInViewport();
// // Click on Reload Config button
await page.getByRole('button', { name: 'Reload Config' }).click();
// await page.locator('button[title*="Reload Config "]').click();
await expect(dialogModal).toBeVisible();
await expect(dialogModal).toBeInViewport();
const modalOkButton = page.locator(
'#MsgBoxModal .modal-dialog > .modal-content > .modal-footer > .btn-primary:has-text("Ok")',
);
await expect(modalOkButton).toBeVisible();
await modalOkButton.click();
await expect(page.getByText('Config reloaded successfully.')).toBeInViewport();
2024-04-08 13:34:37 +00:00
});
test('Trade page - drag and drop', async ({ page }) => {
await page.goto('/trade');
2024-04-08 05:33:42 +00:00
2024-04-08 13:34:37 +00:00
const multiPane = page.locator('.drag-header', { hasText: 'Multi Pane' });
2024-04-08 05:33:42 +00:00
2024-04-10 05:03:14 +00:00
const multiPanebb = await multiPane.boundingBox();
await page.locator('#avatar-drop').click();
await page.getByText('Lock layout').uncheck();
2024-04-08 05:33:42 +00:00
const chartHeader = await page.locator('.drag-header:has-text("Chart")');
2024-04-07 18:57:50 +00:00
await expect(multiPane).toBeInViewport();
await expect(chartHeader).toBeInViewport();
2024-04-08 05:33:42 +00:00
// Test drag and drop functionality
const chartHeaderbb = await chartHeader.boundingBox();
if (chartHeaderbb) {
await chartHeader.hover();
await page.mouse.down();
await page.mouse.move(chartHeaderbb?.x + chartHeaderbb.width / 2, chartHeaderbb?.y + 200);
await page.mouse.up();
await expect(multiPane).toBeInViewport();
2024-04-10 05:03:14 +00:00
// Multipane wasn't moved.
await expect(multiPanebb).toEqual(await multiPane.boundingBox());
2024-04-08 05:33:42 +00:00
await expect(chartHeader).toBeInViewport();
2024-04-10 05:03:14 +00:00
// ChartHeader was moved down
await expect(chartHeaderbb).not.toEqual(await chartHeader.boundingBox());
2024-04-08 05:33:42 +00:00
}
});
2024-04-07 17:53:32 +00:00
});