1
0
mirror of https://github.com/morris/vanilla-todo.git synced 2025-09-09 05:30:42 +02:00

add basic testing, fix #8

This commit is contained in:
Morris Brodersen
2023-05-13 18:20:50 +02:00
parent 97c1b625a3
commit 9d1c3b7b8f
5 changed files with 143 additions and 2 deletions

27
test/e2e/addItem.test.mjs Normal file
View File

@@ -0,0 +1,27 @@
import { expect, test } from '@playwright/test';
test("Add item to today's todo list (Enter)", async ({ page }) => {
await page.goto('http://localhost:8080');
const input = page.locator('.-today .todo-item-input > input').filter();
await input.focus();
await input.type('Hello, world!');
await page.keyboard.press('Enter');
await expect(page.locator('.-today .todo-item > .label')).toHaveText(
'Hello, world!'
);
});
test("Add item to today's todo list (click)", async ({ page }) => {
await page.goto('http://localhost:8080');
const input = page.locator('.-today .todo-item-input > input').filter();
await input.focus();
await input.type('Hello, world!');
await page.locator('.-today .todo-item-input > .save').click();
await expect(page.locator('.-today .todo-item > .label')).toHaveText(
'Hello, world!'
);
});

9
test/unit/util.test.mjs Normal file
View File

@@ -0,0 +1,9 @@
import { expect, test } from '@playwright/test';
import util from '../../public/scripts/util.js';
test('formatDate', () => {
expect(util.formatDate(new Date(0))).toEqual('January 1st 1970');
expect(util.formatDate(new Date('2023-05-13 12:00:00'))).toEqual(
'May 13th 2023'
);
});