mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-22 16:46:10 -08:00
- Drop the Alt Horizontal row from Alt+C; no action read this binding - Remove the key from config defaults, resolver, IPC validator, and types - Regenerate config.example.jsonc and remove the inactive-binding exemption
564 lines
22 KiB
TypeScript
564 lines
22 KiB
TypeScript
import assert from 'node:assert/strict';
|
||
import test from 'node:test';
|
||
|
||
import { CORE_DEFAULT_CONFIG } from '../../config/definitions/defaults-core';
|
||
import { getDefaultControllerFieldGroupingBindings } from '../../shared/controller-field-grouping';
|
||
import { getDefaultControllerReviewBindings } from '../../shared/controller-review';
|
||
import { CONTROLLER_SCREENS } from '../../shared/controller-screens';
|
||
import type { ControllerFaceButtonLabels, ResolvedControllerConfig } from '../../types';
|
||
import type { ControllerScreenLearning } from './controller-config-form';
|
||
import { createControllerConfigForm } from './controller-config-form.js';
|
||
|
||
type ActionId = keyof ResolvedControllerConfig['bindings'];
|
||
|
||
const BINDINGS: ResolvedControllerConfig['bindings'] = {
|
||
toggleLookup: { kind: 'button', buttonIndex: 0 },
|
||
closeLookup: { kind: 'button', buttonIndex: 1 },
|
||
toggleKeyboardOnlyMode: { kind: 'button', buttonIndex: 3 },
|
||
mineCard: { kind: 'button', buttonIndex: 2 },
|
||
quitMpv: { kind: 'button', buttonIndex: 6 },
|
||
previousAudio: { kind: 'none' },
|
||
nextAudio: { kind: 'button', buttonIndex: 5 },
|
||
playCurrentAudio: { kind: 'button', buttonIndex: 4 },
|
||
toggleMpvPause: { kind: 'button', buttonIndex: 9 },
|
||
holdSecondarySub: { kind: 'none' },
|
||
previousEntry: { kind: 'none' },
|
||
nextEntry: { kind: 'none' },
|
||
toggleCharacterNavigation: { kind: 'none' },
|
||
previousSubtitle: { kind: 'none' },
|
||
nextSubtitle: { kind: 'none' },
|
||
replaySubtitle: { kind: 'none' },
|
||
playNextSubtitle: { kind: 'none' },
|
||
leftStickHorizontal: { kind: 'axis', axisIndex: 0, dpadFallback: 'horizontal' },
|
||
leftStickVertical: { kind: 'axis', axisIndex: 1, dpadFallback: 'vertical' },
|
||
rightStickVertical: { kind: 'axis', axisIndex: 4, dpadFallback: 'none' },
|
||
};
|
||
|
||
/** Minimal DOM element: enough for the form's createElement/appendChild/click usage. */
|
||
class FakeElement {
|
||
className = '';
|
||
textContent = '';
|
||
title = '';
|
||
type = '';
|
||
children: FakeElement[] = [];
|
||
private readonly listeners = new Map<string, Array<(event: Event) => void>>();
|
||
private readonly attributes = new Map<string, string>();
|
||
|
||
readonly classList = {
|
||
add: (...tokens: string[]) => {
|
||
this.className = [...new Set([...this.classes(), ...tokens])].join(' ');
|
||
},
|
||
contains: (token: string) => this.classes().includes(token),
|
||
toggle: (token: string, force?: boolean) => {
|
||
const on = force ?? !this.classes().includes(token);
|
||
const rest = this.classes().filter((existing) => existing !== token);
|
||
this.className = (on ? [...rest, token] : rest).join(' ');
|
||
return on;
|
||
},
|
||
};
|
||
|
||
set innerHTML(value: string) {
|
||
if (value === '') this.children = [];
|
||
}
|
||
|
||
appendChild(child: FakeElement): FakeElement {
|
||
this.children.push(child);
|
||
return child;
|
||
}
|
||
|
||
addEventListener(type: string, listener: (event: Event) => void): void {
|
||
this.listeners.set(type, [...(this.listeners.get(type) ?? []), listener]);
|
||
}
|
||
|
||
click(): void {
|
||
const event = { stopPropagation: () => {}, preventDefault: () => {} } as unknown as Event;
|
||
for (const listener of this.listeners.get('click') ?? []) listener(event);
|
||
}
|
||
|
||
setAttribute(name: string, value: string): void {
|
||
this.attributes.set(name, value);
|
||
}
|
||
|
||
getAttribute(name: string): string | null {
|
||
return this.attributes.get(name) ?? null;
|
||
}
|
||
|
||
private classes(): string[] {
|
||
return this.className.split(' ').filter(Boolean);
|
||
}
|
||
}
|
||
|
||
function findAll(root: FakeElement, className: string): FakeElement[] {
|
||
return root.children.flatMap((child) => [
|
||
...(child.classList.contains(className) ? [child] : []),
|
||
...findAll(child, className),
|
||
]);
|
||
}
|
||
|
||
function findOne(root: FakeElement, className: string, text?: string): FakeElement {
|
||
const match = findAll(root, className).find(
|
||
(el) => text === undefined || el.textContent === text,
|
||
);
|
||
assert.ok(match, `missing .${className}${text === undefined ? '' : ` "${text}"`}`);
|
||
return match;
|
||
}
|
||
|
||
/** Renders the form into a fake container with `document` stubbed for the duration. */
|
||
function renderForm(
|
||
learningActionId: ActionId | null,
|
||
options: {
|
||
bindings?: typeof BINDINGS;
|
||
mapping?: string;
|
||
faceButtonLabels?: ControllerFaceButtonLabels;
|
||
} = {},
|
||
) {
|
||
const previousDocument = Object.getOwnPropertyDescriptor(globalThis, 'document');
|
||
Object.defineProperty(globalThis, 'document', {
|
||
configurable: true,
|
||
value: { createElement: () => new FakeElement() },
|
||
});
|
||
|
||
try {
|
||
const calls: string[] = [];
|
||
const container = new FakeElement();
|
||
createControllerConfigForm({
|
||
container: container as unknown as HTMLElement,
|
||
getBindings: () => options.bindings ?? BINDINGS,
|
||
getControllerMapping: () => options.mapping,
|
||
getFaceButtonLabels: () => options.faceButtonLabels,
|
||
getLearningActionId: () => learningActionId,
|
||
getDpadLearningActionId: () => null,
|
||
onLearn: (actionId, bindingType) => calls.push(`learn:${actionId}:${bindingType}`),
|
||
onClear: (actionId) => calls.push(`clear:${actionId}`),
|
||
onReset: (actionId) => calls.push(`reset:${actionId}`),
|
||
onDpadLearn: (actionId) => calls.push(`dpadLearn:${actionId}`),
|
||
onDpadClear: (actionId) => calls.push(`dpadClear:${actionId}`),
|
||
onDpadReset: (actionId) => calls.push(`dpadReset:${actionId}`),
|
||
}).render();
|
||
|
||
const row = (label: string) => {
|
||
const match = findAll(container, 'controller-config-row').find(
|
||
(el) => findOne(el, 'controller-config-label').textContent === label,
|
||
);
|
||
assert.ok(match, `missing row "${label}"`);
|
||
return match;
|
||
};
|
||
return { calls, container, row };
|
||
} finally {
|
||
if (previousDocument) {
|
||
Object.defineProperty(globalThis, 'document', previousDocument);
|
||
} else {
|
||
Reflect.deleteProperty(globalThis, 'document');
|
||
}
|
||
}
|
||
}
|
||
|
||
test('controller config form renders grouped rows with friendly binding labels', () => {
|
||
const { container } = renderForm(null);
|
||
|
||
assert.deepEqual(
|
||
findAll(container, 'controller-config-group').map((el) => el.textContent),
|
||
['Lookup', 'Playback', 'Subtitles', 'Popup Audio', 'Navigation'],
|
||
);
|
||
assert.deepEqual(
|
||
findAll(container, 'controller-config-row').map((row) => [
|
||
findOne(row, 'controller-config-label').textContent,
|
||
findOne(row, 'controller-config-badge').textContent,
|
||
]),
|
||
[
|
||
['Toggle Lookup', 'A'],
|
||
['Close Lookup', 'B'],
|
||
['Previous Entry', 'None'],
|
||
['Next Entry', 'None'],
|
||
['Mine Card', 'X'],
|
||
['Toggle Keyboard-Only Mode', 'Y'],
|
||
['Toggle MPV Pause', 'R3 / RS'],
|
||
['Show Secondary Subtitle (Hold)', 'None'],
|
||
['Quit MPV', 'Back / Select'],
|
||
['Previous Subtitle', 'None'],
|
||
['Next Subtitle', 'None'],
|
||
['Replay Subtitle', 'None'],
|
||
['Play Next Subtitle', 'None'],
|
||
['Previous Audio', 'None'],
|
||
['Next Audio', 'RB / R1'],
|
||
['Play Current Audio', 'LB / L1'],
|
||
['Toggle Character Navigation', 'None'],
|
||
['Token Move (Stick)', 'Left Stick X'],
|
||
['Token Move (D-pad)', 'D-pad ↔'],
|
||
['Popup Scroll (Stick)', 'Left Stick Y'],
|
||
['Popup Scroll (D-pad)', 'D-pad ↕'],
|
||
['Popup Jump (Stick)', 'Right Stick Y'],
|
||
['Popup Jump (D-pad)', 'None'],
|
||
],
|
||
);
|
||
assert.deepEqual(
|
||
findAll(container, 'disabled').map((badge) => badge.textContent),
|
||
['None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None'],
|
||
);
|
||
assert.deepEqual(findAll(container, 'expanded'), []);
|
||
assert.deepEqual(findAll(container, 'controller-config-edit-panel'), []);
|
||
});
|
||
|
||
test('controller config form expands the learning row with a listening edit panel', () => {
|
||
const { container, row } = renderForm('toggleLookup');
|
||
|
||
assert.deepEqual(
|
||
findAll(container, 'expanded').map((el) => findOne(el, 'controller-config-label').textContent),
|
||
['Toggle Lookup'],
|
||
);
|
||
// The edit panel is inserted directly after the expanded row.
|
||
const rowIndex = container.children.indexOf(row('Toggle Lookup'));
|
||
const panel = container.children[rowIndex + 1];
|
||
assert.ok(panel);
|
||
assert.equal(panel.classList.contains('controller-config-edit-panel'), true);
|
||
|
||
const hint = findOne(panel, 'controller-config-edit-hint');
|
||
assert.equal(hint.textContent, 'Press a button, or hold one and press another for a combo…');
|
||
assert.equal(hint.classList.contains('learning'), true);
|
||
assert.equal(findOne(panel, 'btn-learn').textContent, 'Listening…');
|
||
});
|
||
|
||
type Locate = (row: FakeElement, panel: FakeElement) => FakeElement;
|
||
|
||
for (const c of [
|
||
{
|
||
control: 'row badge',
|
||
locate: (row) => findOne(row, 'controller-config-badge'),
|
||
expected: 'learn:toggleLookup:discrete',
|
||
},
|
||
{
|
||
control: 'row reset icon',
|
||
locate: (row) => findOne(row, 'controller-config-reset-icon'),
|
||
expected: 'reset:toggleLookup',
|
||
},
|
||
{
|
||
control: 'row edit icon',
|
||
locate: (row) => findOne(row, 'controller-config-edit-icon'),
|
||
expected: 'learn:toggleLookup:discrete',
|
||
},
|
||
{
|
||
control: 'panel Learn',
|
||
locate: (_row, panel) => findOne(panel, 'btn-learn'),
|
||
expected: 'learn:toggleLookup:discrete',
|
||
},
|
||
{
|
||
control: 'panel Clear',
|
||
locate: (_row, panel) => findOne(panel, 'btn-secondary', 'Clear'),
|
||
expected: 'clear:toggleLookup',
|
||
},
|
||
{
|
||
control: 'panel Reset',
|
||
locate: (_row, panel) => findOne(panel, 'btn-secondary', 'Reset'),
|
||
expected: 'reset:toggleLookup',
|
||
},
|
||
] satisfies Array<{ control: string; locate: Locate; expected: string }>) {
|
||
test(`controller config form ${c.control} dispatches ${c.expected}`, () => {
|
||
const { calls, container, row } = renderForm('toggleLookup');
|
||
|
||
c.locate(row('Toggle Lookup'), findOne(container, 'controller-config-edit-panel')).click();
|
||
|
||
assert.deepEqual(calls, [c.expected]);
|
||
});
|
||
}
|
||
|
||
test('controller config form names buttons by the W3C standard layout for standard pads', () => {
|
||
const bindings: typeof BINDINGS = {
|
||
...BINDINGS,
|
||
quitMpv: { kind: 'button', buttonIndex: 6 },
|
||
toggleMpvPause: { kind: 'button', buttonIndex: 10 },
|
||
holdSecondarySub: { kind: 'button', buttonIndex: 11 },
|
||
previousEntry: { kind: 'button', buttonIndex: 8 },
|
||
nextEntry: { kind: 'button', buttonIndex: 9 },
|
||
rightStickVertical: { kind: 'axis', axisIndex: 3, dpadFallback: 'none' },
|
||
};
|
||
const badge = (row: FakeElement) => findOne(row, 'controller-config-badge').textContent;
|
||
|
||
const standard = renderForm(null, { bindings, mapping: 'standard' });
|
||
assert.equal(badge(standard.row('Quit MPV')), 'LT / L2');
|
||
assert.equal(badge(standard.row('Previous Entry')), 'Back / Select');
|
||
assert.equal(badge(standard.row('Next Entry')), 'Start / Options');
|
||
assert.equal(badge(standard.row('Toggle MPV Pause')), 'L3 / LS');
|
||
assert.equal(badge(standard.row('Show Secondary Subtitle (Hold)')), 'R3 / RS');
|
||
assert.equal(badge(standard.row('Popup Jump (Stick)')), 'Right Stick Y');
|
||
|
||
// Pads without the standard mapping keep the previous names.
|
||
const raw = renderForm(null, { bindings, mapping: '' });
|
||
assert.equal(badge(raw.row('Quit MPV')), 'Back / Select');
|
||
assert.equal(badge(raw.row('Previous Entry')), 'L3 / LS');
|
||
});
|
||
|
||
test('controller config form names face buttons Nintendo-style when configured', () => {
|
||
const badge = (row: FakeElement) => findOne(row, 'controller-config-badge').textContent;
|
||
const bindings: typeof BINDINGS = {
|
||
...BINDINGS,
|
||
toggleLookup: { kind: 'button', buttonIndex: 0 },
|
||
closeLookup: { kind: 'button', buttonIndex: 1 },
|
||
mineCard: { kind: 'button', buttonIndex: 2 },
|
||
toggleKeyboardOnlyMode: { kind: 'button', buttonIndex: 3 },
|
||
};
|
||
|
||
const form = renderForm(null, { bindings, mapping: 'standard', faceButtonLabels: 'nintendo' });
|
||
assert.equal(badge(form.row('Toggle Lookup')), 'B');
|
||
assert.equal(badge(form.row('Close Lookup')), 'A');
|
||
assert.equal(badge(form.row('Mine Card')), 'Y');
|
||
assert.equal(badge(form.row('Toggle Keyboard-Only Mode')), 'X');
|
||
// Non-face buttons keep their names.
|
||
assert.equal(badge(form.row('Next Audio')), 'RB / R1');
|
||
});
|
||
|
||
type ReviewFormOptions = {
|
||
reviewBindings?: ResolvedControllerConfig['reviewBindings'];
|
||
fieldGroupingBindings?: ResolvedControllerConfig['fieldGroupingBindings'];
|
||
learning?: ControllerScreenLearning | null;
|
||
faceButtonLabels?: ControllerFaceButtonLabels;
|
||
};
|
||
|
||
/** Renders the form with the dialog groups; `act` runs while `document` is still stubbed. */
|
||
function withReviewForm(
|
||
options: ReviewFormOptions,
|
||
act: (env: {
|
||
calls: string[];
|
||
container: FakeElement;
|
||
reviewRow: (label: string) => FakeElement;
|
||
}) => void,
|
||
): void {
|
||
const previousDocument = Object.getOwnPropertyDescriptor(globalThis, 'document');
|
||
Object.defineProperty(globalThis, 'document', {
|
||
configurable: true,
|
||
value: { createElement: () => new FakeElement() },
|
||
});
|
||
try {
|
||
const calls: string[] = [];
|
||
const container = new FakeElement();
|
||
createControllerConfigForm({
|
||
container: container as unknown as HTMLElement,
|
||
getBindings: () => BINDINGS,
|
||
getLearningActionId: () => null,
|
||
getDpadLearningActionId: () => null,
|
||
onLearn: () => {},
|
||
onClear: () => {},
|
||
onReset: () => {},
|
||
onDpadLearn: () => {},
|
||
onDpadClear: () => {},
|
||
onDpadReset: () => {},
|
||
getScreenGroups: () => {
|
||
const bindings = {
|
||
reviewBindings: options.reviewBindings ?? getDefaultControllerReviewBindings(),
|
||
fieldGroupingBindings:
|
||
options.fieldGroupingBindings ?? getDefaultControllerFieldGroupingBindings(),
|
||
};
|
||
return CONTROLLER_SCREENS.map((screen) => ({
|
||
screen,
|
||
bindings: bindings[screen.configKey],
|
||
}));
|
||
},
|
||
getScreenInputContext: () => ({
|
||
mapping: 'standard',
|
||
faceButtonLabels: options.faceButtonLabels ?? 'xbox',
|
||
buttonIndices: CORE_DEFAULT_CONFIG.controller.buttonIndices,
|
||
}),
|
||
getScreenLearning: () => options.learning ?? null,
|
||
onScreenLearn: (screenId, actionId) => calls.push(`learn:${screenId}:${actionId}`),
|
||
onScreenClear: (screenId, actionId) => calls.push(`clear:${screenId}:${actionId}`),
|
||
onScreenReset: (screenId, actionId) => calls.push(`reset:${screenId}:${actionId}`),
|
||
onScreenResetAll: (screenId) => calls.push(`resetAll:${screenId}`),
|
||
}).render();
|
||
const reviewRow = (label: string) => {
|
||
const match = findAll(container, 'controller-config-row').find(
|
||
(el) => findOne(el, 'controller-config-label').textContent === label,
|
||
);
|
||
assert.ok(match, `missing row "${label}"`);
|
||
return match;
|
||
};
|
||
act({ calls, container, reviewRow });
|
||
} finally {
|
||
if (previousDocument) {
|
||
Object.defineProperty(globalThis, 'document', previousDocument);
|
||
} else {
|
||
Reflect.deleteProperty(globalThis, 'document');
|
||
}
|
||
}
|
||
}
|
||
|
||
const badgeOf = (row: FakeElement) => findOne(row, 'controller-config-badge').textContent;
|
||
|
||
test('controller config form keeps the review group collapsed until opened', () => {
|
||
withReviewForm({}, ({ calls, container, reviewRow }) => {
|
||
const header = findOne(container, 'controller-config-group-toggle');
|
||
assert.match(header.textContent, /Review media timing/);
|
||
assert.equal(
|
||
findAll(container, 'controller-config-subgroup').length,
|
||
0,
|
||
'collapsed group shows no rows',
|
||
);
|
||
|
||
header.click();
|
||
assert.deepEqual(
|
||
findAll(container, 'controller-config-subgroup').map((el) => el.textContent),
|
||
['While editing', 'After Cancel'],
|
||
);
|
||
assert.equal(badgeOf(reviewRow('Use this timing')), 'A');
|
||
assert.equal(badgeOf(reviewRow('Earlier −2s')), 'D-pad ◀');
|
||
assert.equal(badgeOf(reviewRow('Start +0.1s')), 'L1 + D-pad ▶');
|
||
assert.equal(badgeOf(reviewRow('Reset screenshot frame')), 'L1 + R1');
|
||
assert.equal(badgeOf(reviewRow('Keep editing')), 'B');
|
||
|
||
findOne(container, 'controller-config-group-action', 'Reset all').click();
|
||
findOne(reviewRow('Start +0.1s'), 'controller-config-edit-icon').click();
|
||
findOne(reviewRow('Start +0.1s'), 'controller-config-reset-icon').click();
|
||
assert.deepEqual(calls, [
|
||
'resetAll:review',
|
||
'learn:review:startForward',
|
||
'reset:review:startForward',
|
||
]);
|
||
});
|
||
});
|
||
|
||
test('controller config form shows the hold button while a review combo is being learned', () => {
|
||
withReviewForm(
|
||
{ learning: { screenId: 'review', actionId: 'startForward', holdLabel: 'L2' } },
|
||
({ container, reviewRow }) => {
|
||
assert.equal(badgeOf(reviewRow('Start +0.1s')), 'L2 + …');
|
||
assert.match(
|
||
findOne(container, 'controller-config-edit-hint').textContent,
|
||
/Holding L2: press another button for a combo, or let go to use L2 alone/,
|
||
);
|
||
},
|
||
);
|
||
});
|
||
|
||
test('controller config form warns about review bindings that clash', () => {
|
||
const reviewBindings = {
|
||
...getDefaultControllerReviewBindings(),
|
||
play: {
|
||
kind: 'combo' as const,
|
||
press: { kind: 'face' as const, letter: 'a' as const },
|
||
hold: null,
|
||
},
|
||
};
|
||
withReviewForm({ reviewBindings }, ({ container, reviewRow }) => {
|
||
findOne(container, 'controller-config-group-toggle').click();
|
||
const warnings = findAll(container, 'controller-config-warning').map((el) => el.textContent);
|
||
assert.deepEqual(warnings, ['⚠ Same as Play selection', '⚠ Same as Use this timing']);
|
||
assert.equal(reviewRow('Play selection').classList.contains('has-warning'), true);
|
||
});
|
||
});
|
||
|
||
test('controller config form warns when main actions share an input', () => {
|
||
const { container, row } = renderForm(null, {
|
||
bindings: { ...BINDINGS, nextSubtitle: { kind: 'button', buttonIndex: 15 } },
|
||
mapping: 'standard',
|
||
});
|
||
|
||
assert.deepEqual(
|
||
findAll(container, 'controller-config-warning').map((el) => el.textContent),
|
||
['\u26a0 Same as Token Move (D-pad)', '\u26a0 Same as Next Subtitle'],
|
||
);
|
||
assert.equal(row('Next Subtitle').classList.contains('has-warning'), true);
|
||
assert.equal(row('Token Move (D-pad)').classList.contains('has-warning'), true);
|
||
assert.equal(row('Next Audio').classList.contains('has-warning'), false);
|
||
});
|
||
|
||
test('an edit panel slides in when it opens, not each time the list is redrawn', () => {
|
||
withReviewForm({}, ({ container, reviewRow }) => {
|
||
const panel = () => findOne(container, 'controller-config-edit-panel');
|
||
const kept = () => panel().classList.contains('controller-config-edit-panel-kept');
|
||
|
||
reviewRow('Toggle Lookup').click();
|
||
assert.equal(kept(), false, 'opening animates');
|
||
|
||
// Any other click redraws the whole list; the open panel is recreated as it was.
|
||
findOne(container, 'controller-config-group-toggle').click();
|
||
assert.equal(kept(), true);
|
||
|
||
reviewRow('Toggle Lookup').click();
|
||
assert.deepEqual(findAll(container, 'controller-config-edit-panel'), []);
|
||
reviewRow('Toggle Lookup').click();
|
||
assert.equal(kept(), false, 'reopening animates again');
|
||
|
||
reviewRow('Close Lookup').click();
|
||
assert.equal(kept(), false, 'another row opening animates');
|
||
});
|
||
});
|
||
|
||
/** The dialog group headers, in order. */
|
||
const groupHeaders = (container: FakeElement) =>
|
||
findAll(container, 'controller-config-group-toggle');
|
||
|
||
test('controller config form lists the duplicate card layout as its own group', () => {
|
||
withReviewForm({}, ({ calls, container, reviewRow }) => {
|
||
const headers = groupHeaders(container);
|
||
assert.deepEqual(
|
||
headers.map((el) => el.textContent.replace(/Reset all$/, '')),
|
||
['▸ Review media timing', '▸ Duplicate card (field grouping)'],
|
||
);
|
||
|
||
headers[1]!.click();
|
||
assert.deepEqual(
|
||
findAll(container, 'controller-config-subgroup').map((el) => el.textContent),
|
||
['Choosing the card', 'Merge preview'],
|
||
'only the opened group shows rows',
|
||
);
|
||
assert.equal(badgeOf(reviewRow('Original card')), 'D-pad ◀');
|
||
assert.equal(badgeOf(reviewRow('New card')), 'D-pad ▶');
|
||
assert.equal(badgeOf(reviewRow('Delete duplicate on/off')), 'X');
|
||
assert.equal(badgeOf(reviewRow('Continue')), 'A');
|
||
assert.equal(badgeOf(reviewRow('Confirm merge')), 'A');
|
||
assert.equal(badgeOf(reviewRow('Back')), 'B');
|
||
assert.equal(badgeOf(reviewRow('Compact / Full')), 'Y');
|
||
assert.equal(badgeOf(reviewRow('Scroll down')), 'D-pad ▼');
|
||
// Cancel on the preview is unbound by default (B goes back, B again cancels).
|
||
const cancels = findAll(container, 'controller-config-row').filter(
|
||
(el) => findOne(el, 'controller-config-label').textContent === 'Cancel',
|
||
);
|
||
assert.deepEqual(cancels.map(badgeOf), ['B', 'None']);
|
||
assert.equal(findAll(container, 'controller-config-warning').length, 0);
|
||
|
||
findOne(container, 'controller-config-group-action', 'Reset all').click();
|
||
findOne(reviewRow('Continue'), 'controller-config-edit-icon').click();
|
||
assert.deepEqual(calls, ['resetAll:fieldGrouping', 'learn:fieldGrouping:continue']);
|
||
});
|
||
});
|
||
|
||
test('learning a duplicate card action opens only that group', () => {
|
||
withReviewForm(
|
||
{ learning: { screenId: 'fieldGrouping', actionId: 'back', holdLabel: null } },
|
||
({ container }) => {
|
||
const headers = groupHeaders(container);
|
||
assert.equal(headers[0]!.getAttribute('aria-expanded'), 'false');
|
||
assert.equal(headers[1]!.getAttribute('aria-expanded'), 'true');
|
||
assert.match(
|
||
findOne(container, 'controller-config-edit-hint').textContent,
|
||
/Press a button, or hold one and press another for a combo/,
|
||
);
|
||
},
|
||
);
|
||
});
|
||
|
||
test('controller config form names face buttons with PlayStation symbols when configured', () => {
|
||
const badge = (row: FakeElement) => findOne(row, 'controller-config-badge').textContent;
|
||
const bindings: typeof BINDINGS = {
|
||
...BINDINGS,
|
||
toggleLookup: { kind: 'button', buttonIndex: 0 },
|
||
closeLookup: { kind: 'button', buttonIndex: 1 },
|
||
mineCard: { kind: 'button', buttonIndex: 2 },
|
||
toggleKeyboardOnlyMode: { kind: 'button', buttonIndex: 3 },
|
||
};
|
||
|
||
const form = renderForm(null, { bindings, mapping: 'standard', faceButtonLabels: 'playstation' });
|
||
assert.equal(badge(form.row('Toggle Lookup')), '╳');
|
||
assert.equal(badge(form.row('Close Lookup')), '○');
|
||
assert.equal(badge(form.row('Mine Card')), '□');
|
||
assert.equal(badge(form.row('Toggle Keyboard-Only Mode')), '△');
|
||
assert.equal(badge(form.row('Next Audio')), 'RB / R1');
|
||
|
||
// The dialog groups print the same symbols.
|
||
withReviewForm({ faceButtonLabels: 'playstation' }, ({ container, reviewRow }) => {
|
||
findOne(container, 'controller-config-group-toggle').click();
|
||
assert.equal(badgeOf(reviewRow('Use this timing')), '╳');
|
||
assert.equal(badgeOf(reviewRow('Keep editing')), '○');
|
||
assert.equal(badgeOf(reviewRow('Play selection')), '□');
|
||
assert.equal(badgeOf(reviewRow('Reset timing')), '△');
|
||
});
|
||
});
|