1
0
mirror of https://github.com/morris/vanilla-todo.git synced 2025-08-22 05:33:06 +02:00

add data import/export (#11)

This commit is contained in:
Morris Brodersen
2024-06-24 07:25:56 +02:00
parent 7204404fdc
commit 46932737bc
5 changed files with 101 additions and 0 deletions

View File

@@ -6,3 +6,22 @@ test('formatDate', () => {
expect(formatDate(new Date(0))).toEqual('January 1st 1970');
expect(formatDate(new Date('2023-05-13 12:00:00'))).toEqual('May 13th 2023');
});
test('toDataURL', async ({ page }) => {
// Needs to be tested in the browser because FileReader is not available in Node.js
// However, this approach does not support test coverage :'(
await page.goto('http://localhost:8080');
const dataURL = await page.evaluate(async () => {
const { toDataURL } = await import('./scripts/util.js');
const text = 'a Ā 𐀀 文 🦄';
const json = JSON.stringify({ text });
const dataURL = await toDataURL(json, 'application/json;charset=utf-8');
return dataURL;
});
expect(dataURL).toEqual(
'data:application/json;charset=utf-8;base64,eyJ0ZXh0IjoiYSDEgCDwkICAIOaWhyDwn6aEIn0=',
);
});