-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the job edit page and ensures it aligns with the designs. Test coverage has also been improved and the test approach has been aligned across the entire suite of tests. feat: add job edit page fix: use hook without refetch fix: use initial values for edit form fix: use different label for edit form feat: add update job hook refactor: use simple hooks directly fix: fetch only whitelisted fields fix: disallow editing of system jobs fix: use flyoutmenu fix: fix data for user settings fix: move sync call to setstate to async chore(dependency): update ui chore(dependency): remove react resolutions fix(i18n): change namespace separator for string with colon character test(coverage): start improving test coverage fix(forms): format number values to string test: add tests test: add form fields tests test: add remaining form fields tests chore: update comment test: add initial jobaddform test test: add job form tests chore: remove comment test: add form tests test: update component tests test(hooks): add use update job test test(config): update test coverage settings to ignore translations refactor: simplify hooks for retrieving parameters test(services): update service testing coverage test: add minimal test for not authorized route test: add tests for job list selectors test(joblist): add tests for job list container test(joblist): add tests for remaining job list components test: add remaining tests test(joblist): use data-test attribute for new job button test refactor: deduplicate job forms test: simplify test cleanup test: silence react act warnings caused by popper test: use uniform approach for tests test: update remaining tests test: fix job form test chore: remove enzyme-to-json
- Loading branch information
ismay
committed
Jan 13, 2021
1 parent
0265476
commit aa51d10
Showing
137 changed files
with
3,167 additions
and
1,540 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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,76 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import { useGetMe, selectors } from '../../hooks/me' | ||
import { shallow, mount } from 'enzyme' | ||
import { useDataQuery } from '@dhis2/app-runtime' | ||
import expectRenderError from '../../../test/expect-render-error' | ||
import { getAuthorized } from './selectors' | ||
import AuthWall from './AuthWall' | ||
|
||
jest.mock('../../hooks/me', () => ({ | ||
useGetMe: jest.fn(), | ||
selectors: { | ||
getAuthorized: jest.fn(), | ||
}, | ||
jest.mock('@dhis2/app-runtime', () => ({ | ||
useDataQuery: jest.fn(), | ||
})) | ||
|
||
jest.mock('./selectors', () => ({ | ||
getAuthorized: jest.fn(), | ||
})) | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
describe('<AuthWall>', () => { | ||
it('renders a spinner when loading', () => { | ||
useGetMe.mockImplementationOnce(() => ({ loading: true })) | ||
it('shows a loading message when loading', () => { | ||
useDataQuery.mockImplementation(() => ({ loading: true })) | ||
|
||
const wrapper = shallow(<AuthWall>Child</AuthWall>) | ||
const wrapper = mount(<AuthWall>Child</AuthWall>) | ||
const loadingIndicator = wrapper.find({ | ||
'data-test': 'dhis2-uicore-circularloader', | ||
}) | ||
|
||
expect(wrapper).toMatchSnapshot() | ||
expect(loadingIndicator).toHaveLength(1) | ||
expect(wrapper.text()).toEqual( | ||
expect.stringContaining('Checking permissions') | ||
) | ||
}) | ||
|
||
it('throws fetching errors if they occur', () => { | ||
const props = { children: 'Child' } | ||
const error = new Error('Something went wrong') | ||
useGetMe.mockImplementationOnce(() => ({ | ||
const message = 'Something went wrong' | ||
const error = new Error(message) | ||
|
||
useDataQuery.mockImplementation(() => ({ | ||
loading: false, | ||
error, | ||
})) | ||
|
||
expect(() => AuthWall(props)).toThrow(error) | ||
expectRenderError(<AuthWall {...props} />, message) | ||
}) | ||
|
||
it('redirects unauthorized users', () => { | ||
useGetMe.mockImplementationOnce(() => ({ | ||
it('redirects unauthorized users to /notauthorized', () => { | ||
useDataQuery.mockImplementation(() => ({ | ||
loading: false, | ||
error: undefined, | ||
data: {}, | ||
})) | ||
selectors.getAuthorized.mockImplementationOnce(() => false) | ||
getAuthorized.mockImplementation(() => false) | ||
|
||
const wrapper = shallow(<AuthWall>Child</AuthWall>) | ||
const redirect = wrapper.find('Redirect') | ||
const props = redirect.props() | ||
|
||
expect(wrapper).toMatchSnapshot() | ||
expect(redirect).toHaveLength(1) | ||
expect(props).toEqual(expect.objectContaining({ to: '/notauthorized' })) | ||
}) | ||
|
||
it('renders the children for users that are authorized', () => { | ||
useGetMe.mockImplementationOnce(() => ({ | ||
useDataQuery.mockImplementation(() => ({ | ||
loading: false, | ||
error: undefined, | ||
data: {}, | ||
})) | ||
selectors.getAuthorized.mockImplementationOnce(() => true) | ||
getAuthorized.mockImplementation(() => true) | ||
|
||
const wrapper = shallow(<AuthWall>Child</AuthWall>) | ||
|
||
expect(wrapper).toMatchSnapshot() | ||
expect(wrapper.text()).toEqual(expect.stringContaining('Child')) | ||
}) | ||
}) |
32 changes: 0 additions & 32 deletions
32
src/components/AuthWall/__snapshots__/AuthWall.test.js.snap
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
export const getAuthorized = me => { | ||
const { authorities } = me | ||
|
||
if (!authorities) { | ||
return false | ||
} | ||
|
||
const isAuthorized = | ||
authorities.includes('ALL') || | ||
authorities.includes('F_SCHEDULING_ADMIN') | ||
|
||
return isAuthorized | ||
} |
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,23 @@ | ||
import { getAuthorized } from './selectors' | ||
|
||
describe('getAuthorized', () => { | ||
it('should return false if there are no authorities', () => { | ||
expect(getAuthorized({})).toBe(false) | ||
}) | ||
|
||
it('should return true if the authorities include ALL', () => { | ||
const me = { | ||
authorities: ['ALL'], | ||
} | ||
|
||
expect(getAuthorized(me)).toBe(true) | ||
}) | ||
|
||
it('should return true if the authorities include F_SCHEDULING_ADMIN', () => { | ||
const me = { | ||
authorities: ['F_SCHEDULING_ADMIN'], | ||
} | ||
|
||
expect(getAuthorized(me)).toBe(true) | ||
}) | ||
}) |
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.