@@ -3,9 +3,7 @@ | |||
"rules": { | |||
// some dependencies are implictly provided by gatsby | |||
"import/no-extraneous-dependencies": "off" | |||
}, | |||
"parserOptions": { | |||
"warnOnUnsupportedTypeScriptVersion": false | |||
"import/no-extraneous-dependencies": "off", | |||
"testing-library/render-result-naming-convention": "warn" | |||
} | |||
} |
@@ -36,13 +36,13 @@ export default class HeaderListProvider extends React.Component<Props, State> { | |||
headers: PropTypes.object | |||
}; | |||
getChildContext = () => { | |||
getChildContext() { | |||
return { | |||
headers: { | |||
setHeaders: this.setHeaders | |||
} | |||
}; | |||
}; | |||
} | |||
setHeaders = (headers: MarkdownHeading[]) => { | |||
this.setState({ headers }); |
@@ -118,7 +118,9 @@ it('should search', () => { | |||
); | |||
wrapper.instance().handleChange({ currentTarget: { value: 'simply text+:' } } as any); | |||
expect(wrapper).toMatchSnapshot(); | |||
expect(lunr).toBeCalled(); | |||
expect(lunr).toHaveBeenCalled(); | |||
expect(wrapper.instance().index).toBeDefined(); | |||
expect((wrapper.instance().index as any).search).toBeCalledWith('simply~1 simply* text~1 text*'); | |||
expect((wrapper.instance().index as any).search).toHaveBeenCalledWith( | |||
'simply~1 simply* text~1 text*' | |||
); | |||
}); |
@@ -3,26 +3,7 @@ | |||
"rules": { | |||
"camelcase": "off", | |||
"promise/no-return-wrap": "warn", | |||
"react/jsx-curly-brace-presence": "warn" | |||
}, | |||
"parserOptions": { | |||
"warnOnUnsupportedTypeScriptVersion": false | |||
}, | |||
"plugins": ["testing-library"], | |||
"overrides": [ | |||
{ | |||
"files": [ | |||
"**/__tests__/**/*-it.{ts,tsx}" | |||
], | |||
"extends": [ | |||
"plugin:testing-library/react" | |||
], | |||
"rules": { | |||
"testing-library/await-async-query": "error", | |||
"testing-library/no-await-sync-query": "error", | |||
"testing-library/no-debugging-utils": "error", | |||
"testing-library/no-dom-import": "error" | |||
} | |||
} | |||
] | |||
"react/jsx-curly-brace-presence": "warn", | |||
"testing-library/render-result-naming-convention": "warn" | |||
} | |||
} |
@@ -121,7 +121,7 @@ it('loads the project binding, if any', async () => { | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
expect(getProjectAlmBinding).toBeCalled(); | |||
expect(getProjectAlmBinding).toHaveBeenCalled(); | |||
expect(wrapper.state().projectBinding).toBeUndefined(); | |||
wrapper.setProps({ location: mockLocation({ query: { id: 'bar' } }) }); | |||
@@ -132,10 +132,13 @@ it('loads the project binding, if any', async () => { | |||
it("doesn't load branches portfolio", async () => { | |||
const wrapper = shallowRender({ location: mockLocation({ query: { id: 'portfolioKey' } }) }); | |||
await waitAndUpdate(wrapper); | |||
expect(getBranches).not.toBeCalled(); | |||
expect(getPullRequests).not.toBeCalled(); | |||
expect(getComponentData).toBeCalledWith({ component: 'portfolioKey', branch: undefined }); | |||
expect(getComponentNavigation).toBeCalledWith({ component: 'portfolioKey', branch: undefined }); | |||
expect(getBranches).not.toHaveBeenCalled(); | |||
expect(getPullRequests).not.toHaveBeenCalled(); | |||
expect(getComponentData).toHaveBeenCalledWith({ component: 'portfolioKey', branch: undefined }); | |||
expect(getComponentNavigation).toHaveBeenCalledWith({ | |||
component: 'portfolioKey', | |||
branch: undefined | |||
}); | |||
}); | |||
it('updates branches on change', async () => { | |||
@@ -153,10 +156,10 @@ it('updates branches on change', async () => { | |||
loading: false | |||
}); | |||
wrapper.instance().handleBranchesChange(); | |||
expect(getBranches).toBeCalledWith('projectKey'); | |||
expect(getPullRequests).toBeCalledWith('projectKey'); | |||
expect(getBranches).toHaveBeenCalledWith('projectKey'); | |||
expect(getPullRequests).toHaveBeenCalledWith('projectKey'); | |||
await waitAndUpdate(wrapper); | |||
expect(updateBranchStatus).toBeCalledTimes(2); | |||
expect(updateBranchStatus).toHaveBeenCalledTimes(2); | |||
}); | |||
it('fetches status', async () => { | |||
@@ -166,7 +169,7 @@ it('fetches status', async () => { | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
expect(getTasksForComponent).toBeCalledWith('portfolioKey'); | |||
expect(getTasksForComponent).toHaveBeenCalledWith('portfolioKey'); | |||
}); | |||
it('filters correctly the pending tasks for a main branch', () => { | |||
@@ -338,7 +341,7 @@ it('should redirect if the user has no access', async () => { | |||
); | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
expect(handleRequiredAuthorization).toBeCalled(); | |||
expect(handleRequiredAuthorization).toHaveBeenCalled(); | |||
}); | |||
it('should redirect if the component is a portfolio', async () => { | |||
@@ -354,7 +357,7 @@ it('should redirect if the component is a portfolio', async () => { | |||
router: mockRouter({ replace }) | |||
}); | |||
await waitAndUpdate(wrapper); | |||
expect(replace).toBeCalledWith({ pathname: '/portfolio', search: `?id=${componentKey}` }); | |||
expect(replace).toHaveBeenCalledWith({ pathname: '/portfolio', search: `?id=${componentKey}` }); | |||
}); | |||
it('should display display the unavailable page if the component needs issue sync', async () => { | |||
@@ -382,7 +385,7 @@ it('should correctly reload last task warnings if anything got dismissed', async | |||
(getAnalysisStatus as jest.Mock).mockClear(); | |||
wrapper.instance().handleWarningDismiss(); | |||
expect(getAnalysisStatus).toBeCalledTimes(1); | |||
expect(getAnalysisStatus).toHaveBeenCalledTimes(1); | |||
}); | |||
describe('should correctly validate the project binding depending on the context', () => { | |||
@@ -407,7 +410,7 @@ describe('should correctly validate the project binding depending on the context | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper.state().projectBindingErrors).toBe(projectBindingErrors); | |||
expect(validateProjectAlmBinding).toBeCalledTimes(n); | |||
expect(validateProjectAlmBinding).toHaveBeenCalledTimes(n); | |||
}); | |||
}); | |||
@@ -59,7 +59,7 @@ it('should work for WebAnalytics plugin', () => { | |||
expect(wrapper).toMatchSnapshot(); | |||
expect(wrapper.find('Helmet').prop('onChangeClientState')).toBe(wrapper.instance().trackPage); | |||
expect(installScript).toBeCalledWith(webAnalyticsJsPath, 'head'); | |||
expect(installScript).toHaveBeenCalledWith(webAnalyticsJsPath, 'head'); | |||
(getWebAnalyticsPageHandlerFromCache as jest.Mock).mockReturnValueOnce(pageChange); | |||
wrapper.instance().trackPage(); |
@@ -50,7 +50,7 @@ it('should redirect non-admin users', () => { | |||
router: mockRouter({ replace }) | |||
}); | |||
expect(wrapper.type()).toBeNull(); | |||
expect(replace).toBeCalled(); | |||
expect(replace).toHaveBeenCalled(); | |||
}); | |||
it('should handle acknowledgement and redirect', async () => { | |||
@@ -63,7 +63,7 @@ it('should handle acknowledgement and redirect', async () => { | |||
await new Promise(setImmediate); | |||
expect(setSimpleSettingValue).toBeCalled(); | |||
expect(setSimpleSettingValue).toHaveBeenCalled(); | |||
}); | |||
function shallowRender(props: Partial<PluginRiskConsentProps> = {}) { |
@@ -33,7 +33,7 @@ it('should render correctly', () => { | |||
it('should redirect for authorization if needed', () => { | |||
mountRender({ component: mockComponent({ configuration: { showSettings: false } }) }); | |||
expect(handleRequiredAuthorization).toBeCalled(); | |||
expect(handleRequiredAuthorization).toHaveBeenCalled(); | |||
}); | |||
function mountRender(props: Partial<ProjectAdminContainer['props']> = {}) { |
@@ -36,38 +36,38 @@ it('should get existing history', () => { | |||
const history = [{ key: 'foo', name: 'Foo', icon: 'TRK' }]; | |||
(get as jest.Mock).mockReturnValueOnce(JSON.stringify(history)); | |||
expect(RecentHistory.get()).toEqual(history); | |||
expect(get).toBeCalledWith('sonar_recent_history'); | |||
expect(get).toHaveBeenCalledWith('sonar_recent_history'); | |||
}); | |||
it('should get empty history', () => { | |||
(get as jest.Mock).mockReturnValueOnce(null); | |||
expect(RecentHistory.get()).toEqual([]); | |||
expect(get).toBeCalledWith('sonar_recent_history'); | |||
expect(get).toHaveBeenCalledWith('sonar_recent_history'); | |||
}); | |||
it('should return [] and clear history in case of failure', () => { | |||
(get as jest.Mock).mockReturnValueOnce('not a json'); | |||
expect(RecentHistory.get()).toEqual([]); | |||
expect(get).toBeCalledWith('sonar_recent_history'); | |||
expect(remove).toBeCalledWith('sonar_recent_history'); | |||
expect(get).toHaveBeenCalledWith('sonar_recent_history'); | |||
expect(remove).toHaveBeenCalledWith('sonar_recent_history'); | |||
}); | |||
it('should save history', () => { | |||
const history = [{ key: 'foo', name: 'Foo', icon: 'TRK' }]; | |||
RecentHistory.set(history); | |||
expect(save).toBeCalledWith('sonar_recent_history', JSON.stringify(history)); | |||
expect(save).toHaveBeenCalledWith('sonar_recent_history', JSON.stringify(history)); | |||
}); | |||
it('should clear history', () => { | |||
RecentHistory.clear(); | |||
expect(remove).toBeCalledWith('sonar_recent_history'); | |||
expect(remove).toHaveBeenCalledWith('sonar_recent_history'); | |||
}); | |||
it('should add item to history', () => { | |||
const history = [{ key: 'foo', name: 'Foo', icon: 'TRK' }]; | |||
(get as jest.Mock).mockReturnValueOnce(JSON.stringify(history)); | |||
RecentHistory.add('bar', 'Bar', 'VW'); | |||
expect(save).toBeCalledWith( | |||
expect(save).toHaveBeenCalledWith( | |||
'sonar_recent_history', | |||
JSON.stringify([{ key: 'bar', name: 'Bar', icon: 'VW' }, ...history]) | |||
); | |||
@@ -80,7 +80,7 @@ it('should keep 10 items maximum', () => { | |||
} | |||
(get as jest.Mock).mockReturnValueOnce(JSON.stringify(history)); | |||
RecentHistory.add('bar', 'Bar', 'VW'); | |||
expect(save).toBeCalledWith( | |||
expect(save).toHaveBeenCalledWith( | |||
'sonar_recent_history', | |||
JSON.stringify([{ key: 'bar', name: 'Bar', icon: 'VW' }, ...history.slice(0, 9)]) | |||
); | |||
@@ -93,7 +93,7 @@ it('should remove component from history', () => { | |||
} | |||
(get as jest.Mock).mockReturnValueOnce(JSON.stringify(history)); | |||
RecentHistory.remove('key-5'); | |||
expect(save).toBeCalledWith( | |||
expect(save).toHaveBeenCalledWith( | |||
'sonar_recent_history', | |||
JSON.stringify([...history.slice(0, 5), ...history.slice(6)]) | |||
); |
@@ -120,7 +120,7 @@ it('should handle connection errors', async () => { | |||
it('should require authentication if user is not logged in', () => { | |||
renderSonarLintConnection({ currentUser: mockCurrentUser() }); | |||
expect(handleRequiredAuthentication).toBeCalled(); | |||
expect(handleRequiredAuthentication).toHaveBeenCalled(); | |||
}); | |||
it('should redirect if port is not provided', () => { |
@@ -17,7 +17,7 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
import { fireEvent, screen } from '@testing-library/dom'; | |||
import { fireEvent, screen } from '@testing-library/react'; | |||
import * as React from 'react'; | |||
import { getValues } from '../../../api/settings'; | |||
import { renderComponent } from '../../../helpers/testReactTestingUtils'; |
@@ -43,7 +43,7 @@ describe('fetchBranchStatus', () => { | |||
wrapper.instance().fetchBranchStatus(mockBranch({ name: branchName }), projectKey); | |||
expect(getQualityGateProjectStatus).toBeCalledWith({ projectKey, branch: branchName }); | |||
expect(getQualityGateProjectStatus).toHaveBeenCalledWith({ projectKey, branch: branchName }); | |||
await waitAndUpdate(wrapper); | |||
@@ -48,9 +48,9 @@ it('should render React extensions correctly', async () => { | |||
const wrapper = shallowRender(); | |||
expect(wrapper).toMatchSnapshot(); | |||
expect(getExtensionStart).toBeCalledWith('foo'); | |||
expect(getExtensionStart).toHaveBeenCalledWith('foo'); | |||
await waitAndUpdate(wrapper); | |||
expect(start).toBeCalled(); | |||
expect(start).toHaveBeenCalled(); | |||
expect(wrapper).toMatchSnapshot(); | |||
}); | |||
@@ -63,11 +63,11 @@ it('should handle Function extensions correctly', async () => { | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
expect(start).toBeCalled(); | |||
expect(start).toHaveBeenCalled(); | |||
wrapper.setProps({ extension: { key: 'bar', name: 'Bar' } }); | |||
await waitAndUpdate(wrapper); | |||
expect(stop).toBeCalled(); | |||
expect(stop).toHaveBeenCalled(); | |||
}); | |||
it('should unmount an extension before starting a new one', async () => { |
@@ -40,7 +40,7 @@ it('should render correctly when the extension is found', () => { | |||
}), | |||
{ pluginKey: 'pluginId', extensionKey: 'extensionId' } | |||
); | |||
expect(getExtensionStart).toBeCalledWith('pluginId/extensionId'); | |||
expect(getExtensionStart).toHaveBeenCalledWith('pluginId/extensionId'); | |||
}); | |||
it('should render correctly when the extension is not found', () => { |
@@ -36,7 +36,7 @@ jest.mock('../../../../helpers/extensions', () => ({ | |||
it('should not render when no component is passed', () => { | |||
renderProjectPageExtension(); | |||
expect(screen.queryByText('page_not_found')).not.toBeInTheDocument(); | |||
expect(getExtensionStart).not.toBeCalledWith('pluginId/extensionId'); | |||
expect(getExtensionStart).not.toHaveBeenCalledWith('pluginId/extensionId'); | |||
}); | |||
it('should render correctly when the extension is found', () => { | |||
@@ -44,7 +44,7 @@ it('should render correctly when the extension is found', () => { | |||
mockComponent({ extensions: [{ key: 'pluginId/extensionId', name: 'name' }] }), | |||
{ params: { pluginKey: 'pluginId', extensionKey: 'extensionId' } } | |||
); | |||
expect(getExtensionStart).toBeCalledWith('pluginId/extensionId'); | |||
expect(getExtensionStart).toHaveBeenCalledWith('pluginId/extensionId'); | |||
}); | |||
it('should render correctly when the extension is not found', () => { |
@@ -32,7 +32,7 @@ it('should call language', async () => { | |||
(getLanguages as jest.Mock).mockResolvedValueOnce(languages); | |||
const wrapper = shallowRender(); | |||
expect(getLanguages).toBeCalled(); | |||
expect(getLanguages).toHaveBeenCalled(); | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper.state()).toEqual({ languages }); | |||
}); |
@@ -34,7 +34,7 @@ it('should call metric', async () => { | |||
(getAllMetrics as jest.Mock).mockResolvedValueOnce(Object.values(metrics)); | |||
const wrapper = shallowRender(); | |||
expect(getAllMetrics).toBeCalled(); | |||
expect(getAllMetrics).toHaveBeenCalled(); | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper.state()).toEqual({ metrics }); | |||
}); |
@@ -288,28 +288,42 @@ it.each([ | |||
expect(wrapper.find(Alert).props().variant).toBe(alertVariant); | |||
// Formatted message values prop. | |||
// eslint-disable-next-line jest/no-conditional-in-test | |||
if (/_X/.test(expectedMessage)) { | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(messageProps.values?.type).toBe(`background_task.type.${currentTask.type}`); | |||
} else { | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(messageProps.values?.type).toBeUndefined(); | |||
} | |||
// eslint-disable-next-line jest/no-conditional-in-test | |||
if (currentTask.branch) { | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(messageProps.values?.branch).toBe(currentTask.branch); | |||
} else { | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(messageProps.values?.branch).toBeUndefined(); | |||
} | |||
// eslint-disable-next-line jest/no-conditional-in-test | |||
if (showBackgroundTasks) { | |||
// eslint-disable-next-line jest/no-conditional-in-test | |||
if (onBackgroudTaskPage) { | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(messageProps.values?.url).toBeUndefined(); | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(messageProps.values?.stacktrace).toBe('background_tasks.show_stacktrace'); | |||
} else { | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(messageProps.values?.url).toBeDefined(); | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(messageProps.values?.stacktrace).toBeUndefined(); | |||
} | |||
} else { | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(messageProps.values?.url).toBeUndefined(); | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(messageProps.values?.stacktrace).toBeUndefined(); | |||
} | |||
} |
@@ -32,7 +32,7 @@ it('should call onPageChange when clicked', () => { | |||
wrapper.simulate('click'); | |||
expect(onPageChange).toBeCalledWith(to); | |||
expect(onPageChange).toHaveBeenCalledWith(to); | |||
}); | |||
function shallowRender(props: Partial<DrawerLinkProps<string>> = {}) { |
@@ -32,7 +32,7 @@ it('should call onClose when button is clicked', () => { | |||
const wrapper = shallowRender({ onClose, displayed: true }); | |||
wrapper.find(ClearButton).simulate('click'); | |||
expect(onClose).toBeCalled(); | |||
expect(onClose).toHaveBeenCalled(); | |||
}); | |||
function shallowRender(props: Partial<InfoDrawerProps> = {}) { |
@@ -32,7 +32,7 @@ it('should call onPageChange when clicked', () => { | |||
wrapper.find('.back-button').simulate('click'); | |||
expect(onPageChange).toBeCalledTimes(1); | |||
expect(onPageChange).toHaveBeenCalledTimes(1); | |||
}); | |||
function shallowRender(props: Partial<InfoDrawerPageProps> = {}) { |
@@ -40,7 +40,7 @@ it('should render correctly', async () => { | |||
expect(wrapper).toMatchSnapshot(); | |||
expect(wrapper.find('.project-info-deprecated-rules').exists()).toBe(true); | |||
expect(wrapper.find('.project-info-deleted-profile').exists()).toBe(true); | |||
expect(searchRules).toBeCalled(); | |||
expect(searchRules).toHaveBeenCalled(); | |||
}); | |||
function shallowRender(props: Partial<MetaQualityProfiles['props']> = {}) { |
@@ -38,7 +38,7 @@ it('searches tags on mount', () => { | |||
Promise.resolve({ tags: ['foo', 'bar'] }) | |||
); | |||
mount(<MetaTagsSelector selectedTags={[]} setProjectTags={jest.fn()} />); | |||
expect(searchProjectTags).toBeCalledWith({ ps: 9, q: '' }); | |||
expect(searchProjectTags).toHaveBeenCalledWith({ ps: 9, q: '' }); | |||
}); | |||
it('selects and deselects tags', () => { |
@@ -17,7 +17,7 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
import { screen } from '@testing-library/dom'; | |||
import { screen } from '@testing-library/react'; | |||
import * as React from 'react'; | |||
import { mockAppState, mockCurrentUser } from '../../../../../helpers/testMocks'; | |||
import { renderComponent } from '../../../../../helpers/testReactTestingUtils'; |
@@ -50,9 +50,9 @@ it('should remove the toaster when click on dismiss', async () => { | |||
updateDismissedNotices | |||
}); | |||
wrapper.find('.toaster-actions ButtonLink').simulate('click'); | |||
expect(dismissNotice).toBeCalled(); | |||
expect(dismissNotice).toHaveBeenCalled(); | |||
await waitAndUpdate(wrapper); | |||
expect(updateDismissedNotices).toBeCalled(); | |||
expect(updateDismissedNotices).toHaveBeenCalled(); | |||
}); | |||
it('should remove the toaster and navigate to sonarlint when click on learn more', async () => { | |||
@@ -62,9 +62,9 @@ it('should remove the toaster and navigate to sonarlint when click on learn more | |||
updateDismissedNotices | |||
}); | |||
wrapper.find('.toaster-actions .button-primary').simulate('click'); | |||
expect(dismissNotice).toBeCalled(); | |||
expect(dismissNotice).toHaveBeenCalled(); | |||
await waitAndUpdate(wrapper); | |||
expect(updateDismissedNotices).toBeCalled(); | |||
expect(updateDismissedNotices).toHaveBeenCalled(); | |||
}); | |||
function shallowRender(props: Partial<PromotionNotificationProps> = {}) { |
@@ -69,7 +69,7 @@ it('opens selected project on enter', () => { | |||
}); | |||
keydown({ key: KeyboardKeys.Enter }); | |||
expect(router.push).toBeCalledWith({ | |||
expect(router.push).toHaveBeenCalledWith({ | |||
pathname: '/dashboard', | |||
search: queryToSearch({ id: selectedKey }) | |||
}); | |||
@@ -88,7 +88,7 @@ it('opens selected portfolio on enter', () => { | |||
}); | |||
keydown({ key: KeyboardKeys.Enter }); | |||
expect(router.push).toBeCalledWith({ | |||
expect(router.push).toHaveBeenCalledWith({ | |||
pathname: '/portfolio', | |||
search: queryToSearch({ id: selectedKey }) | |||
}); | |||
@@ -107,7 +107,7 @@ it('opens selected subportfolio on enter', () => { | |||
}); | |||
keydown({ key: KeyboardKeys.Enter }); | |||
expect(router.push).toBeCalledWith({ | |||
expect(router.push).toHaveBeenCalledWith({ | |||
pathname: '/portfolio', | |||
search: queryToSearch({ id: selectedKey }) | |||
}); |
@@ -37,14 +37,14 @@ it('should trigger showing more', () => { | |||
stopPropagation() {} | |||
} | |||
}); | |||
expect(onMoreClick).toBeCalledWith('TRK'); | |||
expect(onMoreClick).toHaveBeenCalledWith('TRK'); | |||
}); | |||
it('should select on mouse over', () => { | |||
const onSelect = jest.fn(); | |||
const wrapper = shallowRender({ onSelect }); | |||
wrapper.find('a').simulate('mouseenter', { currentTarget: { dataset: { qualifier: 'TRK' } } }); | |||
expect(onSelect).toBeCalledWith('qualifier###TRK'); | |||
expect(onSelect).toHaveBeenCalledWith('qualifier###TRK'); | |||
}); | |||
function shallowRender(props: Partial<SearchShowMore['props']> = {}) { |
@@ -32,7 +32,7 @@ it('should transform path parameters to search params', () => { | |||
renderNavigateWithParams(transformParams); | |||
expect(transformParams).toBeCalled(); | |||
expect(transformParams).toHaveBeenCalled(); | |||
expect(screen.getByText('/target?also=this&key=hello&subkey=test')).toBeInTheDocument(); | |||
}); | |||
@@ -47,7 +47,7 @@ afterAll(() => { | |||
it('should not render for anonymous user', () => { | |||
handleRequiredAuthorization(); | |||
expect(replace).toBeCalledWith( | |||
expect(replace).toHaveBeenCalledWith( | |||
'/sessions/new?return_to=%2Fpath%3Fid%3D12%23tag&authorizationError=true' | |||
); | |||
}); |
@@ -166,7 +166,7 @@ it('should handle a currentUser not logged in', () => { | |||
renderAccountApp(mockCurrentUser()); | |||
// Make sure we're redirected to the login screen | |||
expect(replace).toBeCalledWith('/sessions/new?return_to=%2Faccount'); | |||
expect(replace).toHaveBeenCalledWith('/sessions/new?return_to=%2Faccount'); | |||
locationMock.mockRestore(); | |||
}); | |||
@@ -241,7 +241,7 @@ describe('profile page', () => { | |||
await user.click(toggle); | |||
expect(setKeyboardShortcutEnabled).toBeCalledWith(false); | |||
expect(setKeyboardShortcutEnabled).toHaveBeenCalledWith(false); | |||
}); | |||
}); | |||
@@ -288,15 +288,20 @@ describe('security page', () => { | |||
const tokenTypeLabel = `users.tokens.${tokenTypeOption}`; | |||
const tokenTypeShortLabel = `users.tokens.${tokenTypeOption}.short`; | |||
// eslint-disable-next-line jest/no-conditional-in-test | |||
if (tokenTypeOption === TokenType.Project) { | |||
await selectEvent.select(screen.getAllByRole('textbox')[1], [tokenTypeLabel]); | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(generateButton).toBeDisabled(); | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(screen.getAllByRole('textbox')).toHaveLength(4); | |||
await selectEvent.select(screen.getAllByRole('textbox')[2], ['Project Name 1']); | |||
expect(generateButton).not.toBeDisabled(); | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(generateButton).toBeEnabled(); | |||
} else { | |||
await selectEvent.select(screen.getAllByRole('textbox')[1], [tokenTypeLabel]); | |||
expect(generateButton).not.toBeDisabled(); | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(generateButton).toBeEnabled(); | |||
} | |||
await user.click(generateButton); | |||
@@ -307,10 +312,15 @@ describe('security page', () => { | |||
expect(screen.getByRole('button', { name: 'copy_to_clipboard' })).toBeInTheDocument(); | |||
const lastTokenCreated = tokenMock.getLastToken(); | |||
// eslint-disable-next-line jest/no-conditional-in-test | |||
if (lastTokenCreated === undefined) { | |||
throw new Error("Couldn't find the latest generated token."); | |||
} | |||
expect(screen.getByLabelText('users.new_token').textContent).toBe(lastTokenCreated.token); | |||
// eslint-disable-next-line jest/no-conditional-in-test | |||
expect(screen.getByLabelText('users.new_token')).toHaveTextContent( | |||
// eslint-disable-next-line jest/no-conditional-in-test | |||
lastTokenCreated.token ?? '' | |||
); | |||
expect(screen.getAllByRole('row')).toHaveLength(4); // 3 tokens + header | |||
@@ -319,7 +329,9 @@ describe('security page', () => { | |||
}); | |||
expect(await within(row).findByText(tokenTypeShortLabel)).toBeInTheDocument(); | |||
// eslint-disable-next-line jest/no-conditional-in-test | |||
if (tokenTypeOption === TokenType.Project) { | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(await within(row).findByText('Project Name 1')).toBeInTheDocument(); | |||
} | |||
@@ -520,7 +532,7 @@ describe('notifications page', () => { | |||
await user.keyboard('[ArrowDown][ArrowDown][ArrowUp][Enter]'); | |||
const addButton = screen.getByRole('button', { name: 'add_verb' }); | |||
expect(addButton).not.toBeDisabled(); | |||
expect(addButton).toBeEnabled(); | |||
await user.click(addButton); | |||
@@ -581,6 +593,9 @@ describe('projects page', () => { | |||
expect(within(project1).getAllByRole('link')).toHaveLength(6); | |||
const project2 = getProjectBlock('Project 2'); | |||
// FP | |||
// eslint-disable-next-line jest-dom/prefer-in-document | |||
expect(within(project2).getAllByRole('link')).toHaveLength(1); | |||
}); | |||
@@ -621,6 +636,8 @@ describe('projects page', () => { | |||
renderAccountApp(mockLoggedInUser(), projectsPagePath); | |||
// FP | |||
// eslint-disable-next-line jest-dom/prefer-in-document | |||
expect(await screen.findAllByRole('heading', { name: /Project \d/ })).toHaveLength(1); | |||
const showMoreButton = await screen.findByRole('button', { name: 'show_more' }); |
@@ -50,16 +50,16 @@ describe('Search', () => { | |||
const component = shallow(<Search {...defaultProps} onFilterUpdate={searchSpy} />); | |||
const searchInput = component.find('SearchBox'); | |||
searchInput.prop<Function>('onChange')('some search query'); | |||
expect(searchSpy).toBeCalledWith({ query: 'some search query' }); | |||
expect(searchSpy).toHaveBeenCalledWith({ query: 'some search query' }); | |||
}); | |||
it('should reload', () => { | |||
const reloadSpy = jest.fn(); | |||
const component = shallow(<Search {...defaultProps} onReload={reloadSpy} />); | |||
const reloadButton = component.find('.js-reload'); | |||
expect(reloadSpy).not.toBeCalled(); | |||
expect(reloadSpy).not.toHaveBeenCalled(); | |||
click(reloadButton); | |||
expect(reloadSpy).toBeCalled(); | |||
expect(reloadSpy).toHaveBeenCalled(); | |||
}); | |||
}); | |||
@@ -50,13 +50,13 @@ it('closes', () => { | |||
const onClose = jest.fn(); | |||
const wrapper = shallow(<ScannerContext onClose={onClose} task={task} />); | |||
click(wrapper.find('.js-modal-close')); | |||
expect(onClose).toBeCalled(); | |||
expect(onClose).toHaveBeenCalled(); | |||
}); | |||
it('fetches scanner context on mount', async () => { | |||
const wrapper = shallow(<ScannerContext onClose={jest.fn()} task={task} />); | |||
expect(wrapper.state()).toEqual({}); | |||
expect(getTask).toBeCalledWith('123', ['scannerContext']); | |||
expect(getTask).toHaveBeenCalledWith('123', ['scannerContext']); | |||
await new Promise(setImmediate); | |||
expect(wrapper.state()).toEqual({ scannerContext: 'context' }); | |||
}); |
@@ -50,13 +50,13 @@ it('closes', () => { | |||
const onClose = jest.fn(); | |||
const wrapper = shallow(<Stacktrace onClose={onClose} task={task} />); | |||
click(wrapper.find('.js-modal-close')); | |||
expect(onClose).toBeCalled(); | |||
expect(onClose).toHaveBeenCalled(); | |||
}); | |||
it('fetches scanner context on mount', async () => { | |||
const wrapper = shallow(<Stacktrace onClose={jest.fn()} task={task} />); | |||
expect(wrapper.state()).toEqual({ loading: true }); | |||
expect(getTask).toBeCalledWith('123', ['stacktrace']); | |||
expect(getTask).toHaveBeenCalledWith('123', ['stacktrace']); | |||
await new Promise(setImmediate); | |||
expect(wrapper.state()).toEqual({ loading: false, stacktrace: 'stacktrace' }); | |||
}); |
@@ -46,9 +46,9 @@ it('should not show cancel pending button', () => { | |||
it('should trigger cancelling pending', () => { | |||
const onCancelAllPending = jest.fn(); | |||
const result = shallowRender({ onCancelAllPending }); | |||
expect(onCancelAllPending).not.toBeCalled(); | |||
expect(onCancelAllPending).not.toHaveBeenCalled(); | |||
result.find('ConfirmButton').prop<Function>('onConfirm')(); | |||
expect(onCancelAllPending).toBeCalled(); | |||
expect(onCancelAllPending).toHaveBeenCalled(); | |||
}); | |||
function shallowRender(props: Partial<Props> = {}) { |
@@ -37,9 +37,9 @@ it('should render without the filter link', () => { | |||
it('should trigger filtering failures', () => { | |||
const onShowFailing = jest.fn(); | |||
const result = shallowRender({ onShowFailing }); | |||
expect(onShowFailing).not.toBeCalled(); | |||
expect(onShowFailing).not.toHaveBeenCalled(); | |||
click(result.find('ButtonLink')); | |||
expect(onShowFailing).toBeCalled(); | |||
expect(onShowFailing).toHaveBeenCalled(); | |||
}); | |||
function shallowRender(props: Partial<Props> = {}) { |
@@ -47,5 +47,5 @@ it('returns new worker count', async () => { | |||
submit(wrapper.find('form')); | |||
await new Promise(setImmediate); | |||
expect(onClose).toBeCalled(); | |||
expect(onClose).toHaveBeenCalled(); | |||
}); |
@@ -98,7 +98,7 @@ it('should refresh branch status if issues are updated', async () => { | |||
await waitAndUpdate(wrapper); | |||
instance.handleIssueChange(mockIssue()); | |||
expect(fetchBranchStatus).toBeCalledWith(branchLike, 'foo'); | |||
expect(fetchBranchStatus).toHaveBeenCalledWith(branchLike, 'foo'); | |||
}); | |||
it('should load more behave correctly', async () => { |
@@ -57,7 +57,7 @@ it('should render correctly', async () => { | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper).toMatchSnapshot('loaded'); | |||
expect(getRuleDetails).toBeCalledWith( | |||
expect(getRuleDetails).toHaveBeenCalledWith( | |||
expect.objectContaining({ | |||
actives: true, | |||
key: 'squid:S1337' | |||
@@ -72,7 +72,7 @@ it('should correctly handle prop changes', async () => { | |||
jest.clearAllMocks(); | |||
wrapper.setProps({ ruleKey }); | |||
expect(getRuleDetails).toBeCalledWith( | |||
expect(getRuleDetails).toHaveBeenCalledWith( | |||
expect.objectContaining({ | |||
actives: true, | |||
key: ruleKey | |||
@@ -119,7 +119,7 @@ it('should correctly handle activation', async () => { | |||
wrapper.instance().handleActivate(); | |||
await waitAndUpdate(wrapper); | |||
expect(onActivate).toBeCalledWith( | |||
expect(onActivate).toHaveBeenCalledWith( | |||
'foo', | |||
'squid:S1337', | |||
expect.objectContaining({ | |||
@@ -137,7 +137,7 @@ it('should correctly handle deactivation', async () => { | |||
wrapper.instance().handleDeactivate(); | |||
await waitAndUpdate(wrapper); | |||
expect(onDeactivate).toBeCalledWith(selectedProfile.key, 'squid:S1337'); | |||
expect(onDeactivate).toHaveBeenCalledWith(selectedProfile.key, 'squid:S1337'); | |||
}); | |||
it('should correctly handle deletion', async () => { | |||
@@ -147,8 +147,8 @@ it('should correctly handle deletion', async () => { | |||
wrapper.instance().handleDelete(); | |||
await waitAndUpdate(wrapper); | |||
expect(deleteRule).toBeCalledWith(expect.objectContaining({ key: 'squid:S1337' })); | |||
expect(onDelete).toBeCalledWith('squid:S1337'); | |||
expect(deleteRule).toHaveBeenCalledWith(expect.objectContaining({ key: 'squid:S1337' })); | |||
expect(onDelete).toHaveBeenCalledWith('squid:S1337'); | |||
}); | |||
function shallowRender(props: Partial<RuleDetails['props']> = {}) { |
@@ -47,7 +47,7 @@ it('should fetch issues and render', async () => { | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper).toMatchSnapshot(); | |||
expect(getFacet).toBeCalledWith( | |||
expect(getFacet).toHaveBeenCalledWith( | |||
{ | |||
resolved: 'false', | |||
rules: 'foo' |
@@ -86,7 +86,7 @@ it('should edit tags', () => { | |||
.prop('overlay') as RuleDetailsTagsPopup; | |||
overlay.props.setTags(['foo', 'bar']); | |||
expect(onTagsChange).toBeCalledWith(['foo', 'bar']); | |||
expect(onTagsChange).toHaveBeenCalledWith(['foo', 'bar']); | |||
}); | |||
function shallowRender(props: Partial<RuleDetailsMeta['props']> = {}) { |
@@ -34,7 +34,7 @@ it('should render tags', () => { | |||
it('should search tags', async () => { | |||
const wrapper = shallowRender(); | |||
wrapper.prop<Function>('onSearch')('sys'); | |||
expect(getRuleTags).toBeCalledWith({ ps: 11, q: 'sys' }); | |||
expect(getRuleTags).toHaveBeenCalledWith({ ps: 11, q: 'sys' }); | |||
await new Promise(setImmediate); | |||
wrapper.update(); | |||
// should not contain system tags | |||
@@ -46,10 +46,10 @@ it('should select & unselect tags', () => { | |||
const wrapper = shallowRender({ setTags }); | |||
wrapper.prop<Function>('onSelect')('another'); | |||
expect(setTags).lastCalledWith(['foo', 'another']); | |||
expect(setTags).toHaveBeenLastCalledWith(['foo', 'another']); | |||
wrapper.prop<Function>('onUnselect')('foo'); | |||
expect(setTags).lastCalledWith([]); | |||
expect(setTags).toHaveBeenLastCalledWith([]); | |||
}); | |||
function shallowRender(props?: Partial<Props>) { |
@@ -38,7 +38,7 @@ it('should open rule', () => { | |||
const onOpen = jest.fn(); | |||
const wrapper = shallowRender({ onOpen }); | |||
wrapper.find(Link).simulate('click', mockEvent({ button: 0 })); | |||
expect(onOpen).toBeCalledWith('javascript:S1067'); | |||
expect(onOpen).toHaveBeenCalledWith('javascript:S1067'); | |||
}); | |||
it('handle activation', () => { | |||
@@ -48,7 +48,7 @@ it('handle activation', () => { | |||
const wrapper = shallowRender({ onActivate, rule, selectedProfile: profile }); | |||
wrapper.instance().handleActivate('MAJOR'); | |||
expect(onActivate).toBeCalledWith(profile.key, rule.key, { | |||
expect(onActivate).toHaveBeenCalledWith(profile.key, rule.key, { | |||
severity: 'MAJOR', | |||
inherit: 'NONE' | |||
}); | |||
@@ -61,14 +61,14 @@ it('handle deactivation', async () => { | |||
const wrapper = shallowRender({ onDeactivate, rule, selectedProfile: profile }); | |||
wrapper.instance().handleDeactivate(); | |||
expect(deactivateRule).toBeCalledWith( | |||
expect(deactivateRule).toHaveBeenCalledWith( | |||
expect.objectContaining({ | |||
key: profile.key, | |||
rule: rule.key | |||
}) | |||
); | |||
await waitAndUpdate(wrapper); | |||
expect(onDeactivate).toBeCalledWith(profile.key, rule.key); | |||
expect(onDeactivate).toHaveBeenCalledWith(profile.key, rule.key); | |||
}); | |||
describe('renderActions', () => { |
@@ -33,28 +33,28 @@ it('should filter by similar language', () => { | |||
const onFilterChange = jest.fn(); | |||
const wrapper = mountRenderAction('language', { onFilterChange }); | |||
click(wrapper); | |||
expect(onFilterChange).toBeCalledWith({ languages: ['js'] }); | |||
expect(onFilterChange).toHaveBeenCalledWith({ languages: ['js'] }); | |||
}); | |||
it('should filter by similar type', () => { | |||
const onFilterChange = jest.fn(); | |||
const wrapper = mountRenderAction('type', { onFilterChange }); | |||
click(wrapper); | |||
expect(onFilterChange).toBeCalledWith({ types: ['CODE_SMELL'] }); | |||
expect(onFilterChange).toHaveBeenCalledWith({ types: ['CODE_SMELL'] }); | |||
}); | |||
it('should filter by similar severity', () => { | |||
const onFilterChange = jest.fn(); | |||
const wrapper = mountRenderAction('severity', { onFilterChange }); | |||
click(wrapper); | |||
expect(onFilterChange).toBeCalledWith({ severities: ['MAJOR'] }); | |||
expect(onFilterChange).toHaveBeenCalledWith({ severities: ['MAJOR'] }); | |||
}); | |||
it('should filter by similar tag', () => { | |||
const onFilterChange = jest.fn(); | |||
const wrapper = mountRenderAction('tag', { onFilterChange }); | |||
click(wrapper); | |||
expect(onFilterChange).toBeCalledWith({ tags: ['x'] }); | |||
expect(onFilterChange).toHaveBeenCalledWith({ tags: ['x'] }); | |||
}); | |||
function mountRenderAction(actionName: string, props: Partial<SimilarRulesFilter['props']> = {}) { |
@@ -37,7 +37,7 @@ it('should handle search', async () => { | |||
await wrapper.instance().handleSearch(query); | |||
expect(getRuleTags).toBeCalledWith({ ps: 50, q: query }); | |||
expect(getRuleTags).toHaveBeenCalledWith({ ps: 50, q: query }); | |||
}); | |||
describe('ListStyleFacet Renderers', () => { |
@@ -113,7 +113,7 @@ it('should refresh branch status if issues are updated', async () => { | |||
await waitAndUpdate(wrapper); | |||
instance.handleIssueChange(mockIssue()); | |||
expect(fetchBranchStatus).toBeCalledWith(branchLike, 'foo'); | |||
expect(fetchBranchStatus).toHaveBeenCalledWith(branchLike, 'foo'); | |||
}); | |||
it('should render a warning message when user does not have access to all projects whithin a Portfolio', async () => { |
@@ -63,7 +63,7 @@ it('should correctly enhance leaf components', async () => { | |||
const updateLoading = jest.fn(); | |||
const wrapper = shallowRender({ updateLoading }); | |||
expect(updateLoading).toBeCalledWith({ bubbles: true }); | |||
expect(updateLoading).toHaveBeenCalledWith({ bubbles: true }); | |||
expect(getComponentLeaves).toHaveBeenCalledWith( | |||
'foo', | |||
[ |
@@ -40,7 +40,7 @@ it('should correctly trigger a selection change', () => { | |||
const handleViewChange = jest.fn(); | |||
const wrapper = shallowRender({ handleViewChange }); | |||
wrapper.instance().handleChange({ icon: <ListIcon />, label: 'List View', value: 'list' }); | |||
expect(handleViewChange).toBeCalledWith('list'); | |||
expect(handleViewChange).toHaveBeenCalledWith('list'); | |||
}); | |||
function shallowRender(props: Partial<MeasureViewSelect['props']> = {}) { |
@@ -87,16 +87,16 @@ it('should correctly bind key events for file navigation', () => { | |||
}); | |||
keydown({ key: KeyboardKeys.DownArrow }); | |||
expect(handleSelect).toBeCalledWith(FILES[0]); | |||
expect(handleSelect).toHaveBeenCalledWith(FILES[0]); | |||
keydown({ key: KeyboardKeys.UpArrow }); | |||
expect(handleSelect).toBeCalledWith(FILES[2]); | |||
expect(handleSelect).toHaveBeenCalledWith(FILES[2]); | |||
keydown({ key: KeyboardKeys.RightArrow, ctrlKey: true }); | |||
expect(handleOpen).not.toBeCalled(); | |||
expect(handleOpen).not.toHaveBeenCalled(); | |||
keydown({ key: KeyboardKeys.RightArrow }); | |||
expect(handleOpen).toBeCalled(); | |||
expect(handleOpen).toHaveBeenCalled(); | |||
}); | |||
function shallowRender(props: Partial<FilesView['props']> = {}) { |
@@ -53,7 +53,7 @@ it('should correctly handle form interactions', () => { | |||
// Expect correct calls to be made when submitting. | |||
submit(wrapper.find('form')); | |||
expect(onPersonalAccessTokenCreate).toBeCalled(); | |||
expect(onPersonalAccessTokenCreate).toHaveBeenCalled(); | |||
// If validation fails, we toggle the submitting flag and call useEffect() | |||
// to set the `touched` flag to false again. Trigger a re-render, and mock |
@@ -74,7 +74,7 @@ it('should open when clicked', () => { | |||
.props() | |||
.onClick(); | |||
expect(onOpen).toBeCalled(); | |||
expect(onOpen).toHaveBeenCalled(); | |||
expect( | |||
wrapper | |||
@@ -104,7 +104,7 @@ it('should close when clicked', () => { | |||
.props() | |||
.onClick(); | |||
expect(onOpen).not.toBeCalled(); | |||
expect(onOpen).not.toHaveBeenCalled(); | |||
expect( | |||
wrapper | |||
@@ -124,7 +124,7 @@ it('should trigger selection when repo is clicked', () => { | |||
.props() | |||
.onCheck(mockEvent()); | |||
expect(onSelectRepository).toBeCalledWith(repo); | |||
expect(onSelectRepository).toHaveBeenCalledWith(repo); | |||
}); | |||
function shallowRender(overrides: Partial<AzureProjectAccordionProps> = {}) { |
@@ -54,14 +54,14 @@ it('should render correctly', () => { | |||
it('should correctly fetch binding info on mount', async () => { | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
expect(checkPersonalAccessTokenIsValid).toBeCalledWith('foo'); | |||
expect(checkPersonalAccessTokenIsValid).toHaveBeenCalledWith('foo'); | |||
}); | |||
it('should correctly handle a valid PAT', async () => { | |||
(checkPersonalAccessTokenIsValid as jest.Mock).mockResolvedValueOnce({ status: true }); | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
expect(checkPersonalAccessTokenIsValid).toBeCalled(); | |||
expect(checkPersonalAccessTokenIsValid).toHaveBeenCalled(); | |||
expect(wrapper.state().patIsValid).toBe(true); | |||
}); | |||
@@ -69,7 +69,7 @@ it('should correctly handle an invalid PAT', async () => { | |||
(checkPersonalAccessTokenIsValid as jest.Mock).mockResolvedValueOnce({ status: false }); | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
expect(checkPersonalAccessTokenIsValid).toBeCalled(); | |||
expect(checkPersonalAccessTokenIsValid).toHaveBeenCalled(); | |||
expect(wrapper.state().patIsValid).toBe(false); | |||
}); | |||
@@ -77,12 +77,12 @@ it('should correctly handle setting a new PAT', async () => { | |||
const router = mockRouter(); | |||
const wrapper = shallowRender({ router }); | |||
wrapper.instance().handlePersonalAccessTokenCreate('token'); | |||
expect(setAlmPersonalAccessToken).toBeCalledWith('foo', 'token'); | |||
expect(setAlmPersonalAccessToken).toHaveBeenCalledWith('foo', 'token'); | |||
expect(wrapper.state().submittingToken).toBe(true); | |||
(checkPersonalAccessTokenIsValid as jest.Mock).mockResolvedValueOnce({ status: false }); | |||
await waitAndUpdate(wrapper); | |||
expect(checkPersonalAccessTokenIsValid).toBeCalled(); | |||
expect(checkPersonalAccessTokenIsValid).toHaveBeenCalled(); | |||
expect(wrapper.state().submittingToken).toBe(false); | |||
expect(wrapper.state().tokenValidationFailed).toBe(true); | |||
@@ -91,7 +91,7 @@ it('should correctly handle setting a new PAT', async () => { | |||
wrapper.instance().handlePersonalAccessTokenCreate('correct token'); | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper.state().tokenValidationFailed).toBe(false); | |||
expect(router.replace).toBeCalled(); | |||
expect(router.replace).toHaveBeenCalled(); | |||
}); | |||
it('should correctly fetch projects and repositories on mount', async () => { | |||
@@ -103,9 +103,9 @@ it('should correctly fetch projects and repositories on mount', async () => { | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
expect(getAzureProjects).toBeCalled(); | |||
expect(getAzureRepositories).toBeCalledTimes(1); | |||
expect(getAzureRepositories).toBeCalledWith('foo', project.name); | |||
expect(getAzureProjects).toHaveBeenCalled(); | |||
expect(getAzureRepositories).toHaveBeenCalledTimes(1); | |||
expect(getAzureRepositories).toHaveBeenCalledWith('foo', project.name); | |||
}); | |||
it('should handle opening a project', async () => { | |||
@@ -132,7 +132,7 @@ it('should handle opening a project', async () => { | |||
wrapper.instance().handleOpenProject(projects[1].name); | |||
await waitAndUpdate(wrapper); | |||
expect(getAzureRepositories).toBeCalledWith('foo', projects[1].name); | |||
expect(getAzureRepositories).toHaveBeenCalledWith('foo', projects[1].name); | |||
expect(wrapper.state().repositories).toEqual({ | |||
[projects[0].name]: firstProjectRepos, | |||
@@ -152,7 +152,7 @@ it('should handle searching for repositories', async () => { | |||
wrapper.instance().handleSearchRepositories(query); | |||
expect(wrapper.state().searching).toBe(true); | |||
expect(searchAzureRepositories).toBeCalledWith('foo', query); | |||
expect(searchAzureRepositories).toHaveBeenCalledWith('foo', query); | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper.state().searching).toBe(false); | |||
expect(wrapper.state().searchResults).toEqual(repositories); | |||
@@ -167,7 +167,7 @@ it('should handle searching for repositories', async () => { | |||
(searchAzureRepositories as jest.Mock).mockClear(); | |||
wrapper.instance().handleSearchRepositories(''); | |||
expect(searchAzureRepositories).not.toBeCalled(); | |||
expect(searchAzureRepositories).not.toHaveBeenCalled(); | |||
expect(wrapper.state().searchResults).toBeUndefined(); | |||
expect(wrapper.state().searchQuery).toBeUndefined(); | |||
}); | |||
@@ -184,10 +184,14 @@ it('should select and import a repository', async () => { | |||
wrapper.instance().handleImportRepository(); | |||
expect(wrapper.state().importing).toBe(true); | |||
expect(importAzureRepository).toBeCalledWith('foo', repository.projectName, repository.name); | |||
expect(importAzureRepository).toHaveBeenCalledWith( | |||
'foo', | |||
repository.projectName, | |||
repository.name | |||
); | |||
await waitAndUpdate(wrapper); | |||
expect(onProjectCreate).toBeCalledWith('baz'); | |||
expect(onProjectCreate).toHaveBeenCalledWith('baz'); | |||
expect(wrapper.state().importing).toBe(false); | |||
}); | |||
@@ -201,12 +205,12 @@ it('should handle no settings', () => { | |||
wrapper.instance().checkPersonalAccessToken(); | |||
wrapper.instance().handlePersonalAccessTokenCreate(''); | |||
expect(getAzureProjects).not.toBeCalled(); | |||
expect(getAzureRepositories).not.toBeCalled(); | |||
expect(searchAzureRepositories).not.toBeCalled(); | |||
expect(importAzureRepository).not.toBeCalled(); | |||
expect(checkPersonalAccessTokenIsValid).not.toBeCalled(); | |||
expect(setAlmPersonalAccessToken).not.toBeCalled(); | |||
expect(getAzureProjects).not.toHaveBeenCalled(); | |||
expect(getAzureRepositories).not.toHaveBeenCalled(); | |||
expect(searchAzureRepositories).not.toHaveBeenCalled(); | |||
expect(importAzureRepository).not.toHaveBeenCalled(); | |||
expect(checkPersonalAccessTokenIsValid).not.toHaveBeenCalled(); | |||
expect(setAlmPersonalAccessToken).not.toHaveBeenCalled(); | |||
}); | |||
function shallowRender(overrides: Partial<AzureProjectCreate['props']> = {}) { |
@@ -42,7 +42,7 @@ it('should correctly handle search', () => { | |||
const onSearch = jest.fn(); | |||
const wrapper = shallowRender({ onSearch }); | |||
change(wrapper.find(SearchBox), 'foo'); | |||
expect(onSearch).toBeCalledWith('foo'); | |||
expect(onSearch).toHaveBeenCalledWith('foo'); | |||
}); | |||
function shallowRender(props: Partial<BitbucketImportRepositoryFormProps> = {}) { |
@@ -54,7 +54,7 @@ it('should correctly handle selecting repos', () => { | |||
.at(0) | |||
.props() | |||
.onCheck(''); | |||
expect(onSelectRepository).toBeCalledWith(repo); | |||
expect(onSelectRepository).toHaveBeenCalledWith(repo); | |||
}); | |||
function shallowRender(props: Partial<BitbucketProjectAccordionProps> = {}) { |
@@ -79,12 +79,12 @@ it('should correctly fetch projects and repos', async () => { | |||
await wrapper.instance().handlePersonalAccessTokenCreated(); | |||
// Opens first project on mount. | |||
expect(getBitbucketServerProjects).toBeCalledWith('foo'); | |||
expect(getBitbucketServerProjects).toHaveBeenCalledWith('foo'); | |||
expect(wrapper.state().projects).toHaveLength(2); | |||
// Check repos got loaded. | |||
await waitAndUpdate(wrapper); | |||
expect(getBitbucketServerRepositories).toBeCalledWith('foo', 'Project 1'); | |||
expect(getBitbucketServerRepositories).toHaveBeenCalledWith('foo', 'Project 1'); | |||
expect(wrapper.state().projectRepositories).toEqual( | |||
expect.objectContaining({ | |||
project1: expect.objectContaining({ | |||
@@ -106,9 +106,9 @@ it('should correctly import a repo', async () => { | |||
instance.handleSelectRepository(repo); | |||
instance.handleImportRepository(); | |||
expect(importBitbucketServerProject).toBeCalledWith('foo', repo.projectKey, repo.slug); | |||
expect(importBitbucketServerProject).toHaveBeenCalledWith('foo', repo.projectKey, repo.slug); | |||
await waitAndUpdate(wrapper); | |||
expect(onProjectCreate).toBeCalledWith('baz'); | |||
expect(onProjectCreate).toHaveBeenCalledWith('baz'); | |||
}); | |||
it('should correctly handle search', async () => { | |||
@@ -117,12 +117,12 @@ it('should correctly handle search', async () => { | |||
// Don't trigger search on empty query. | |||
instance.handleSearch(''); | |||
expect(searchForBitbucketServerRepositories).not.toBeCalled(); | |||
expect(searchForBitbucketServerRepositories).not.toHaveBeenCalled(); | |||
expect(wrapper.state().searching).toBe(false); | |||
expect(wrapper.state().searchResults).toBeUndefined(); | |||
instance.handleSearch('bar'); | |||
expect(searchForBitbucketServerRepositories).toBeCalledWith('foo', 'bar'); | |||
expect(searchForBitbucketServerRepositories).toHaveBeenCalledWith('foo', 'bar'); | |||
expect(wrapper.state().searching).toBe(true); | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper.state().searching).toBe(false); |
@@ -67,23 +67,23 @@ it('should correctly pass the selected mode up', () => { | |||
const almButton = 'button.create-project-mode-type-alm'; | |||
click(wrapper.find('button.create-project-mode-type-manual')); | |||
expect(onSelectMode).toBeCalledWith(CreateProjectModes.Manual); | |||
expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.Manual); | |||
onSelectMode.mockClear(); | |||
click(wrapper.find(almButton).at(0)); | |||
expect(onSelectMode).toBeCalledWith(CreateProjectModes.AzureDevOps); | |||
expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.AzureDevOps); | |||
onSelectMode.mockClear(); | |||
click(wrapper.find(almButton).at(1)); | |||
expect(onSelectMode).toBeCalledWith(CreateProjectModes.BitbucketServer); | |||
expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.BitbucketServer); | |||
onSelectMode.mockClear(); | |||
click(wrapper.find(almButton).at(2)); | |||
expect(onSelectMode).toBeCalledWith(CreateProjectModes.GitHub); | |||
expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.GitHub); | |||
onSelectMode.mockClear(); | |||
click(wrapper.find(almButton).at(3)); | |||
expect(onSelectMode).toBeCalledWith(CreateProjectModes.GitLab); | |||
expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.GitLab); | |||
onSelectMode.mockClear(); | |||
wrapper = shallowRender( | |||
@@ -92,7 +92,7 @@ it('should correctly pass the selected mode up', () => { | |||
); | |||
click(wrapper.find(almButton).at(1)); | |||
expect(onSelectMode).toBeCalledWith(CreateProjectModes.BitbucketCloud); | |||
expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.BitbucketCloud); | |||
onSelectMode.mockClear(); | |||
}); | |||
@@ -39,7 +39,7 @@ beforeEach(jest.clearAllMocks); | |||
it('should render correctly', () => { | |||
expect(shallowRender()).toMatchSnapshot(); | |||
expect(getAlmSettings).toBeCalled(); | |||
expect(getAlmSettings).toHaveBeenCalled(); | |||
}); | |||
it.each([ |
@@ -72,8 +72,8 @@ it('should redirect when no code', async () => { | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
expect(getGithubClientId).toBeCalled(); | |||
expect(window.location.replace).toBeCalled(); | |||
expect(getGithubClientId).toHaveBeenCalled(); | |||
expect(window.location.replace).toHaveBeenCalled(); | |||
}); | |||
it('should redirect when no code - github.com', async () => { | |||
@@ -82,8 +82,8 @@ it('should redirect when no code - github.com', async () => { | |||
}); | |||
await waitAndUpdate(wrapper); | |||
expect(getGithubClientId).toBeCalled(); | |||
expect(window.location.replace).toBeCalledWith( | |||
expect(getGithubClientId).toHaveBeenCalled(); | |||
expect(window.location.replace).toHaveBeenCalledWith( | |||
'github.com/login/oauth/authorize?client_id=client-id-124&redirect_uri=http://localhost/projects/create?mode=github' | |||
); | |||
}); | |||
@@ -94,7 +94,7 @@ it('should not redirect when invalid clientId', async () => { | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper.state().error).toBe(true); | |||
expect(window.location.replace).not.toBeCalled(); | |||
expect(window.location.replace).not.toHaveBeenCalled(); | |||
}); | |||
it('should fetch organizations when code', async () => { | |||
@@ -110,8 +110,8 @@ it('should fetch organizations when code', async () => { | |||
}); | |||
await waitAndUpdate(wrapper); | |||
expect(replace).toBeCalled(); | |||
expect(getGithubOrganizations).toBeCalled(); | |||
expect(replace).toHaveBeenCalled(); | |||
expect(getGithubOrganizations).toHaveBeenCalled(); | |||
expect(wrapper.state().organizations).toBe(organizations); | |||
}); | |||
@@ -133,7 +133,7 @@ it('should handle org selection', async () => { | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper.state().selectedOrganization).toBe(organizations[0]); | |||
expect(getGithubRepositories).toBeCalled(); | |||
expect(getGithubRepositories).toHaveBeenCalled(); | |||
expect(wrapper.state().repositories).toBe(repositories); | |||
}); | |||
@@ -158,7 +158,7 @@ it('should load more', async () => { | |||
await waitAndUpdate(wrapper); | |||
expect(getGithubRepositories).toBeCalled(); | |||
expect(getGithubRepositories).toHaveBeenCalled(); | |||
expect(wrapper.state().repositories).toEqual([...startRepos, ...repositories]); | |||
}); | |||
@@ -182,7 +182,7 @@ it('should handle search', async () => { | |||
await waitAndUpdate(wrapper); | |||
expect(getGithubRepositories).toBeCalledWith({ | |||
expect(getGithubRepositories).toHaveBeenCalledWith({ | |||
almSetting: 'a', | |||
organization: 'o1', | |||
page: 1, | |||
@@ -212,7 +212,7 @@ it('should handle importing', async () => { | |||
const wrapper = shallowRender({ onProjectCreate }); | |||
wrapper.instance().handleImportRepository(); | |||
expect(importGithubRepository).not.toBeCalled(); | |||
expect(importGithubRepository).not.toHaveBeenCalled(); | |||
const selectedOrganization = { key: 'org1', name: 'org1' }; | |||
const selectedRepository = mockGitHubRepository(); | |||
@@ -223,12 +223,12 @@ it('should handle importing', async () => { | |||
wrapper.instance().handleImportRepository(); | |||
await waitAndUpdate(wrapper); | |||
expect(importGithubRepository).toBeCalledWith( | |||
expect(importGithubRepository).toHaveBeenCalledWith( | |||
'a', | |||
selectedOrganization.key, | |||
selectedRepository.key | |||
); | |||
expect(onProjectCreate).toBeCalledWith(project.key); | |||
expect(onProjectCreate).toHaveBeenCalledWith(project.key); | |||
}); | |||
function shallowRender(props: Partial<GitHubProjectCreate['props']> = {}) { |
@@ -86,7 +86,7 @@ describe('callback', () => { | |||
it('should be called when org is selected', () => { | |||
const value = 'o1'; | |||
wrapper.find(Select).simulate('change', { value }); | |||
expect(onSelectOrganization).toBeCalledWith(value); | |||
expect(onSelectOrganization).toHaveBeenCalledWith(value); | |||
}); | |||
it('should be called when searchbox is changed', () => { | |||
@@ -95,7 +95,7 @@ describe('callback', () => { | |||
.find(SearchBox) | |||
.props() | |||
.onChange(value); | |||
expect(onSearch).toBeCalledWith(value); | |||
expect(onSearch).toHaveBeenCalledWith(value); | |||
}); | |||
it('should be called when repo is selected', () => { | |||
@@ -104,7 +104,7 @@ describe('callback', () => { | |||
.find(Radio) | |||
.props() | |||
.onCheck(value); | |||
expect(onSelectRepository).toBeCalledWith(value); | |||
expect(onSelectRepository).toHaveBeenCalledWith(value); | |||
}); | |||
}); | |||
@@ -79,7 +79,7 @@ it('should fetch more projects and preserve search', async () => { | |||
expect(wrapper.state().loadingMore).toBe(false); | |||
expect(wrapper.state().projects).toEqual(projects); | |||
expect(getGitlabProjects).toBeCalledWith(expect.objectContaining({ query: 'query' })); | |||
expect(getGitlabProjects).toHaveBeenCalledWith(expect.objectContaining({ query: 'query' })); | |||
}); | |||
it('should search for projects', async () => { | |||
@@ -120,7 +120,7 @@ it('should search for projects', async () => { | |||
expect(wrapper.state().searchQuery).toBe(query); | |||
expect(wrapper.state().projects).toEqual([projects[3], projects[4]]); | |||
expect(getGitlabProjects).toBeCalledWith(expect.objectContaining({ query })); | |||
expect(getGitlabProjects).toHaveBeenCalledWith(expect.objectContaining({ query })); | |||
}); | |||
it('should import', async () => { | |||
@@ -150,7 +150,7 @@ it('should import', async () => { | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper.state().importingGitlabProjectId).toBeUndefined(); | |||
expect(onProjectCreate).toBeCalledWith(createdProjectkey); | |||
expect(onProjectCreate).toHaveBeenCalledWith(createdProjectkey); | |||
}); | |||
it('should do nothing with missing settings', async () => { |
@@ -55,7 +55,7 @@ describe('appropriate callback', () => { | |||
.first() | |||
.simulate('click'); | |||
expect(onImport).toBeCalled(); | |||
expect(onImport).toHaveBeenCalled(); | |||
}); | |||
it('should be assigned to the list footer', () => { |
@@ -133,7 +133,7 @@ it('should submit form input', async () => { | |||
await user.keyboard('test'); | |||
await user.click(screen.getByRole('button', { name: 'set_up' })); | |||
expect(createProject).toHaveBeenCalledWith({ name: 'test', project: 'test' }); | |||
expect(onProjectCreate).toBeCalled(); | |||
expect(onProjectCreate).toHaveBeenCalled(); | |||
}); | |||
it('should handle create failure', async () => { |
@@ -82,8 +82,8 @@ it('should correctly handle form interactions', async () => { | |||
// Expect correct calls to be made when submitting. | |||
submit(wrapper.find('form')); | |||
expect(onPersonalAccessTokenCreated).toBeCalled(); | |||
expect(setAlmPersonalAccessToken).toBeCalledWith('key', 'token', undefined); | |||
expect(onPersonalAccessTokenCreated).toHaveBeenCalled(); | |||
expect(setAlmPersonalAccessToken).toHaveBeenCalledWith('key', 'token', undefined); | |||
}); | |||
it('should correctly handle form for bitbucket interactions', async () => { | |||
@@ -106,8 +106,8 @@ it('should correctly handle form for bitbucket interactions', async () => { | |||
// Expect correct calls to be made when submitting. | |||
submit(wrapper.find('form')); | |||
expect(onPersonalAccessTokenCreated).toBeCalled(); | |||
expect(setAlmPersonalAccessToken).toBeCalledWith('key', 'token', 'username'); | |||
expect(onPersonalAccessTokenCreated).toHaveBeenCalled(); | |||
expect(setAlmPersonalAccessToken).toHaveBeenCalledWith('key', 'token', 'username'); | |||
}); | |||
it('should show error when issue', async () => { |
@@ -115,7 +115,7 @@ it('should not break the whole doc when one page cannot be parsed', () => { | |||
const pages = getPages(); | |||
expect(pages.length).toBe(2); | |||
expect(pages[0].content).toBe(''); | |||
expect(console.error).toBeCalledTimes(1); | |||
expect(console.error).toHaveBeenCalledTimes(1); | |||
console.error = originalConsoleError; | |||
}); |
@@ -95,14 +95,14 @@ beforeEach(() => { | |||
it('should render correctly for SonarQube', async () => { | |||
const wrapper = shallowRender(); | |||
expect(wrapper.find('DeferredSpinner').exists()).toBe(true); | |||
expect(addSideBarClass).toBeCalled(); | |||
expect(addSideBarClass).toHaveBeenCalled(); | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper).toMatchSnapshot(); | |||
expect(wrapper.find('ScreenPositionHelper').dive()).toMatchSnapshot(); | |||
wrapper.unmount(); | |||
expect(removeSideBarClass).toBeCalled(); | |||
expect(removeSideBarClass).toHaveBeenCalled(); | |||
}); | |||
it("should show a 404 if the page doesn't exist", async () => { |
@@ -149,9 +149,9 @@ describe('search engine', () => { | |||
it('should trigger a search if query is set', () => { | |||
const wrapper = shallowRender({ query: undefined }); | |||
expect(wrapper.instance().index.search).not.toBeCalled(); | |||
expect(wrapper.instance().index.search).not.toHaveBeenCalled(); | |||
wrapper.setProps({ query: 'si:+mply text' }); | |||
expect(wrapper.instance().index.search).toBeCalledWith('simply~1 simply* text~1 text*'); | |||
expect(wrapper.instance().index.search).toHaveBeenCalledWith('simply~1 simply* text~1 text*'); | |||
}); | |||
}); | |||
@@ -217,7 +217,7 @@ describe('tokenContextPluginCallback', () => { | |||
it('should only register the plugin once', () => { | |||
tokenContextPlugin(mockLunrBuilder()); | |||
tokenContextPlugin(mockLunrBuilder()); | |||
expect((lunr as any).Pipeline.registerFunction).toBeCalledTimes(1); | |||
expect((lunr as any).Pipeline.registerFunction).toHaveBeenCalledTimes(1); | |||
}); | |||
}); | |||
@@ -137,7 +137,7 @@ it('should search for groups', async () => { | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
wrapper.find('SearchBox').prop<Function>('onChange')('foo'); | |||
expect(searchUsersGroups).toBeCalledWith({ q: 'foo' }); | |||
expect(searchUsersGroups).toHaveBeenCalledWith({ q: 'foo' }); | |||
expect(wrapper.state('query')).toBe('foo'); | |||
}); | |||
@@ -33,6 +33,6 @@ it('should edit members', () => { | |||
expect(wrapper).toMatchSnapshot(); | |||
wrapper.find('EditMembersModal').prop<Function>('onClose')(); | |||
expect(onEdit).toBeCalled(); | |||
expect(onEdit).toHaveBeenCalled(); | |||
expect(wrapper).toMatchSnapshot(); | |||
}); |
@@ -38,12 +38,12 @@ it('should render form', async () => { | |||
change(wrapper.find('[name="name"]'), 'foo'); | |||
change(wrapper.find('[name="description"]'), 'bar'); | |||
submit(wrapper.find('form')); | |||
expect(onSubmit).toBeCalledWith({ description: 'bar', name: 'foo' }); | |||
expect(onSubmit).toHaveBeenCalledWith({ description: 'bar', name: 'foo' }); | |||
await new Promise(setImmediate); | |||
expect(onClose).toBeCalled(); | |||
expect(onClose).toHaveBeenCalled(); | |||
onClose.mockClear(); | |||
click(wrapper.find('ResetButtonLink')); | |||
expect(onClose).toBeCalled(); | |||
expect(onClose).toHaveBeenCalled(); | |||
}); |
@@ -31,5 +31,5 @@ it('should create new group', () => { | |||
expect(wrapper).toMatchSnapshot(); | |||
wrapper.find('Form').prop<Function>('onSubmit')({ name: 'foo', description: 'bar' }); | |||
expect(onCreate).toBeCalledWith({ name: 'foo', description: 'bar' }); | |||
expect(onCreate).toHaveBeenCalledWith({ name: 'foo', description: 'bar' }); | |||
}); |
@@ -50,7 +50,7 @@ it('should be able to bulk change', async () => { | |||
renderIssueApp(mockCurrentUser({ isLoggedIn: true })); | |||
// Check that the bulk button has correct behavior | |||
expect(await screen.findByRole('button', { name: 'bulk_change' })).toHaveAttribute('disabled'); | |||
expect(await screen.findByRole('button', { name: 'bulk_change' })).toBeDisabled(); | |||
await user.click(screen.getByRole('checkbox', { name: 'issues.select_all_issues' })); | |||
expect( | |||
screen.getByRole('button', { name: 'issues.bulk_change_X_issues.500' }) | |||
@@ -75,7 +75,7 @@ it('should be able to bulk change', async () => { | |||
await user.click(screen.getByRole('textbox', { name: 'issue.comment.formlink' })); | |||
await user.keyboard('New Comment'); | |||
expect(screen.getByRole('button', { name: 'apply' })).toHaveAttribute('disabled'); | |||
expect(screen.getByRole('button', { name: 'apply' })).toBeDisabled(); | |||
await selectEvent.select(screen.getByRole('textbox', { name: 'issue.set_type' }), [ | |||
'issue.type.BUG' | |||
@@ -207,6 +207,9 @@ it('should open issue and navigate', async () => { | |||
// check for extended description | |||
const extendedDescriptions = screen.getAllByText('Extended Description'); | |||
// FP | |||
// eslint-disable-next-line jest-dom/prefer-in-document | |||
expect(extendedDescriptions).toHaveLength(1); | |||
// Select the previous issue (with a simple rule) through keyboard shortcut |
@@ -112,7 +112,7 @@ it('should handle assignee search', async () => { | |||
const wrapper = shallowRender({ onAssigneeSelect }); | |||
wrapper.instance().handleAssigneeSearch('a', jest.fn()); | |||
expect(searchAssignees).not.toBeCalled(); | |||
expect(searchAssignees).not.toHaveBeenCalled(); | |||
const result = await new Promise((resolve: (opts: AssigneeOption[]) => void) => { | |||
wrapper.instance().handleAssigneeSearch('someone', resolve); |
@@ -62,7 +62,7 @@ it('should properly handle the search for tags', async () => { | |||
await new Promise(resolve => { | |||
wrapper.instance().handleTagsSearch('query', resolve); | |||
}); | |||
expect(searchIssueTags).toBeCalled(); | |||
expect(searchIssueTags).toHaveBeenCalled(); | |||
}); | |||
it.each([ |
@@ -134,8 +134,8 @@ it('should render a list of issue', async () => { | |||
expect(wrapper.state().referencedComponentsById).toEqual({ 'foo-uuid': referencedComponent }); | |||
expect(wrapper.state().referencedComponentsByKey).toEqual({ 'foo-key': referencedComponent }); | |||
expect(addSideBarClass).toBeCalled(); | |||
expect(addWhitePageClass).toBeCalled(); | |||
expect(addSideBarClass).toHaveBeenCalled(); | |||
expect(addWhitePageClass).toHaveBeenCalled(); | |||
}); | |||
it('should handle my issue change properly', () => { | |||
@@ -143,7 +143,7 @@ it('should handle my issue change properly', () => { | |||
const wrapper = shallowRender({ router: mockRouter({ push }) }); | |||
wrapper.instance().handleMyIssuesChange(true); | |||
expect(push).toBeCalledWith({ | |||
expect(push).toHaveBeenCalledWith({ | |||
pathname: '/issues', | |||
query: { | |||
id: 'foo', | |||
@@ -164,14 +164,14 @@ it('should not render for anonymous user', () => { | |||
currentUser: mockCurrentUser({ isLoggedIn: false }), | |||
location: mockLocation({ query: { myIssues: true.toString() } }) | |||
}); | |||
expect(handleRequiredAuthentication).toBeCalled(); | |||
expect(handleRequiredAuthentication).toHaveBeenCalled(); | |||
}); | |||
it('should handle reset properly', () => { | |||
const push = jest.fn(); | |||
const wrapper = shallowRender({ router: mockRouter({ push }) }); | |||
wrapper.instance().handleReset(); | |||
expect(push).toBeCalledWith({ | |||
expect(push).toHaveBeenCalledWith({ | |||
pathname: '/issues', | |||
query: { | |||
id: 'foo', | |||
@@ -193,16 +193,16 @@ it('should open standard facets for vulnerabilities and hotspots', () => { | |||
instance.handleFacetToggle('standards'); | |||
expect(wrapper.state('openFacets').standards).toEqual(false); | |||
expect(fetchFacet).not.toBeCalled(); | |||
expect(fetchFacet).not.toHaveBeenCalled(); | |||
instance.handleFacetToggle('standards'); | |||
expect(wrapper.state('openFacets').standards).toEqual(true); | |||
expect(wrapper.state('openFacets').sonarsourceSecurity).toEqual(true); | |||
expect(fetchFacet).lastCalledWith('sonarsourceSecurity'); | |||
expect(fetchFacet).toHaveBeenLastCalledWith('sonarsourceSecurity'); | |||
instance.handleFacetToggle('owaspTop10'); | |||
expect(wrapper.state('openFacets').owaspTop10).toEqual(true); | |||
expect(fetchFacet).lastCalledWith('owaspTop10'); | |||
expect(fetchFacet).toHaveBeenLastCalledWith('owaspTop10'); | |||
}); | |||
it('should correctly bind key events for issue navigation', async () => { | |||
@@ -211,7 +211,7 @@ it('should correctly bind key events for issue navigation', async () => { | |||
const wrapper = shallowRender({ router: mockRouter({ push }) }); | |||
await waitAndUpdate(wrapper); | |||
expect(addEventListenerSpy).toBeCalledTimes(2); | |||
expect(addEventListenerSpy).toHaveBeenCalledTimes(2); | |||
expect(wrapper.state('selected')).toBe(ISSUES[0].key); | |||
@@ -231,12 +231,12 @@ it('should correctly bind key events for issue navigation', async () => { | |||
expect(wrapper.state('selected')).toBe(ISSUES[3].key); | |||
keydown({ key: KeyboardKeys.RightArrow, ctrlKey: true }); | |||
expect(push).not.toBeCalled(); | |||
expect(push).not.toHaveBeenCalled(); | |||
keydown({ key: KeyboardKeys.RightArrow }); | |||
expect(push).toBeCalledTimes(1); | |||
expect(push).toHaveBeenCalledTimes(1); | |||
keydown({ key: KeyboardKeys.LeftArrow }); | |||
expect(push).toBeCalledTimes(2); | |||
expect(push).toHaveBeenCalledTimes(2); | |||
addEventListenerSpy.mockReset(); | |||
}); | |||
@@ -246,9 +246,9 @@ it('should correctly clean up on unmount', () => { | |||
const wrapper = shallowRender(); | |||
wrapper.unmount(); | |||
expect(removeSideBarClass).toBeCalled(); | |||
expect(removeWhitePageClass).toBeCalled(); | |||
expect(removeEventListenerSpy).toBeCalledTimes(2); | |||
expect(removeSideBarClass).toHaveBeenCalled(); | |||
expect(removeWhitePageClass).toHaveBeenCalled(); | |||
expect(removeEventListenerSpy).toHaveBeenCalledTimes(2); | |||
removeEventListenerSpy.mockReset(); | |||
}); | |||
@@ -312,7 +312,7 @@ it('should correctly handle filter changes', () => { | |||
sonarsourceSecurity: true, | |||
standards: true | |||
}); | |||
expect(push).toBeCalled(); | |||
expect(push).toHaveBeenCalled(); | |||
instance.handleFilterChange({ types: ['BUGS'] }); | |||
expect(instance.state.openFacets).toEqual({ | |||
types: true, | |||
@@ -413,11 +413,11 @@ it('should refresh branch status if issues are updated', async () => { | |||
const updatedIssue: Issue = { ...ISSUES[0], type: 'SECURITY_HOTSPOT' }; | |||
instance.handleIssueChange(updatedIssue); | |||
expect(wrapper.state().issues[0].type).toEqual(updatedIssue.type); | |||
expect(fetchBranchStatus).toBeCalledWith(branchLike, component.key); | |||
expect(fetchBranchStatus).toHaveBeenCalledWith(branchLike, component.key); | |||
fetchBranchStatus.mockClear(); | |||
instance.handleBulkChangeDone(); | |||
expect(fetchBranchStatus).toBeCalled(); | |||
expect(fetchBranchStatus).toHaveBeenCalled(); | |||
}); | |||
it('should update the open issue when it is changed', async () => { | |||
@@ -455,7 +455,7 @@ it('should handle createAfter query param with time', async () => { | |||
(searchIssues as jest.Mock).mockClear(); | |||
wrapper.instance().fetchIssues({}); | |||
expect(searchIssues).toBeCalledWith( | |||
expect(searchIssues).toHaveBeenCalledWith( | |||
expect.objectContaining({ createdAfter: '2020-10-21T17:21:00+0000' }) | |||
); | |||
}); |
@@ -31,7 +31,7 @@ it('should render correctly', async () => { | |||
expect(wrapper).toMatchSnapshot(); | |||
click(wrapper.find('.concise-issue-box')); | |||
expect(onClick).toBeCalledWith(issue.key); | |||
expect(onClick).toHaveBeenCalledWith(issue.key); | |||
expect(shallowRender({ issue: mockIssue(true), selected: true })).toMatchSnapshot(); | |||
}); |
@@ -71,7 +71,7 @@ it('Should fetch data', async () => { | |||
(getIssueFlowSnippets as jest.Mock).mockClear(); | |||
wrapper.setProps({ issue: mockIssue(true, { key: 'foo' }) }); | |||
expect(getIssueFlowSnippets).toBeCalledWith('foo'); | |||
expect(getIssueFlowSnippets).toHaveBeenCalledWith('foo'); | |||
}); | |||
it('Should handle no access rights', async () => { |
@@ -68,7 +68,7 @@ it('should render additional child in line', () => { | |||
verticalBuffer: 5 | |||
}); | |||
expect(renderAdditionalChildInLine).toBeCalledWith(sourceline); | |||
expect(renderAdditionalChildInLine).toHaveBeenCalledWith(sourceline); | |||
}); | |||
it('should render correctly when at the top of the file', () => { |
@@ -40,13 +40,13 @@ it('should call onChange', () => { | |||
const itemOnClick = wrapper.find('ListStyleFacet').prop<Function>('onItemClick'); | |||
itemOnClick(''); | |||
expect(onChange).lastCalledWith({ assigned: false, assignees: [] }); | |||
expect(onChange).toHaveBeenLastCalledWith({ assigned: false, assignees: [] }); | |||
itemOnClick('bar'); | |||
expect(onChange).lastCalledWith({ assigned: true, assignees: ['bar'] }); | |||
expect(onChange).toHaveBeenLastCalledWith({ assigned: true, assignees: ['bar'] }); | |||
itemOnClick('baz', true); | |||
expect(onChange).lastCalledWith({ assigned: true, assignees: ['baz', 'foo'] }); | |||
expect(onChange).toHaveBeenLastCalledWith({ assigned: true, assignees: ['baz', 'foo'] }); | |||
}); | |||
describe('test behavior', () => { |
@@ -43,7 +43,7 @@ it('should filter when clicked', async () => { | |||
await user.click(screen.getByText('issues.new_code')); | |||
expect(onChange).toBeCalledWith({ | |||
expect(onChange).toHaveBeenCalledWith({ | |||
createdAfter: undefined, | |||
createdAt: undefined, | |||
createdBefore: undefined, | |||
@@ -60,7 +60,7 @@ it('should be clearable', async () => { | |||
await user.click(screen.getByText('clear')); | |||
expect(onChange).toBeCalledWith({ | |||
expect(onChange).toHaveBeenCalledWith({ | |||
inNewCodePeriod: undefined | |||
}); | |||
}); |
@@ -50,7 +50,7 @@ it('should callback to load search results', () => { | |||
{ key: '2', name: 'seecond' } | |||
]); | |||
expect(loadSearchResultCount).toBeCalledWith('projects', { projects: ['1', '2'] }); | |||
expect(loadSearchResultCount).toHaveBeenCalledWith('projects', { projects: ['1', '2'] }); | |||
}); | |||
it('should handle search for projects globally', async () => { | |||
@@ -59,8 +59,8 @@ it('should handle search for projects globally', async () => { | |||
await wrapper.instance().handleSearch(query); | |||
expect(searchProjects).toBeCalled(); | |||
expect(getTree).not.toBeCalled(); | |||
expect(searchProjects).toHaveBeenCalled(); | |||
expect(getTree).not.toHaveBeenCalled(); | |||
}); | |||
it('should handle search for projects in portfolio', async () => { | |||
@@ -71,8 +71,8 @@ it('should handle search for projects in portfolio', async () => { | |||
await wrapper.instance().handleSearch(query); | |||
expect(searchProjects).not.toBeCalled(); | |||
expect(getTree).toBeCalled(); | |||
expect(searchProjects).not.toHaveBeenCalled(); | |||
expect(getTree).toHaveBeenCalled(); | |||
}); | |||
describe("ListStyleFacet's renderers", () => { |
@@ -40,7 +40,9 @@ it('should handle search', async () => { | |||
await wrapper.instance().handleSearch(query); | |||
expect(searchRules).toBeCalledWith(expect.objectContaining({ languages: 'js,java', q: query })); | |||
expect(searchRules).toHaveBeenCalledWith( | |||
expect.objectContaining({ languages: 'js,java', q: query }) | |||
); | |||
}); | |||
describe('ListStyleFacet Renderers', () => { |
@@ -39,10 +39,10 @@ it('should correctly handle facet header clicks', () => { | |||
const wrapper = shallowRender({ onChange, onToggle }); | |||
wrapper.find(FacetHeader).props().onClear!(); | |||
expect(onChange).toBeCalledWith({ scopes: [] }); | |||
expect(onChange).toHaveBeenCalledWith({ scopes: [] }); | |||
wrapper.find(FacetHeader).props().onClick!(); | |||
expect(onToggle).toBeCalledWith('scopes'); | |||
expect(onToggle).toHaveBeenCalledWith('scopes'); | |||
}); | |||
it('should correctly handle facet item clicks', () => { |
@@ -70,21 +70,21 @@ jest.mock('../../../../helpers/security-standard', () => ({ | |||
it('should render closed', () => { | |||
expect(shallowRender()).toMatchSnapshot(); | |||
expect(getStandards).not.toBeCalled(); | |||
expect(getStandards).not.toHaveBeenCalled(); | |||
}); | |||
it('should toggle standards facet', () => { | |||
const onToggle = jest.fn(); | |||
const wrapper = shallowRender({ onToggle }); | |||
click(wrapper.children('FacetHeader')); | |||
expect(onToggle).toBeCalledWith('standards'); | |||
expect(onToggle).toHaveBeenCalledWith('standards'); | |||
}); | |||
it('should clear standards facet', () => { | |||
const onChange = jest.fn(); | |||
const wrapper = shallowRender({ onChange }); | |||
wrapper.children('FacetHeader').prop<Function>('onClear')(); | |||
expect(onChange).toBeCalledWith({ | |||
expect(onChange).toHaveBeenCalledWith({ | |||
cwe: [], | |||
owaspTop10: [], | |||
'owaspTop10-2021': [], | |||
@@ -112,7 +112,7 @@ it('should render sub-facets', () => { | |||
sonarsourceSecurityStats: { 'sql-injection': 12 } | |||
}) | |||
).toMatchSnapshot(); | |||
expect(getStandards).toBeCalled(); | |||
expect(getStandards).toHaveBeenCalled(); | |||
}); | |||
it('should show sonarsource facet more button', () => { | |||
@@ -192,7 +192,7 @@ it('should select items', () => { | |||
.find(`FacetBox[property="${facet}"]`) | |||
.find(`FacetItem[value="${value}"]`) | |||
.prop<Function>('onClick')(value, multiple); | |||
expect(onChange).lastCalledWith({ [facet]: expectedValue }); | |||
expect(onChange).toHaveBeenLastCalledWith({ [facet]: expectedValue }); | |||
} | |||
}); | |||
@@ -200,11 +200,11 @@ it('should toggle sub-facets', () => { | |||
const onToggle = jest.fn(); | |||
const wrapper = shallowRender({ onToggle, open: true }); | |||
click(wrapper.find('FacetBox[property="owaspTop10"]').children('FacetHeader')); | |||
expect(onToggle).lastCalledWith('owaspTop10'); | |||
expect(onToggle).toHaveBeenLastCalledWith('owaspTop10'); | |||
click(wrapper.find('FacetBox[property="sansTop25"]').children('FacetHeader')); | |||
expect(onToggle).lastCalledWith('sansTop25'); | |||
expect(onToggle).toHaveBeenLastCalledWith('sansTop25'); | |||
click(wrapper.find('FacetBox[property="sonarsourceSecurity"]').children('FacetHeader')); | |||
expect(onToggle).lastCalledWith('sonarsourceSecurity'); | |||
expect(onToggle).toHaveBeenLastCalledWith('sonarsourceSecurity'); | |||
}); | |||
it('should display correct selection', () => { |
@@ -30,14 +30,14 @@ it('should toggle status facet', () => { | |||
const onToggle = jest.fn(); | |||
const wrapper = shallowRender({ onToggle }); | |||
click(wrapper.children('FacetHeader')); | |||
expect(onToggle).toBeCalledWith('statuses'); | |||
expect(onToggle).toHaveBeenCalledWith('statuses'); | |||
}); | |||
it('should clear status facet', () => { | |||
const onChange = jest.fn(); | |||
const wrapper = shallowRender({ onChange, statuses: ['CONFIRMED'] }); | |||
wrapper.children('FacetHeader').prop<Function>('onClear')(); | |||
expect(onChange).toBeCalledWith({ statuses: [] }); | |||
expect(onChange).toHaveBeenCalledWith({ statuses: [] }); | |||
}); | |||
it('should select a status', () => { | |||
@@ -52,7 +52,7 @@ it('should select a status', () => { | |||
.find(`FacetItemsList`) | |||
.find(`FacetItem[value="${status}"]`) | |||
.prop<Function>('onClick')(status, multiple); | |||
expect(onChange).lastCalledWith({ statuses: expected }); | |||
expect(onChange).toHaveBeenLastCalledWith({ statuses: expected }); | |||
wrapper.setProps({ statuses: expected }); | |||
} | |||
}); |
@@ -30,14 +30,14 @@ it('should toggle type facet', () => { | |||
const onToggle = jest.fn(); | |||
const wrapper = shallowRender({ onToggle }); | |||
click(wrapper.children('FacetHeader')); | |||
expect(onToggle).toBeCalledWith('types'); | |||
expect(onToggle).toHaveBeenCalledWith('types'); | |||
}); | |||
it('should clear types facet', () => { | |||
const onChange = jest.fn(); | |||
const wrapper = shallowRender({ onChange, types: ['BUGS'] }); | |||
wrapper.children('FacetHeader').prop<Function>('onClear')(); | |||
expect(onChange).toBeCalledWith({ types: [] }); | |||
expect(onChange).toHaveBeenCalledWith({ types: [] }); | |||
}); | |||
it('should select a type', () => { | |||
@@ -51,7 +51,7 @@ it('should select a type', () => { | |||
.find(`FacetItemsList`) | |||
.find(`FacetItem[value="${type}"]`) | |||
.prop<Function>('onClick')(type, multiple); | |||
expect(onChange).lastCalledWith({ types: expected }); | |||
expect(onChange).toHaveBeenLastCalledWith({ types: expected }); | |||
wrapper.setProps({ types: expected }); | |||
} | |||
}); |
@@ -95,12 +95,17 @@ describe('Maintenance', () => { | |||
const title = await screen.findByRole('heading', { name: heading }); | |||
expect(title).toBeInTheDocument(); | |||
// eslint-disable-next-line jest/no-conditional-in-test | |||
if (body) { | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(screen.getByText(body)).toBeInTheDocument(); | |||
} | |||
// eslint-disable-next-line jest/no-conditional-in-test | |||
if (linkInfo) { | |||
const link = screen.getByRole('link', { name: linkInfo.name }); | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(link).toBeInTheDocument(); | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(link).toHaveAttribute('href', linkInfo.href); | |||
} | |||
} | |||
@@ -188,18 +193,26 @@ describe('Setup', () => { | |||
const title = await screen.findByRole('heading', { name: heading }); | |||
expect(title).toBeInTheDocument(); | |||
// eslint-disable-next-line jest/no-conditional-in-test | |||
if (bodyText.length) { | |||
bodyText.forEach(text => { | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(screen.getByText(text)).toBeInTheDocument(); | |||
}); | |||
} | |||
// eslint-disable-next-line jest/no-conditional-in-test | |||
if (payload) { | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(screen.getByText(payload.message)).toBeInTheDocument(); | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(screen.getByText('background_tasks.table.started')).toBeInTheDocument(); | |||
} | |||
// eslint-disable-next-line jest/no-conditional-in-test | |||
if (linkInfo) { | |||
const link = screen.getByRole('link', { name: linkInfo.name }); | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(link).toBeInTheDocument(); | |||
// eslint-disable-next-line jest/no-conditional-expect | |||
expect(link).toHaveAttribute('href', linkInfo.href); | |||
} | |||
} |
@@ -72,14 +72,14 @@ it('should handle accepting the risk', async () => { | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
expect(getValue).toBeCalledWith({ key: SettingsKey.PluginRiskConsent }); | |||
expect(getValue).toHaveBeenCalledWith({ key: SettingsKey.PluginRiskConsent }); | |||
wrapper.instance().acknowledgeRisk(); | |||
await new Promise(setImmediate); | |||
expect(setSimpleSettingValue).toBeCalled(); | |||
expect(getValue).toBeCalledWith({ key: SettingsKey.PluginRiskConsent }); | |||
expect(setSimpleSettingValue).toHaveBeenCalled(); | |||
expect(getValue).toHaveBeenCalledWith({ key: SettingsKey.PluginRiskConsent }); | |||
expect(wrapper.state().riskConsent).toBe(RiskConsent.Accepted); | |||
}); | |||
@@ -87,16 +87,16 @@ it('should fetch plugin info', async () => { | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
expect(getInstalledPluginsWithUpdates).toBeCalled(); | |||
expect(getAvailablePlugins).toBeCalled(); | |||
expect(getInstalledPluginsWithUpdates).toHaveBeenCalled(); | |||
expect(getAvailablePlugins).toHaveBeenCalled(); | |||
wrapper.setProps({ location: mockLocation({ query: { filter: 'updates' } }) }); | |||
await waitAndUpdate(wrapper); | |||
expect(getPluginUpdates).toBeCalled(); | |||
expect(getPluginUpdates).toHaveBeenCalled(); | |||
wrapper.setProps({ location: mockLocation({ query: { filter: 'installed' } }) }); | |||
await waitAndUpdate(wrapper); | |||
expect(getInstalledPlugins).toBeCalled(); | |||
expect(getInstalledPlugins).toHaveBeenCalled(); | |||
}); | |||
function shallowRender(props: Partial<App['props']> = {}) { |
@@ -203,8 +203,8 @@ describe('project overview', () => { | |||
it("should correctly load a project's status", async () => { | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
expect(getQualityGateProjectStatus).toBeCalled(); | |||
expect(getMeasuresWithPeriodAndMetrics).toBeCalled(); | |||
expect(getQualityGateProjectStatus).toHaveBeenCalled(); | |||
expect(getMeasuresWithPeriodAndMetrics).toHaveBeenCalled(); | |||
// Check the conditions got correctly enhanced with measure meta data. | |||
const { qgStatuses } = wrapper.state(); | |||
@@ -270,9 +270,9 @@ describe('application overview', () => { | |||
it("should correctly load an application's status", async () => { | |||
const wrapper = shallowRender({ component }); | |||
await waitAndUpdate(wrapper); | |||
expect(getApplicationQualityGate).toBeCalled(); | |||
expect(getApplicationLeak).toBeCalled(); | |||
expect(getMeasuresWithPeriodAndMetrics).toBeCalled(); | |||
expect(getApplicationQualityGate).toHaveBeenCalled(); | |||
expect(getApplicationLeak).toHaveBeenCalled(); | |||
expect(getMeasuresWithPeriodAndMetrics).toHaveBeenCalled(); | |||
// Check the conditions got correctly enhanced with measure meta data. | |||
const { qgStatuses } = wrapper.state(); | |||
@@ -339,8 +339,8 @@ describe('application overview', () => { | |||
it("should correctly load a component's history", async () => { | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
expect(getProjectActivity).toBeCalled(); | |||
expect(getAllTimeMachineData).toBeCalled(); | |||
expect(getProjectActivity).toHaveBeenCalled(); | |||
expect(getAllTimeMachineData).toHaveBeenCalled(); | |||
const { measuresHistory } = wrapper.state(); | |||
expect(measuresHistory).toHaveLength(6); | |||
@@ -370,11 +370,15 @@ it.each([ | |||
it('should correctly handle graph type storage', () => { | |||
const wrapper = shallowRender(); | |||
expect(getActivityGraph).toBeCalledWith(BRANCH_OVERVIEW_ACTIVITY_GRAPH, 'foo'); | |||
expect(getActivityGraph).toHaveBeenCalledWith(BRANCH_OVERVIEW_ACTIVITY_GRAPH, 'foo'); | |||
expect(wrapper.state().graph).toBe(GraphType.coverage); | |||
wrapper.instance().handleGraphChange(GraphType.issues); | |||
expect(saveActivityGraph).toBeCalledWith(BRANCH_OVERVIEW_ACTIVITY_GRAPH, 'foo', GraphType.issues); | |||
expect(saveActivityGraph).toHaveBeenCalledWith( | |||
BRANCH_OVERVIEW_ACTIVITY_GRAPH, | |||
'foo', | |||
GraphType.issues | |||
); | |||
expect(wrapper.state().graph).toBe(GraphType.issues); | |||
}); | |||
@@ -73,8 +73,8 @@ it('should render correctly for a passed QG', async () => { | |||
expect(wrapper.find('QualityGateConditions').exists()).toBe(false); | |||
expect(getMeasuresWithMetrics).toBeCalled(); | |||
expect(fetchBranchStatus).toBeCalled(); | |||
expect(getMeasuresWithMetrics).toHaveBeenCalled(); | |||
expect(fetchBranchStatus).toHaveBeenCalled(); | |||
}); | |||
it('should render correctly if conditions are ignored', async () => { | |||
@@ -107,7 +107,7 @@ it('should render correctly for a failed QG', async () => { | |||
it('should correctly fetch all required metrics for a passing QG', async () => { | |||
const wrapper = shallowRender({ conditions: [] }); | |||
await waitAndUpdate(wrapper); | |||
expect(getMeasuresWithMetrics).toBeCalledWith('my-project', PR_METRICS, expect.any(Object)); | |||
expect(getMeasuresWithMetrics).toHaveBeenCalledWith('my-project', PR_METRICS, expect.any(Object)); | |||
}); | |||
it('should correctly fetch all required metrics for a failing QG', async () => { | |||
@@ -115,7 +115,7 @@ it('should correctly fetch all required metrics for a failing QG', async () => { | |||
conditions: [mockQualityGateStatusCondition({ level: 'ERROR', metric: 'foo' })] | |||
}); | |||
await waitAndUpdate(wrapper); | |||
expect(getMeasuresWithMetrics).toBeCalledWith( | |||
expect(getMeasuresWithMetrics).toHaveBeenCalledWith( | |||
'my-project', | |||
[...PR_METRICS, 'foo'], | |||
expect.any(Object) |
@@ -54,10 +54,10 @@ it('should correctly toggle user permissions', () => { | |||
const instance = wrapper.instance(); | |||
instance.handleToggleUser(user, grantPermission); | |||
expect(grantPermissionToUser).toBeCalledWith(user.login, grantPermission); | |||
expect(grantPermissionToUser).toHaveBeenCalledWith(user.login, grantPermission); | |||
instance.handleToggleUser(user, revokePermission); | |||
expect(revokePermissionFromUser).toBeCalledWith(user.login, revokePermission); | |||
expect(revokePermissionFromUser).toHaveBeenCalledWith(user.login, revokePermission); | |||
}); | |||
it('should correctly toggle group permissions', () => { | |||
@@ -70,10 +70,10 @@ it('should correctly toggle group permissions', () => { | |||
const instance = wrapper.instance(); | |||
instance.handleToggleGroup(group, grantPermission); | |||
expect(grantPermissionToGroup).toBeCalledWith(group.name, grantPermission); | |||
expect(grantPermissionToGroup).toHaveBeenCalledWith(group.name, grantPermission); | |||
instance.handleToggleGroup(group, revokePermission); | |||
expect(revokePermissionFromGroup).toBeCalledWith(group.name, revokePermission); | |||
expect(revokePermissionFromGroup).toHaveBeenCalledWith(group.name, revokePermission); | |||
}); | |||
function shallowRender(props: Partial<AllHoldersList['props']> = {}) { |
@@ -83,7 +83,7 @@ it('should correctly update the selected date', () => { | |||
const updateQuery = jest.fn(); | |||
const wrapper = shallowRender({ updateQuery }); | |||
wrapper.instance().updateSelectedDate(selectedDate); | |||
expect(updateQuery).toBeCalledWith({ selectedDate }); | |||
expect(updateQuery).toHaveBeenCalledWith({ selectedDate }); | |||
}); | |||
it('should correctly reset scroll if filters change', () => { |
@@ -109,12 +109,12 @@ it('should be clickable', () => { | |||
const updateSelectedDate = jest.fn(); | |||
const wrapper = shallowRender({ analysis: mockParsedAnalysis({ date }), updateSelectedDate }); | |||
click(wrapper); | |||
expect(updateSelectedDate).toBeCalledWith(date); | |||
expect(updateSelectedDate).toHaveBeenCalledWith(date); | |||
}); | |||
it('should trigger a scroll to itself if selected', () => { | |||
mountRender({ parentScrollContainer: document.createElement('ul'), selected: true }); | |||
expect(scrollToElement).toBeCalled(); | |||
expect(scrollToElement).toHaveBeenCalled(); | |||
}); | |||
function shallowRender(props: Partial<ProjectActivityAnalysisProps> = {}) { |
@@ -31,14 +31,14 @@ it('should correctly confirm', () => { | |||
const onConfirm = jest.fn(); | |||
const wrapper = shallowRender({ onConfirm }); | |||
wrapper.find(ConfirmModal).prop('onConfirm')(); | |||
expect(onConfirm).toBeCalledWith('foo', 'bar'); | |||
expect(onConfirm).toHaveBeenCalledWith('foo', 'bar'); | |||
}); | |||
it('should correctly cancel', () => { | |||
const onClose = jest.fn(); | |||
const wrapper = shallowRender({ onClose }); | |||
wrapper.find(ConfirmModal).prop('onClose')(); | |||
expect(onClose).toBeCalled(); | |||
expect(onClose).toHaveBeenCalled(); | |||
}); | |||
function shallowRender(props: Partial<RemoveEventFormProps> = {}) { |
@@ -80,7 +80,7 @@ it('should render correctly', async () => { | |||
const wrapper = shallowRender(); | |||
await waitAndUpdate(wrapper); | |||
expect(getProjectActivity).toBeCalled(); | |||
expect(getProjectActivity).toHaveBeenCalled(); | |||
expect(wrapper.state().analyses).toHaveLength(4); | |||
}); | |||
@@ -89,7 +89,7 @@ it('should reload analyses after range change', () => { | |||
wrapper.instance().handleRangeChange({ value: 30 }); | |||
expect(getProjectActivity).toBeCalledWith({ | |||
expect(getProjectActivity).toHaveBeenCalledWith({ | |||
branch: 'master', | |||
project: 'project1', | |||
from: toShortNotSoISOString(subDays(new Date(), 30)) |
@@ -56,7 +56,7 @@ it('should handle reset', () => { | |||
wrapper.instance().resetToDefault('master'); | |||
expect(resetNewCodePeriod).toBeCalledWith({ | |||
expect(resetNewCodePeriod).toHaveBeenCalledWith({ | |||
project: component.key, | |||
branch: 'master' | |||
}); |
@@ -70,7 +70,7 @@ it('should callback to open modal when clicked', () => { | |||
.first() | |||
.simulate('click'); | |||
expect(openEditModal).toBeCalledWith(branch); | |||
expect(openEditModal).toHaveBeenCalledWith(branch); | |||
}); | |||
it('should callback to reset when clicked', () => { | |||
@@ -86,7 +86,7 @@ it('should callback to reset when clicked', () => { | |||
.at(1) | |||
.simulate('click'); | |||
expect(resetToDefault).toBeCalledWith(branchName); | |||
expect(resetToDefault).toHaveBeenCalledWith(branchName); | |||
}); | |||
function shallowRender(props: Partial<BranchListRowProps> = {}) { |
@@ -126,7 +126,7 @@ it('should correctly propagate an update of purge settings', () => { | |||
.props() | |||
.onUpdatePurgeSetting(); | |||
expect(onBranchesChange).toBeCalled(); | |||
expect(onBranchesChange).toHaveBeenCalled(); | |||
}); | |||
function shallowRender(props: Partial<BranchLikeTabs['props']> = {}) { |
@@ -55,7 +55,7 @@ it('should correctly call the webservice if the user changes the value', async ( | |||
expect(excludeBranchFromPurge).toHaveBeenCalled(); | |||
expect(wrapper.state().excludedFromPurge).toBe(true); | |||
await waitAndUpdate(wrapper); | |||
expect(onUpdatePurgeSetting).toBeCalled(); | |||
expect(onUpdatePurgeSetting).toHaveBeenCalled(); | |||
}); | |||
function shallowRender(props?: Partial<BranchPurgeSetting['props']>) { |
@@ -53,8 +53,8 @@ it('deletes branch', async () => { | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper.state().loading).toBe(false); | |||
expect(onDelete).toBeCalled(); | |||
expect(deleteBranch).toBeCalledWith({ branch: 'feature/foo', project: 'foo' }); | |||
expect(onDelete).toHaveBeenCalled(); | |||
expect(deleteBranch).toHaveBeenCalledWith({ branch: 'feature/foo', project: 'foo' }); | |||
}); | |||
it('deletes pull request', async () => { | |||
@@ -67,8 +67,8 @@ it('deletes pull request', async () => { | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper.state().loading).toBe(false); | |||
expect(onDelete).toBeCalled(); | |||
expect(deletePullRequest).toBeCalledWith({ project: 'foo', pullRequest: '1001' }); | |||
expect(onDelete).toHaveBeenCalled(); | |||
expect(deletePullRequest).toHaveBeenCalledWith({ project: 'foo', pullRequest: '1001' }); | |||
}); | |||
it('cancels', () => { | |||
@@ -78,7 +78,7 @@ it('cancels', () => { | |||
click(wrapper.find('ResetButtonLink')); | |||
return doAsync().then(() => { | |||
expect(onClose).toBeCalled(); | |||
expect(onClose).toHaveBeenCalled(); | |||
}); | |||
}); | |||
@@ -91,8 +91,8 @@ it('stops loading on WS error', async () => { | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper.state().loading).toBe(false); | |||
expect(onDelete).not.toBeCalled(); | |||
expect(deleteBranch).toBeCalledWith({ branch: 'feature/foo', project: 'foo' }); | |||
expect(onDelete).not.toHaveBeenCalled(); | |||
expect(deleteBranch).toHaveBeenCalledWith({ branch: 'feature/foo', project: 'foo' }); | |||
}); | |||
function shallowRender( |
@@ -49,8 +49,8 @@ it('renames branch', async () => { | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper.state().loading).toBe(false); | |||
expect(onRename).toBeCalled(); | |||
expect(renameBranch).toBeCalledWith('foo', 'dev'); | |||
expect(onRename).toHaveBeenCalled(); | |||
expect(renameBranch).toHaveBeenCalledWith('foo', 'dev'); | |||
}); | |||
it('cancels', () => { | |||
@@ -60,7 +60,7 @@ it('cancels', () => { | |||
click(wrapper.find('ResetButtonLink')); | |||
return doAsync().then(() => { | |||
expect(onClose).toBeCalled(); | |||
expect(onClose).toHaveBeenCalled(); | |||
}); | |||
}); | |||
@@ -73,7 +73,7 @@ it('stops loading on WS error', async () => { | |||
await waitAndUpdate(wrapper); | |||
expect(wrapper.state().loading).toBe(false); | |||
expect(onRename).not.toBeCalled(); | |||
expect(onRename).not.toHaveBeenCalled(); | |||
}); | |||
function shallowRender(onRename: () => void = jest.fn(), onClose: () => void = jest.fn()) { |