-
Notifications
You must be signed in to change notification settings - Fork 81
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: Add tags to info sidebar of library component [FC-0062] #1299
Changes from 7 commits
fc25b9a
fd1f2e0
428f125
3445d13
8c38bd1
208cf68
2ed9ad8
1db25e8
0ec25b4
a505f8c
be07463
ff7bd2a
54f272d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -9,6 +9,7 @@ import { | |||
screen, | ||||
within, | ||||
} from '@testing-library/react'; | ||||
import { useParams } from 'react-router-dom'; | ||||
|
||||
import ContentTagsDrawer from './ContentTagsDrawer'; | ||||
import { | ||||
|
@@ -30,9 +31,9 @@ const mockNavigate = jest.fn(); | |||
|
||||
jest.mock('react-router-dom', () => ({ | ||||
...jest.requireActual('react-router-dom'), | ||||
useParams: () => ({ | ||||
useParams: jest.fn(() => ({ | ||||
contentId, | ||||
}), | ||||
})), | ||||
useNavigate: () => mockNavigate, | ||||
})); | ||||
|
||||
|
@@ -86,6 +87,9 @@ describe('<ContentTagsDrawer />', () => { | |||
isError: false, | ||||
mutate: mockMutate, | ||||
}); | ||||
useParams.mockReturnValue({ | ||||
contentId, | ||||
}); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that you can use the new frontend-app-authoring/src/testUtils.tsx Line 62 in b6ec5e1
Might be too big of refactor to bother with now though; just making sure you're aware :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||
}); | ||||
|
||||
const setupMockDataForStagedTagsTesting = () => { | ||||
|
@@ -479,6 +483,15 @@ describe('<ContentTagsDrawer />', () => { | |||
expect(getByText('Manage tags')).toBeInTheDocument(); | ||||
}); | ||||
|
||||
it('should throw error when contentId is undefined', () => { | ||||
useParams.mockReturnValue({ | ||||
contentId: undefined, | ||||
}); | ||||
expect(() => { | ||||
render(<RootWrapper />); | ||||
}).toThrow('Error: contentId cannot be null.'); | ||||
}); | ||||
|
||||
it('shows spinner before the content data query is complete', async () => { | ||||
await act(async () => { | ||||
const { getAllByRole } = render(<RootWrapper />); | ||||
|
@@ -495,17 +508,29 @@ describe('<ContentTagsDrawer />', () => { | |||
}); | ||||
}); | ||||
|
||||
it('shows the content display name after the query is complete', async () => { | ||||
it('shows the content display name after the query is complete in drawer variant', async () => { | ||||
useContentData.mockReturnValue({ | ||||
isSuccess: true, | ||||
data: { | ||||
displayName: 'Unit 1', | ||||
}, | ||||
}); | ||||
await act(async () => { | ||||
const { getByText } = render(<RootWrapper />); | ||||
expect(getByText('Unit 1')).toBeInTheDocument(); | ||||
render(<RootWrapper />); | ||||
expect(await screen.findByText('Unit 1')).toBeInTheDocument(); | ||||
expect(await screen.findByText('Manage tags')).toBeInTheDocument(); | ||||
}); | ||||
|
||||
it('shows the content display name after the query is complete in component variant', async () => { | ||||
useContentData.mockReturnValue({ | ||||
isSuccess: true, | ||||
data: { | ||||
displayName: 'Unit 1', | ||||
}, | ||||
}); | ||||
render(<RootWrapper variant="component" />); | ||||
expect(await screen.findByText('Loading...')).toBeInTheDocument(); | ||||
expect(screen.queryByText('Unit 1')).not.toBeInTheDocument(); | ||||
expect(screen.queryByText('Manage tags')).not.toBeInTheDocument(); | ||||
}); | ||||
|
||||
it('shows content using params', async () => { | ||||
|
@@ -580,10 +605,31 @@ describe('<ContentTagsDrawer />', () => { | |||
}); | ||||
}); | ||||
|
||||
it('should be read only on first render', async () => { | ||||
it('should be read only on first render on drawer variant', async () => { | ||||
setupMockDataForStagedTagsTesting(); | ||||
render(<RootWrapper />); | ||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument(); | ||||
expect(screen.getByRole('button', { name: /close/i })); | ||||
expect(screen.getByRole('button', { name: /edit tags/i })); | ||||
|
||||
// Not show delete tag buttons | ||||
expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument(); | ||||
|
||||
// Not show add a tag select | ||||
expect(screen.queryByText(/add a tag/i)).not.toBeInTheDocument(); | ||||
|
||||
// Not show cancel button | ||||
expect(screen.queryByRole('button', { name: /cancel/i })).not.toBeInTheDocument(); | ||||
|
||||
// Not show save button | ||||
expect(screen.queryByRole('button', { name: /save/i })).not.toBeInTheDocument(); | ||||
}); | ||||
|
||||
it('should be read only on first render on component variant', async () => { | ||||
setupMockDataForStagedTagsTesting(); | ||||
render(<RootWrapper variant="component" />); | ||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument(); | ||||
expect(screen.getByRole('button', { name: /manage tags/i })); | ||||
|
||||
// Not show delete tag buttons | ||||
expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument(); | ||||
|
@@ -598,7 +644,7 @@ describe('<ContentTagsDrawer />', () => { | |||
expect(screen.queryByRole('button', { name: /save/i })).not.toBeInTheDocument(); | ||||
}); | ||||
|
||||
it('should change to edit mode when click on `Edit tags`', async () => { | ||||
it('should change to edit mode when click on `Edit tags` on drawer variant', async () => { | ||||
setupMockDataForStagedTagsTesting(); | ||||
render(<RootWrapper />); | ||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument(); | ||||
|
@@ -622,7 +668,31 @@ describe('<ContentTagsDrawer />', () => { | |||
expect(screen.getByRole('button', { name: /save/i })).toBeInTheDocument(); | ||||
}); | ||||
|
||||
it('should change to read mode when click on `Cancel`', async () => { | ||||
it('should change to edit mode when click on `Manage tags` on component variant', async () => { | ||||
setupMockDataForStagedTagsTesting(); | ||||
render(<RootWrapper variant="component" />); | ||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument(); | ||||
const manageTagsButton = screen.getByRole('button', { | ||||
name: /manage tags/i, | ||||
}); | ||||
fireEvent.click(manageTagsButton); | ||||
|
||||
// Show delete tag buttons | ||||
expect(screen.getAllByRole('button', { | ||||
name: /delete/i, | ||||
}).length).toBe(2); | ||||
|
||||
// Show add a tag select | ||||
expect(screen.getByText(/add a tag/i)).toBeInTheDocument(); | ||||
|
||||
// Show cancel button | ||||
expect(screen.getByRole('button', { name: /cancel/i })).toBeInTheDocument(); | ||||
|
||||
// Show save button | ||||
expect(screen.getByRole('button', { name: /save/i })).toBeInTheDocument(); | ||||
}); | ||||
|
||||
it('should change to read mode when click on `Cancel` on drawer variant', async () => { | ||||
setupMockDataForStagedTagsTesting(); | ||||
render(<RootWrapper />); | ||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument(); | ||||
|
@@ -649,6 +719,33 @@ describe('<ContentTagsDrawer />', () => { | |||
expect(screen.queryByRole('button', { name: /save/i })).not.toBeInTheDocument(); | ||||
}); | ||||
|
||||
it('should change to read mode when click on `Cancel` on component variant', async () => { | ||||
setupMockDataForStagedTagsTesting(); | ||||
render(<RootWrapper variant="component" />); | ||||
expect(await screen.findByText('Taxonomy 1')).toBeInTheDocument(); | ||||
const manageTagsButton = screen.getByRole('button', { | ||||
name: /manage tags/i, | ||||
}); | ||||
fireEvent.click(manageTagsButton); | ||||
|
||||
const cancelButton = screen.getByRole('button', { | ||||
name: /cancel/i, | ||||
}); | ||||
fireEvent.click(cancelButton); | ||||
|
||||
// Not show delete tag buttons | ||||
expect(screen.queryByRole('button', { name: /delete/i })).not.toBeInTheDocument(); | ||||
|
||||
// Not show add a tag select | ||||
expect(screen.queryByText(/add a tag/i)).not.toBeInTheDocument(); | ||||
|
||||
// Not show cancel button | ||||
expect(screen.queryByRole('button', { name: /cancel/i })).not.toBeInTheDocument(); | ||||
|
||||
// Not show save button | ||||
expect(screen.queryByRole('button', { name: /save/i })).not.toBeInTheDocument(); | ||||
}); | ||||
|
||||
it('shows spinner when loading commit tags', async () => { | ||||
setupMockDataForStagedTagsTesting(); | ||||
useContentTaxonomyTagsUpdater.mockReturnValue({ | ||||
|
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.
If you have some time, could you please update these tests to use the mock API instead of mocking the hooks?
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.
Sure, let me check 👍
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.
Updated: a505f8c