40 lines
2.0 KiB
JavaScript
40 lines
2.0 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { readFile } from 'node:fs/promises';
|
|
import test from 'node:test';
|
|
|
|
import {
|
|
getImageAddMode,
|
|
isFitOnAddEnabled,
|
|
} from '../js/utils/canvas_input_utils.js';
|
|
|
|
const [canvasIOSource, canvasViewSource, interactionsSource, inputUtilsSource] = await Promise.all([
|
|
readFile(new URL('../src/io/canvas_io.ts', import.meta.url), 'utf8'),
|
|
readFile(new URL('../src/app/canvas_view.ts', import.meta.url), 'utf8'),
|
|
readFile(new URL('../src/canvas/canvas_interactions.ts', import.meta.url), 'utf8'),
|
|
readFile(new URL('../src/utils/canvas_input_utils.ts', import.meta.url), 'utf8'),
|
|
]);
|
|
|
|
test('image entry points use the shared fit_on_add policy', () => {
|
|
assert.match(inputUtilsSource, /export function isFitOnAddEnabled\(/);
|
|
assert.match(inputUtilsSource, /export function getImageAddMode\(/);
|
|
assert.equal((canvasIOSource.match(/getImageAddMode\(this/g) ?? []).length, 3);
|
|
assert.equal((canvasIOSource.match(/isFitOnAddEnabled\(this/g) ?? []).length, 2);
|
|
assert.equal((canvasViewSource.match(/getImageAddMode\(node/g) ?? []).length, 2);
|
|
assert.equal((interactionsSource.match(/getImageAddMode\(this/g) ?? []).length, 1);
|
|
assert.doesNotMatch(canvasIOSource, /find\(.*fit_on_add/);
|
|
assert.doesNotMatch(canvasViewSource, /find\(.*fit_on_add/);
|
|
assert.doesNotMatch(interactionsSource, /find\(.*fit_on_add/);
|
|
});
|
|
|
|
test('shared fit_on_add helper preserves fit and center behavior', () => {
|
|
assert.equal(isFitOnAddEnabled([{ name: 'fit_on_add', value: true }]), true);
|
|
assert.equal(isFitOnAddEnabled([{ name: 'fit_on_add', value: false }]), false);
|
|
assert.equal(isFitOnAddEnabled([{ name: 'fit_on_add', value: 1 }]), true);
|
|
assert.equal(isFitOnAddEnabled([{ name: 'other', value: true }]), false);
|
|
assert.equal(isFitOnAddEnabled(undefined), false);
|
|
|
|
assert.equal(getImageAddMode([{ name: 'fit_on_add', value: true }]), 'fit');
|
|
assert.equal(getImageAddMode([{ name: 'fit_on_add', value: false }]), 'center');
|
|
assert.equal(getImageAddMode(undefined), 'center');
|
|
});
|