refactor(ui): finalize review fixes for action cards and view model
- Guard ActionCard click-outside listener behind open state - Add aria-expanded to ActionGroup collapse toggle - Use optional chaining and drop non-null assertions in column projection
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { content } from '../../content/index';
|
||||
import { buildContent } from '../../content/schema';
|
||||
import { buildStoryContent } from '../../content/storySchema';
|
||||
import { content } from '../../content/index';
|
||||
import { createGameState, enqueueAction, performAction, startAction } from '../../engine/game';
|
||||
import { enterStoryNode } from '../../engine/story';
|
||||
import { formatOfflineDuration, toView } from '../viewModel';
|
||||
@@ -91,8 +91,20 @@ describe('toView()', () => {
|
||||
const content = contentWithActions(
|
||||
[{ id: 'gold', name: 'Gold' }],
|
||||
[
|
||||
{ id: 'a', name: 'Alpha', group: DEFAULT_GROUP, durationMs: 1000, yields: [{ resourceId: 'gold', amount: 1 }] },
|
||||
{ id: 'b', name: 'Bravo', group: DEFAULT_GROUP, durationMs: 1000, yields: [{ resourceId: 'gold', amount: 1 }] },
|
||||
{
|
||||
id: 'a',
|
||||
name: 'Alpha',
|
||||
group: DEFAULT_GROUP,
|
||||
durationMs: 1000,
|
||||
yields: [{ resourceId: 'gold', amount: 1 }],
|
||||
},
|
||||
{
|
||||
id: 'b',
|
||||
name: 'Bravo',
|
||||
group: DEFAULT_GROUP,
|
||||
durationMs: 1000,
|
||||
yields: [{ resourceId: 'gold', amount: 1 }],
|
||||
},
|
||||
],
|
||||
);
|
||||
const state = createGameState(content);
|
||||
@@ -200,7 +212,11 @@ describe('action columns projection', () => {
|
||||
const state = createGameState(content);
|
||||
const view = toView(state, content);
|
||||
expect(view.actionColumns.map((c) => c.kind)).toEqual([
|
||||
'instant', 'loop', 'timed', 'story', 'context',
|
||||
'instant',
|
||||
'loop',
|
||||
'timed',
|
||||
'story',
|
||||
'context',
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -246,7 +262,10 @@ describe('story tree projection', () => {
|
||||
enterStoryNode(state, content, 'fork_choice');
|
||||
const view = toView(state, content);
|
||||
// fork_choice should be a node in the tree, marked active+seen, with route children
|
||||
const findNode = (nodes: typeof view.story.tree, id: string): (typeof nodes)[number] | undefined => {
|
||||
const findNode = (
|
||||
nodes: typeof view.story.tree,
|
||||
id: string,
|
||||
): (typeof nodes)[number] | undefined => {
|
||||
for (const n of nodes) {
|
||||
if (n.id === id) return n;
|
||||
const deeper = findNode(n.children, id);
|
||||
|
||||
Reference in New Issue
Block a user