From 5d11ac61e0067a2e1b8d5461d02c41a74a292a26 Mon Sep 17 00:00:00 2001 From: Caleb Evans Date: Sat, 31 Aug 2024 18:44:44 -0700 Subject: [PATCH] Run Prettier on all files Also update npm scripts per new convention --- .github/workflows/tests.yml | 4 +- .prettierignore | 1 + README.md | 6 +- index.html | 69 +++++++------ package.json | 3 +- test/app.spec.js | 186 ++++++++++++++++-------------------- test/frame.spec.js | 102 ++++++++++---------- test/story-metadata.spec.js | 22 ++--- test/story.spec.js | 186 ++++++++++++++++++------------------ 9 files changed, 283 insertions(+), 296 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ac7c054..6af7cf6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,9 +5,9 @@ name: tests on: push: - branches: [ "*" ] + branches: ['*'] pull_request: - branches: [ "*" ] + branches: ['*'] jobs: test: diff --git a/.prettierignore b/.prettierignore index 5c32cb1..2b7feaf 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,6 +4,7 @@ node_modules .env .env.* !.env.example +/.aider* # Ignore files for PNPM, NPM and YARN pnpm-lock.yaml diff --git a/README.md b/README.md index 76392c1..0affa2c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Flip Book -*Copyright 2018-2023 Caleb Evans* -*Released under the MIT license* -*For my friend and brother, Bill.* +_Copyright 2018-2023 Caleb Evans_ +_Released under the MIT license_ +_For my friend and brother, Bill._ [![tests](https://github.com/caleb531/flip-book/actions/workflows/tests.yml/badge.svg)](https://github.com/caleb531/flip-book/actions/workflows/tests.yml) diff --git a/index.html b/index.html index f2a35f1..bd8d940 100644 --- a/index.html +++ b/index.html @@ -1,33 +1,44 @@ - + - - - - - - - - Flip Book | Animate your imagination | Caleb Evans - - - - - - + + + + + + + + Flip Book | Animate your imagination | Caleb Evans + + + + + + + - +
-
- - - + + diff --git a/package.json b/package.json index f8aee84..a2d8e98 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "dev": "vite", "build": "vite build", "preview": "vite preview", - "lint": "eslint", + "eslint": "eslint .", + "lint": "prettier --write .", "test": "vitest run", "coverage": "vitest run --coverage" }, diff --git a/test/app.spec.js b/test/app.spec.js index 702e391..7e10fc6 100644 --- a/test/app.spec.js +++ b/test/app.spec.js @@ -1,149 +1,133 @@ -import App from "../scripts/models/app.js"; -import StoryMetadata from "../scripts/models/story-metadata.js"; -import Story from "../scripts/models/story.js"; -import appStorage from "../scripts/models/app-storage.js"; +import App from '../scripts/models/app.js'; +import StoryMetadata from '../scripts/models/story-metadata.js'; +import Story from '../scripts/models/story.js'; +import appStorage from '../scripts/models/app-storage.js'; -describe("app model", async () => { - it("should initialize with default arguments", async () => { +describe('app model', async () => { + it('should initialize with default arguments', async () => { let app = new App(); - expect(app).toHaveProperty("stories"); + expect(app).toHaveProperty('stories'); expect(app.stories).toHaveLength(1); expect(app.stories[0]).toBeInstanceOf(StoryMetadata); - expect(app).toHaveProperty("selectedStoryIndex", 0); - expect(app).toHaveProperty("selectedStoryIndex", 0); + expect(app).toHaveProperty('selectedStoryIndex', 0); + expect(app).toHaveProperty('selectedStoryIndex', 0); }); - it("should initialize with supplied arguments", async () => { + it('should initialize with supplied arguments', async () => { let app = new App({ - stories: [ - { name: "Foo Story" }, - { name: "Bar Story" }, - { name: "Baz Story" }, - ], - selectedStoryIndex: 1, + stories: [{ name: 'Foo Story' }, { name: 'Bar Story' }, { name: 'Baz Story' }], + selectedStoryIndex: 1 }); await app.loadSelectedStory(); - expect(app).toHaveProperty("stories"); + expect(app).toHaveProperty('stories'); expect(app.stories).toHaveLength(3); expect(app.stories[0]).toBeInstanceOf(StoryMetadata); - expect(app.stories[0]).toHaveProperty("name", "Foo Story"); - expect(app).toHaveProperty("selectedStoryIndex", 1); + expect(app.stories[0]).toHaveProperty('name', 'Foo Story'); + expect(app).toHaveProperty('selectedStoryIndex', 1); expect(app.selectedStory).toBeInstanceOf(Story); }); - it("should select story", async () => { + it('should select story', async () => { let app = new App({ stories: [ - { name: "Foo Story" }, - { name: "Bar Story" }, - { name: "Baz Story" }, - { name: "Last Story" }, - ], + { name: 'Foo Story' }, + { name: 'Bar Story' }, + { name: 'Baz Story' }, + { name: 'Last Story' } + ] }); await app.loadSelectedStory(); - expect(app).toHaveProperty("selectedStoryIndex", 0); + expect(app).toHaveProperty('selectedStoryIndex', 0); await app.selectStory(2); - expect(app).toHaveProperty("selectedStoryIndex", 2); + expect(app).toHaveProperty('selectedStoryIndex', 2); }); - it("should load story data when selecting story", async () => { + it('should load story data when selecting story', async () => { let app = new App({ stories: [ - { name: "Foo Story" }, - { name: "Bar Story" }, - { name: "Baz Story" }, - { name: "Last Story" }, - ], + { name: 'Foo Story' }, + { name: 'Bar Story' }, + { name: 'Baz Story' }, + { name: 'Last Story' } + ] }); await app.loadSelectedStory(); - expect(app).toHaveProperty("selectedStoryIndex", 0); + expect(app).toHaveProperty('selectedStoryIndex', 0); await app.selectStory(2); expect(app.selectedStory).toBeInstanceOf(Story); - expect(app.selectedStory).toHaveProperty("metadata"); + expect(app.selectedStory).toHaveProperty('metadata'); expect(app.selectedStory.metadata).toEqual(app.stories[2]); }); - it("should get selected story metadata", async () => { + it('should get selected story metadata', async () => { let app = new App({ stories: [{}, {}, {}], - selectedStoryIndex: 1, + selectedStoryIndex: 1 }); await app.loadSelectedStory(); expect(app.getSelectedStoryMetadata()).toEqual(app.stories[1]); }); - it("should get selected story metadata", async () => { + it('should get selected story metadata', async () => { let app = new App({ - stories: [ - { name: "Foo Story" }, - { name: "Bar Story" }, - { name: "Baz Story" }, - ], - selectedStoryIndex: 1, + stories: [{ name: 'Foo Story' }, { name: 'Bar Story' }, { name: 'Baz Story' }], + selectedStoryIndex: 1 }); await app.loadSelectedStory(); - expect(await app.getSelectedStoryName()).toEqual("Bar Story"); + expect(await app.getSelectedStoryName()).toEqual('Bar Story'); }); - it("should rename selected story", async () => { + it('should rename selected story', async () => { let app = new App({ - stories: [ - { name: "Foo Story" }, - { name: "Bar Story" }, - { name: "Baz Story" }, - ], - selectedStoryIndex: 1, + stories: [{ name: 'Foo Story' }, { name: 'Bar Story' }, { name: 'Baz Story' }], + selectedStoryIndex: 1 }); await app.loadSelectedStory(); - await app.renameSelectedStory("Story Reborn"); - expect(app.stories[1].name).toEqual("Story Reborn"); + await app.renameSelectedStory('Story Reborn'); + expect(app.stories[1].name).toEqual('Story Reborn'); }); - it("should delete selected story", async () => { + it('should delete selected story', async () => { let app = new App({ - stories: [ - { name: "Foo Story" }, - { name: "Bar Story" }, - { name: "Baz Story" }, - ], - selectedStoryIndex: 1, + stories: [{ name: 'Foo Story' }, { name: 'Bar Story' }, { name: 'Baz Story' }], + selectedStoryIndex: 1 }); await app.loadSelectedStory(); await app.deleteSelectedStory(); expect(app.stories).toHaveLength(2); - expect(app.stories[0].name).toEqual("Foo Story"); - expect(app.stories[1].name).toEqual("Baz Story"); + expect(app.stories[0].name).toEqual('Foo Story'); + expect(app.stories[1].name).toEqual('Baz Story'); }); - it("should delete the only story by replacing it", async () => { + it('should delete the only story by replacing it', async () => { let app = new App({ - stories: [{ name: "Foo Story", createdDate: Date.now() }], + stories: [{ name: 'Foo Story', createdDate: Date.now() }] }); await app.loadSelectedStory(); await app.deleteSelectedStory(); - expect(app.stories[0]).toHaveProperty("name", "My First Story"); + expect(app.stories[0]).toHaveProperty('name', 'My First Story'); }); - it("should create new story", async () => { + it('should create new story', async () => { let app = new App(); let defaultStory = app.stories[0]; - await app.createNewStoryWithName("My New Story"); + await app.createNewStoryWithName('My New Story'); expect(app.stories).toHaveLength(2); expect(app.selectedStoryIndex).toEqual(0); expect(app.stories[0]).not.toEqual(defaultStory); expect(app.stories[1]).toEqual(defaultStory); }); - it("should add existing story", async () => { + it('should add existing story', async () => { let app = new App(); let story = new Story({ frames: [{}, {}], selectedFrameIndex: 1, frameDuration: 125, metadata: { - name: "My Test Story", - createdDate: Date.now(), - }, + name: 'My Test Story', + createdDate: Date.now() + } }); let defaultStory = app.stories[0]; await app.addExistingStory(story); @@ -154,61 +138,55 @@ describe("app model", async () => { expect(app.stories[1]).toEqual(defaultStory); }); - it("should export JSON", async () => { + it('should export JSON', async () => { let json = new App().toJSON(); - expect(json).toHaveProperty("stories"); - expect(json).toHaveProperty("selectedStoryIndex"); + expect(json).toHaveProperty('stories'); + expect(json).toHaveProperty('selectedStoryIndex'); }); - it("should save", async () => { + it('should save', async () => { let app = new App({ - stories: [ - { name: "Foo Story" }, - { name: "Bar Story" }, - { name: "Baz Story" }, - ], - selectedStoryIndex: 1, + stories: [{ name: 'Foo Story' }, { name: 'Bar Story' }, { name: 'Baz Story' }], + selectedStoryIndex: 1 }); await app.loadSelectedStory(); - let key = "flipbook-manifest"; + let key = 'flipbook-manifest'; await appStorage.remove(key); await app.save(); - expect(JSON.stringify(await appStorage.get(key))).toEqual( - JSON.stringify(app), - ); + expect(JSON.stringify(await appStorage.get(key))).toEqual(JSON.stringify(app)); }); - it("should do nothing if nothing to restore", async () => { - await appStorage.remove("flipbook-manifest"); + it('should do nothing if nothing to restore', async () => { + await appStorage.remove('flipbook-manifest'); let app = await App.restore(); - expect(app).toHaveProperty("stories"); + expect(app).toHaveProperty('stories'); expect(app.stories).toHaveLength(1); expect(app.selectedStoryIndex).toEqual(0); - expect(app.stories[0].name).toEqual("My First Story"); - expect(app.selectedStory.metadata.name).toEqual("My First Story"); + expect(app.stories[0].name).toEqual('My First Story'); + expect(app.selectedStory.metadata.name).toEqual('My First Story'); }); - it("should restore persisted app data", async () => { - await appStorage.set("flipbook-manifest", { + it('should restore persisted app data', async () => { + await appStorage.set('flipbook-manifest', { stories: [ - { name: "Foo", createdDate: Date.now() }, - { name: "Bar", createdDate: Date.now() + 10 }, - { name: "Baz", createdDate: Date.now() + 20 }, + { name: 'Foo', createdDate: Date.now() }, + { name: 'Bar', createdDate: Date.now() + 10 }, + { name: 'Baz', createdDate: Date.now() + 20 } ], - selectedStoryIndex: 1, + selectedStoryIndex: 1 }); let app = await App.restore(); - expect(app).toHaveProperty("stories"); + expect(app).toHaveProperty('stories'); expect(app.stories).toHaveLength(3); expect(app.selectedStoryIndex).toEqual(1); - expect(app.stories[0].name).toEqual("Foo"); - expect(app.stories[1].name).toEqual("Bar"); - expect(app.stories[2].name).toEqual("Baz"); + expect(app.stories[0].name).toEqual('Foo'); + expect(app.stories[1].name).toEqual('Bar'); + expect(app.stories[2].name).toEqual('Baz'); }); - it("should save immediately if app is created from scratch", async () => { - await appStorage.remove("flipbook-manifest"); + it('should save immediately if app is created from scratch', async () => { + await appStorage.remove('flipbook-manifest'); await App.restore(); - expect(await appStorage.get("flipbook-manifest")).not.toBeNull(); + expect(await appStorage.get('flipbook-manifest')).not.toBeNull(); }); }); diff --git a/test/frame.spec.js b/test/frame.spec.js index ad757f1..f568599 100644 --- a/test/frame.spec.js +++ b/test/frame.spec.js @@ -1,94 +1,94 @@ -import Frame from "../scripts/models/frame.js"; +import Frame from '../scripts/models/frame.js'; -describe("frame model", async () => { - it("should initialize with default arguments", async () => { +describe('frame model', async () => { + it('should initialize with default arguments', async () => { let frame = new Frame(); - expect(frame.styles).toHaveProperty("strokeStyle", "#000"); - expect(frame.styles).toHaveProperty("lineWidth", 12); + expect(frame.styles).toHaveProperty('strokeStyle', '#000'); + expect(frame.styles).toHaveProperty('lineWidth', 12); expect(frame.strokeGroups).toHaveLength(0); expect(frame.undoHistory).toHaveLength(0); }); - it("should initialize with default arguments", async () => { + it('should initialize with default arguments', async () => { let frame = new Frame({ styles: { - strokeStyle: "#6c3", - lineWidth: 8, + strokeStyle: '#6c3', + lineWidth: 8 }, strokeGroups: [ { points: [[300, 150]], - styles: { strokeStyle: "#c33", lineWidth: 16 }, - }, - ], + styles: { strokeStyle: '#c33', lineWidth: 16 } + } + ] }); - expect(frame.styles).toHaveProperty("strokeStyle", "#6c3"); - expect(frame.styles).toHaveProperty("lineWidth", 8); + expect(frame.styles).toHaveProperty('strokeStyle', '#6c3'); + expect(frame.styles).toHaveProperty('lineWidth', 8); expect(frame.strokeGroups).toHaveLength(1); expect(frame.strokeGroups[0].points).toHaveLength(1); expect(frame.strokeGroups[0].points[0][0]).toEqual(300); expect(frame.strokeGroups[0].points[0][1]).toEqual(150); - expect(frame.strokeGroups[0].styles).toHaveProperty("strokeStyle", "#c33"); - expect(frame.strokeGroups[0].styles).toHaveProperty("lineWidth", 16); + expect(frame.strokeGroups[0].styles).toHaveProperty('strokeStyle', '#c33'); + expect(frame.strokeGroups[0].styles).toHaveProperty('lineWidth', 16); }); - it("should read groups argument into strokeGroups", async () => { + it('should read groups argument into strokeGroups', async () => { let frame = new Frame({ groups: [ { points: [[300, 150]], - styles: { strokeStyle: "#c33", lineWidth: 16 }, - }, - ], + styles: { strokeStyle: '#c33', lineWidth: 16 } + } + ] }); - expect(frame).not.toHaveProperty("groups"); - expect(frame).toHaveProperty("strokeGroups"); + expect(frame).not.toHaveProperty('groups'); + expect(frame).toHaveProperty('strokeGroups'); expect(frame.strokeGroups).toHaveLength(1); expect(frame.strokeGroups[0].points).toHaveLength(1); expect(frame.strokeGroups[0].points[0][0]).toEqual(300); expect(frame.strokeGroups[0].points[0][1]).toEqual(150); - expect(frame.strokeGroups[0].styles).toHaveProperty("strokeStyle", "#c33"); - expect(frame.strokeGroups[0].styles).toHaveProperty("lineWidth", 16); + expect(frame.strokeGroups[0].styles).toHaveProperty('strokeStyle', '#c33'); + expect(frame.strokeGroups[0].styles).toHaveProperty('lineWidth', 16); }); - it("should add new group", async () => { + it('should add new group', async () => { let frame = new Frame(); frame.startNewGroup({ styles: { - strokeStyle: "#6c3", - lineWidth: 20, - }, + strokeStyle: '#6c3', + lineWidth: 20 + } }); expect(frame.strokeGroups).toHaveLength(1); expect(frame.strokeGroups[0].points).toHaveLength(0); - expect(frame.strokeGroups[0].styles).toHaveProperty("strokeStyle", "#6c3"); - expect(frame.strokeGroups[0].styles).toHaveProperty("lineWidth", 20); + expect(frame.strokeGroups[0].styles).toHaveProperty('strokeStyle', '#6c3'); + expect(frame.strokeGroups[0].styles).toHaveProperty('lineWidth', 20); }); - it("should add new point", async () => { + it('should add new point', async () => { let frame = new Frame(); frame.startNewGroup({ styles: { - strokeStyle: "#6c3", - lineWidth: 20, - }, + strokeStyle: '#6c3', + lineWidth: 20 + } }); frame.addPoint(300, 150); expect(frame.strokeGroups).toHaveLength(1); expect(frame.strokeGroups[0].points).toHaveLength(1); expect(frame.strokeGroups[0].points[0][0]).toEqual(300); expect(frame.strokeGroups[0].points[0][1]).toEqual(150); - expect(frame.strokeGroups[0].styles).toHaveProperty("strokeStyle", "#6c3"); - expect(frame.strokeGroups[0].styles).toHaveProperty("lineWidth", 20); + expect(frame.strokeGroups[0].styles).toHaveProperty('strokeStyle', '#6c3'); + expect(frame.strokeGroups[0].styles).toHaveProperty('lineWidth', 20); }); - it("should combine points with same slope", async () => { + it('should combine points with same slope', async () => { let frame = new Frame(); frame.startNewGroup({ styles: { - strokeStyle: "#6c3", - lineWidth: 20, - }, + strokeStyle: '#6c3', + lineWidth: 20 + } }); frame.addPoint(300, 150); frame.addPoint(2, 0); @@ -99,7 +99,7 @@ describe("frame model", async () => { expect(frame.strokeGroups[0].points[1][1]).toEqual(0); }); - it("should count points in last group", async () => { + it('should count points in last group', async () => { let frame = new Frame(); frame.startNewGroup(); expect(frame.countPointsInLastStrokeGroup()).toEqual(0); @@ -110,12 +110,12 @@ describe("frame model", async () => { expect(frame.countPointsInLastStrokeGroup()).toEqual(3); }); - it("should count zero points if there are no groups", async () => { + it('should count zero points if there are no groups', async () => { let frame = new Frame(); expect(frame.countPointsInLastStrokeGroup()).toEqual(0); }); - it("should undo stroke", async () => { + it('should undo stroke', async () => { let frame = new Frame(); frame.startNewGroup(); frame.addPoint(300, 150); @@ -128,13 +128,13 @@ describe("frame model", async () => { expect(frame.undoHistory[0]).toEqual(lastGroup); }); - it("should do nothing if there is nothing to undo", async () => { + it('should do nothing if there is nothing to undo', async () => { let frame = new Frame(); frame.undo(); expect(frame.undoHistory).toHaveLength(0); }); - it("should redo stroke", async () => { + it('should redo stroke', async () => { let frame = new Frame(); frame.startNewGroup(); frame.addPoint(300, 150); @@ -148,13 +148,13 @@ describe("frame model", async () => { expect(frame.strokeGroups[1]).toEqual(lastGroup); }); - it("should do nothing if there is nothing to redo", async () => { + it('should do nothing if there is nothing to redo', async () => { let frame = new Frame(); frame.redo(); expect(frame.undoHistory).toHaveLength(0); }); - it("should reset undo history", async () => { + it('should reset undo history', async () => { let frame = new Frame(); frame.startNewGroup(); frame.addPoint(300, 150); @@ -164,11 +164,11 @@ describe("frame model", async () => { expect(frame.undoHistory).toHaveLength(0); }); - it("should export JSON", async () => { + it('should export JSON', async () => { let json = new Frame().toJSON(); - expect(json).toHaveProperty("styles"); - expect(json.styles).toHaveProperty("strokeStyle"); - expect(json.styles).toHaveProperty("lineWidth"); - expect(json).toHaveProperty("strokeGroups"); + expect(json).toHaveProperty('styles'); + expect(json.styles).toHaveProperty('strokeStyle'); + expect(json.styles).toHaveProperty('lineWidth'); + expect(json).toHaveProperty('strokeGroups'); }); }); diff --git a/test/story-metadata.spec.js b/test/story-metadata.spec.js index 026f861..21e38c9 100644 --- a/test/story-metadata.spec.js +++ b/test/story-metadata.spec.js @@ -1,21 +1,21 @@ -import StoryMetadata from "../scripts/models/story-metadata.js"; +import StoryMetadata from '../scripts/models/story-metadata.js'; -describe("story metadata model", async () => { - it("should initialize with default arguments", async () => { +describe('story metadata model', async () => { + it('should initialize with default arguments', async () => { let storyMetadata = new StoryMetadata(); - expect(storyMetadata).toHaveProperty("name", "My First Story"); - expect(storyMetadata).toHaveProperty("createdDate"); + expect(storyMetadata).toHaveProperty('name', 'My First Story'); + expect(storyMetadata).toHaveProperty('createdDate'); }); - it("should initialize with supplied arguments", async () => { + it('should initialize with supplied arguments', async () => { let storyMetadata = new StoryMetadata(); - expect(storyMetadata).toHaveProperty("name", "My First Story"); - expect(storyMetadata).toHaveProperty("createdDate"); + expect(storyMetadata).toHaveProperty('name', 'My First Story'); + expect(storyMetadata).toHaveProperty('createdDate'); }); - it("should export JSON", async () => { + it('should export JSON', async () => { let json = new StoryMetadata().toJSON(); - expect(json).toHaveProperty("name"); - expect(json).toHaveProperty("createdDate"); + expect(json).toHaveProperty('name'); + expect(json).toHaveProperty('createdDate'); }); }); diff --git a/test/story.spec.js b/test/story.spec.js index f93257e..d15b0a6 100644 --- a/test/story.spec.js +++ b/test/story.spec.js @@ -1,22 +1,22 @@ -import Story from "../scripts/models/story.js"; -import Frame from "../scripts/models/frame.js"; -import appStorage from "../scripts/models/app-storage.js"; +import Story from '../scripts/models/story.js'; +import Frame from '../scripts/models/frame.js'; +import appStorage from '../scripts/models/app-storage.js'; -describe("story model", async () => { - it("should initialize with default arguments", async () => { +describe('story model', async () => { + it('should initialize with default arguments', async () => { let story = new Story(); expect(story.frames).toHaveLength(1); - expect(story).toHaveProperty("selectedFrameIndex", 0); - expect(story).toHaveProperty("frameDuration", 100); - expect(story).toHaveProperty("numPreviousFramesToShow", 1); - expect(story.metadata).toHaveProperty("name", "My First Story"); - expect(story).toHaveProperty("playing", false); - expect(story).toHaveProperty("exportedGifSize", 1080); - expect(story.frameStyles).toHaveProperty("strokeStyle", "#000"); - expect(story.frameStyles).toHaveProperty("lineWidth", 12); + expect(story).toHaveProperty('selectedFrameIndex', 0); + expect(story).toHaveProperty('frameDuration', 100); + expect(story).toHaveProperty('numPreviousFramesToShow', 1); + expect(story.metadata).toHaveProperty('name', 'My First Story'); + expect(story).toHaveProperty('playing', false); + expect(story).toHaveProperty('exportedGifSize', 1080); + expect(story.frameStyles).toHaveProperty('strokeStyle', '#000'); + expect(story.frameStyles).toHaveProperty('lineWidth', 12); }); - it("should initialize with supplied arguments", async () => { + it('should initialize with supplied arguments', async () => { let createdDate = Date.now(); let story = new Story({ frames: [{}, {}], @@ -24,41 +24,41 @@ describe("story model", async () => { frameDuration: 125, numPreviousFramesToShow: 2, metadata: { - name: "My Test Story", - createdDate: createdDate, + name: 'My Test Story', + createdDate: createdDate }, exportedGifSize: 720, frameStyles: { - strokeStyle: "#6c3", - lineWidth: 8, - }, + strokeStyle: '#6c3', + lineWidth: 8 + } }); expect(story.frames).toHaveLength(2); expect(story.frames[0]).toBeInstanceOf(Frame); - expect(story).toHaveProperty("selectedFrameIndex", 1); - expect(story).toHaveProperty("frameDuration", 125); - expect(story).toHaveProperty("numPreviousFramesToShow", 2); - expect(story.metadata).toHaveProperty("name", "My Test Story"); - expect(story.metadata).toHaveProperty("createdDate", createdDate); - expect(story).toHaveProperty("playing", false); - expect(story).toHaveProperty("exportedGifSize", 720); - expect(story.frameStyles).toHaveProperty("strokeStyle", "#6c3"); - expect(story.frameStyles).toHaveProperty("lineWidth", 8); + expect(story).toHaveProperty('selectedFrameIndex', 1); + expect(story).toHaveProperty('frameDuration', 125); + expect(story).toHaveProperty('numPreviousFramesToShow', 2); + expect(story.metadata).toHaveProperty('name', 'My Test Story'); + expect(story.metadata).toHaveProperty('createdDate', createdDate); + expect(story).toHaveProperty('playing', false); + expect(story).toHaveProperty('exportedGifSize', 720); + expect(story.frameStyles).toHaveProperty('strokeStyle', '#6c3'); + expect(story.frameStyles).toHaveProperty('lineWidth', 8); }); - it("should honor showPreviousFrame when false", async () => { + it('should honor showPreviousFrame when false', async () => { let story = new Story({ showPreviousFrame: false }); - expect(story).toHaveProperty("numPreviousFramesToShow", 0); + expect(story).toHaveProperty('numPreviousFramesToShow', 0); }); - it("should honor showPreviousFrame when true", async () => { + it('should honor showPreviousFrame when true', async () => { let story = new Story({ showPreviousFrame: true }); - expect(story).toHaveProperty("numPreviousFramesToShow", 1); + expect(story).toHaveProperty('numPreviousFramesToShow', 1); }); - it("should select frame", async () => { + it('should select frame', async () => { let story = new Story({ - frames: [new Frame(), new Frame(), new Frame()], + frames: [new Frame(), new Frame(), new Frame()] }); expect(story.selectedFrameIndex).toEqual(0); story.selectFrame(2); @@ -67,132 +67,130 @@ describe("story model", async () => { expect(story.selectedFrameIndex).toEqual(1); }); - it("should get selected frame", async () => { + it('should get selected frame', async () => { let story = new Story({ frames: [new Frame(), new Frame(), new Frame()], - selectedFrameIndex: 1, + selectedFrameIndex: 1 }); expect(story.getSelectedFrame()).toEqual(story.frames[1]); }); - it("should get last previous frame by default", async () => { + it('should get last previous frame by default', async () => { let story = new Story({ frames: [new Frame(), new Frame(), new Frame()], selectedFrameIndex: 2, - numPreviousFramesToShow: 1, + numPreviousFramesToShow: 1 }); expect(story.getPreviousFramesToShow()).toHaveLength(1); expect(story.getPreviousFramesToShow()[0]).toEqual(story.frames[1]); }); - it("should get all previous frames", async () => { + it('should get all previous frames', async () => { let story = new Story({ frames: [new Frame(), new Frame(), new Frame()], selectedFrameIndex: 2, - numPreviousFramesToShow: 2, + numPreviousFramesToShow: 2 }); expect(story.getPreviousFramesToShow()).toHaveLength(2); expect(story.getPreviousFramesToShow()[0]).toEqual(story.frames[0]); expect(story.getPreviousFramesToShow()[1]).toEqual(story.frames[1]); }); - it("should get as many previous frames even if bound is exceeded", async () => { + it('should get as many previous frames even if bound is exceeded', async () => { let story = new Story({ frames: [new Frame(), new Frame(), new Frame()], selectedFrameIndex: 1, - numPreviousFramesToShow: 2, + numPreviousFramesToShow: 2 }); expect(story.getPreviousFramesToShow()).toHaveLength(1); expect(story.getPreviousFramesToShow()[0]).toEqual(story.frames[0]); }); - it("should not wrap around to get previous frame", async () => { + it('should not wrap around to get previous frame', async () => { let story = new Story({ - frames: [new Frame(), new Frame(), new Frame()], + frames: [new Frame(), new Frame(), new Frame()] }); expect(story.getPreviousFramesToShow()).toHaveLength(0); }); - it("should select next frame", async () => { + it('should select next frame', async () => { let story = new Story({ - frames: [new Frame(), new Frame(), new Frame()], + frames: [new Frame(), new Frame(), new Frame()] }); story.selectNextFrame(); expect(story.getSelectedFrame()).toEqual(story.frames[1]); }); - it("should wrap around when selecting next frame", async () => { + it('should wrap around when selecting next frame', async () => { let story = new Story({ frames: [new Frame(), new Frame(), new Frame()], - selectedFrameIndex: 2, + selectedFrameIndex: 2 }); story.selectNextFrame(); expect(story.getSelectedFrame()).toEqual(story.frames[0]); }); - it("should select previous frame", async () => { + it('should select previous frame', async () => { let story = new Story({ frames: [new Frame(), new Frame(), new Frame()], - selectedFrameIndex: 2, + selectedFrameIndex: 2 }); story.selectPreviousFrame(); expect(story.getSelectedFrame()).toEqual(story.frames[1]); }); - it("should wrap around when selecting previous frame", async () => { + it('should wrap around when selecting previous frame', async () => { let story = new Story({ - frames: [new Frame(), new Frame(), new Frame()], + frames: [new Frame(), new Frame(), new Frame()] }); story.selectPreviousFrame(); expect(story.getSelectedFrame()).toEqual(story.frames[2]); }); - it("should add new frame", async () => { + it('should add new frame', async () => { let story = new Story({ frames: [new Frame(), new Frame(), new Frame()], - selectedFrameIndex: 1, + selectedFrameIndex: 1 }); story.addNewFrame(); expect(story.frames.length).toEqual(4); expect(story.selectedFrameIndex).toEqual(2); }); - it("should duplicate current frame", async () => { + it('should duplicate current frame', async () => { let story = new Story({ frames: [new Frame(), new Frame(), new Frame()], - selectedFrameIndex: 2, + selectedFrameIndex: 2 }); story.duplicateCurrentFrame(); expect(story.frames.length).toEqual(4); expect(story.selectedFrameIndex).toEqual(3); - expect(JSON.stringify(story.frames[2])).toEqual( - JSON.stringify(story.frames[3]), - ); + expect(JSON.stringify(story.frames[2])).toEqual(JSON.stringify(story.frames[3])); }); - it("should delete selected frame", async () => { + it('should delete selected frame', async () => { let story = new Story({ frames: [new Frame(), new Frame(), new Frame(), new Frame()], - selectedFrameIndex: 2, + selectedFrameIndex: 2 }); story.deleteSelectedFrame(); expect(story.frames.length).toEqual(3); expect(story.selectedFrameIndex).toEqual(1); }); - it("should delete the only frame by replacing it", async () => { + it('should delete the only frame by replacing it', async () => { let story = new Story({ - frames: [new Frame()], + frames: [new Frame()] }); let deletedFrame = story.frames[0]; story.deleteSelectedFrame(); expect(story.frames[0]).not.toEqual(deletedFrame); }); - it("should move selected frame", async () => { + it('should move selected frame', async () => { let story = new Story({ frames: [new Frame(), new Frame(), new Frame(), new Frame(), new Frame()], - selectedFrameIndex: 2, + selectedFrameIndex: 2 }); let oldIndex = 1; let newIndex = 3; @@ -205,27 +203,27 @@ describe("story model", async () => { expect(story.frames[4]).toEqual(oldFrames[4]); }); - it("should get frames per second", async () => { + it('should get frames per second', async () => { let story = new Story({ frames: [new Frame()], - frameDuration: 125, + frameDuration: 125 }); expect(story.getFramesPerSecond()).toEqual(8); }); - it("should set frames per second", async () => { + it('should set frames per second', async () => { let story = new Story({ - frames: [new Frame()], + frames: [new Frame()] }); story.setFramesPerSecond(8); expect(story.frameDuration).toEqual(125); }); - it("should play", async () => { + it('should play', async () => { let frameDuration = 125; let story = new Story({ frames: [new Frame(), new Frame(), new Frame()], - frameDuration, + frameDuration }); vi.useFakeTimers(); let callback = vi.fn(); @@ -239,11 +237,11 @@ describe("story model", async () => { vi.useRealTimers(); }); - it("should wrap around when playing", async () => { + it('should wrap around when playing', async () => { let frameDuration = 125; let story = new Story({ frames: [new Frame(), new Frame(), new Frame()], - frameDuration, + frameDuration }); vi.useFakeTimers(); let callback = vi.fn(); @@ -261,11 +259,11 @@ describe("story model", async () => { vi.useRealTimers(); }); - it("should play without a user callback", async () => { + it('should play without a user callback', async () => { let frameDuration = 125; let story = new Story({ frames: [new Frame(), new Frame(), new Frame()], - frameDuration, + frameDuration }); vi.useFakeTimers(); story.play(); @@ -275,11 +273,11 @@ describe("story model", async () => { vi.useRealTimers(); }); - it("should pause", async () => { + it('should pause', async () => { let frameDuration = 125; let story = new Story({ frames: [new Frame(), new Frame(), new Frame()], - frameDuration, + frameDuration }); vi.useFakeTimers(); let callback = vi.fn(); @@ -297,49 +295,47 @@ describe("story model", async () => { vi.useRealTimers(); }); - it("should undo", async () => { + it('should undo', async () => { let story = new Story({ frames: [new Frame(), new Frame(), new Frame()], - selectedFrameIndex: 1, + selectedFrameIndex: 1 }); story.frames[1].undo = vi.fn(); story.undo(); expect(story.frames[1].undo).toHaveBeenCalledOnce(); }); - it("should redo", async () => { + it('should redo', async () => { let story = new Story({ frames: [new Frame(), new Frame(), new Frame()], - selectedFrameIndex: 1, + selectedFrameIndex: 1 }); story.frames[1].redo = vi.fn(); story.redo(); expect(story.frames[1].redo).toHaveBeenCalledOnce(); }); - it("should export JSON", async () => { + it('should export JSON', async () => { let json = new Story().toJSON(); - expect(json).toHaveProperty("frames"); - expect(json).toHaveProperty("selectedFrameIndex"); - expect(json).toHaveProperty("frameDuration"); - expect(json).toHaveProperty("numPreviousFramesToShow"); - expect(json).toHaveProperty("frameStyles"); - expect(json).toHaveProperty("exportedGifSize"); + expect(json).toHaveProperty('frames'); + expect(json).toHaveProperty('selectedFrameIndex'); + expect(json).toHaveProperty('frameDuration'); + expect(json).toHaveProperty('numPreviousFramesToShow'); + expect(json).toHaveProperty('frameStyles'); + expect(json).toHaveProperty('exportedGifSize'); }); - it("should save", async () => { + it('should save', async () => { let createdDate = Date.now(); let story = new Story({ metadata: { - name: "Foo", - createdDate, - }, + name: 'Foo', + createdDate + } }); let key = `flipbook-story-${createdDate}`; await appStorage.remove(key); await story.save(); - expect(JSON.stringify(await appStorage.get(key))).toEqual( - JSON.stringify(story), - ); + expect(JSON.stringify(await appStorage.get(key))).toEqual(JSON.stringify(story)); }); });