Skip to content

Commit 0bdc5eb

Browse files
committed
some more tests
1 parent 7ad871d commit 0bdc5eb

File tree

4 files changed

+66
-14
lines changed

4 files changed

+66
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"lint": "eslint 'src/**/*.*'",
1111
"serve": "vite preview",
1212
"dev:test": "vite dev --port 8888 --mode=test",
13-
"test": ""
13+
"test": "playwright test"
1414
},
1515
"packageManager": "[email protected]",
1616
"engines": {

src/stores/cycle.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,14 @@ import { Interval, IntervalType } from '@/types';
44
import { useStorage } from '@vueuse/core';
55
import { uniqId } from '@/utils';
66

7-
const initialIntervals = () => [
8-
{
9-
type: IntervalType.Work,
10-
duration: 45 * 60 * 1000,
11-
id: uniqId([]),
12-
},
13-
];
14-
157
export const useCycle = defineStore('cycle', () => {
16-
const intervals =
17-
import.meta.env.MODE !== 'test'
18-
? useStorage<Interval[]>('intervals', initialIntervals())
19-
: ref<Interval[]>(initialIntervals());
8+
const intervals = useStorage<Interval[]>('intervals', [
9+
{
10+
type: IntervalType.Work,
11+
duration: 45 * 60 * 1000,
12+
id: uniqId([]),
13+
},
14+
]);
2015

2116
const countdowns = ref<number[]>([]);
2217
const current = ref(0);

tests/timer.spec.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
import { test, expect } from '@playwright/test';
2+
import { uid } from 'uid';
3+
import { IntervalType } from '../src/types';
4+
5+
const mockInterval = (type: IntervalType, duration: number) => ({
6+
type,
7+
duration: duration * 60 * 1000,
8+
id: uid(),
9+
});
210

311
test.describe('initial state', () => {
412
test.beforeEach(async ({ page }) => {
@@ -27,3 +35,46 @@ test.describe('initial state', () => {
2735
).toBeVisible();
2836
});
2937
});
38+
39+
test.describe('functionality', () => {
40+
test.beforeEach(async ({ page }) => {
41+
// set two intervals
42+
await page.addInitScript(
43+
(intervals) => {
44+
window.localStorage.setItem('intervals', JSON.stringify(intervals));
45+
},
46+
[
47+
mockInterval(IntervalType.Work, 1),
48+
mockInterval(IntervalType.ShortBreak, 2),
49+
],
50+
);
51+
await page.goto('/');
52+
});
53+
test('list of two intervals', async ({ page }) => {
54+
const list = page.getByRole('list', { name: 'Intervals' });
55+
await expect(list.getByRole('listitem')).toHaveCount(2);
56+
});
57+
58+
test('play', async ({ page }) => {
59+
await page.getByRole('button', { name: 'Play' }).click();
60+
61+
await expect(page.getByRole('button', { name: 'Play' })).not.toBeVisible();
62+
await expect(page.getByRole('button', { name: 'Pause' })).toBeVisible();
63+
});
64+
65+
test('pause', async ({ page }) => {
66+
await page.getByRole('button', { name: 'Play' }).click();
67+
68+
await expect(page.getByRole('button', { name: 'Play' })).not.toBeVisible();
69+
await page.getByRole('button', { name: 'Pause' }).click();
70+
await expect(page.getByRole('button', { name: 'Play' })).toBeVisible();
71+
});
72+
73+
test('skip', async ({ page }) => {
74+
await expect(page.getByRole('timer')).toContainText('01:00');
75+
await page.getByRole('button', { name: 'Skip' }).click();
76+
await page.waitForTimeout(700);
77+
78+
await expect(page.getByRole('timer')).toContainText('02:00');
79+
});
80+
});

tsconfig.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
"@/*": ["src/*"]
2828
}
2929
},
30-
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
30+
"include": [
31+
"src/**/*.ts",
32+
"src/**/*.d.ts",
33+
"src/**/*.tsx",
34+
"src/**/*.vue",
35+
"test/**/*.ts"
36+
],
3137
"references": [{ "path": "./tsconfig.node.json" }]
3238
}

0 commit comments

Comments
 (0)