mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-05-07 20:32:26 +00:00
69 lines
2.6 KiB
TypeScript
69 lines
2.6 KiB
TypeScript
import { expect } from '@playwright/test';
|
|
import type { Page } from '@playwright/test';
|
|
|
|
export async function startOrStopTimerWithButton(page: Page) {
|
|
await page
|
|
.getByTestId('dashboard_timer')
|
|
.getByTestId('timer_button')
|
|
.and(page.locator(':visible'))
|
|
.click();
|
|
}
|
|
|
|
export async function assertThatTimerHasStarted(page: Page) {
|
|
await expect(
|
|
page
|
|
.getByTestId('dashboard_timer')
|
|
.getByTestId('timer_button')
|
|
.and(page.locator(':visible'))
|
|
).toHaveClass(/bg-red-400\/80/);
|
|
}
|
|
|
|
export function newTimeEntryResponse(
|
|
page: Page,
|
|
{ description = '', status = 201, tags = [] } = {}
|
|
) {
|
|
return page.waitForResponse(async (response) => {
|
|
return (
|
|
response.url().includes('/time-entries') &&
|
|
response.status() === status &&
|
|
(await response.headerValue('Content-Type')) === 'application/json' &&
|
|
(await response.json()).data.id !== null &&
|
|
(await response.json()).data.start !== null &&
|
|
(await response.json()).data.end === null &&
|
|
(await response.json()).data.project_id === null &&
|
|
(await response.json()).data.description === description &&
|
|
(await response.json()).data.task_id === null &&
|
|
(await response.json()).data.user_id !== null &&
|
|
JSON.stringify((await response.json()).data.tags) === JSON.stringify(tags)
|
|
);
|
|
});
|
|
}
|
|
|
|
export async function assertThatTimerIsStopped(page: Page) {
|
|
await expect(
|
|
page
|
|
.getByTestId('dashboard_timer')
|
|
.getByTestId('timer_button')
|
|
.and(page.locator(':visible'))
|
|
).toHaveClass(/bg-accent-300\/70/);
|
|
}
|
|
|
|
export async function stoppedTimeEntryResponse(page: Page, { description = '', tags = [] } = {}) {
|
|
return page.waitForResponse(async (response) => {
|
|
return (
|
|
response.status() === 200 &&
|
|
response.url().includes('/time-entries/') &&
|
|
(await response.headerValue('Content-Type')) === 'application/json' &&
|
|
(await response.json()).data.id !== null &&
|
|
(await response.json()).data.start !== null &&
|
|
(await response.json()).data.end !== null &&
|
|
(await response.json()).data.project_id === null &&
|
|
(await response.json()).data.description === description &&
|
|
(await response.json()).data.task_id === null &&
|
|
(await response.json()).data.duration !== null &&
|
|
(await response.json()).data.user_id !== null &&
|
|
JSON.stringify((await response.json()).data.tags) === JSON.stringify(tags)
|
|
);
|
|
});
|
|
}
|