-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workspace and locally-persistent-workspace
Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
- Loading branch information
1 parent
31b3012
commit ff1eff9
Showing
1 changed file
with
91 additions
and
0 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
packages/rmf-dashboard-framework/src/components/workspace.test.tsx
This file contains 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,91 @@ | ||
import { screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { beforeEach, describe, expect, it } from 'vitest'; | ||
|
||
import { RmfApiProvider } from '../hooks'; | ||
import { MockRmfApi, render, TestProviders } from '../utils/test-utils.test'; | ||
import { MicroAppManifest } from './micro-app'; | ||
import { InitialWindow, LocallyPersistentWorkspace, Workspace } from './workspace'; | ||
|
||
const mockMicroApp: MicroAppManifest = { | ||
Component: () => <div>Mock App</div>, | ||
appId: 'mock-app', | ||
displayName: 'Mock App', | ||
}; | ||
|
||
describe('workspace', () => { | ||
const rmfApi = new MockRmfApi(); | ||
|
||
const Base = (props: React.PropsWithChildren<{}>) => { | ||
return ( | ||
<TestProviders> | ||
<RmfApiProvider value={rmfApi}>{props.children}</RmfApiProvider> | ||
</TestProviders> | ||
); | ||
}; | ||
|
||
it('renders without crashing', () => { | ||
render( | ||
<Base> | ||
<Workspace initialWindows={[]} allowDesignMode={false} appRegistry={[]} /> | ||
</Base>, | ||
); | ||
}); | ||
|
||
it('renders initial windows', () => { | ||
const initialWindows: InitialWindow[] = [ | ||
{ | ||
layout: { x: 0, y: 0, w: 1, h: 1 }, | ||
microApp: mockMicroApp, | ||
}, | ||
]; | ||
render(<Workspace initialWindows={initialWindows} />); | ||
expect(screen.getByText('Mock App')).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('LocallyPersistentWorkspace', () => { | ||
const storageKey = 'test-workspace'; | ||
|
||
beforeEach(() => { | ||
localStorage.clear(); | ||
}); | ||
|
||
it('loads initial windows from localStorage', () => { | ||
const savedLayout = [ | ||
{ | ||
layout: { i: 'window-0', x: 0, y: 0, w: 1, h: 1 }, | ||
appId: 'mock-app', | ||
}, | ||
]; | ||
localStorage.setItem(storageKey, JSON.stringify(savedLayout)); | ||
|
||
render( | ||
<LocallyPersistentWorkspace | ||
defaultWindows={[]} | ||
storageKey={storageKey} | ||
appRegistry={[mockMicroApp]} | ||
/>, | ||
); | ||
|
||
expect(screen.getByText('Mock App')).toBeTruthy(); | ||
}); | ||
|
||
it('falls back to default windows when localStorage is empty', () => { | ||
const defaultWindows: InitialWindow[] = [ | ||
{ | ||
layout: { x: 0, y: 0, w: 1, h: 1 }, | ||
microApp: mockMicroApp, | ||
}, | ||
]; | ||
render( | ||
<LocallyPersistentWorkspace | ||
defaultWindows={defaultWindows} | ||
storageKey={storageKey} | ||
appRegistry={[mockMicroApp]} | ||
/>, | ||
); | ||
|
||
expect(screen.getByText('Mock App')).toBeTruthy(); | ||
}); | ||
}); |