54 lines
2.3 KiB
TypeScript
54 lines
2.3 KiB
TypeScript
/**
|
||
* What "Apply" in the Project settings dialog (#183) actually carries out. The dialog itself is a
|
||
* widget and needs a canvas; the rule behind it is a pure function and is tested here.
|
||
*/
|
||
import { describe, expect, it } from 'vitest';
|
||
import { settingsChanges, type ProjectSettings } from '../../src/editor/ProjectSettingsDialog';
|
||
|
||
const before: ProjectSettings = {
|
||
name: 'Demo project',
|
||
playFrom: 'start',
|
||
collisionLayers: ['Default', 'Enemies'],
|
||
};
|
||
|
||
describe('project settings', () => {
|
||
it('reports nothing to do when nothing was touched', () => {
|
||
expect(settingsChanges(before, { ...before, collisionLayers: ['Default', 'Enemies'] })).toEqual({
|
||
playFrom: 'start',
|
||
});
|
||
});
|
||
|
||
it('renames only when the name really differs', () => {
|
||
expect(settingsChanges(before, { ...before, name: 'Tetris' }).name).toBe('Tetris');
|
||
expect(settingsChanges(before, { ...before, name: 'Demo project' }).name).toBeUndefined();
|
||
});
|
||
|
||
it('trims the name and keeps the old one when only blanks are left', () => {
|
||
expect(settingsChanges(before, { ...before, name: ' Tetris ' }).name).toBe('Tetris');
|
||
expect(settingsChanges(before, { ...before, name: ' ' }).name).toBeUndefined();
|
||
});
|
||
|
||
it('writes the layers when one was added, renamed or dropped', () => {
|
||
const changed = (layers: string[]) => settingsChanges(before, { ...before, collisionLayers: layers });
|
||
expect(changed(['Default', 'Enemies', 'Pickups']).collisionLayers).toEqual([
|
||
'Default',
|
||
'Enemies',
|
||
'Pickups',
|
||
]);
|
||
expect(changed(['Default', 'Foes']).collisionLayers).toEqual(['Default', 'Foes']);
|
||
expect(changed(['Default']).collisionLayers).toEqual(['Default']);
|
||
});
|
||
|
||
it('hands back a copy of the layers, not the array the dialog goes on editing', () => {
|
||
const edited = ['Default', 'Foes'];
|
||
const change = settingsChanges(before, { ...before, collisionLayers: edited });
|
||
edited.push('Later');
|
||
expect(change.collisionLayers).toEqual(['Default', 'Foes']);
|
||
});
|
||
|
||
it('always reports the start-scene switch – it is a preference, not an undo step', () => {
|
||
expect(settingsChanges(before, { ...before, playFrom: 'active' }).playFrom).toBe('active');
|
||
expect(settingsChanges(before, { ...before, playFrom: 'start' }).playFrom).toBe('start');
|
||
});
|
||
});
|