fix(studio): lint and test fixes: zoom bar labels without the studio object, tile zooms in a helper, tests without non-null assertions or the window toast

This commit is contained in:
Maurice
2026-10-24 10:07:26 +02:00
parent 44ea1ea0ba
commit 92be8a7ca5
6 changed files with 38 additions and 27 deletions
@@ -2,6 +2,10 @@ import { act, render } from '@testing-library/react';
import { MAX_SPREAD_ELEMENTS, type BookDocument, type BookElement, type BookSpread } from '@trek/shared';
import { beforeEach, describe, expect, it, vi } from 'vitest';
const toast = vi.hoisted(() => ({ warning: vi.fn() }));
vi.mock('../../../src/components/shared/Toast', () => ({ useToast: () => toast }));
vi.mock('../../../src/i18n', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
import { StudioNotices } from '../../../src/components/Studio/StudioNotices';
import { useStudioStore } from '../../../src/store/studioStore';
@@ -56,7 +60,7 @@ beforeEach(() => {
describe('a full page', () => {
it('FE-STUDIO-FULL-001: refuses one more element and counts the refusal', () => {
expect(store().addElement(0, el('extra'))).toBe(false);
expect(store().doc!.spreads[0].elements).toHaveLength(MAX_SPREAD_ELEMENTS);
expect(store().doc?.spreads[0]?.elements).toHaveLength(MAX_SPREAD_ELEMENTS);
expect(store().refusedFull).toBe(1);
expect(store().addElement(1, el('fits'))).toBe(true);
expect(store().refusedFull).toBe(1);
@@ -65,25 +69,24 @@ describe('a full page', () => {
it('FE-STUDIO-FULL-002: a paste onto it is refused and counted', () => {
useStudioStore.setState({ clipboard: { fromSpreadId: 'room', elements: [el('a')] } });
store().paste(0);
expect(store().doc!.spreads[0].elements).toHaveLength(MAX_SPREAD_ELEMENTS);
expect(store().doc?.spreads[0]?.elements).toHaveLength(MAX_SPREAD_ELEMENTS);
expect(store().refusedFull).toBe(1);
});
it('FE-STUDIO-FULL-003: a duplicate on it is refused and counted', () => {
store().duplicate(0, ['f0']);
expect(store().doc!.spreads[0].elements).toHaveLength(MAX_SPREAD_ELEMENTS);
expect(store().doc?.spreads[0]?.elements).toHaveLength(MAX_SPREAD_ELEMENTS);
expect(store().refusedFull).toBe(1);
});
it('FE-STUDIO-FULL-004: the Studio says it once per refusal', () => {
const addToast = vi.fn();
window.__addToast = addToast;
toast.warning.mockClear();
render(<StudioNotices />);
expect(addToast).not.toHaveBeenCalled();
expect(toast.warning).not.toHaveBeenCalled();
act(() => store().refuseFull());
expect(addToast).toHaveBeenCalledTimes(1);
expect(addToast.mock.calls[0][1]).toBe('warning');
expect(toast.warning).toHaveBeenCalledTimes(1);
expect(toast.warning).toHaveBeenLastCalledWith('journey.studio.pageFull');
act(() => store().refuseFull());
expect(addToast).toHaveBeenCalledTimes(2);
expect(toast.warning).toHaveBeenCalledTimes(2);
});
});