forked from gregzanch/cram
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: floorplan sketch editor #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rdmiller
wants to merge
3
commits into
varese-dev
Choose a base branch
from
feature/floorplan-sketch-editor
base: varese-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
src/components/workbench/__tests__/defaultLayout.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /** | ||
| * Layout migration tests. | ||
| * | ||
| * Persisted layouts are restored verbatim and never consult DEFAULT_LAYOUT, so | ||
| * a panel added after a user's layout was saved is invisible to them until the | ||
| * stored model is patched. | ||
| */ | ||
|
|
||
| import { describe, it, expect } from 'vitest'; | ||
| import type { IJsonModel } from 'flexlayout-react'; | ||
| import { DEFAULT_LAYOUT, PANEL_IDS, SKETCH_TAB, ensureSketchTab } from '../defaultLayout'; | ||
|
|
||
| /** A layout of the shape saved before the Sketch panel existed. */ | ||
| const legacyLayout = (): IJsonModel => ({ | ||
| global: {}, | ||
| borders: [ | ||
| { | ||
| type: 'border', | ||
| location: 'right', | ||
| size: 320, | ||
| selected: 1, | ||
| children: [ | ||
| { type: 'tab', id: 'objects', name: 'Objects', component: 'ObjectsPanel' }, | ||
| { type: 'tab', id: 'solvers', name: 'Solvers', component: 'SolversPanel' }, | ||
| { type: 'tab', id: 'renderer', name: 'Renderer', component: 'RendererPanel' }, | ||
| ], | ||
| }, | ||
| ], | ||
| layout: { | ||
| type: 'row', | ||
| children: [ | ||
| { | ||
| type: 'tabset', | ||
| id: 'main', | ||
| children: [{ type: 'tab', id: 'canvas', name: 'Canvas', component: 'CanvasPanel' }], | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
|
|
||
| const rightBorder = (layout: IJsonModel) => | ||
| (layout.borders ?? []).find((b) => b.location === 'right'); | ||
|
|
||
| const tabIds = (layout: IJsonModel) => | ||
| (rightBorder(layout)?.children ?? []).map((c) => (c as { id?: string }).id); | ||
|
|
||
| describe('ensureSketchTab', () => { | ||
| it('adds the Sketch tab to a layout saved before it existed', () => { | ||
| const migrated = ensureSketchTab(legacyLayout()); | ||
| expect(tabIds(migrated)).toEqual(['objects', 'solvers', 'renderer', PANEL_IDS.SKETCH]); | ||
| }); | ||
|
|
||
| it('gives the added tab the same shape as the default', () => { | ||
| const migrated = ensureSketchTab(legacyLayout()); | ||
| const added = rightBorder(migrated)!.children!.at(-1); | ||
| expect(added).toEqual(SKETCH_TAB); | ||
| }); | ||
|
|
||
| it('leaves the current tab selection alone', () => { | ||
| const migrated = ensureSketchTab(legacyLayout()); | ||
| expect(rightBorder(migrated)!.selected).toBe(1); | ||
| }); | ||
|
|
||
| it('is a no-op when the tab is already present', () => { | ||
| const already = ensureSketchTab(legacyLayout()); | ||
| expect(ensureSketchTab(already)).toBe(already); | ||
| }); | ||
|
|
||
| it('is a no-op on the default layout', () => { | ||
| expect(ensureSketchTab(DEFAULT_LAYOUT)).toBe(DEFAULT_LAYOUT); | ||
| }); | ||
|
|
||
| it('is idempotent across repeated loads', () => { | ||
| let layout = legacyLayout(); | ||
| for (let i = 0; i < 3; i++) layout = ensureSketchTab(layout); | ||
| expect(tabIds(layout).filter((id) => id === PANEL_IDS.SKETCH)).toHaveLength(1); | ||
| }); | ||
|
|
||
| it('does not mutate the stored layout', () => { | ||
| const original = legacyLayout(); | ||
| const snapshot = JSON.stringify(original); | ||
| ensureSketchTab(original); | ||
| expect(JSON.stringify(original)).toBe(snapshot); | ||
| }); | ||
|
|
||
| it('finds the tab even when it sits in the main layout rather than a border', () => { | ||
| const layout = legacyLayout(); | ||
| (layout.layout.children[0] as { children: unknown[] }).children.push({ ...SKETCH_TAB }); | ||
| expect(ensureSketchTab(layout)).toBe(layout); | ||
| }); | ||
|
|
||
| it('creates a right border when the saved layout has none', () => { | ||
| const layout = { ...legacyLayout(), borders: [] }; | ||
| const migrated = ensureSketchTab(layout); | ||
| expect(tabIds(migrated)).toEqual([PANEL_IDS.SKETCH]); | ||
| }); | ||
|
|
||
| it('leaves a newly created border closed rather than forcing it open', () => { | ||
| const migrated = ensureSketchTab({ ...legacyLayout(), borders: [] }); | ||
| expect(rightBorder(migrated)!.selected).toBe(-1); | ||
| }); | ||
|
|
||
| it('tolerates a layout with no borders key at all', () => { | ||
| const layout = legacyLayout(); | ||
| delete layout.borders; | ||
| expect(tabIds(ensureSketchTab(layout))).toEqual([PANEL_IDS.SKETCH]); | ||
| }); | ||
|
|
||
| it('does not disturb borders in other locations', () => { | ||
| const layout = legacyLayout(); | ||
| layout.borders!.push({ | ||
| type: 'border', | ||
| location: 'bottom', | ||
| children: [{ type: 'tab', id: 'results', name: 'Results', component: 'ResultsPanel' }], | ||
| }); | ||
|
|
||
| const migrated = ensureSketchTab(layout); | ||
|
|
||
| const bottom = migrated.borders!.find((b) => b.location === 'bottom'); | ||
| expect(bottom!.children!.map((c) => (c as { id?: string }).id)).toEqual(['results']); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.