Merge branch 'gh15-reset-button'

This commit is contained in:
Yanick Champoux 2022-04-17 12:29:29 -04:00
commit 156330c990
7 changed files with 140 additions and 99 deletions

View File

@ -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",

View File

@ -3,38 +3,35 @@
</svelte:head>
<main>
<Ribbon />
<Header on:changeTab={({ detail }) => activeTab = detail}/>
<Header on:changeTab={({ detail }) => (activeTab = detail)} />
<div class:hide={activeTab !== 'editor'}>
<div class:hide={activeTab !== "editor"}>
<ShipEdit />
</div>
<div class:hide={activeTab !== 'json'}>
<div class:hide={activeTab !== "json"}>
<JsonOutput />
</div>
{#if activeTab === 'print'}
{#if activeTab === "print"}
<PrintOutput ship={$state} />
{/if}
</main>
<script>
import { getContext } from 'svelte';
import { getContext } from "svelte";
import { Modal, Card, Nav } from "svelte-chota";
import Ribbon from "./Ribbon.svelte";
import Header from "./Header.svelte";
import ShipEdit from "./ShipEdit/index.svelte";
import About from "./About.svelte";
import JsonOutput from './Output/Json.svelte';
import PrintOutput from './Output/Print/index.svelte';
import JsonOutput from "./Output/Json.svelte";
import PrintOutput from "./Output/Print/index.svelte";
let activeTab = 'editor';
$: console.log(activeTab);
let activeTab = "editor";
const {state} = getContext('ship');
const { state } = getContext("ship");
</script>
<style>

View File

@ -1,19 +1,22 @@
<header>
<h1>The Docks</h1>
<h2>
a <a href="https://shop.groundzerogames.co.uk/rules.html"
>Full Thrust</a
> ship builder
a <a href="https://shop.groundzerogames.co.uk/rules.html">Full Thrust</a> ship
builder
</h2>
<a on:click|preventDefault={() => (showAbout = true)}>about the app</a>
</header>
<div>
<div class="menu">
<Tabs bind:active={activeTab}>
<Tab tabid="editor">editor</Tab>
<Tab tabid="json">json view</Tab>
<Tab tabid="print">print view</Tab>
</Tabs>
<div class="actions">
<a on:click|preventDefault={resetShip}>reset ship</a>
</div>
</div>
<Modal bind:open={showAbout}>
@ -21,16 +24,23 @@
</Modal>
<script>
import { createEventDispatcher } from 'svelte';
import { getContext, createEventDispatcher } from "svelte";
import { Modal, Card, Nav, Tab, Tabs } from "svelte-chota";
import About from "./About.svelte";
let showAbout = false;
let activeTab = 'editor';
let activeTab = "editor";
const ship = getContext("ship");
const dispatch = createEventDispatcher();
$: dispatch( 'changeTab', activeTab );
$: dispatch("changeTab", activeTab);
const resetShip = () => {
if (!window.confirm("you really want to reset the ship?")) return;
ship.dispatch.resetShip();
};
</script>
<style>
@ -73,4 +83,12 @@ $: dispatch( 'changeTab', activeTab );
margin-right: 1em;
padding-bottom: 0.125em !important;
}
.menu {
display: flex;
align-items: baseline;
}
.menu .actions {
flex: 1;
text-align: right;
}
</style>

View File

@ -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();
});

View File

@ -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 } }));

View File

@ -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,

9
vitest.config.js Normal file
View File

@ -0,0 +1,9 @@
import { extractFromSvelteConfig } from "vitest-svelte-kit";
export default extractFromSvelteConfig().then((config) => ({
...config,
test: {
globals: true,
environment: "jsdom",
},
}));