fix chapter battle nbr

This commit is contained in:
Yanick Champoux 2023-01-14 14:32:36 -05:00
parent 3cb78f03ba
commit b4f12a2347
4 changed files with 58 additions and 20 deletions

View File

@ -33,6 +33,7 @@
"dependencies": {
"@ernane/svelte-star-rating": "^1.1.2",
"@sveltejs/vite-plugin-svelte": "^2.0.2",
"@testing-library/svelte": "^3.2.2",
"@yanick/updeep-remeda": "^2.1.0",
"beercss": "^3.0.4",
"dexie": "^3.2.2",

View File

@ -15,7 +15,11 @@
</h5>
</nav>
</header>
<h6>Chapter {chapter}, battle {chapterBattle} -- {status}</h6>
<h6>
Chapter {chapter},
<span class="battleNbr">battle {chapterBattle}?</span>
-- {status}
</h6>
<dl>
{#if status === 'ongoing'}
<dt>wave</dt>
@ -103,13 +107,14 @@
export let params;
const { activeCampaign, event } = getContext('api');
const api = getContext('api');
export let activeCampaign = api?.activeCampaign;
export let event = api?.event;
event.setActiveCampaign(params.campaignId);
event?.setActiveCampaign(params.campaignId);
$: battles = $activeCampaign?.battles;
$: battle = battles && battles[params.battleId - 1];
$: console.log($activeCampaign);
$: scenario = battle?.scenario;
$: status = battle?.status;
$: wave = battle?.wave;
@ -117,13 +122,14 @@
$: character = battle?.character;
$: city = battle?.city;
$: console.log(battle);
let chapter = 1 + parseInt(params.battleId / 2);
let chapterBattle = params.battleId % 2;
let chapterBattle =
params.battleId >= 7
? params.battleId - 6
: 1 + ((params.battleId - 1) % 2);
const battleVerdict = (verdict) => () =>
event.setBattleVerdict(params.battleId, verdict);
event?.setBattleVerdict(params.battleId, verdict);
// $: event.setBattleDifficulty(params.battleId, difficulty);
</script>

View File

@ -0,0 +1,31 @@
import { test, expect, afterEach } from 'vitest';
import { render, cleanup } from '@testing-library/svelte';
import Battle from '../Battle.svelte';
import { readable } from 'svelte/store';
const activeCampaign = readable({
battles: Array(12)
.fill(null)
.map((_, i) => ({
id: i + 1,
})),
});
afterEach(cleanup);
test.each([
[2, 2],
[3, 1],
[7, 1],
[8, 2],
[9, 3],
])('chapter battle (%i,%i))', (battleId, expected) => {
const { container } = render(Battle, {
params: { battleId },
activeCampaign,
});
expect(container.querySelector('.battleNbr').innerHTML).toMatch(
'battle ' + expected,
);
});

View File

@ -1,12 +1,12 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
console.log(import.meta);
/** @type {import('vite').UserConfig} */
const config = {
plugins: [svelte()],
test: {
include: ['src/**/*.{test,spec}.{js,ts}'],
environment: 'jsdom',
},
resolve: {
alias: {