Files
feuerwerk/tests/editor/project-settings.test.ts
T
adminandClaude Opus 5.5 c88f57cf0a
game-maker / gate (push) Successful in 2m52s
game-maker / suite (push) Successful in 14m31s
Let a project choose how its game link is zoomed (#279)
The page of a released game always drew the camera at Auto, the
largest whole step that fits. A camera of 300x180 in a window of
1280x800 stands at step 4 and leaves a border left and right. The
issue asks for Fit next to it. Answered there: a setting of its own
rather than the scale of the Game tab, and no switch for the player.

- The project has a field gameLinkZoom, 'auto' or 'fit'. A document
  without it reads as 'auto', so nothing changes for a project that
  is there already. No format bump.
- Project settings has a row "Link zoom" with a menu of Auto and
  Fit. It is an undo step of its own, SetGameLinkZoomCommand.
- GameScreen hands the field to cameraView where it passed a fixed
  'auto'.
- gameScale, the scale of the Game tab, is not touched and does not
  reach the link.
- The released copy is frozen, so the change reaches the link only
  with "Update release".

Decided here:

- The row is called "Link zoom", not "Game link zoom" as proposed.
  The longer label is wider than the label column of the dialog and
  pushed its button 12 px out of line with the others.
- The undo step keeps the name "Game link zoom", which is what the
  tooltip of the undo button shows.
- A note under the row says "The released game at the largest whole
  step that fits, or filling the window."

Tests:
- Gate on melektaus-atx: 211 files, 3227 tests (3219 + 8), exit 0
- e2e 60 on melektaus-atx: 19 checks, all pass
- e2e 35,46,59,60: 74 checks, all pass
- No full run and no smokes. The sum of 1671 (1668 + 3) is reckoned,
  1668 is what CI counted for 9e869df.
- Eight unit tests: the default, saving and loading, values that
  are not a choice, undo, gameScale left alone, the factor of Fit
  for a window larger and smaller than the camera, and the rule
  behind Apply.
- Three e2e checks in block 60i of module 60, with the real mouse:
  Auto to Fit in the dialog, update the release, open the link
  without a session and measure scale, frame and pixels. Fit reads
  4.267 where Auto reads 4.
- Nine unit counter-probes and three browser counter-probes all fail
  their tests.
- Not checked in the browser: Fit in a window smaller than the
  camera, which has a unit test, and Fit under a display scale above
  100 %. Nothing was looked at after the build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 13:53:10 +02:00

73 lines
3.4 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',
whilePlaying: 'balanced',
gameLinkZoom: 'auto',
collisionLayers: ['Default', 'Enemies'],
symbolScale: 1,
};
describe('project settings', () => {
it('reports nothing to do when nothing was touched', () => {
expect(settingsChanges(before, { ...before, collisionLayers: ['Default', 'Enemies'] })).toEqual({});
});
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('writes the symbol scale only when it changed, kept inside 0.1 to 4', () => {
expect(settingsChanges(before, { ...before, symbolScale: 1 }).symbolScale).toBeUndefined();
expect(settingsChanges(before, { ...before, symbolScale: 0.5 }).symbolScale).toBe(0.5);
expect(settingsChanges(before, { ...before, symbolScale: 0.01 }).symbolScale).toBe(0.1);
expect(settingsChanges(before, { ...before, symbolScale: 9 }).symbolScale).toBe(4);
expect(settingsChanges(before, { ...before, symbolScale: Number.NaN }).symbolScale).toBeUndefined();
});
it('writes the start-scene switch only when it changed (#226)', () => {
expect(settingsChanges(before, { ...before, playFrom: 'active' }).playFrom).toBe('active');
expect(settingsChanges(before, { ...before, playFrom: 'start' }).playFrom).toBeUndefined();
});
it('writes the While playing preset only when it changed (#265)', () => {
expect(settingsChanges(before, { ...before, whilePlaying: 'live' }).whilePlaying).toBe('live');
expect(settingsChanges(before, { ...before, whilePlaying: 'balanced' }).whilePlaying).toBeUndefined();
});
it('writes the zoom of the game link only when it changed (#279)', () => {
expect(settingsChanges(before, { ...before, gameLinkZoom: 'fit' }).gameLinkZoom).toBe('fit');
expect(settingsChanges(before, { ...before, gameLinkZoom: 'auto' }).gameLinkZoom).toBeUndefined();
});
});