From 8d99a63648d2ef58a5c21ca4b27316b4dced37e9 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 17 Apr 2022 12:21:50 -0400 Subject: [PATCH 1/6] add vitest and testing-library --- package.json | 6 +++++- vitest.config.js | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 vitest.config.js diff --git a/package.json b/package.json index 710e89f..bfa5b6b 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,8 @@ "@sveltejs/adapter-static": "^1.0.0-next.28", "@sveltejs/kit": "^1.0.0-next.288", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.38", + "@testing-library/svelte": "^3.1.1", + "@testing-library/user-event": "^13.5.0", "eslint": "^8.10.0", "eslint-config-prettier": "^8.4.0", "eslint-plugin-svelte3": "^3.4.1", @@ -25,7 +27,9 @@ "prettier-plugin-svelte": "^2.6.0", "standard-version": "^9.3.2", "storybook-builder-vite": "0.1.21", - "svelte": "^3.46.4" + "svelte": "^3.46.4", + "vitest": "^0.9.3", + "vitest-svelte-kit": "^0.0.6" }, "dependencies": { "@storybook/addon-essentials": "^6.4.19", diff --git a/vitest.config.js b/vitest.config.js new file mode 100644 index 0000000..78214f1 --- /dev/null +++ b/vitest.config.js @@ -0,0 +1,9 @@ +import { extractFromSvelteConfig } from "vitest-svelte-kit"; + +export default extractFromSvelteConfig().then((config) => ({ + ...config, + test: { + globals: true, + environment: "jsdom", + }, + })); From 6e819dbce6a373eca840b06dea7a632b213d88a4 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 17 Apr 2022 12:22:28 -0400 Subject: [PATCH 2/6] set original thrust to 0 --- src/lib/shipDux/propulsion/drive.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/shipDux/propulsion/drive.js b/src/lib/shipDux/propulsion/drive.js index f165e7d..c6fbb48 100644 --- a/src/lib/shipDux/propulsion/drive.js +++ b/src/lib/shipDux/propulsion/drive.js @@ -7,7 +7,7 @@ import reqs from "../reqs.js"; const dux = new Updux({ subduxes: { reqs }, initial: { - rating: 1, + rating: 0, advanced: false, }, actions: { @@ -20,7 +20,7 @@ dux.setMutation("setDrive", (changes) => u(changes)); dux.setMutation("setDriveReqs", (reqs) => u({ reqs })); // needs to be at the top level -export const calculateDriveReqs = store => +export const calculateDriveReqs = (store) => createSelector( [ (ship) => ship.reqs.mass, @@ -29,7 +29,7 @@ export const calculateDriveReqs = store => ], (ship_mass, rating, advanced) => store.dispatch.setDriveReqs(calcDriveReqs(ship_mass, rating, advanced)) - ); + ); export function calcDriveReqs(shipMass, rating, advanced = false) { const mass = Math.ceil(rating * 0.05 * shipMass); From f9228916f336334461b766a7542f217925b0941c Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 17 Apr 2022 12:23:25 -0400 Subject: [PATCH 3/6] add dux action 'resetShip' --- src/lib/shipDux/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib/shipDux/index.js b/src/lib/shipDux/index.js index bae5914..16f884c 100644 --- a/src/lib/shipDux/index.js +++ b/src/lib/shipDux/index.js @@ -25,6 +25,7 @@ const dux = new Updux({ setShipReqs: null, setUITransform: null, resetLayout: null, + resetShip: null, }, }); @@ -37,6 +38,8 @@ function resetUITransform(thing) { ); } +dux.setMutation("resetShip", () => () => dux.initial); + dux.setMutation("resetLayout", () => resetUITransform); dux.setMutation("setShipMass", (mass) => u({ reqs: { mass } })); From 9a37720c86c1ca50284f1655286329224b5c44c9 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 17 Apr 2022 12:26:25 -0400 Subject: [PATCH 4/6] add test --- src/lib/components/Header.test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/lib/components/Header.test.js diff --git a/src/lib/components/Header.test.js b/src/lib/components/Header.test.js new file mode 100644 index 0000000..1270067 --- /dev/null +++ b/src/lib/components/Header.test.js @@ -0,0 +1,10 @@ +import { test, expect } from "vitest"; +import { render } from "@testing-library/svelte"; + +import App from "./Header.svelte"; + +test("reset ship link is present", () => { + const { queryByText } = render(App); + + expect(queryByText("reset ship")).toBeTruthy(); +}); From 255b29601234e5c42180f51b70cb4dcd47abb550 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 17 Apr 2022 12:27:33 -0400 Subject: [PATCH 5/6] remove a console.log --- src/lib/components/App.svelte | 69 +++++++++++++++++------------------ 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/src/lib/components/App.svelte b/src/lib/components/App.svelte index 2dd8b48..162c76b 100644 --- a/src/lib/components/App.svelte +++ b/src/lib/components/App.svelte @@ -1,54 +1,51 @@ - +
+ +
(activeTab = detail)} /> - -
activeTab = detail}/> - -
+
-
-
+
+
-
- -{#if activeTab === 'print'} - -{/if} +
+ {#if activeTab === "print"} + + {/if}
From ea3d36292cb03c484bb86f04eb775e64e9f27aae Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Sun, 17 Apr 2022 12:28:36 -0400 Subject: [PATCH 6/6] add 'reset ship' link --- src/lib/components/Header.svelte | 136 +++++++++++++++++-------------- 1 file changed, 77 insertions(+), 59 deletions(-) diff --git a/src/lib/components/Header.svelte b/src/lib/components/Header.svelte index 26ecf9b..c0c9657 100644 --- a/src/lib/components/Header.svelte +++ b/src/lib/components/Header.svelte @@ -1,76 +1,94 @@
-

The Docks

-

- a Full Thrust ship builder -

- (showAbout = true)}>about the app +

The Docks

+

+ a Full Thrust ship + builder +

+ (showAbout = true)}>about the app
-
- - editor - json view - print view - + - +