-
Notifications
You must be signed in to change notification settings - Fork 345
feat(content-sharing): Convert Content Sharing V2 API Response #4285
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f46594a
feat: Convert Content Sharing V2 API Response
reneshen0328 06dbaa4
fix: import type directly from shared feature
reneshen0328 d96f849
fix: remove TODO
reneshen0328 1f33c87
fix: update usm package version
reneshen0328 8f5b2e1
fix: nits and remove not needed token
reneshen0328 6510952
fix: import types
reneshen0328 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
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
132 changes: 132 additions & 0 deletions
132
src/elements/content-sharing/__tests__/ContentSharingV2.test.tsx
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,132 @@ | ||
| import React from 'react'; | ||
| import { render, RenderResult, screen, waitFor } from '@testing-library/react'; | ||
|
|
||
| import { | ||
| DEFAULT_ITEM_API_RESPONSE, | ||
| DEFAULT_USER_API_RESPONSE, | ||
| MOCK_ITEM, | ||
| MOCK_ITEM_API_RESPONSE_WITH_SHARED_LINK, | ||
| MOCK_ITEM_API_RESPONSE_WITH_CLASSIFICATION, | ||
| } from '../utils/__mocks__/ContentSharingV2Mocks'; | ||
| import { CONTENT_SHARING_ITEM_FIELDS } from '../constants'; | ||
|
|
||
| import ContentSharingV2 from '../ContentSharingV2'; | ||
|
|
||
| const createAPIMock = (fileAPI, folderAPI, usersAPI) => ({ | ||
| getFileAPI: jest.fn().mockReturnValue(fileAPI), | ||
| getFolderAPI: jest.fn().mockReturnValue(folderAPI), | ||
| getUsersAPI: jest.fn().mockReturnValue(usersAPI), | ||
| }); | ||
|
|
||
| const createSuccessMock = responseFromAPI => (id, successFn) => { | ||
| return Promise.resolve(responseFromAPI).then(response => { | ||
| successFn(response); | ||
| }); | ||
| }; | ||
|
|
||
| const getDefaultUserMock = jest.fn().mockImplementation(createSuccessMock(DEFAULT_USER_API_RESPONSE)); | ||
| const getDefaultFileMock = jest.fn().mockImplementation(createSuccessMock(DEFAULT_ITEM_API_RESPONSE)); | ||
| const getFileMockWithSharedLink = jest | ||
| .fn() | ||
| .mockImplementation(createSuccessMock(MOCK_ITEM_API_RESPONSE_WITH_SHARED_LINK)); | ||
| const getFileMockWithClassification = jest | ||
| .fn() | ||
| .mockImplementation(createSuccessMock(MOCK_ITEM_API_RESPONSE_WITH_CLASSIFICATION)); | ||
| const getDefaultFolderMock = jest.fn().mockImplementation(createSuccessMock(DEFAULT_ITEM_API_RESPONSE)); | ||
| const defaultAPIMock = createAPIMock( | ||
| { getFile: getDefaultFileMock }, | ||
| { getFolderFields: getDefaultFolderMock }, | ||
| { getUser: getDefaultUserMock }, | ||
| ); | ||
|
|
||
| const getWrapper = (props): RenderResult => | ||
| render( | ||
| <ContentSharingV2 | ||
| api={defaultAPIMock} | ||
| itemID={MOCK_ITEM.id} | ||
| itemType={MOCK_ITEM.type} | ||
| hasProviders={true} | ||
| {...props} | ||
| />, | ||
| ); | ||
|
|
||
| describe('elements/content-sharing/ContentSharingV2', () => { | ||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| test('should see the correct elements for files', async () => { | ||
| getWrapper({}); | ||
| await waitFor(() => { | ||
| expect(getDefaultFileMock).toHaveBeenCalledWith( | ||
| MOCK_ITEM.id, | ||
| expect.any(Function), | ||
| {}, | ||
| { | ||
| fields: CONTENT_SHARING_ITEM_FIELDS, | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| expect(screen.getByRole('heading', { name: 'Share ‘Box Development Guide.pdf’' })).toBeVisible(); | ||
| expect(screen.getByRole('combobox', { name: 'Invite People' })).toBeVisible(); | ||
| expect(screen.getByRole('switch', { name: 'Shared link' })).toBeVisible(); | ||
| }); | ||
|
|
||
| test('should see the correct elements for folders', async () => { | ||
| getWrapper({ itemType: 'folder' }); | ||
| await waitFor(() => { | ||
| expect(getDefaultFolderMock).toHaveBeenCalledWith( | ||
| MOCK_ITEM.id, | ||
| expect.any(Function), | ||
| {}, | ||
| { | ||
| fields: CONTENT_SHARING_ITEM_FIELDS, | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| expect(screen.getByRole('heading', { name: 'Share ‘Box Development Guide.pdf’' })).toBeVisible(); | ||
| expect(screen.getByRole('combobox', { name: 'Invite People' })).toBeVisible(); | ||
| expect(screen.getByRole('switch', { name: 'Shared link' })).toBeVisible(); | ||
| }); | ||
|
|
||
| test('should see the shared link elements if shared link is present', async () => { | ||
| getWrapper({ | ||
| api: createAPIMock({ getFile: getFileMockWithSharedLink }, null, { getUser: getDefaultUserMock }), | ||
| }); | ||
| await waitFor(() => { | ||
| expect(getFileMockWithSharedLink).toHaveBeenCalledWith( | ||
| MOCK_ITEM.id, | ||
| expect.any(Function), | ||
| {}, | ||
| { | ||
| fields: CONTENT_SHARING_ITEM_FIELDS, | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| expect(await screen.findByLabelText('Shared link URL')).toBeVisible(); | ||
| expect(await screen.findByRole('button', { name: 'People with the link' })).toBeVisible(); | ||
| expect(await screen.findByRole('button', { name: 'Can view and download' })).toBeVisible(); | ||
| expect(screen.getByRole('button', { name: 'Link Settings' })).toBeVisible(); | ||
| expect(screen.getByRole('button', { name: 'Copy' })).toBeVisible(); | ||
| }); | ||
|
|
||
| test('should see the classification elements if classification is present', async () => { | ||
| getWrapper({ | ||
| api: createAPIMock({ getFile: getFileMockWithClassification }, null, { getUser: getDefaultUserMock }), | ||
| }); | ||
| await waitFor(() => { | ||
| expect(getFileMockWithClassification).toHaveBeenCalledWith( | ||
| MOCK_ITEM.id, | ||
| expect.any(Function), | ||
| {}, | ||
| { | ||
| fields: CONTENT_SHARING_ITEM_FIELDS, | ||
| }, | ||
| ); | ||
| }); | ||
| expect(screen.getByText('BLUE')).toBeVisible(); | ||
| }); | ||
| }); |
9 changes: 9 additions & 0 deletions
9
src/elements/content-sharing/stories/ContentSharingV2.stories.tsx
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
10 changes: 10 additions & 0 deletions
10
src/elements/content-sharing/stories/tests/ContentSharingV2-visual.stories.tsx
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.