Skip to content

Commit

Permalink
Merge pull request #12 from solidtime-io/feature/add_time_overview
Browse files Browse the repository at this point in the history
Feature/add time overview
  • Loading branch information
Onatcer authored Mar 27, 2024
2 parents 0c779b5 + 6103499 commit 76c90dd
Show file tree
Hide file tree
Showing 52 changed files with 2,461 additions and 973 deletions.
433 changes: 433 additions & 0 deletions e2e/time.spec.ts

Large diffs are not rendered by default.

82 changes: 21 additions & 61 deletions e2e/timetracker.spec.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,29 @@
import { expect, test } from '../playwright/fixtures';
import { PLAYWRIGHT_BASE_URL } from '../playwright/config';
import {
assertThatTimerHasStarted,
assertThatTimerIsStopped,
newTimeEntryResponse,
startOrStopTimerWithButton,
stoppedTimeEntryResponse,
} from './utils/currentTimeEntry';

async function goToDashboard(page) {
await page.goto(PLAYWRIGHT_BASE_URL + '/dashboard');
}

async function startOrStopTimerWithButton(page) {
await page
.locator('[data-testid="dashboard_timer"] [data-testid="timer_button"]')
.click();
}

async function assertThatTimerHasStarted(page) {
await page.locator(
'[data-testid="dashboard_timer"] [data-testid="timer_button"].bg-red-400/80'
);
}

function newTimeEntryResponse(page) {
return page.waitForResponse(async (response) => {
return (
response.status() === 201 &&
(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 === '' &&
(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([])
);
});
}

async function assertThatTimerIsStopped(page) {
await page.locator(
'[data-testid="dashboard_timer"] [data-testid="timer_button"].bg-accent-300/70'
);
}

test('test that starting and stopping a timer without description and project works', async ({
page,
}) => {
await goToDashboard(page);
const newTimeEntryPromise = newTimeEntryResponse(page);
await startOrStopTimerWithButton(page);
await newTimeEntryPromise;
await assertThatTimerHasStarted(page);
await Promise.all([
newTimeEntryResponse(page),
startOrStopTimerWithButton(page),
assertThatTimerHasStarted(page),
]);
await page.waitForTimeout(1500);
await Promise.all([
page.waitForResponse(async (response) => {
return (
response.status() === 200 &&
(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 === '' &&
(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([])
);
}),
stoppedTimeEntryResponse(page),
startOrStopTimerWithButton(page),
]);
await assertThatTimerIsStopped(page);
Expand Down Expand Up @@ -471,6 +425,12 @@ test('test that adding a new tag when the timer is running', async ({
await assertThatTimerIsStopped(page);
});

// test that adding a new tag when the timer is running

// test that search is working

// test that adding a tag and project and starting the timer afterwards works and sets the project and tag correctly

// test that changing the project works

// test that sidebar timetracker starts and stops timer

// test that sidebar timetracker changes state when tmer on dashboard is started
61 changes: 61 additions & 0 deletions e2e/utils/currentTimeEntry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { expect, Page } from '@playwright/test';

export async function startOrStopTimerWithButton(page: Page) {
await page
.locator('[data-testid="dashboard_timer"] [data-testid="timer_button"]')
.click();
}

export async function assertThatTimerHasStarted(page: Page) {
await page.locator(
'[data-testid="dashboard_timer"] [data-testid="timer_button"].bg-red-400/80'
);
}

export function newTimeEntryResponse(page: Page) {
return page.waitForResponse(async (response) => {
return (
response.status() === 201 &&
(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 === '' &&
(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([])
);
});
}

export async function assertThatTimerIsStopped(page: Page) {
await expect(
page.locator(
'[data-testid="dashboard_timer"] [data-testid="timer_button"]'
)
).toHaveClass(/bg-accent-300\/50/);
}

export async function stoppedTimeEntryResponse(page: Page) {
return page.waitForResponse(async (response) => {
return (
response.status() === 200 &&
(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 === '' &&
(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([])
);
});
}
Loading

0 comments on commit 76c90dd

Please sign in to comment.