-
Notifications
You must be signed in to change notification settings - Fork 306
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
feat(storage-browser): integrate browser navigation events #5941
Merged
calebpollman
merged 6 commits into
feat-storage-browser/main
from
feat-storage-browser/browser-navigation
Oct 25, 2024
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7df9f79
feat(storage-browser): integrate browser navigation
calebpollman 65bb318
feat(storage-browser): add routed example app
calebpollman ff1ebdb
fix unit tests
calebpollman b4e4c4b
remove unused test utilities
calebpollman 99be6e8
remove testUtils pattern from jest coverage exclusion
calebpollman a5b5816
fix navigation e2e test
calebpollman 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 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
156 changes: 50 additions & 106 deletions
156
...ages/react-storage/src/components/StorageBrowser/__tests__/StorageBrowserDefault.spec.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 |
---|---|---|
@@ -1,122 +1,66 @@ | ||
import React from 'react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import * as ActionsModule from '../do-not-import-from-here/actions'; | ||
import * as ControlsModule from '../context/control'; | ||
import { ViewsProvider } from '../views/context'; | ||
import * as StoreModule from '../providers/store'; | ||
import * as ViewsModule from '../views/context'; | ||
import { StorageBrowserDefault } from '../StorageBrowserDefault'; | ||
|
||
jest.spyOn(ActionsModule, 'useLocationsData').mockReturnValue([ | ||
{ | ||
isLoading: false, | ||
data: { result: [], nextToken: undefined }, | ||
hasError: false, | ||
message: undefined, | ||
}, | ||
jest.fn(), | ||
]); | ||
|
||
jest.spyOn(ActionsModule, 'useAction').mockReturnValue([ | ||
{ | ||
data: { result: [], nextToken: undefined }, | ||
hasError: false, | ||
isLoading: false, | ||
message: undefined, | ||
}, | ||
jest.fn(), | ||
]); | ||
|
||
const INITIAL_NAVIGATE_STATE = [ | ||
{ location: undefined, history: [], path: undefined }, | ||
jest.fn(), | ||
]; | ||
const INITIAL_LOCATION_ACTIONS_STATE = [ | ||
{ selected: { type: undefined, items: undefined }, actions: {} }, | ||
jest.fn(), | ||
]; | ||
jest.spyOn(ViewsModule, 'useViews').mockReturnValue({ | ||
LocationsView: () => <div data-testid="LOCATIONS_VIEW" />, | ||
LocationDetailView: () => <div data-testid="LOCATION_DETAIL_VIEW" />, | ||
LocationActionView: () => <div data-testid="LOCATION_ACTION_VIEW" />, | ||
}); | ||
|
||
const useControlSpy = jest.spyOn(ControlsModule, 'useControl'); | ||
const useStoreSpy = jest.spyOn(StoreModule, 'useStore'); | ||
|
||
const WrappedStorageBrowser = () => ( | ||
<ViewsProvider> | ||
<StorageBrowserDefault /> | ||
</ViewsProvider> | ||
); | ||
const location = { | ||
id: 'an-id-👍🏼', | ||
bucket: 'test-bucket', | ||
permission: 'READWRITE', | ||
prefix: 'test-prefix/', | ||
type: 'PREFIX', | ||
}; | ||
|
||
describe('StorageBrowserDefault', () => { | ||
beforeEach(() => { | ||
useControlSpy.mockClear(); | ||
afterEach(jest.clearAllMocks); | ||
|
||
it('renders the `LocationsView` by default', () => { | ||
useStoreSpy.mockReturnValueOnce([ | ||
{ | ||
actionType: undefined, | ||
history: { current: undefined, previous: undefined }, | ||
} as StoreModule.UseStoreState, | ||
jest.fn(), | ||
]); | ||
const { getByTestId } = render(<StorageBrowserDefault />); | ||
|
||
expect(getByTestId('LOCATIONS_VIEW')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders the `LocationsView` by default', async () => { | ||
useControlSpy.mockImplementation( | ||
(type) => | ||
({ | ||
LOCATION_ACTIONS: INITIAL_LOCATION_ACTIONS_STATE, | ||
NAVIGATE: INITIAL_NAVIGATE_STATE, | ||
})[type] | ||
); | ||
it('renders the `LocationDetailView` when a location is selected', () => { | ||
useStoreSpy.mockReturnValueOnce([ | ||
{ | ||
actionType: undefined, | ||
history: { current: location, previous: [location] }, | ||
} as StoreModule.UseStoreState, | ||
jest.fn(), | ||
]); | ||
|
||
await waitFor(() => { | ||
render(<WrappedStorageBrowser />); | ||
}); | ||
const { getByTestId } = render(<StorageBrowserDefault />); | ||
|
||
expect(screen.getByTestId('LOCATIONS_VIEW')).toBeInTheDocument(); | ||
expect(getByTestId('LOCATION_DETAIL_VIEW')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders the `LocationDetailView` when a location is selected', async () => { | ||
useControlSpy.mockImplementation( | ||
(type) => | ||
({ | ||
LOCATION_ACTIONS: INITIAL_LOCATION_ACTIONS_STATE, | ||
NAVIGATE: [ | ||
{ | ||
location: { | ||
scope: 's3://test-bucket/*', | ||
permission: 'READWRITE', | ||
type: 'BUCKET', | ||
}, | ||
history: [{ prefix: '', position: 0 }], | ||
}, | ||
], | ||
})[type] | ||
); | ||
|
||
await waitFor(() => { | ||
render(<WrappedStorageBrowser />); | ||
}); | ||
|
||
expect(screen.getByTestId('LOCATION_DETAIL_VIEW')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders the `LocationActionView` when an action is selected', async () => { | ||
useControlSpy.mockImplementation( | ||
(type) => | ||
({ | ||
LOCATION_ACTIONS: [ | ||
{ | ||
actions: { CREATE_FOLDER: {} }, | ||
selected: { type: 'CREATE_FOLDER', items: undefined }, | ||
}, | ||
jest.fn(), | ||
], | ||
NAVIGATE: [ | ||
{ | ||
location: { | ||
scope: 's3://test-bucket/*', | ||
permission: 'READWRITE', | ||
type: 'BUCKET', | ||
}, | ||
history: [{ prefix: '', position: 0 }], | ||
}, | ||
], | ||
})[type] | ||
); | ||
|
||
render(<WrappedStorageBrowser />); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByTestId('LOCATION_ACTION_VIEW')).toBeInTheDocument(); | ||
}); | ||
it('renders the `LocationActionView` when an action is selected', () => { | ||
useStoreSpy.mockReturnValueOnce([ | ||
{ | ||
actionType: 'super-coll-action-type', | ||
history: { current: location, previous: [location] }, | ||
} as StoreModule.UseStoreState, | ||
jest.fn(), | ||
]); | ||
const { getByTestId } = render(<StorageBrowserDefault />); | ||
|
||
expect(getByTestId('LOCATION_ACTION_VIEW')).toBeInTheDocument(); | ||
}); | ||
}); |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor drop in branch coverage but will be addressed in other migration PRs