Merge branch 'sky14-battle-0'

This commit is contained in:
Yanick Champoux 2023-01-14 14:32:53 -05:00
commit 929b833a49
4 changed files with 58 additions and 20 deletions

View File

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

View File

@ -15,7 +15,11 @@
</h5> </h5>
</nav> </nav>
</header> </header>
<h6>Chapter {chapter}, battle {chapterBattle} -- {status}</h6> <h6>
Chapter {chapter},
<span class="battleNbr">battle {chapterBattle}?</span>
-- {status}
</h6>
<dl> <dl>
{#if status === 'ongoing'} {#if status === 'ongoing'}
<dt>wave</dt> <dt>wave</dt>
@ -103,13 +107,14 @@
export let params; 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; $: battles = $activeCampaign?.battles;
$: battle = battles && battles[params.battleId - 1]; $: battle = battles && battles[params.battleId - 1];
$: console.log($activeCampaign);
$: scenario = battle?.scenario; $: scenario = battle?.scenario;
$: status = battle?.status; $: status = battle?.status;
$: wave = battle?.wave; $: wave = battle?.wave;
@ -117,13 +122,14 @@
$: character = battle?.character; $: character = battle?.character;
$: city = battle?.city; $: city = battle?.city;
$: console.log(battle);
let chapter = 1 + parseInt(params.battleId / 2); 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) => () => const battleVerdict = (verdict) => () =>
event.setBattleVerdict(params.battleId, verdict); event?.setBattleVerdict(params.battleId, verdict);
// $: event.setBattleDifficulty(params.battleId, difficulty); // $: event.setBattleDifficulty(params.battleId, difficulty);
</script> </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 { sveltekit } from '@sveltejs/kit/vite';
import { svelte } from '@sveltejs/vite-plugin-svelte'; import { svelte } from '@sveltejs/vite-plugin-svelte';
console.log(import.meta);
/** @type {import('vite').UserConfig} */ /** @type {import('vite').UserConfig} */
const config = { const config = {
plugins: [svelte()], plugins: [svelte()],
test: { test: {
include: ['src/**/*.{test,spec}.{js,ts}'], include: ['src/**/*.{test,spec}.{js,ts}'],
environment: 'jsdom',
}, },
resolve: { resolve: {
alias: { alias: {