From 008452fd86fa78abb7c3e71290ccaad1ac5bc01b Mon Sep 17 00:00:00 2001 From: Johnny A <5891646+johnny243@users.noreply.github.com> Date: Wed, 15 Jun 2022 11:43:43 -0400 Subject: [PATCH] fix: tasksLoaded tests (#1106) --- .../package.json | 16 ++------- .../public/package.json | 7 ---- .../public/sample.ext.json | 1 - .../src/features/tasks/tasks-slice.test.ts | 34 ++++++------------- .../src/features/tasks/tasks-slice.ts | 4 +-- 5 files changed, 15 insertions(+), 47 deletions(-) diff --git a/packages/components/src/org.standardnotes.advanced-checklist/package.json b/packages/components/src/org.standardnotes.advanced-checklist/package.json index 23b8048eb..62292764a 100644 --- a/packages/components/src/org.standardnotes.advanced-checklist/package.json +++ b/packages/components/src/org.standardnotes.advanced-checklist/package.json @@ -14,21 +14,11 @@ "homepage": ".", "scripts": { "analyze": "source-map-explorer 'build/static/js/*.js'", - "start": "react-app-rewired start", - "prepublishOnly": "npm run build", - "clean-deploy-cache": "rm -rf node_modules/.cache/gh-pages", - "predeploy": "yarn run pretty && yarn run build && yarn clean-deploy-cache", - "deploy-build": "yarn run predeploy && gh-pages -b build -d build", - "deploy-dev": "yarn run predeploy && gh-pages -b dev -d build", - "deploy-stable": "yarn run predeploy && gh-pages -b gh-pages -d build", + "start": "react-scripts start", "test:coverage": "npm run test -- --coverage --watchAll", "eject": "react-scripts eject", - "serve": "serve -s -p 3000 build", - "server-public": "http-server -p 3000 --cors", - "server-root": "http-server ./ -p 3000 --cors", - "server": "http-server ./build -p 3000 --cors", - "components:compile": "react-app-rewired build", - "components:test": "react-app-rewired test --watchAll=false", + "components:compile": "react-scripts build", + "components:test": "react-scripts test --watchAll=false", "components:lint": "prettier --write 'src/**/*.{html,css,scss,js,jsx,ts,tsx,json}' README.md" }, "eslintConfig": { diff --git a/packages/components/src/org.standardnotes.advanced-checklist/public/package.json b/packages/components/src/org.standardnotes.advanced-checklist/public/package.json index cafe75dfd..7b5df3522 100644 --- a/packages/components/src/org.standardnotes.advanced-checklist/public/package.json +++ b/packages/components/src/org.standardnotes.advanced-checklist/public/package.json @@ -8,13 +8,6 @@ ], "private": true, "license": "AGPL-3.0-or-later", - "repository": { - "type": "git", - "url": "https://github.com/standardnotes/advanced-checklist.git" - }, - "bugs": { - "url": "https://github.com/standardnotes/advanced-checklist/issues" - }, "sn": { "main": "index.html" } diff --git a/packages/components/src/org.standardnotes.advanced-checklist/public/sample.ext.json b/packages/components/src/org.standardnotes.advanced-checklist/public/sample.ext.json index 3cfa7ecf7..f831e465b 100644 --- a/packages/components/src/org.standardnotes.advanced-checklist/public/sample.ext.json +++ b/packages/components/src/org.standardnotes.advanced-checklist/public/sample.ext.json @@ -8,6 +8,5 @@ "url": "http://localhost:3000/index.html", "download_url": "", "latest_url": "", - "marketing_url": "https://github.com/standardnotes/advanced-checklist", "thumbnail_url": "" } diff --git a/packages/components/src/org.standardnotes.advanced-checklist/src/features/tasks/tasks-slice.test.ts b/packages/components/src/org.standardnotes.advanced-checklist/src/features/tasks/tasks-slice.test.ts index b46cdbfe2..1f2013179 100644 --- a/packages/components/src/org.standardnotes.advanced-checklist/src/features/tasks/tasks-slice.test.ts +++ b/packages/components/src/org.standardnotes.advanced-checklist/src/features/tasks/tasks-slice.test.ts @@ -535,8 +535,16 @@ it('should handle loading tasks into the tasks store, if an invalid payload is p ], } - expect(reducer(previousState, tasksLoaded('null'))).toEqual(previousState) - expect(reducer(previousState, tasksLoaded('undefined'))).toEqual(previousState) + expect(reducer(previousState, tasksLoaded('null'))).toEqual({ + schemaVersion: '1.0.0', + groups: [], + initialized: true + }) + expect(reducer(previousState, tasksLoaded('undefined'))).toMatchObject({ + ...previousState, + initialized: false, + lastError: expect.stringContaining('An error has occurred while parsing the note\'s content') + }) }) it('should initialize the storage with an empty object', () => { @@ -564,28 +572,6 @@ it('should initialize the storage with an empty object', () => { }) }) -it('should not initialize the storage again with an empty object', () => { - const previousState: TasksState = { - schemaVersion: '1.0.0', - groups: [ - { - name: 'Test', - tasks: [ - { - id: 'another-id', - description: 'Another simple task', - completed: false, - createdAt: new Date(), - }, - ], - }, - ], - initialized: true, - } - - expect(reducer(previousState, tasksLoaded(''))).toEqual(previousState) -}) - it('should handle loading tasks into the tasks store, with a valid payload', () => { const previousState: TasksState = { schemaVersion: '1.0.0', diff --git a/packages/components/src/org.standardnotes.advanced-checklist/src/features/tasks/tasks-slice.ts b/packages/components/src/org.standardnotes.advanced-checklist/src/features/tasks/tasks-slice.ts index 33ec2723a..f9ca9726c 100644 --- a/packages/components/src/org.standardnotes.advanced-checklist/src/features/tasks/tasks-slice.ts +++ b/packages/components/src/org.standardnotes.advanced-checklist/src/features/tasks/tasks-slice.ts @@ -295,8 +295,8 @@ const tasksSlice = createSlice({ const parsedState = JSON.parse(payload) as TasksState const newState: TasksState = { - schemaVersion: parsedState.schemaVersion ?? '1.0.0', - groups: parsedState.groups ?? [], + schemaVersion: parsedState?.schemaVersion ?? '1.0.0', + groups: parsedState?.groups ?? [], } if (newState !== initialState) {