-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(fix) O3-3691: The workspace family store shouldn't reset if workspac…
…e of same family is launched (#1103) * Adding a new check to know that the workspace to be opened is of the same sidebar family as of the workspace to be closed * Added tests for workspace renderer and added workspaceFamilyState in the dependency array for the props * Updated documentation * Add check for not clearing store if workspace is opened in the background * Updated documentation * Review updates * Updated documentation * Separate workspace family store handling from closeWorkspace API Co-authored-by: Brandon Istenes <[email protected]> * Update documentation * Update packages/framework/esm-styleguide/src/workspaces/workspaces.ts Co-authored-by: Ian <[email protected]> * Update the comment for testing the default options Co-authored-by: Brandon Istenes <[email protected]> * Review changes * Update documentation --------- Co-authored-by: Brandon Istenes <[email protected]> Co-authored-by: Ian <[email protected]>
- Loading branch information
1 parent
6c99789
commit a099d31
Showing
9 changed files
with
238 additions
and
56 deletions.
There are no files selected for viewing
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
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
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
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
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
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
64 changes: 64 additions & 0 deletions
64
packages/framework/esm-styleguide/src/workspaces/container/workspace-renderer.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,64 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { WorkspaceRenderer } from './workspace-renderer.component'; | ||
import { getWorkspaceFamilyStore, OpenWorkspace } from '../workspaces'; | ||
import Parcel from 'single-spa-react/parcel'; | ||
|
||
const mockFn = jest.fn(); | ||
|
||
jest.mock('single-spa-react/parcel', () => | ||
jest.fn((props) => { | ||
mockFn(props); | ||
return <div data-testid="mocked-parcel" />; | ||
}), | ||
); | ||
|
||
describe('WorkspaceRenderer', () => { | ||
it('should render workspace', async () => { | ||
const mockedCloseWorkspace = jest.fn(); | ||
const mockedCloseWorkspaceWithSavedChanges = jest.fn(); | ||
const mockedPromptBeforeClosing = jest.fn(); | ||
const mockedSetTitle = jest.fn(); | ||
const mockedLoadFn = jest.fn().mockImplementation(() => Promise.resolve({ default: 'file-content' })); | ||
getWorkspaceFamilyStore('test-sidebar-family')?.setState({ | ||
// Testing that the workspace family state should be overrided by additionalProps | ||
foo: false, | ||
workspaceFamilyState: {}, | ||
}); | ||
render( | ||
<WorkspaceRenderer | ||
// @ts-ignore The workspace is of type OpenWorkspace and not all properties are required | ||
workspace={{ | ||
closeWorkspace: mockedCloseWorkspace, | ||
name: 'workspace-name', | ||
load: mockedLoadFn, | ||
title: 'Workspace title', | ||
closeWorkspaceWithSavedChanges: mockedCloseWorkspaceWithSavedChanges, | ||
promptBeforeClosing: mockedPromptBeforeClosing, | ||
setTitle: mockedSetTitle, | ||
additionalProps: { | ||
foo: 'true', | ||
}, | ||
sidebarFamily: 'test-sidebar-family', | ||
}} | ||
additionalPropsFromPage={{ bar: 'true' }} | ||
/>, | ||
); | ||
|
||
expect(screen.getByText('Loading ...')).toBeInTheDocument(); | ||
expect(mockedLoadFn).toHaveBeenCalled(); | ||
await screen.findByTestId('mocked-parcel'); | ||
|
||
expect(mockFn).toHaveBeenCalledWith({ | ||
config: 'file-content', | ||
mountParcel: undefined, | ||
closeWorkspace: mockedCloseWorkspace, | ||
closeWorkspaceWithSavedChanges: mockedCloseWorkspaceWithSavedChanges, | ||
promptBeforeClosing: mockedPromptBeforeClosing, | ||
setTitle: mockedSetTitle, | ||
foo: 'true', | ||
bar: 'true', | ||
workspaceFamilyState: {}, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.