-
Notifications
You must be signed in to change notification settings - Fork 75
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 import taxonomy feature [FC-0036] #675
Changes from 36 commits
0c60c37
c273af1
047530d
303e7ba
3955e91
8176973
4f31714
df441fb
a0e92f0
dc8ed9e
120154e
318bbb7
a8c2fd5
70ac2a7
adacf23
5983953
7756c7f
4202c27
6bcd924
f318dfc
204b2b9
5e0f599
f888ecf
3c8da66
40479c1
46e5d1b
db8ba58
8fe8c07
1440215
e5b8e58
fafcb9b
e80194f
1e0dde3
7cae57b
1002fc6
fdc74c7
e9893dc
a8b4197
a3c40fd
1a31aa9
c6d39e5
583ab51
151ba9e
df9f2a0
67c42cb
793810f
70954b3
68e820d
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 |
---|---|---|
@@ -1,50 +1,53 @@ | ||
import React, { useMemo } from 'react'; | ||
import React from 'react'; | ||
import { IntlProvider, injectIntl } from '@edx/frontend-platform/i18n'; | ||
import { initializeMockApp } from '@edx/frontend-platform'; | ||
import { AppProvider } from '@edx/frontend-platform/react'; | ||
import { act, render, fireEvent } from '@testing-library/react'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { act, fireEvent, render } from '@testing-library/react'; | ||
|
||
import initializeStore from '../store'; | ||
import { getTaxonomyTemplateApiUrl } from './data/api'; | ||
import TaxonomyListPage from './TaxonomyListPage'; | ||
import { useTaxonomyListDataResponse, useIsTaxonomyListDataLoaded } from './data/apiHooks'; | ||
import { importTaxonomy } from './import-tags'; | ||
import { TaxonomyContext } from './common/context'; | ||
|
||
let store; | ||
const mockSetToastMessage = jest.fn(); | ||
const mockDeleteTaxonomy = jest.fn(); | ||
|
||
const taxonomies = [{ | ||
id: 1, | ||
name: 'Taxonomy', | ||
description: 'This is a description', | ||
}]; | ||
|
||
jest.mock('./data/apiHooks', () => ({ | ||
...jest.requireActual('./data/apiHooks'), | ||
useTaxonomyListDataResponse: jest.fn(), | ||
useIsTaxonomyListDataLoaded: jest.fn(), | ||
useDeleteTaxonomy: () => mockDeleteTaxonomy, | ||
})); | ||
jest.mock('./taxonomy-card/TaxonomyCardMenu', () => jest.fn(({ onClickMenuItem }) => ( | ||
// eslint-disable-next-line jsx-a11y/control-has-associated-label | ||
<button type="button" data-testid="test-delete-button" onClick={() => onClickMenuItem('delete')} /> | ||
))); | ||
|
||
const RootWrapper = () => { | ||
const context = useMemo(() => ({ | ||
toastMessage: null, | ||
setToastMessage: mockSetToastMessage, | ||
}), []); | ||
jest.mock('./import-tags', () => ({ | ||
importTaxonomy: jest.fn(), | ||
})); | ||
|
||
const context = { | ||
toastMessage: null, | ||
setToastMessage: jest.fn(), | ||
}; | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
return ( | ||
<AppProvider store={store}> | ||
<IntlProvider locale="en" messages={{}}> | ||
const RootWrapper = () => ( | ||
<AppProvider store={store}> | ||
<IntlProvider locale="en" messages={{}}> | ||
<QueryClientProvider client={queryClient}> | ||
<TaxonomyContext.Provider value={context}> | ||
<TaxonomyListPage intl={injectIntl} /> | ||
</TaxonomyContext.Provider> | ||
</IntlProvider> | ||
</AppProvider> | ||
); | ||
}; | ||
</QueryClientProvider> | ||
</IntlProvider> | ||
</AppProvider> | ||
); | ||
|
||
describe('<TaxonomyListPage />', async () => { | ||
beforeEach(async () => { | ||
|
@@ -102,20 +105,21 @@ describe('<TaxonomyListPage />', async () => { | |
expect(templateButton.href).toBe(getTaxonomyTemplateApiUrl(fileFormat.toLowerCase())); | ||
}); | ||
|
||
it('should show the success toast after delete', async () => { | ||
it('calls the import taxonomy action when the import button is clicked', async () => { | ||
useIsTaxonomyListDataLoaded.mockReturnValue(true); | ||
useTaxonomyListDataResponse.mockReturnValue({ | ||
results: taxonomies, | ||
results: [{ | ||
id: 1, | ||
name: 'Taxonomy', | ||
description: 'This is a description', | ||
}], | ||
}); | ||
mockDeleteTaxonomy.mockImplementationOnce(async (params, callbacks) => { | ||
callbacks.onSuccess(); | ||
await act(async () => { | ||
const { getByTestId } = render(<RootWrapper />); | ||
const importButton = getByTestId('taxonomy-import-button'); | ||
expect(importButton).toBeInTheDocument(); | ||
importButton.click(); | ||
expect(importTaxonomy).toHaveBeenCalled(); | ||
}); | ||
const { getByTestId, getByLabelText } = render(<RootWrapper />); | ||
rpenido marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fireEvent.click(getByTestId('test-delete-button')); | ||
fireEvent.change(getByLabelText('Type DELETE to confirm'), { target: { value: 'DELETE' } }); | ||
fireEvent.click(getByTestId('delete-button')); | ||
|
||
expect(mockDeleteTaxonomy).toBeCalledTimes(1); | ||
expect(mockSetToastMessage).toBeCalledWith(`"${taxonomies[0].name}" deleted`); | ||
}); | ||
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. I think this test can be skipped since it isn't doing anything. It's testing the presence of the import button, and then checking that clicking on the button fires the click handler. I think it should either be a deeper test of that UI or just be skipped. 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. This is only for test coverage. Is it ok to skip it? More about this in the comment at 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. Hmm... I think that is a recurring issue. I've made a suggestion for the test, other than that I guess we should leave it for now. |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
// @ts-check | ||
/* eslint-disable import/prefer-default-export */ | ||
import React from 'react'; | ||
|
||
export const TaxonomyContext = React.createContext({ | ||
toastMessage: null, | ||
setToastMessage: null, | ||
toastMessage: /** @type{null|string} */ (null), | ||
setToastMessage: /** @type{null|function} */ (null), | ||
}); |
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.
This code went to taxonomy-menu feature