diff --git a/packages/core/src/plugins/with-selection.spec.ts b/packages/core/src/plugins/with-selection.spec.ts index b32f28cb2..e415580f5 100644 --- a/packages/core/src/plugins/with-selection.spec.ts +++ b/packages/core/src/plugins/with-selection.spec.ts @@ -1,6 +1,6 @@ import { fakeAsync, tick } from '@angular/core/testing'; import { PlaitBoard, PlaitElement, PlaitPointerType } from '../interfaces'; -import { clearBoardElementHost, clearNodeWeakMap, createTestingBoard, fakeBoardElementHost, fakeNodeWeakMap } from '../testing'; +import { setupTestingBoard, TestingBoardFixture } from '../testing'; import { Transforms } from '../transforms'; import { cacheSelectedElements, createG, getSelectedElements } from '../utils'; import { withOptions } from './with-options'; @@ -12,31 +12,29 @@ const children: PlaitElement[] = [ ]; describe('withSelection', () => { - let board: PlaitBoard; let activeHost: SVGGElement; let drawSelectionRectangle: jasmine.Spy; + let fixture: TestingBoardFixture; beforeEach(() => { - board = createTestingBoard([withOptions, withSelection], children); - fakeNodeWeakMap(board); - activeHost = fakeBoardElementHost(board).activeHost; + fixture = setupTestingBoard([withOptions, withSelection], children); + activeHost = PlaitBoard.getActiveHost(fixture.board); drawSelectionRectangle = jasmine.createSpy('drawSelectionRectangle').and.callFake(() => createG()); - board.drawSelectionRectangle = drawSelectionRectangle; + fixture.board.drawSelectionRectangle = drawSelectionRectangle; }); afterEach(() => { - clearNodeWeakMap(board); - clearBoardElementHost(board); + fixture.destroy(); }); it('should refresh the multi-selection rectangle after viewport changes in hand mode', fakeAsync(() => { - cacheSelectedElements(board, children); - board.afterChange(); + cacheSelectedElements(fixture.board, children); + fixture.board.afterChange(); const initialRectangle = activeHost.firstElementChild; expect(activeHost.contains(initialRectangle)).toBeTrue(); - board.pointer = PlaitPointerType.hand; - Transforms.setViewport(board, { zoom: 1, origination: [10, 10] }); + fixture.board.pointer = PlaitPointerType.hand; + Transforms.setViewport(fixture.board, { zoom: 1, origination: [10, 10] }); tick(); expect(drawSelectionRectangle).toHaveBeenCalledTimes(2); @@ -46,15 +44,15 @@ describe('withSelection', () => { })); it('should not update selected elements from selection operations in hand mode', fakeAsync(() => { - cacheSelectedElements(board, children); - board.pointer = PlaitPointerType.hand; + cacheSelectedElements(fixture.board, children); + fixture.board.pointer = PlaitPointerType.hand; - Transforms.setSelection(board, { + Transforms.setSelection(fixture.board, { anchor: [100, 100], focus: [100, 100] }); tick(); - expect(getSelectedElements(board)).toEqual(children); + expect(getSelectedElements(fixture.board)).toEqual(children); })); }); diff --git a/packages/core/src/testing/core/create-board.ts b/packages/core/src/testing/core/create-board.ts deleted file mode 100644 index a512274fb..000000000 --- a/packages/core/src/testing/core/create-board.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { PlaitBoardOptions, PlaitElement, PlaitPlugin } from '../../interfaces'; -import { createBoard } from '../../plugins/create-board'; -import { KEY_TO_ELEMENT_MAP } from '../../utils'; - -/** - * 1.create board instance - * 2.build fake node weak map - */ -export const createTestingBoard = ( - plugins: PlaitPlugin[], - children: PlaitElement[], - options: PlaitBoardOptions = { readonly: false, hideScrollbar: true, disabledScrollOnNonFocus: false } -) => { - let board = createBoard(children, options); - plugins.forEach((plugin) => { - board = plugin(board); - }); - KEY_TO_ELEMENT_MAP.set(board, new Map()); - return board; -}; diff --git a/packages/core/src/testing/core/fake-weak-map.ts b/packages/core/src/testing/core/fake-weak-map.ts deleted file mode 100644 index 8ea59053f..000000000 --- a/packages/core/src/testing/core/fake-weak-map.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { PlaitBoard } from '../../interfaces/board'; -import { PlaitNode } from '../../interfaces/node'; -import { createG } from '../../utils/dom/common'; -import { BOARD_TO_ELEMENT_HOST, NODE_TO_INDEX, NODE_TO_PARENT } from '../../utils/weak-maps'; - -export const fakeNodeWeakMap = (object: PlaitNode | PlaitBoard) => { - const children = object.children || []; - children.forEach((value, index: number) => { - NODE_TO_PARENT.set(value, object); - NODE_TO_INDEX.set(value, index); - fakeNodeWeakMap(value); - }); -}; - -export const clearNodeWeakMap = (object: PlaitNode | PlaitBoard) => { - const children = object.children || []; - children.forEach((value) => { - NODE_TO_PARENT.delete(value); - NODE_TO_INDEX.delete(value); - clearNodeWeakMap(value); - }); -}; - -export const fakeBoardElementHost = (board: PlaitBoard) => { - const elementHost = { - lowerHost: createG(), - host: createG(), - upperHost: createG(), - topHost: createG(), - activeHost: createG(), - container: document.createElement('div'), - viewportContainer: document.createElement('div') - }; - BOARD_TO_ELEMENT_HOST.set(board, elementHost); - return elementHost; -}; - -export const clearBoardElementHost = (board: PlaitBoard) => { - BOARD_TO_ELEMENT_HOST.delete(board); -}; diff --git a/packages/core/src/testing/core/index.ts b/packages/core/src/testing/core/index.ts deleted file mode 100644 index a5d8c1dee..000000000 --- a/packages/core/src/testing/core/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './create-board'; -export * from './fake-weak-map'; diff --git a/packages/core/src/testing/fixture/index.ts b/packages/core/src/testing/fixture/index.ts new file mode 100644 index 000000000..626f5a69d --- /dev/null +++ b/packages/core/src/testing/fixture/index.ts @@ -0,0 +1,3 @@ +export * from './mock-board'; +export * from './mock-host'; +export * from './mock-weak-map'; diff --git a/packages/core/src/testing/fixture/mock-board.ts b/packages/core/src/testing/fixture/mock-board.ts new file mode 100644 index 000000000..04bb146c5 --- /dev/null +++ b/packages/core/src/testing/fixture/mock-board.ts @@ -0,0 +1,104 @@ +import { PlaitBoard, PlaitBoardOptions, PlaitElement, PlaitPlugin } from '../../interfaces'; +import { createBoard } from '../../plugins/create-board'; +import { cacheSelectedElements, KEY_TO_ELEMENT_MAP } from '../../utils'; +import { IS_BOARD_ALIVE } from '../../utils/weak-maps'; +import { + clearBoardElementHost, + clearBoardHost, + clearBoardRoughSVG, + fakeBoardElementHost, + fakeBoardHost, + fakeBoardRoughSVG +} from './mock-host'; +import { clearNodeWeakMap, clearNodeWeakMapByNodes, fakeNodeWeakMap } from './mock-weak-map'; + +export interface TestingBoardFixture { + board: PlaitBoard; + destroy: () => void; +} + +/** + * 1.create board instance + * 2.build fake node weak map + */ +export const createTestingBoard = ( + plugins: PlaitPlugin[], + children: PlaitElement[], + options: PlaitBoardOptions = { readonly: false, hideScrollbar: true, disabledScrollOnNonFocus: false } +) => { + let board = createBoard(children, options); + plugins.forEach((plugin) => { + board = plugin(board); + }); + KEY_TO_ELEMENT_MAP.set(board, new Map()); + return board; +}; + +export interface SetupTestingBoardOptions { + boardOptions?: PlaitBoardOptions; + selectedElements?: any[]; + withNodeWeakMap?: boolean; + withElementHost?: boolean; + withHost?: boolean; + withRoughSVG?: boolean; + alive?: boolean; +} + +export const setupTestingBoard = ( + plugins: PlaitPlugin[], + children: PlaitElement[], + options: SetupTestingBoardOptions = {} +): TestingBoardFixture => { + const { + boardOptions, + selectedElements, + withNodeWeakMap = true, + withElementHost = true, + withHost = true, + withRoughSVG = false, + alive = true + } = options; + + const board = createTestingBoard(plugins as PlaitPlugin[], children as PlaitElement[], boardOptions); + const initialChildren = board.children; + + if (withNodeWeakMap) { + fakeNodeWeakMap(board); + } + if (withElementHost) { + fakeBoardElementHost(board); + } + if (withHost) { + fakeBoardHost(board); + } + if (withRoughSVG) { + fakeBoardRoughSVG(board); + } + if (selectedElements) { + cacheSelectedElements(board, selectedElements as PlaitElement[]); + } + if (alive) { + IS_BOARD_ALIVE.set(board, true); + } + + const destroy = () => { + if (withNodeWeakMap) { + clearNodeWeakMapByNodes(initialChildren); + clearNodeWeakMap(board); + } + if (withElementHost) { + clearBoardElementHost(board); + } + if (withHost) { + clearBoardHost(board); + } + if (withRoughSVG) { + clearBoardRoughSVG(board); + } + if (alive) { + IS_BOARD_ALIVE.delete(board); + } + }; + + return { board, destroy }; +}; diff --git a/packages/core/src/testing/fixture/mock-host.ts b/packages/core/src/testing/fixture/mock-host.ts new file mode 100644 index 000000000..9087771f1 --- /dev/null +++ b/packages/core/src/testing/fixture/mock-host.ts @@ -0,0 +1,70 @@ +import { RoughSVG } from 'roughjs/bin/svg'; +import { PlaitBoard } from '../../interfaces/board'; +import { createG, createSVG } from '../../utils/dom/common'; +import { BOARD_TO_ELEMENT_HOST, BOARD_TO_HOST, BOARD_TO_ROUGH_SVG } from '../../utils/weak-maps'; + +export const fakeBoardElementHost = (board: PlaitBoard) => { + const elementHost = { + lowerHost: createG(), + host: createG(), + upperHost: createG(), + topHost: createG(), + activeHost: createG(), + container: document.createElement('div'), + viewportContainer: document.createElement('div') + }; + BOARD_TO_ELEMENT_HOST.set(board, elementHost); + return elementHost; +}; + +export const clearBoardElementHost = (board: PlaitBoard) => { + BOARD_TO_ELEMENT_HOST.delete(board); +}; + +export const fakeBoardHost = (board: PlaitBoard) => { + const host = createSVG(); + host.setAttribute('viewBox', '0 0 1000 1000'); + Object.defineProperty(host, 'getBoundingClientRect', { + value: () => + ({ + x: 0, + y: 0, + width: 1000, + height: 1000, + top: 0, + right: 1000, + bottom: 1000, + left: 0 + } as DOMRect) + }); + BOARD_TO_HOST.set(board as PlaitBoard, host); + return host; +}; + +export const clearBoardHost = (board: PlaitBoard) => { + BOARD_TO_HOST.delete(board); +}; + +export const createTestingRoughSVG = () => { + const roughSVG = { + path: () => createG(), + polygon: () => createG(), + circle: () => createG(), + ellipse: () => createG(), + line: () => createG(), + curve: () => createG(), + rectangle: () => createG(), + linearPath: () => createG() + }; + return roughSVG as unknown as RoughSVG; +}; + +export const fakeBoardRoughSVG = (board: PlaitBoard) => { + const roughSVG = createTestingRoughSVG(); + BOARD_TO_ROUGH_SVG.set(board, roughSVG); + return roughSVG; +}; + +export const clearBoardRoughSVG = (board: PlaitBoard) => { + BOARD_TO_ROUGH_SVG.delete(board); +}; diff --git a/packages/core/src/testing/fixture/mock-weak-map.ts b/packages/core/src/testing/fixture/mock-weak-map.ts new file mode 100644 index 000000000..b2e898b58 --- /dev/null +++ b/packages/core/src/testing/fixture/mock-weak-map.ts @@ -0,0 +1,25 @@ +import { PlaitBoard } from '../../interfaces/board'; +import { PlaitNode } from '../../interfaces/node'; +import { NODE_TO_INDEX, NODE_TO_PARENT } from '../../utils/weak-maps'; + +export const fakeNodeWeakMap = (object: PlaitNode | PlaitBoard) => { + const children = object.children || []; + children.forEach((value, index: number) => { + NODE_TO_PARENT.set(value, object); + NODE_TO_INDEX.set(value, index); + fakeNodeWeakMap(value); + }); +}; + +export const clearNodeWeakMap = (object: PlaitNode | PlaitBoard) => { + const children = object.children || []; + clearNodeWeakMapByNodes(children); +}; + +export const clearNodeWeakMapByNodes = (nodes: PlaitNode[]) => { + nodes.forEach((value) => { + NODE_TO_PARENT.delete(value); + NODE_TO_INDEX.delete(value); + clearNodeWeakMap(value); + }); +}; diff --git a/packages/core/src/testing/index.ts b/packages/core/src/testing/index.ts index 8dd94ef46..412389f2f 100644 --- a/packages/core/src/testing/index.ts +++ b/packages/core/src/testing/index.ts @@ -1,2 +1,2 @@ -export * from './core'; -export * from './fake-events'; +export * from './fixture'; +export * from './mock-events'; diff --git a/packages/core/src/testing/fake-events/event-objects.ts b/packages/core/src/testing/mock-events/event-objects.ts similarity index 99% rename from packages/core/src/testing/fake-events/event-objects.ts rename to packages/core/src/testing/mock-events/event-objects.ts index cfdd1258a..81638ed5a 100644 --- a/packages/core/src/testing/fake-events/event-objects.ts +++ b/packages/core/src/testing/mock-events/event-objects.ts @@ -7,7 +7,7 @@ */ import { IS_MAC } from '../../utils/dom/environment'; -import { ModifierKeys } from '../test-element'; +import { ModifierKeys } from './test-element'; /** Used to generate unique IDs for events. */ let uniqueIds = 0; diff --git a/packages/core/src/testing/fake-events/index.ts b/packages/core/src/testing/mock-events/index.ts similarity index 100% rename from packages/core/src/testing/fake-events/index.ts rename to packages/core/src/testing/mock-events/index.ts diff --git a/packages/core/src/testing/test-element.ts b/packages/core/src/testing/mock-events/test-element.ts similarity index 100% rename from packages/core/src/testing/test-element.ts rename to packages/core/src/testing/mock-events/test-element.ts diff --git a/packages/draw/src/plugins/with-table-resize.spec.ts b/packages/draw/src/plugins/with-table-resize.spec.ts new file mode 100644 index 000000000..d2a7e83df --- /dev/null +++ b/packages/draw/src/plugins/with-table-resize.spec.ts @@ -0,0 +1,57 @@ +import { fakeAsync, tick } from '@angular/core/testing'; +import { TestingBoardFixture, createPointerEvent } from '@plait/core'; +import { setupTestingBoard } from '@plait/core'; +import { PlaitTable } from '../interfaces/table'; +import { withDraw } from './with-draw'; + +describe('withTableResize', () => { + let table: PlaitTable; + let fixture: TestingBoardFixture; + + beforeEach(() => { + table = { + id: 'table', + type: 'table', + points: [ + [0, 0], + [200, 100] + ], + rows: [{ id: 'row-1' }], + columns: [ + { id: 'column-1', width: 100 }, + { id: 'column-2', width: 100 } + ], + cells: [ + { id: 'cell-1-1', rowId: 'row-1', columnId: 'column-1' }, + { id: 'cell-1-2', rowId: 'row-1', columnId: 'column-2' } + ] + }; + fixture = setupTestingBoard([withDraw], [table], { + selectedElements: [table], + withRoughSVG: true + }); + }); + + afterEach(() => { + fixture.destroy(); + }); + + it('should restore the original column size when the pointer returns to the resize origin', fakeAsync(() => { + fixture.board.pointerDown(createPointerEvent('pointerdown', 100, 50)); + fixture.board.pointerMove(createPointerEvent('pointermove', 120, 50)); + tick(16); + expect((fixture.board.children[0] as PlaitTable).columns[0].width).toBe(120); + expect((fixture.board.children[0] as PlaitTable).points).toEqual([ + [0, 0], + [220, 100] + ]); + fixture.board.pointerMove(createPointerEvent('pointermove', 100, 50)); + tick(16); + fixture.board.globalPointerUp(createPointerEvent('pointerup', 100, 50)); + expect((fixture.board.children[0] as PlaitTable).columns[0].width).toBe(100); + expect((fixture.board.children[0] as PlaitTable).points).toEqual([ + [0, 0], + [200, 100] + ]); + })); +}); diff --git a/packages/draw/src/plugins/with-table-resize.ts b/packages/draw/src/plugins/with-table-resize.ts index ca51bdc6c..386bad23c 100644 --- a/packages/draw/src/plugins/with-table-resize.ts +++ b/packages/draw/src/plugins/with-table-resize.ts @@ -92,26 +92,24 @@ export function withTableResize(board: PlaitTableBoard) { const sizeOffset = edge === 'start' ? -pointerOffset : pointerOffset; const targetSize = Math.max(MIN_CELL_SIZE, currentSize + sizeOffset); const appliedOffset = targetSize - currentSize; - if (appliedOffset !== 0) { - if (isRow) { - const { rows, points } = updateRows( - resizeRef.element, - resizeRef.element.rows[targetIndex].id, - targetSize, - appliedOffset, - edge - ); - Transforms.setNode(board, { rows, points }, path); - } else { - const { columns, points } = updateColumns( - resizeRef.element, - resizeRef.element.columns[targetIndex].id, - targetSize, - appliedOffset, - edge - ); - Transforms.setNode(board, { columns, points }, path); - } + if (isRow) { + const { rows, points } = updateRows( + resizeRef.element, + resizeRef.element.rows[targetIndex].id, + targetSize, + appliedOffset, + edge + ); + Transforms.setNode(board, { rows, points }, path); + } else { + const { columns, points } = updateColumns( + resizeRef.element, + resizeRef.element.columns[targetIndex].id, + targetSize, + appliedOffset, + edge + ); + Transforms.setNode(board, { columns, points }, path); } } } else if (isCornerHandle(board, resizeRef.handle)) { diff --git a/packages/draw/src/transforms/swimlane.spec.ts b/packages/draw/src/transforms/swimlane.spec.ts index 396033e36..c70394b8a 100644 --- a/packages/draw/src/transforms/swimlane.spec.ts +++ b/packages/draw/src/transforms/swimlane.spec.ts @@ -1,10 +1,16 @@ -import { createTestingBoard, fakeNodeWeakMap } from '@plait/core'; +import { TestingBoardFixture, setupTestingBoard } from '@plait/core'; import { withDraw } from '../plugins/with-draw'; import { PlaitSwimlane, SwimlaneDrawSymbols } from '../interfaces'; import { createDefaultSwimlane } from '../utils/swimlane'; import { addSwimlaneColumn, addSwimlaneRow } from './swimlane'; describe('swimlane transforms', () => { + let fixture: TestingBoardFixture | null = null; + + afterEach(() => { + fixture?.destroy(); + }); + const expectCellsInRowMajorOrder = (swimlane: PlaitSwimlane) => { const expectedPositions = swimlane.rows.flatMap((row) => swimlane.columns.map((column) => ({ rowId: row.id, columnId: column.id })) @@ -17,12 +23,9 @@ describe('swimlane transforms', () => { [0, 0], [600, 300] ]); - const board = createTestingBoard([withDraw], [swimlane]); - fakeNodeWeakMap(board); - - addSwimlaneRow(board, swimlane, 1); - - expectCellsInRowMajorOrder(board.children[0] as PlaitSwimlane); + fixture = setupTestingBoard([withDraw], [swimlane]); + addSwimlaneRow(fixture.board, swimlane, 1); + expectCellsInRowMajorOrder(fixture.board.children[0] as PlaitSwimlane); }); it('should keep cells ordered after adding a column in the middle', () => { @@ -30,11 +33,8 @@ describe('swimlane transforms', () => { [0, 0], [600, 300] ]); - const board = createTestingBoard([withDraw], [swimlane]); - fakeNodeWeakMap(board); - - addSwimlaneColumn(board, swimlane, 1); - - expectCellsInRowMajorOrder(board.children[0] as PlaitSwimlane); + fixture = setupTestingBoard([withDraw], [swimlane]); + addSwimlaneColumn(fixture.board, swimlane, 1); + expectCellsInRowMajorOrder(fixture.board.children[0] as PlaitSwimlane); }); }); diff --git a/packages/draw/src/utils/fill-style.spec.ts b/packages/draw/src/utils/fill-style.spec.ts index 13e3aa2ea..4df962c27 100644 --- a/packages/draw/src/utils/fill-style.spec.ts +++ b/packages/draw/src/utils/fill-style.spec.ts @@ -1,4 +1,5 @@ -import { BOARD_TO_ROUGH_SVG, createTestingBoard, PlaitBoard, RectangleClient } from '@plait/core'; +import { PlaitBoard, RectangleClient, TestingBoardFixture } from '@plait/core'; +import { setupTestingBoard } from '@plait/core'; import { withDraw } from '../plugins/with-draw'; import { Options } from 'roughjs/bin/core'; import { GeometryShapeGenerator } from '../generators/geometry-shape.generator'; @@ -8,25 +9,24 @@ import { PlaitGeometry, BasicShapes, FlowchartSymbols, FILL_STYLES, UMLSymbols } import { drawGeometry } from './geometry'; describe('fillStyle', () => { - let board: PlaitBoard; + let fixture: TestingBoardFixture; beforeEach(() => { - board = createTestingBoard([withDraw], []); - BOARD_TO_ROUGH_SVG.set(board, createTestingRoughSVG()); + fixture = setupTestingBoard([withDraw], [], { + withNodeWeakMap: false, + withElementHost: false, + withHost: false, + withRoughSVG: true + }); }); - const createTestingRoughSVG = () => { - const createG = () => document.createElementNS('http://www.w3.org/2000/svg', 'g') as SVGGElement; - return { - rectangle: () => createG(), - path: () => createG(), - linearPath: () => createG() - } as any; - }; + afterEach(() => { + fixture.destroy(); + }); describe('GeometryShapeGenerator', () => { it('should use solid fillStyle by default', () => { - const roughSVG = PlaitBoard.getRoughSVG(board); + const roughSVG = PlaitBoard.getRoughSVG(fixture.board); const rectangleSpy = spyOn(roughSVG, 'rectangle').and.callThrough(); const element: PlaitGeometry = { id: 'test-default-fill-style', @@ -38,15 +38,13 @@ describe('fillStyle', () => { ], fill: '#FF5733' }; - - new GeometryShapeGenerator(board).draw(element, {}); - + new GeometryShapeGenerator(fixture.board).draw(element, {}); const options = rectangleSpy.calls.mostRecent().args[4] as Options; expect(options.fillStyle).toBe('solid'); }); it('should pass element fillStyle to shape engine', () => { - const roughSVG = PlaitBoard.getRoughSVG(board); + const roughSVG = PlaitBoard.getRoughSVG(fixture.board); const rectangleSpy = spyOn(roughSVG, 'rectangle').and.callThrough(); const element: PlaitGeometry = { id: 'test-custom-fill-style', @@ -60,8 +58,7 @@ describe('fillStyle', () => { fillStyle: 'hachure' }; - new GeometryShapeGenerator(board).draw(element, {}); - + new GeometryShapeGenerator(fixture.board).draw(element, {}); const options = rectangleSpy.calls.mostRecent().args[4] as Options; expect(options.fillStyle).toBe('hachure'); }); @@ -69,7 +66,7 @@ describe('fillStyle', () => { describe('drawGeometry', () => { it('should use solid fillStyle by default when called directly', () => { - const roughSVG = PlaitBoard.getRoughSVG(board); + const roughSVG = PlaitBoard.getRoughSVG(fixture.board); const rectangleSpy = spyOn(roughSVG, 'rectangle').and.callThrough(); const rectangle: RectangleClient = { x: 0, @@ -78,7 +75,7 @@ describe('fillStyle', () => { height: 100 }; - drawGeometry(board, rectangle, BasicShapes.rectangle, { + drawGeometry(fixture.board, rectangle, BasicShapes.rectangle, { stroke: '#000000', strokeWidth: 2, fill: '#FF5733' @@ -89,7 +86,7 @@ describe('fillStyle', () => { }); it('should support all fill styles when called directly', () => { - const roughSVG = PlaitBoard.getRoughSVG(board); + const roughSVG = PlaitBoard.getRoughSVG(fixture.board); const rectangleSpy = spyOn(roughSVG, 'rectangle').and.callThrough(); const rectangle: RectangleClient = { x: 0, @@ -99,7 +96,7 @@ describe('fillStyle', () => { }; FILL_STYLES.forEach((fillStyle) => { - drawGeometry(board, rectangle, BasicShapes.rectangle, { + drawGeometry(fixture.board, rectangle, BasicShapes.rectangle, { stroke: '#000000', strokeWidth: 2, fill: '#FF5733', @@ -112,7 +109,7 @@ describe('fillStyle', () => { }); it('should preserve fillStyle for path based geometry engines', () => { - const roughSVG = PlaitBoard.getRoughSVG(board); + const roughSVG = PlaitBoard.getRoughSVG(fixture.board); const pathSpy = spyOn(roughSVG, 'path').and.callThrough(); const rectangle: RectangleClient = { x: 0, @@ -136,7 +133,7 @@ describe('fillStyle', () => { ]; shapes.forEach((shape) => { - drawGeometry(board, rectangle, shape, roughOptions); + drawGeometry(fixture.board, rectangle, shape, roughOptions); const options = pathSpy.calls.mostRecent().args[1] as Options; expect(options.fillStyle).toBe('hachure'); }); @@ -145,7 +142,7 @@ describe('fillStyle', () => { describe('drawShape', () => { it('should use solid fillStyle by default for table cell fills', () => { - const roughSVG = PlaitBoard.getRoughSVG(board); + const roughSVG = PlaitBoard.getRoughSVG(fixture.board); const rectangleSpy = spyOn(roughSVG, 'rectangle').and.callThrough(); const rectangle: RectangleClient = { x: 0, @@ -164,10 +161,10 @@ describe('fillStyle', () => { columns: [{ id: 'column-1' }], cells: [{ id: 'cell-1', rowId: 'row-1', columnId: 'column-1', fill: '#FF5733' }] }; - (board as any).buildTable = (element: PlaitTable) => element; + (fixture.board as any).buildTable = (element: PlaitTable) => element; drawShape( - board, + fixture.board, rectangle, TableSymbols.table, { @@ -180,6 +177,5 @@ describe('fillStyle', () => { const options = rectangleSpy.calls.mostRecent().args[4] as Options; expect(options.fillStyle).toBe('solid'); }); - }); }); diff --git a/packages/draw/src/utils/swimlane.spec.ts b/packages/draw/src/utils/swimlane.spec.ts index e4a1af996..f9cd95757 100644 --- a/packages/draw/src/utils/swimlane.spec.ts +++ b/packages/draw/src/utils/swimlane.spec.ts @@ -12,11 +12,8 @@ describe('isSwimlanePointers', () => { it('uses the effective pointer by default', () => { board = createTestingBoard([], []); board.pointer = SwimlaneDrawSymbols.swimlaneHorizontal; - expect(isSwimlanePointers(board)).toBeTrue(); - BOARD_TO_TEMPORARY_POINTER.set(board, PlaitPointerType.hand); - expect(isSwimlanePointers(board)).toBeFalse(); }); });