diff options
118 files changed, 399 insertions, 387 deletions
diff --git a/server/sonar-docs/src/__tests__/BrokenLinkSafetyNet.test.js b/server/sonar-docs/src/__tests__/BrokenLinkSafetyNet.test.js index 19fe460df4c..f0af6865816 100644 --- a/server/sonar-docs/src/__tests__/BrokenLinkSafetyNet.test.js +++ b/server/sonar-docs/src/__tests__/BrokenLinkSafetyNet.test.js @@ -66,7 +66,7 @@ it('should have valid links in trees files', () => { }; tree.forEach(walk); }); - expect(hasErrors).toBeFalsy(); + expect(hasErrors).toBe(false); }); it('should have valid links in suggestions file', () => { @@ -84,7 +84,7 @@ it('should have valid links in suggestions file', () => { } }); }); - expect(hasErrors).toBeFalsy(); + expect(hasErrors).toBe(false); }); it('should have valid and uniq links in url metadata field', () => { @@ -103,7 +103,7 @@ it('should have valid and uniq links in url metadata field', () => { urlLists = [...urlLists, file.frontmatter.url]; }); - expect(hasErrors).toBeFalsy(); + expect(hasErrors).toBe(false); }); it('should have valid links pointing to documentation inside pages', () => { @@ -146,7 +146,7 @@ function checkContentUrl(files) { } }); }); - expect(hasErrors).toBeFalsy(); + expect(hasErrors).toBe(false); } function urlExists(files, url) { diff --git a/server/sonar-web/src/main/js/api/marketplace.ts b/server/sonar-web/src/main/js/api/marketplace.ts index 597153813ed..43cfedb3da0 100644 --- a/server/sonar-web/src/main/js/api/marketplace.ts +++ b/server/sonar-web/src/main/js/api/marketplace.ts @@ -44,7 +44,7 @@ export function isValidLicense(): Promise<{ isValidLicense: boolean }> { export function showLicense(): Promise<License> { return getJSON('/api/editions/show_license').catch((response: Response) => { if (response && response.status === 404) { - return Promise.resolve(undefined); + return undefined; } return throwGlobalError(response); }); diff --git a/server/sonar-web/src/main/js/api/news.ts b/server/sonar-web/src/main/js/api/news.ts index c9119054755..cac8117a3da 100644 --- a/server/sonar-web/src/main/js/api/news.ts +++ b/server/sonar-web/src/main/js/api/news.ts @@ -83,7 +83,7 @@ export function fetchPrismicRefs() { if (!master) { return Promise.reject('No master ref found'); } - return Promise.resolve(master); + return master; }); } diff --git a/server/sonar-web/src/main/js/app/components/StartupModal.tsx b/server/sonar-web/src/main/js/app/components/StartupModal.tsx index c5bb1efa37a..836c8d28a4f 100644 --- a/server/sonar-web/src/main/js/app/components/StartupModal.tsx +++ b/server/sonar-web/src/main/js/app/components/StartupModal.tsx @@ -126,7 +126,6 @@ export class StartupModal extends React.PureComponent<Props, State> { if (!license || !license.isValidEdition) { save(LICENSE_PROMPT, toShortNotSoISOString(new Date()), currentUser.login); this.setState({ modal: ModalKey.license }); - return Promise.resolve(); } return Promise.reject(); }); diff --git a/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx index 7609718d572..fa61e919640 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx @@ -100,7 +100,7 @@ it("doesn't load branches portfolio", async () => { expect(getComponentData).toBeCalledWith({ component: 'portfolioKey', branch: undefined }); expect(getComponentNavigation).toBeCalledWith({ component: 'portfolioKey', branch: undefined }); wrapper.update(); - expect(wrapper.find(Inner).exists()).toBeTruthy(); + expect(wrapper.find(Inner).exists()).toBe(true); }); it('updates branches on change', async () => { @@ -153,22 +153,22 @@ it('filters correctly the pending tasks for a main branch', () => { const branch2 = mockBranch({ name: 'branch-2' }); const pullRequest = mockPullRequest(); - expect(component.isSameBranch({}, undefined)).toBeTruthy(); - expect(component.isSameBranch({}, mainBranch)).toBeTruthy(); - expect(component.isSameBranch({}, branch3)).toBeFalsy(); - expect(component.isSameBranch({ branch: branch3.name }, branch3)).toBeTruthy(); - expect(component.isSameBranch({ branch: 'feature' }, branch2)).toBeFalsy(); - expect(component.isSameBranch({ branch: 'branch-6.6' }, branch2)).toBeFalsy(); - expect(component.isSameBranch({ branch: branch2.name }, branch2)).toBeTruthy(); - expect(component.isSameBranch({ branch: 'branch-6.7' }, pullRequest)).toBeFalsy(); - expect(component.isSameBranch({ pullRequest: pullRequest.key }, pullRequest)).toBeTruthy(); + expect(component.isSameBranch({}, undefined)).toBe(true); + expect(component.isSameBranch({}, mainBranch)).toBe(true); + expect(component.isSameBranch({}, branch3)).toBe(false); + expect(component.isSameBranch({ branch: branch3.name }, branch3)).toBe(true); + expect(component.isSameBranch({ branch: 'feature' }, branch2)).toBe(false); + expect(component.isSameBranch({ branch: 'branch-6.6' }, branch2)).toBe(false); + expect(component.isSameBranch({ branch: branch2.name }, branch2)).toBe(true); + expect(component.isSameBranch({ branch: 'branch-6.7' }, pullRequest)).toBe(false); + expect(component.isSameBranch({ pullRequest: pullRequest.key }, pullRequest)).toBe(true); const currentTask = { pullRequest: pullRequest.key, status: STATUSES.IN_PROGRESS } as T.Task; const failedTask = { ...currentTask, status: STATUSES.FAILED }; const pendingTasks = [currentTask, { branch: branch3.name } as T.Task, {} as T.Task]; - expect(component.getCurrentTask(currentTask, undefined)).toBe(undefined); + expect(component.getCurrentTask(currentTask, undefined)).toBeUndefined(); expect(component.getCurrentTask(failedTask, mainBranch)).toBe(failedTask); - expect(component.getCurrentTask(currentTask, mainBranch)).toBe(undefined); + expect(component.getCurrentTask(currentTask, mainBranch)).toBeUndefined(); expect(component.getCurrentTask(currentTask, pullRequest)).toMatchObject(currentTask); expect(component.getPendingTasks(pendingTasks, mainBranch)).toMatchObject([{}]); expect(component.getPendingTasks(pendingTasks, pullRequest)).toMatchObject([currentTask]); diff --git a/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx index 2c15678232c..43dcc83d3e7 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx @@ -70,7 +70,7 @@ it('should render only the children', async () => { const wrapper = getWrapper({ currentEdition: EditionKey.community }); await shouldNotHaveModals(wrapper); expect(showLicense).toHaveBeenCalledTimes(0); - expect(wrapper.find('div').exists()).toBeTruthy(); + expect(wrapper.find('div').exists()).toBe(true); await shouldNotHaveModals(getWrapper({ canAdmin: false })); @@ -121,7 +121,7 @@ describe('closeOnboarding', () => { wrapper.setState({ modal: ModalKey.onboarding }); wrapper.instance().closeOnboarding(); - expect(wrapper.state('modal')).toBe(undefined); + expect(wrapper.state('modal')).toBeUndefined(); expect(skipOnboarding).toHaveBeenCalledTimes(1); }); @@ -134,7 +134,7 @@ describe('openProjectOnboarding', () => { wrapper.instance().openProjectOnboarding(mockOrganization()); - expect(wrapper.state('modal')).toBe(undefined); + expect(wrapper.state('modal')).toBeUndefined(); expect(push).toHaveBeenCalledWith({ pathname: `/projects/create`, @@ -145,12 +145,12 @@ describe('openProjectOnboarding', () => { async function shouldNotHaveModals(wrapper: ShallowWrapper) { await waitAndUpdate(wrapper); - expect(wrapper.find('LicensePromptModal').exists()).toBeFalsy(); + expect(wrapper.find('LicensePromptModal').exists()).toBe(false); } async function shouldDisplayLicense(wrapper: ShallowWrapper) { await waitAndUpdate(wrapper); - expect(wrapper.find('LicensePromptModal').exists()).toBeTruthy(); + expect(wrapper.find('LicensePromptModal').exists()).toBe(true); } function getWrapper(props: Partial<StartupModal['props']> = {}) { diff --git a/server/sonar-web/src/main/js/app/components/embed-docs-modal/EmbedDocsPopup.tsx b/server/sonar-web/src/main/js/app/components/embed-docs-modal/EmbedDocsPopup.tsx index ba32a789521..d431460dada 100644 --- a/server/sonar-web/src/main/js/app/components/embed-docs-modal/EmbedDocsPopup.tsx +++ b/server/sonar-web/src/main/js/app/components/embed-docs-modal/EmbedDocsPopup.tsx @@ -71,7 +71,7 @@ export default class EmbedDocsPopup extends React.PureComponent<Props> { renderSonarCloudLinks() { return ( - <React.Fragment> + <> <li className="divider" /> <li> <a @@ -100,13 +100,13 @@ export default class EmbedDocsPopup extends React.PureComponent<Props> { <li> <ProductNewsMenuItem tag="SonarCloud" /> </li> - </React.Fragment> + </> ); } renderSonarQubeLinks() { return ( - <React.Fragment> + <> <li className="divider" /> <li> <a href="https://community.sonarsource.com/" rel="noopener noreferrer" target="_blank"> @@ -129,7 +129,7 @@ export default class EmbedDocsPopup extends React.PureComponent<Props> { 'Twitter' )} </li> - </React.Fragment> + </> ); } diff --git a/server/sonar-web/src/main/js/app/components/extensions/__tests__/Extension-test.tsx b/server/sonar-web/src/main/js/app/components/extensions/__tests__/Extension-test.tsx index fbb67eb0698..96d1d8e9c2c 100644 --- a/server/sonar-web/src/main/js/app/components/extensions/__tests__/Extension-test.tsx +++ b/server/sonar-web/src/main/js/app/components/extensions/__tests__/Extension-test.tsx @@ -64,7 +64,7 @@ it('should handle Function extensions correctly', async () => { expect(stop).toBeCalled(); }); -it('should unmount an extension before starting a new one', async done => { +it('should unmount an extension before starting a new one', async () => { const reactExtension = jest.fn().mockReturnValue(<div className="extension" />); (getExtensionStart as jest.Mock).mockResolvedValue(reactExtension); @@ -72,16 +72,13 @@ it('should unmount an extension before starting a new one', async done => { await waitAndUpdate(wrapper); expect(wrapper.state('extensionElement')).not.toBeUndefined(); - const start = jest.fn((options: any) => { - expect(options.el).not.toBeUndefined(); - done(); - }); + const start = jest.fn(); (getExtensionStart as jest.Mock).mockResolvedValue(start); wrapper.setProps({ extension: { key: 'bar', name: 'Bar' } }); await waitAndUpdate(wrapper); expect(wrapper.state('extensionElement')).toBeUndefined(); - expect(start).toBeCalled(); + expect(start).toHaveBeenCalled(); }); function shallowRender(props: Partial<Extension['props']> = {}) { diff --git a/server/sonar-web/src/main/js/app/components/extensions/legacy/__tests__/request-legacy-test.ts b/server/sonar-web/src/main/js/app/components/extensions/legacy/__tests__/request-legacy-test.ts index 0e46532c851..41e8c562f32 100644 --- a/server/sonar-web/src/main/js/app/components/extensions/legacy/__tests__/request-legacy-test.ts +++ b/server/sonar-web/src/main/js/app/components/extensions/legacy/__tests__/request-legacy-test.ts @@ -50,7 +50,7 @@ describe('parseError', () => { ).resolves.toBe('Error1. Error2'); }); - it('should parse error and return default message', () => { + it('should parse error and return default message if empty object', () => { return expect( parseError({ response: { @@ -60,7 +60,7 @@ describe('parseError', () => { ).resolves.toBe('default_error_message'); }); - it('should parse error and return default message', () => { + it('should parse error and return default message if undefined', () => { return expect( parseError({ response: { @@ -135,7 +135,8 @@ describe('requestTryAndRepeatUntil', () => { stopRepeat ); - expect(promiseResult).rejects.toBe(undefined); + // eslint-disable-next-line jest/valid-expect + expect(promiseResult).rejects.toBeUndefined(); for (let i = 1; i < 3; i++) { jest.runAllTimers(); diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-test.tsx index aff2c9336f0..eb350f9fd8c 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-test.tsx @@ -31,7 +31,7 @@ it('should render correctly', () => { it('should not render favorite button if the user is not logged in', () => { const wrapper = shallowRender(); - expect(wrapper.find(Favorite).exists()).toBeFalsy(); + expect(wrapper.find(Favorite).exists()).toBe(false); }); function shallowRender(props?: Partial<HeaderProps>) { diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/HeaderMeta-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/HeaderMeta-test.tsx index b69e350ae47..8aa31d61892 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/HeaderMeta-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/HeaderMeta-test.tsx @@ -41,11 +41,11 @@ it('should render correctly for a pull request', () => { it('should render correctly when the user is not logged in', () => { const wrapper = shallowRender({ currentUser: { isLoggedIn: false } }); - expect(wrapper.find(HomePageSelect).exists()).toBeFalsy(); + expect(wrapper.find(HomePageSelect).exists()).toBe(false); }); describe('#getCurrentPage', () => { - test('should return a portfolio page', () => { + it('should return a portfolio page', () => { expect( getCurrentPage( mockComponent({ key: 'foo', qualifier: ComponentQualifier.Portfolio }), @@ -57,7 +57,7 @@ describe('#getCurrentPage', () => { }); }); - test('should return an application page', () => { + it('should return an application page', () => { expect( getCurrentPage( mockComponent({ key: 'foo', qualifier: ComponentQualifier.Application }), @@ -66,7 +66,7 @@ describe('#getCurrentPage', () => { ).toEqual({ type: 'APPLICATION', component: 'foo', branch: 'develop' }); }); - test('should return a project page', () => { + it('should return a project page', () => { expect(getCurrentPage(mockComponent(), mockBranch({ name: 'feature/foo' }))).toEqual({ type: 'PROJECT', component: 'my-project', diff --git a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/CurrentBranchLike-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/CurrentBranchLike-test.tsx index 9f4fddac73e..125bb4d6220 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/CurrentBranchLike-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/CurrentBranchLike-test.tsx @@ -25,7 +25,7 @@ import { ComponentQualifier } from '../../../../../../types/component'; import { CurrentBranchLike, CurrentBranchLikeProps } from '../CurrentBranchLike'; describe('CurrentBranchLikeRenderer should render correctly for application when', () => { - test('there is only one branch and the user can admin the application', () => { + it('there is only one branch and the user can admin the application', () => { const wrapper = shallowRender({ component: mockComponent({ configuration: { showSettings: true }, @@ -36,7 +36,7 @@ describe('CurrentBranchLikeRenderer should render correctly for application when expect(wrapper).toMatchSnapshot(); }); - test("there is only one branch and the user CAN'T admin the application", () => { + it("there is only one branch and the user CAN'T admin the application", () => { const wrapper = shallowRender({ component: mockComponent({ configuration: { showSettings: false }, @@ -47,7 +47,7 @@ describe('CurrentBranchLikeRenderer should render correctly for application when expect(wrapper).toMatchSnapshot(); }); - test('there are many branchlikes', () => { + it('there are many branchlikes', () => { const wrapper = shallowRender({ branchesEnabled: true, component: mockComponent({ @@ -60,7 +60,7 @@ describe('CurrentBranchLikeRenderer should render correctly for application when }); describe('CurrentBranchLikeRenderer should render correctly for project when', () => { - test('branches support is disabled', () => { + it('branches support is disabled', () => { const wrapper = shallowRender({ branchesEnabled: false, component: mockComponent({ @@ -70,7 +70,7 @@ describe('CurrentBranchLikeRenderer should render correctly for project when', ( expect(wrapper).toMatchSnapshot(); }); - test('there is only one branchlike', () => { + it('there is only one branchlike', () => { const wrapper = shallowRender({ branchesEnabled: true, component: mockComponent({ @@ -81,7 +81,7 @@ describe('CurrentBranchLikeRenderer should render correctly for project when', ( expect(wrapper).toMatchSnapshot(); }); - test('there are many branchlikes', () => { + it('there are many branchlikes', () => { const wrapper = shallowRender({ branchesEnabled: true, component: mockComponent({ diff --git a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/Menu-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/Menu-test.tsx index b6d72b224d2..4c0a4bb8797 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/Menu-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/__tests__/Menu-test.tsx @@ -92,19 +92,15 @@ it('should handle keyboard shortcut correctly', () => { const { onKeyDown } = wrapper.find(SearchBox).props(); - if (!onKeyDown) { - fail('onKeyDown should be defined'); - } else { - onKeyDown(mockEvent({ keyCode: KeyCodes.UpArrow })); - expect(wrapper.state().selectedBranchLike).toBe(branchLikes[5]); - - onKeyDown(mockEvent({ keyCode: KeyCodes.DownArrow })); - onKeyDown(mockEvent({ keyCode: KeyCodes.DownArrow })); - expect(wrapper.state().selectedBranchLike).toBe(branchLikes[0]); - - onKeyDown(mockEvent({ keyCode: KeyCodes.Enter })); - expect(push).toHaveBeenCalled(); - } + onKeyDown!(mockEvent({ keyCode: KeyCodes.UpArrow })); + expect(wrapper.state().selectedBranchLike).toBe(branchLikes[5]); + + onKeyDown!(mockEvent({ keyCode: KeyCodes.DownArrow })); + onKeyDown!(mockEvent({ keyCode: KeyCodes.DownArrow })); + expect(wrapper.state().selectedBranchLike).toBe(branchLikes[0]); + + onKeyDown!(mockEvent({ keyCode: KeyCodes.Enter })); + expect(push).toHaveBeenCalled(); }); const branchLikes = mockSetOfBranchAndPullRequest(); diff --git a/server/sonar-web/src/main/js/apps/account/components/__tests__/Account-test.tsx b/server/sonar-web/src/main/js/apps/account/components/__tests__/Account-test.tsx index f073673f2f1..281db92d0b5 100644 --- a/server/sonar-web/src/main/js/apps/account/components/__tests__/Account-test.tsx +++ b/server/sonar-web/src/main/js/apps/account/components/__tests__/Account-test.tsx @@ -34,7 +34,7 @@ it('should render correctly', () => { it('should not render for anonymous user', () => { const wrapper = shallowRender({ currentUser: mockCurrentUser({ isLoggedIn: false }) }); - expect(wrapper.type()).toBe(null); + expect(wrapper.type()).toBeNull(); expect(handleRequiredAuthentication).toBeCalled(); }); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-test.tsx index 474b37f13e3..2e4410f064f 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-test.tsx +++ b/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-test.tsx @@ -21,7 +21,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { click } from 'sonar-ui-common/helpers/testUtils'; import Search from '../components/Search'; -import { CURRENTS, DEBOUNCE_DELAY, DEFAULT_FILTERS, STATUSES } from '../constants'; +import { CURRENTS, DEFAULT_FILTERS, STATUSES } from '../constants'; import { formatDuration } from '../utils'; describe('Constants', () => { @@ -47,23 +47,20 @@ describe('Search', () => { it('should render search form', () => { const component = shallow(<Search {...defaultProps} />); - expect(component.find('SearchBox').exists()).toBeTruthy(); + expect(component.find('SearchBox').exists()).toBe(true); }); it('should not render search form', () => { const component = shallow(<Search {...defaultProps} component={{ id: 'ABCD' }} />); - expect(component.find('SearchBox').exists()).toBeFalsy(); + expect(component.find('SearchBox').exists()).toBe(false); }); - it('should search', done => { + it('should search', () => { const searchSpy = jest.fn(); const component = shallow(<Search {...defaultProps} onFilterUpdate={searchSpy} />); const searchInput = component.find('SearchBox'); searchInput.prop<Function>('onChange')('some search query'); - setTimeout(() => { - expect(searchSpy).toBeCalledWith({ query: 'some search query' }); - done(); - }, DEBOUNCE_DELAY); + expect(searchSpy).toBeCalledWith({ query: 'some search query' }); }); it('should reload', () => { diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskActions-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskActions-test.tsx index 9d87f87ca90..4842ce74854 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskActions-test.tsx +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskActions-test.tsx @@ -36,7 +36,7 @@ it('shows stack trace', () => { expect(wrapper.find('Stacktrace')).toMatchSnapshot(); wrapper.find('Stacktrace').prop<Function>('onClose')(); wrapper.update(); - expect(wrapper.find('Stacktrace').exists()).toBeFalsy(); + expect(wrapper.find('Stacktrace').exists()).toBe(false); }); it('shows scanner context', () => { @@ -45,7 +45,7 @@ it('shows scanner context', () => { expect(wrapper.find('ScannerContext')).toMatchSnapshot(); wrapper.find('ScannerContext').prop<Function>('onClose')(); wrapper.update(); - expect(wrapper.find('ScannerContext').exists()).toBeFalsy(); + expect(wrapper.find('ScannerContext').exists()).toBe(false); }); it('shows warnings', () => { @@ -54,7 +54,7 @@ it('shows warnings', () => { expect(wrapper.find('AnalysisWarningsModal')).toMatchSnapshot(); wrapper.find('AnalysisWarningsModal').prop<Function>('onClose')(); wrapper.update(); - expect(wrapper.find('AnalysisWarningsModal').exists()).toBeFalsy(); + expect(wrapper.find('AnalysisWarningsModal').exists()).toBe(false); }); function shallowRender(fields?: Partial<T.Task>, props?: Partial<TaskActions['props']>) { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsDescription-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsDescription-test.tsx index 09a170a05d6..8c3272617cf 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsDescription-test.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsDescription-test.tsx @@ -73,7 +73,7 @@ it('should add extra description', async () => { const onChange = jest.fn(); const wrapper = getWrapper({ canWrite: true, onChange }); click(wrapper.find('#coding-rules-detail-extend-description')); - expect(wrapper.find('textarea').exists()).toBeTruthy(); + expect(wrapper.find('textarea').exists()).toBe(true); change(wrapper.find('textarea'), 'new description'); click(wrapper.find('#coding-rules-detail-extend-description-submit')); await waitAndUpdate(wrapper); diff --git a/server/sonar-web/src/main/js/apps/component-measures/__tests__/utils-test.ts b/server/sonar-web/src/main/js/apps/component-measures/__tests__/utils-test.ts index 35eb2d2dfc2..b507940e6fe 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/__tests__/utils-test.ts +++ b/server/sonar-web/src/main/js/apps/component-measures/__tests__/utils-test.ts @@ -209,7 +209,7 @@ describe('Component classification', () => { it('should be file type', () => { [ComponentQualifier.File, ComponentQualifier.TestFile].forEach(qual => { const component = componentBuilder(qual); - expect(utils.isFileType(component)).toBeTruthy(); + expect(utils.isFileType(component)).toBe(true); }); }); @@ -220,7 +220,7 @@ describe('Component classification', () => { ComponentQualifier.Application ].forEach(qual => { const component = componentBuilder(qual); - expect(utils.isViewType(component)).toBeTruthy(); + expect(utils.isViewType(component)).toBe(true); }); }); }); diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureHeader-test.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureHeader-test.tsx index 016c46b55ec..f97a1bd2473 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureHeader-test.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureHeader-test.tsx @@ -84,13 +84,13 @@ it('should not render link to activity page for files', () => { shallow(<MeasureHeader {...PROPS} />) .find('HistoryIcon') .exists() - ).toBeTruthy(); + ).toBe(true); expect( shallow(<MeasureHeader {...PROPS} component={{ ...PROPS.component, qualifier: 'FIL' }} />) .find('HistoryIcon') .exists() - ).toBeFalsy(); + ).toBe(false); }); it('should display secondary measure too', () => { diff --git a/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/Sidebar-test.tsx b/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/Sidebar-test.tsx index e13ebb28982..461d7d59c9f 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/Sidebar-test.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/Sidebar-test.tsx @@ -29,9 +29,9 @@ it('should correctly toggle facets', () => { const wrapper = shallowRender(); expect(wrapper.state('openFacets').bugs).toBeUndefined(); (wrapper.instance() as Sidebar).toggleFacet('bugs'); - expect(wrapper.state('openFacets').bugs).toBeTruthy(); + expect(wrapper.state('openFacets').bugs).toBe(true); (wrapper.instance() as Sidebar).toggleFacet('bugs'); - expect(wrapper.state('openFacets').bugs).toBeFalsy(); + expect(wrapper.state('openFacets').bugs).toBe(false); }); function shallowRender(props = {}) { diff --git a/server/sonar-web/src/main/js/apps/create/components/__tests__/UpgradeOrganizationAdvantages-test.tsx b/server/sonar-web/src/main/js/apps/create/components/__tests__/UpgradeOrganizationAdvantages-test.tsx index ec34be7e22b..388b00f408b 100644 --- a/server/sonar-web/src/main/js/apps/create/components/__tests__/UpgradeOrganizationAdvantages-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/components/__tests__/UpgradeOrganizationAdvantages-test.tsx @@ -21,6 +21,6 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import UpgradeOrganizationAdvantages from '../UpgradeOrganizationAdvantages'; -it('should render correctly ', () => { +it('should render correctly', () => { expect(shallow(<UpgradeOrganizationAdvantages />)).toMatchSnapshot(); }); diff --git a/server/sonar-web/src/main/js/apps/create/components/__tests__/__snapshots__/UpgradeOrganizationAdvantages-test.tsx.snap b/server/sonar-web/src/main/js/apps/create/components/__tests__/__snapshots__/UpgradeOrganizationAdvantages-test.tsx.snap index 9a93403230e..dce3b0b46e6 100644 --- a/server/sonar-web/src/main/js/apps/create/components/__tests__/__snapshots__/UpgradeOrganizationAdvantages-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/create/components/__tests__/__snapshots__/UpgradeOrganizationAdvantages-test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`should render correctly 1`] = ` +exports[`should render correctly 1`] = ` <ul className="note" > diff --git a/server/sonar-web/src/main/js/apps/create/organization/CreateOrganization.tsx b/server/sonar-web/src/main/js/apps/create/organization/CreateOrganization.tsx index 9f546c857c8..f074bde4aaa 100644 --- a/server/sonar-web/src/main/js/apps/create/organization/CreateOrganization.tsx +++ b/server/sonar-web/src/main/js/apps/create/organization/CreateOrganization.tsx @@ -170,7 +170,7 @@ export class CreateOrganization extends React.PureComponent<Props & WithRouterPr return getAlmOrganization({ installationId }) .then(({ almOrganization, boundOrganization }) => { if (boundOrganization) { - return Promise.resolve({ almOrganization, boundOrganization }); + return { almOrganization, boundOrganization }; } return this.setValidOrgKey(almOrganization); }) diff --git a/server/sonar-web/src/main/js/apps/create/organization/__tests__/CreateOrganization-test.tsx b/server/sonar-web/src/main/js/apps/create/organization/__tests__/CreateOrganization-test.tsx index 4b1f7a339ae..1f1e0a03dad 100644 --- a/server/sonar-web/src/main/js/apps/create/organization/__tests__/CreateOrganization-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/organization/__tests__/CreateOrganization-test.tsx @@ -180,11 +180,11 @@ it('should switch tabs', async () => { expect(wrapper).toMatchSnapshot(); (wrapper.find('Tabs').prop('onChange') as Function)('manual'); - expect(wrapper.find('ManualOrganizationCreate').hasClass('hidden')).toBeFalsy(); - expect(wrapper.find('withRouter(RemoteOrganizationChoose)').hasClass('hidden')).toBeTruthy(); + expect(wrapper.find('ManualOrganizationCreate').hasClass('hidden')).toBe(false); + expect(wrapper.find('withRouter(RemoteOrganizationChoose)').hasClass('hidden')).toBe(true); (wrapper.find('Tabs').prop('onChange') as Function)('auto'); - expect(wrapper.find('withRouter(RemoteOrganizationChoose)').hasClass('hidden')).toBeFalsy(); - expect(wrapper.find('ManualOrganizationCreate').hasClass('hidden')).toBeTruthy(); + expect(wrapper.find('withRouter(RemoteOrganizationChoose)').hasClass('hidden')).toBe(false); + expect(wrapper.find('ManualOrganizationCreate').hasClass('hidden')).toBe(true); }); it('should reload the alm organization when the url query changes', async () => { diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectPageSonarCloud-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectPageSonarCloud-test.tsx index 40d1365d6aa..67788031ac1 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectPageSonarCloud-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectPageSonarCloud-test.tsx @@ -75,9 +75,9 @@ it('should switch tabs', async () => { expect(wrapper).toMatchSnapshot(); wrapper.find('Tabs').prop<Function>('onChange')('manual'); - expect(wrapper.find('ManualProjectCreate').exists()).toBeTruthy(); + expect(wrapper.find('ManualProjectCreate').exists()).toBe(true); wrapper.find('Tabs').prop<Function>('onChange')('auto'); - expect(wrapper.find('AutoProjectCreate').exists()).toBeTruthy(); + expect(wrapper.find('AutoProjectCreate').exists()).toBe(true); }); function getWrapper(props = {}) { diff --git a/server/sonar-web/src/main/js/apps/documentation/components/MenuExternalLink.tsx b/server/sonar-web/src/main/js/apps/documentation/components/MenuExternalLink.tsx index f0a4b78e3d6..9d417749373 100644 --- a/server/sonar-web/src/main/js/apps/documentation/components/MenuExternalLink.tsx +++ b/server/sonar-web/src/main/js/apps/documentation/components/MenuExternalLink.tsx @@ -27,7 +27,7 @@ interface Props { export function MenuExternalLink({ title, url }: Props) { return ( - <a href={url} key={title} target="_blank"> + <a href={url} key={title} target="_blank" rel="noopener noreferrer"> <h3 className="list-group-item-heading"> <DetachIcon className="spacer-right" /> {title} diff --git a/server/sonar-web/src/main/js/apps/groups/components/__tests__/List-test.tsx b/server/sonar-web/src/main/js/apps/groups/components/__tests__/List-test.tsx index 9b8ce999486..c0495a5da38 100644 --- a/server/sonar-web/src/main/js/apps/groups/components/__tests__/List-test.tsx +++ b/server/sonar-web/src/main/js/apps/groups/components/__tests__/List-test.tsx @@ -30,7 +30,7 @@ it('should not render "Anyone"', () => { shallowRender(false) .find('.js-anyone') .exists() - ).toBeFalsy(); + ).toBe(false); }); function shallowRender(showAnyone = true) { diff --git a/server/sonar-web/src/main/js/apps/issues/components/App.tsx b/server/sonar-web/src/main/js/apps/issues/components/App.tsx index cf838a1407a..d93cfe3ac7c 100644 --- a/server/sonar-web/src/main/js/apps/issues/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/issues/components/App.tsx @@ -192,9 +192,10 @@ export default class App extends React.PureComponent<Props, State> { } componentWillReceiveProps(nextProps: Props) { - const openIssue = this.getOpenIssue(nextProps, this.state.issues); + const { issues, selected } = this.state; + const openIssue = this.getOpenIssue(nextProps, issues); - if (openIssue && openIssue.key !== this.state.selected) { + if (openIssue && openIssue.key !== selected) { this.setState({ locationsNavigator: false, selected: openIssue.key, diff --git a/server/sonar-web/src/main/js/apps/issues/components/ListItem.tsx b/server/sonar-web/src/main/js/apps/issues/components/ListItem.tsx index 1662793de1c..780d2bda72f 100644 --- a/server/sonar-web/src/main/js/apps/issues/components/ListItem.tsx +++ b/server/sonar-web/src/main/js/apps/issues/components/ListItem.tsx @@ -39,13 +39,7 @@ interface Props { selected: boolean; } -interface State { - similarIssues: boolean; -} - -export default class ListItem extends React.PureComponent<Props, State> { - state: State = { similarIssues: false }; - +export default class ListItem extends React.PureComponent<Props> { handleFilter = (property: string, issue: T.Issue) => { const { onFilterChange } = this.props; diff --git a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetViewer-test.tsx b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetViewer-test.tsx index 70382f6c53d..bf878ef92d1 100644 --- a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetViewer-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/ComponentSourceSnippetViewer-test.tsx @@ -270,7 +270,7 @@ describe('getNodes', () => { const rootNode = wrapper.instance().rootNodeRef; mockDom(rootNode.current!); - expect(wrapper.instance().cleanDom(3)); + wrapper.instance().cleanDom(3); const nodes = wrapper.instance().getNodes(3); expect(nodes!.wrapper.style.maxHeight).toBe(''); expect(nodes!.table.style.marginTop).toBe(''); diff --git a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/CrossComponentSourceViewerWrapper-test.tsx b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/CrossComponentSourceViewerWrapper-test.tsx index 318e6646d6b..b9feec7f79d 100644 --- a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/CrossComponentSourceViewerWrapper-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/CrossComponentSourceViewerWrapper-test.tsx @@ -96,7 +96,7 @@ it('should handle line popup', async () => { expect(wrapper.state('linePopup')).toEqual(linePopup); wrapper.find('ComponentSourceSnippetViewer').prop<Function>('onLinePopupToggle')(linePopup); - expect(wrapper.state('linePopup')).toEqual(undefined); + expect(wrapper.state('linePopup')).toBeUndefined(); const openLinePopup = { ...linePopup, open: true }; wrapper.find('ComponentSourceSnippetViewer').prop<Function>('onLinePopupToggle')(openLinePopup); diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/CreationDateFacet.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/CreationDateFacet.tsx index 6150e08b809..3c7bb54b9dc 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/CreationDateFacet.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/CreationDateFacet.tsx @@ -153,6 +153,7 @@ class CreationDateFacet extends React.PureComponent<Props & InjectedIntlProps> { const tooltipEndDate = endDate || new Date(); const tooltip = ( + // eslint-disable-next-line react/jsx-fragments <React.Fragment> {formatMeasure(stats[start], 'SHORT_INT')} <br /> diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/StandardFacet.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/StandardFacet.tsx index 11cf9da8ed7..f43048c2a42 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/StandardFacet.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/StandardFacet.tsx @@ -61,7 +61,6 @@ interface Props { } interface State { - cweQuery: string; standards: T.Standards; } @@ -72,7 +71,6 @@ export default class StandardFacet extends React.PureComponent<Props, State> { mounted = false; property = STANDARDS; state: State = { - cweQuery: '', standards: { owaspTop10: {}, sansTop25: {}, cwe: {}, sonarsourceSecurity: {} } }; diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/DirectoryFacet-test.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/DirectoryFacet-test.tsx index 0e583e31522..800f4027c85 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/DirectoryFacet-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/DirectoryFacet-test.tsx @@ -37,17 +37,17 @@ describe("ListStyleFacet's callback props", () => { const wrapper = shallowRender(); const instance = wrapper.instance(); - test('#getSearchResultText()', () => { + it('#getSearchResultText()', () => { expect(instance.getSearchResultText({ name: 'bar' } as TreeComponentWithPath)).toBe('bar'); }); - test('#getSearchResultKey()', () => { + it('#getSearchResultKey()', () => { expect(instance.getSearchResultKey({ path: 'foo/bar' } as TreeComponentWithPath)).toBe( 'foo/bar' ); }); - test('#getFacetItemText()', () => { + it('#getFacetItemText()', () => { expect(instance.getFacetItemText('foo/bar')).toBe('foo/bar'); }); }); diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/FileFacet-test.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/FileFacet-test.tsx index ae17bf6d19f..fa8bfb140fd 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/FileFacet-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/FileFacet-test.tsx @@ -37,18 +37,18 @@ describe("ListStyleFacet's callback props", () => { const wrapper = shallowRender(); const instance = wrapper.instance(); - test('#getSearchResultText()', () => { + it('#getSearchResultText()', () => { expect(instance.getSearchResultText({ path: 'foo/bar.js' } as TreeComponentWithPath)).toBe( 'foo/bar.js' ); }); - test('#getSearchResultKey()', () => { + it('#getSearchResultKey()', () => { expect(instance.getSearchResultKey({ key: 'foo' } as TreeComponentWithPath)).toBe('fooUuid'); expect(instance.getSearchResultKey({ key: 'bar' } as TreeComponentWithPath)).toBe('bar'); }); - test('#getFacetItemText()', () => { + it('#getFacetItemText()', () => { expect(instance.getFacetItemText('fooUuid')).toBe('foo/bar.js'); expect(instance.getFacetItemText('bar')).toBe('bar'); }); diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/PluginActions.tsx b/server/sonar-web/src/main/js/apps/marketplace/components/PluginActions.tsx index 6f7eff92d19..57b237d965f 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/components/PluginActions.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/components/PluginActions.tsx @@ -80,7 +80,7 @@ export default class PluginActions extends React.PureComponent<Props, State> { <p className="little-spacer-bottom"> {translate('marketplace.available_under_commercial_license')} </p> - <a href={plugin.homepageUrl} target="_blank"> + <a href={plugin.homepageUrl} target="_blank" rel="noopener noreferrer"> {translate('marketplace.learn_more')} </a> </div> @@ -131,7 +131,8 @@ export default class PluginActions extends React.PureComponent<Props, State> { <a className="js-plugin-terms nowrap little-spacer-left" href={plugin.termsAndConditionsUrl} - target="_blank"> + target="_blank" + rel="noopener noreferrer"> {translate('marketplace.terms_and_conditions')} </a> </p> diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/PluginChangeLogItem.tsx b/server/sonar-web/src/main/js/apps/marketplace/components/PluginChangeLogItem.tsx index 1ad2b626fd7..057e04a691c 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/components/PluginChangeLogItem.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/components/PluginChangeLogItem.tsx @@ -47,7 +47,11 @@ export default function PluginChangeLogItem({ release, update }: Props) { <DateFormatter date={release.date} /> </span> {release.changeLogUrl && ( - <a className="js-plugin-changelog-link" href={release.changeLogUrl} target="_blank"> + <a + className="js-plugin-changelog-link" + href={release.changeLogUrl} + target="_blank" + rel="noopener noreferrer"> {translate('marketplace.release_notes')} </a> )} diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/PluginOrganization.tsx b/server/sonar-web/src/main/js/apps/marketplace/components/PluginOrganization.tsx index 147f0b40cf0..204fbb5c216 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/components/PluginOrganization.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/components/PluginOrganization.tsx @@ -22,11 +22,11 @@ import { FormattedMessage } from 'react-intl'; import { translate } from 'sonar-ui-common/helpers/l10n'; import { Plugin } from '../../../api/plugins'; -interface Props { +export interface PluginOrganizationProps { plugin: Plugin; } -export default function PluginOrganization({ plugin }: Props) { +export default function PluginOrganization({ plugin }: PluginOrganizationProps) { if (!plugin.organizationName) { return null; } @@ -37,7 +37,11 @@ export default function PluginOrganization({ plugin }: Props) { id="marketplace.developed_by_x" values={{ organization: plugin.organizationUrl ? ( - <a className="js-plugin-organization" href={plugin.organizationUrl} target="_blank"> + <a + className="js-plugin-organization" + href={plugin.organizationUrl} + target="_blank" + rel="noopener noreferrer"> {plugin.organizationName} </a> ) : ( diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/PluginUrls.tsx b/server/sonar-web/src/main/js/apps/marketplace/components/PluginUrls.tsx index 1da28f7432e..6a13802c3f9 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/components/PluginUrls.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/components/PluginUrls.tsx @@ -34,14 +34,22 @@ export default function PluginUrls({ plugin }: Props) { <ul className="list-inline"> {plugin.homepageUrl && ( <li> - <a className="js-plugin-homepage" href={plugin.homepageUrl} target="_blank"> + <a + className="js-plugin-homepage" + href={plugin.homepageUrl} + target="_blank" + rel="noopener noreferrer"> {translate('marketplace.homepage')} </a> </li> )} {plugin.issueTrackerUrl && ( <li> - <a className="js-plugin-issues" href={plugin.issueTrackerUrl} target="_blank"> + <a + className="js-plugin-issues" + href={plugin.issueTrackerUrl} + target="_blank" + rel="noopener noreferrer"> {translate('marketplace.issue_tracker')} </a> </li> diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/PluginOrganization-test.tsx b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/PluginOrganization-test.tsx new file mode 100644 index 00000000000..8489e6893b9 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/PluginOrganization-test.tsx @@ -0,0 +1,44 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import { shallow } from 'enzyme'; +import * as React from 'react'; +import PluginOrganization, { PluginOrganizationProps } from '../PluginOrganization'; + +it('should render correctly', () => { + const wrapper = shallowRender(); + expect(wrapper).toMatchSnapshot(); +}); + +it('should render correctly with no organization name', () => { + const wrapper = shallowRender({ + plugin: { key: 'test', name: 'test', organizationName: undefined } + }); + expect(wrapper.type()).toBeNull(); +}); + +function shallowRender(props?: Partial<PluginOrganizationProps>) { + return shallow( + <PluginOrganization + plugin={{ key: 'test', name: 'test', organizationName: 'org', organizationUrl: 'org_url' }} + {...props} + /> + ); +} diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/PluginActions-test.tsx.snap b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/PluginActions-test.tsx.snap index dc924345af0..6f229d96527 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/PluginActions-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/PluginActions-test.tsx.snap @@ -24,6 +24,7 @@ exports[`should render available plugin correctly 1`] = ` <a className="js-plugin-terms nowrap little-spacer-left" href="https://url" + rel="noopener noreferrer" target="_blank" > marketplace.terms_and_conditions @@ -50,6 +51,7 @@ exports[`should render available plugin correctly 2`] = ` marketplace.available_under_commercial_license </p> <a + rel="noopener noreferrer" target="_blank" > marketplace.learn_more diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/PluginOrganization-test.tsx.snap b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/PluginOrganization-test.tsx.snap new file mode 100644 index 00000000000..38339993d42 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/PluginOrganization-test.tsx.snap @@ -0,0 +1,24 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render correctly 1`] = ` +<li + className="little-spacer-bottom" +> + <FormattedMessage + defaultMessage="marketplace.developed_by_x" + id="marketplace.developed_by_x" + values={ + Object { + "organization": <a + className="js-plugin-organization" + href="org_url" + rel="noopener noreferrer" + target="_blank" + > + org + </a>, + } + } + /> +</li> +`; diff --git a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/PluginUrls-test.tsx.snap b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/PluginUrls-test.tsx.snap index a55d3214845..4a29b84eb51 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/PluginUrls-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/PluginUrls-test.tsx.snap @@ -11,6 +11,7 @@ exports[`should display only one url 1`] = ` <a className="js-plugin-homepage" href="homepageurl" + rel="noopener noreferrer" target="_blank" > marketplace.homepage @@ -31,6 +32,7 @@ exports[`should display the urls 1`] = ` <a className="js-plugin-homepage" href="homepageurl" + rel="noopener noreferrer" target="_blank" > marketplace.homepage @@ -40,6 +42,7 @@ exports[`should display the urls 1`] = ` <a className="js-plugin-issues" href="issuetrackerurl" + rel="noopener noreferrer" target="_blank" > marketplace.issue_tracker diff --git a/server/sonar-web/src/main/js/apps/organizationMembers/SyncMemberForm.tsx b/server/sonar-web/src/main/js/apps/organizationMembers/SyncMemberForm.tsx index b300f2d3440..6e1f3a0e802 100644 --- a/server/sonar-web/src/main/js/apps/organizationMembers/SyncMemberForm.tsx +++ b/server/sonar-web/src/main/js/apps/organizationMembers/SyncMemberForm.tsx @@ -61,7 +61,6 @@ export class SyncMemberForm extends React.PureComponent<Props, State> { if (membersSync) { return this.handleMemberSync(); } - return Promise.resolve(); }); }; diff --git a/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/AddMemberForm-test.tsx b/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/AddMemberForm-test.tsx index c08ee407544..1be6c70cd74 100644 --- a/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/AddMemberForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/AddMemberForm-test.tsx @@ -51,9 +51,9 @@ it('should correctly handle user interactions', () => { /> ); click(wrapper.find('Button')); - expect(wrapper.state('open')).toBeTruthy(); + expect(wrapper.state('open')).toBe(true); (wrapper.instance() as AddMemberForm).closeForm(); - expect(wrapper.state('open')).toBeFalsy(); + expect(wrapper.state('open')).toBe(false); }); it('should search users', () => { diff --git a/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/ManageMemberGroupsForm-test.tsx b/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/ManageMemberGroupsForm-test.tsx index 0f44fe35924..7ce1733550c 100644 --- a/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/ManageMemberGroupsForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/ManageMemberGroupsForm-test.tsx @@ -85,13 +85,13 @@ it('should render', () => { it('should correctly select the groups', () => { const form = getMountedForm(); - expect(form.instance.isGroupSelected('11')).toBeTruthy(); - expect(form.instance.isGroupSelected('7')).toBeFalsy(); + expect(form.instance.isGroupSelected('11')).toBe(true); + expect(form.instance.isGroupSelected('7')).toBe(false); form.instance.onCheck('11', false); form.instance.onCheck('7', true); expect(form.wrapper.state('userGroups')).toMatchSnapshot(); - expect(form.instance.isGroupSelected('11')).toBeFalsy(); - expect(form.instance.isGroupSelected('7')).toBeTruthy(); + expect(form.instance.isGroupSelected('11')).toBe(false); + expect(form.instance.isGroupSelected('7')).toBe(true); }); it('should correctly handle the submit event and close the modal', () => { diff --git a/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/RemoveMemberForm-test.tsx b/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/RemoveMemberForm-test.tsx index fbf9a173608..657b6797190 100644 --- a/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/RemoveMemberForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/RemoveMemberForm-test.tsx @@ -25,7 +25,7 @@ import RemoveMemberForm from '../RemoveMemberForm'; const member = { login: 'admin', name: 'Admin Istrator', avatar: '', groupCount: 3 }; const organization = { key: 'myorg', name: 'MyOrg' }; -it('should render ', () => { +it('should render', () => { const wrapper = shallow( <RemoveMemberForm member={member} diff --git a/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/__snapshots__/RemoveMemberForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/__snapshots__/RemoveMemberForm-test.tsx.snap index c4a8afef3ef..44022d1568c 100644 --- a/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/__snapshots__/RemoveMemberForm-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/__snapshots__/RemoveMemberForm-test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`should render 1`] = ` +exports[`should render 1`] = ` <Modal contentLabel="users.remove" key="remove-member-modal" diff --git a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAccessContainer-test.tsx b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAccessContainer-test.tsx index 5ccfa205250..2854c474a80 100644 --- a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAccessContainer-test.tsx +++ b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAccessContainer-test.tsx @@ -78,10 +78,10 @@ describe('component', () => { describe('access functions', () => { it('should correctly handle access to admin only space', () => { - expect( - hasAdminAccess({ currentUser: loggedInUser, organization: adminOrganization }) - ).toBeTruthy(); - expect(hasAdminAccess({ currentUser, organization: adminOrganization })).toBeFalsy(); - expect(hasAdminAccess({ currentUser: loggedInUser, organization })).toBeFalsy(); + expect(hasAdminAccess({ currentUser: loggedInUser, organization: adminOrganization })).toBe( + true + ); + expect(hasAdminAccess({ currentUser, organization: adminOrganization })).toBe(false); + expect(hasAdminAccess({ currentUser: loggedInUser, organization })).toBe(false); }); }); diff --git a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationMeta-test.tsx b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationMeta-test.tsx index 679695e69c2..851f649cf75 100644 --- a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationMeta-test.tsx +++ b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationMeta-test.tsx @@ -48,5 +48,5 @@ it('renders with private badge', () => { ) .find('DocTooltip') .exists() - ).toBeTruthy(); + ).toBe(true); }); diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/ActivityPanel-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/ActivityPanel-test.tsx index 21856507dd6..4d451a3033b 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/ActivityPanel-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/ActivityPanel-test.tsx @@ -45,22 +45,14 @@ it('should correctly pass the leak period start date', () => { .find(GraphsHistory) .props(); - if (leakPeriodDate) { - expect(leakPeriodDate.getTime()).toBe(1503844430000); /* 2017-08-27T16:33:50+0200 */ - } else { - fail('leakPeriodDate should have been set'); - } + expect(leakPeriodDate!.getTime()).toBe(1503844430000); /* 2017-08-27T16:33:50+0200 */ // Leak period start is older than the oldest historic measure. ({ leakPeriodDate } = shallowRender({ leakPeriodDate: parseDate('2015-08-27T16:33:50+0200') }) .find(GraphsHistory) .props()); - if (leakPeriodDate) { - expect(leakPeriodDate.getTime()).toBe(1477578830000); /* 2016-10-27T16:33:50+0200 */ - } else { - fail('leakPeriodDate should have been set'); - } + expect(leakPeriodDate!.getTime()).toBe(1477578830000); /* 2016-10-27T16:33:50+0200 */ }); function shallowRender(props: Partial<ActivityPanelProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.tsx index 3d2050e8bb8..9951d9473f2 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.tsx @@ -45,7 +45,7 @@ it('should render BranchOverview', () => { getWrapper() .find(BranchOverview) .exists() - ).toBeTruthy(); + ).toBe(true); }); function getWrapper(props = {}) { diff --git a/server/sonar-web/src/main/js/apps/permissions/project/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/permissions/project/components/__tests__/App-test.tsx index d5e8e7c3c77..9e88b16affe 100644 --- a/server/sonar-web/src/main/js/apps/permissions/project/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/permissions/project/components/__tests__/App-test.tsx @@ -88,7 +88,7 @@ describe('should manage state correctly', () => { instance.handlePermissionSelect('foo'); expect(wrapper.state('selectedPermission')).toBe('foo'); instance.handlePermissionSelect('foo'); - expect(wrapper.state('selectedPermission')).toBe(undefined); + expect(wrapper.state('selectedPermission')).toBeUndefined(); }); it('should add and remove permission to a group', async () => { diff --git a/server/sonar-web/src/main/js/apps/portfolio/components/Report.tsx b/server/sonar-web/src/main/js/apps/portfolio/components/Report.tsx index e969ef5a6c1..0dbbf100e52 100644 --- a/server/sonar-web/src/main/js/apps/portfolio/components/Report.tsx +++ b/server/sonar-web/src/main/js/apps/portfolio/components/Report.tsx @@ -78,7 +78,8 @@ export default class Report extends React.PureComponent<Props, State> { <a download={component.name + ' - Executive Report.pdf'} href={getReportUrl(component.key)} - target="_blank"> + target="_blank" + rel="noopener noreferrer"> {translate('report.print')} </a> </li> @@ -102,7 +103,8 @@ export default class Report extends React.PureComponent<Props, State> { className="button" download={component.name + ' - Executive Report.pdf'} href={getReportUrl(component.key)} - target="_blank"> + target="_blank" + rel="noopener noreferrer"> {translate('report.print')} </a> ); diff --git a/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/__snapshots__/Report-test.tsx.snap b/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/__snapshots__/Report-test.tsx.snap index d35590311e2..3852cde2841 100644 --- a/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/__snapshots__/Report-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/__snapshots__/Report-test.tsx.snap @@ -12,6 +12,7 @@ exports[`renders 2`] = ` <a download="Foo - Executive Report.pdf" href="/api/governance_reports/download?componentKey=foo" + rel="noopener noreferrer" target="_blank" > report.print diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.tsx index c4960998b5a..4f38d5f2ec1 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/ProjectActivityAppContainer.tsx @@ -57,7 +57,6 @@ export interface State { initialized: boolean; metrics: T.Metric[]; measuresHistory: MeasureHistory[]; - paging?: T.Paging; query: Query; } @@ -195,12 +194,11 @@ export default class ProjectActivityAppContainer extends React.PureComponent<Pro fetchAllActivities = (topLevelComponent: string) => { this.setState({ analysesLoading: true }); this.loadAllActivities(topLevelComponent).then( - ({ analyses, paging }) => { + ({ analyses }) => { if (this.mounted) { this.setState({ analyses, - analysesLoading: false, - paging + analysesLoading: false }); } }, @@ -259,15 +257,14 @@ export default class ProjectActivityAppContainer extends React.PureComponent<Pro getAllMetrics(), this.fetchMeasuresHistory(graphMetrics) ]).then( - ([{ analyses, paging }, metrics, measuresHistory]) => { + ([{ analyses }, metrics, measuresHistory]) => { if (this.mounted) { this.setState({ analyses, graphLoading: false, initialized: true, measuresHistory, - metrics: this.filterMetrics(component, metrics), - paging + metrics: this.filterMetrics(component, metrics) }); this.fetchAllActivities(topLevelComponent); diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx index 9af8ca3b21e..fb297573273 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx @@ -60,11 +60,7 @@ it('should render correctly', () => { const timeFormatter = shallowRender() .find(TimeFormatter) .prop('children'); - if (!timeFormatter) { - fail('TimeFormatter instance not found'); - } else { - expect(timeFormatter('formatted_time')).toMatchSnapshot('formatted time'); - } + expect(timeFormatter!('formatted_time')).toMatchSnapshot('formatted time'); }); it('should show the correct admin options', () => { diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTabs-test.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTabs-test.tsx index d0004824c8c..77bc27836d7 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTabs-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTabs-test.tsx @@ -60,7 +60,7 @@ it('should render deletion modal correctly', () => { .props() .onClose(); expect(wrapper.state().deleting).toBeUndefined(); - expect(wrapper.find(DeleteBranchModal).exists()).toBeFalsy(); + expect(wrapper.find(DeleteBranchModal).exists()).toBe(false); wrapper .find(BranchLikeTable) @@ -71,7 +71,7 @@ it('should render deletion modal correctly', () => { .props() .onDelete(); expect(wrapper.state().deleting).toBeUndefined(); - expect(wrapper.find(DeleteBranchModal).exists()).toBeFalsy(); + expect(wrapper.find(DeleteBranchModal).exists()).toBe(false); expect(onBranchesChange).toHaveBeenCalled(); }); @@ -91,7 +91,7 @@ it('should render renaming modal correctly', () => { .props() .onClose(); expect(wrapper.state().renaming).toBeUndefined(); - expect(wrapper.find(RenameBranchModal).exists()).toBeFalsy(); + expect(wrapper.find(RenameBranchModal).exists()).toBe(false); wrapper .find(BranchLikeTable) @@ -102,7 +102,7 @@ it('should render renaming modal correctly', () => { .props() .onRename(); expect(wrapper.state().renaming).toBeUndefined(); - expect(wrapper.find(RenameBranchModal).exists()).toBeFalsy(); + expect(wrapper.find(RenameBranchModal).exists()).toBe(false); expect(onBranchesChange).toHaveBeenCalled(); }); @@ -114,7 +114,7 @@ it('should NOT render renaming modal for non-main branch', () => { .props() .onRename(mockPullRequest()); expect(wrapper.state().renaming).toBeDefined(); - expect(wrapper.find(RenameBranchModal).exists()).toBeFalsy(); + expect(wrapper.find(RenameBranchModal).exists()).toBe(false); }); function shallowRender(props: Partial<BranchLikeTabs['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchPurgeSetting-test.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchPurgeSetting-test.tsx index 8b74b6d24f6..737c1f0cb3f 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchPurgeSetting-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchPurgeSetting-test.tsx @@ -49,13 +49,9 @@ it('should correctly call the webservice if the user changes the value', () => { const { onChange } = wrapper.find(Toggle).props(); - if (!onChange) { - fail(); - } else { - onChange(false); - expect(excludeBranchFromPurge).toHaveBeenCalled(); - expect(wrapper.state().excludedFromPurge).toBe(true); - } + onChange!(false); + expect(excludeBranchFromPurge).toHaveBeenCalled(); + expect(wrapper.state().excludedFromPurge).toBe(true); }); function shallowRender(props?: Partial<BranchPurgeSetting['props']>) { diff --git a/server/sonar-web/src/main/js/apps/projectQualityProfiles/__tests__/ProfileRow-test.tsx b/server/sonar-web/src/main/js/apps/projectQualityProfiles/__tests__/ProfileRow-test.tsx index 1f10c59b443..fe384a2731f 100644 --- a/server/sonar-web/src/main/js/apps/projectQualityProfiles/__tests__/ProfileRow-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectQualityProfiles/__tests__/ProfileRow-test.tsx @@ -45,9 +45,9 @@ it('changes profile', async () => { (wrapper.instance() as ProfileRow).mounted = true; wrapper.find('Select').prop<Function>('onChange')({ value: 'baz' }); expect(onChangeProfile).toBeCalledWith('foo', 'baz'); - expect(wrapper.state().loading).toBeTruthy(); + expect(wrapper.state().loading).toBe(true); await new Promise(setImmediate); - expect(wrapper.state().loading).toBeFalsy(); + expect(wrapper.state().loading).toBe(false); }); function randomProfile(key: string) { diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageHeader-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageHeader-test.tsx index b8b174e2b24..292d6caff94 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageHeader-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageHeader-test.tsx @@ -34,7 +34,7 @@ it('should not render projects total', () => { shallowRender({ total: undefined }) .find('#projects-total') .exists() - ).toBeFalsy(); + ).toBe(false); }); it('should render disabled sorting options for visualizations', () => { diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageSidebar-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageSidebar-test.tsx index f00200dbf10..197b42b5ea9 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageSidebar-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageSidebar-test.tsx @@ -60,7 +60,7 @@ it('reset function should work correctly with view and visualizations', () => { visualization="bugs" /> ); - expect(sidebar.find('ClearAll').exists()).toBeFalsy(); + expect(sidebar.find('ClearAll').exists()).toBe(false); sidebar.setProps({ query: { size: '3' } }); - expect(sidebar.find('ClearAll').exists()).toBeTruthy(); + expect(sidebar.find('ClearAll').exists()).toBe(true); }); diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCard-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCard-test.tsx index dce3b87d09c..0fcbf20e45d 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCard-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCard-test.tsx @@ -45,14 +45,14 @@ const PROJECT: Project = { it('should show <ProjectCardOverall/> by default', () => { const wrapper = shallowRender(); - expect(wrapper.find('ProjectCardOverall')).toBeTruthy(); - expect(wrapper.find('ProjectCardLeak')).toBeTruthy(); + expect(wrapper.find('ProjectCardOverall').exists()).toBe(true); + expect(wrapper.find('ProjectCardLeak').exists()).toBe(false); }); it('should show <ProjectCardLeak/> when asked', () => { - const wrapper = shallowRender(); - expect(wrapper.find('ProjectCardLeak')).toBeTruthy(); - expect(wrapper.find('ProjectCardOverall')).toBeTruthy(); + const wrapper = shallowRender('leak'); + expect(wrapper.find('ProjectCardLeak').exists()).toBe(true); + expect(wrapper.find('ProjectCardOverall').exists()).toBe(false); }); function shallowRender(type?: string) { diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardLeak-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardLeak-test.tsx index 070c8594579..ee5e548d38f 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardLeak-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardLeak-test.tsx @@ -51,7 +51,7 @@ const USER_LOGGED_IN = mockLoggedInUser(); it('should display analysis date and leak start date', () => { const card = shallowRender(PROJECT); - expect(card.find('.project-card-dates').exists()).toBeTruthy(); + expect(card.find('.project-card-dates').exists()).toBe(true); expect(card.find('.project-card-dates').find('.project-card-leak-date')).toHaveLength(1); expect(card.find('.project-card-dates').find('DateTimeFormatter')).toHaveLength(1); }); @@ -59,7 +59,7 @@ it('should display analysis date and leak start date', () => { it('should not display analysis date or leak start date', () => { const project = { ...PROJECT, analysisDate: undefined }; const card = shallowRender(project); - expect(card.find('.project-card-dates').exists()).toBeFalsy(); + expect(card.find('.project-card-dates').exists()).toBe(false); }); it('should display tags', () => { @@ -68,7 +68,7 @@ it('should display tags', () => { shallowRender(project) .find('TagsList') .exists() - ).toBeTruthy(); + ).toBe(true); }); it('should display private badge', () => { @@ -77,7 +77,7 @@ it('should display private badge', () => { shallowRender(project) .find('Connect(PrivacyBadge)') .exists() - ).toBeTruthy(); + ).toBe(true); }); it('should display the leak measures and quality gate', () => { diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardOverall-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardOverall-test.tsx index 05515572ce2..369c72ba783 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardOverall-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCardOverall-test.tsx @@ -48,12 +48,12 @@ it('should display analysis date (and not leak period) when defined', () => { shallowRender(PROJECT) .find('.project-card-dates') .exists() - ).toBeTruthy(); + ).toBe(true); expect( shallowRender({ ...PROJECT, analysisDate: undefined }) .find('.project-card-dates') .exists() - ).toBeFalsy(); + ).toBe(false); }); it('should not display the quality gate', () => { @@ -62,7 +62,7 @@ it('should not display the quality gate', () => { shallowRender(project) .find('ProjectCardOverallQualityGate') .exists() - ).toBeFalsy(); + ).toBe(false); }); it('should display tags', () => { @@ -71,7 +71,7 @@ it('should display tags', () => { shallowRender(project) .find('TagsList') .exists() - ).toBeTruthy(); + ).toBe(true); }); it('should display private badge', () => { @@ -80,7 +80,7 @@ it('should display private badge', () => { shallowRender(project) .find('Connect(PrivacyBadge)') .exists() - ).toBeTruthy(); + ).toBe(true); }); it('should display the overall measures and quality gate', () => { diff --git a/server/sonar-web/src/main/js/apps/projects/filters/__tests__/SearchableFilterFooter-test.tsx b/server/sonar-web/src/main/js/apps/projects/filters/__tests__/SearchableFilterFooter-test.tsx index e8378f6b1f8..42b173c2c7b 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/__tests__/SearchableFilterFooter-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/filters/__tests__/SearchableFilterFooter-test.tsx @@ -39,7 +39,7 @@ it('should render items without the ones in the facet', () => { expect(wrapper.find('Select').prop('options')).toMatchSnapshot(); }); -it('should render items without the ones in the facet', () => { +it('should properly handle a change of the facet value', () => { const onQueryChange = jest.fn(); const wrapper = shallow( <SearchableFilterFooter diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/App-test.tsx index 0dd88a69ce0..44acaf3c167 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/App-test.tsx @@ -122,11 +122,11 @@ it('selects and deselects projects', async () => { it('creates project', () => { const wrapper = shallowRender(); - expect(wrapper.find('CreateProjectForm').exists()).toBeFalsy(); + expect(wrapper.find('CreateProjectForm').exists()).toBe(false); wrapper.find('Header').prop<Function>('onProjectCreate')(); wrapper.update(); - expect(wrapper.find('CreateProjectForm').exists()).toBeTruthy(); + expect(wrapper.find('CreateProjectForm').exists()).toBe(true); wrapper.find('CreateProjectForm').prop<Function>('onProjectCreated')(); wrapper.update(); @@ -134,7 +134,7 @@ it('creates project', () => { wrapper.find('CreateProjectForm').prop<Function>('onClose')(); wrapper.update(); - expect(wrapper.find('CreateProjectForm').exists()).toBeFalsy(); + expect(wrapper.find('CreateProjectForm').exists()).toBe(false); }); it('changes default project visibility', () => { diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Header-test.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Header-test.tsx index 7e2611b058d..3ca70e81917 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Header-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Header-test.tsx @@ -54,7 +54,7 @@ it('changes default visibility', () => { modalWrapper.prop<Function>('onClose')(); wrapper.update(); - expect(wrapper.find('ChangeDefaultVisibilityForm').exists()).toBeFalsy(); + expect(wrapper.find('ChangeDefaultVisibilityForm').exists()).toBe(false); }); function shallowRender(props?: { [P in keyof Props]?: Props[P] }) { diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Search-test.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Search-test.tsx index d694d9eb10f..3ea6d19af83 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Search-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Search-test.tsx @@ -58,9 +58,9 @@ it('selects provisioned', () => { it('does not render provisioned filter for portfolios', () => { const wrapper = shallowRender(); - expect(wrapper.find('Checkbox[id="projects-provisioned"]').exists()).toBeTruthy(); + expect(wrapper.find('Checkbox[id="projects-provisioned"]').exists()).toBe(true); wrapper.setProps({ qualifiers: 'VW' }); - expect(wrapper.find('Checkbox[id="projects-provisioned"]').exists()).toBeFalsy(); + expect(wrapper.find('Checkbox[id="projects-provisioned"]').exists()).toBe(false); }); it('updates analysis date', () => { @@ -108,7 +108,7 @@ it('bulk applies permission template', () => { expect(wrapper.find('BulkApplyTemplateModal')).toMatchSnapshot(); wrapper.find('BulkApplyTemplateModal').prop<Function>('onClose')(); wrapper.update(); - expect(wrapper.find('BulkApplyTemplateModal').exists()).toBeFalsy(); + expect(wrapper.find('BulkApplyTemplateModal').exists()).toBe(false); }); function shallowRender(props?: { [P in keyof Props]?: Props[P] }) { diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogContainer.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogContainer.tsx index 3f69f6dc2eb..541d876d245 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogContainer.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/ChangelogContainer.tsx @@ -101,12 +101,12 @@ export class ChangelogContainer extends React.PureComponent<Props, State> { getProfileChangelog(query.since, query.to, profile, this.state.page + 1) .then((r: any) => { if (this.mounted && this.state.events) { - this.setState({ - events: [...this.state.events, ...r.events], + this.setState(({ events = [] }) => ({ + events: [...events, ...r.events], total: r.total, page: r.p, loading: false - }); + })); } }) .catch(this.stopLoading); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogContainer-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogContainer-test.tsx index 9e6979c4e52..176cda52f04 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogContainer-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogContainer-test.tsx @@ -61,7 +61,10 @@ it('should load more properly', async () => { await waitAndUpdate(wrapper); wrapper.instance().loadMore(mockEvent()); + await waitAndUpdate(wrapper); + expect(getProfileChangelog).toHaveBeenLastCalledWith(undefined, undefined, expect.anything(), 2); + expect(wrapper.state().events?.length).toBe(6); }); function shallowRender() { diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/DeleteProfileForm.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/components/DeleteProfileForm.tsx index f86509975c1..db2be386ab1 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/components/DeleteProfileForm.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/DeleteProfileForm.tsx @@ -33,12 +33,11 @@ interface Props { interface State { loading: boolean; - name: string | null; } export default class DeleteProfileForm extends React.PureComponent<Props, State> { mounted = false; - state: State = { loading: false, name: null }; + state: State = { loading: false }; componentDidMount() { this.mounted = true; diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissions-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissions-test.tsx index ef1e4eed56a..c99a3938557 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissions-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissions-test.tsx @@ -56,14 +56,14 @@ it('opens add users form', async () => { const wrapper = shallow(<ProfilePermissions profile={profile} />); expect(searchUsers).toHaveBeenCalled(); await waitAndUpdate(wrapper); - expect(wrapper.find('ProfilePermissionsForm').exists()).toBeFalsy(); + expect(wrapper.find('ProfilePermissionsForm').exists()).toBe(false); click(wrapper.find('Button')); - expect(wrapper.find('ProfilePermissionsForm').exists()).toBeTruthy(); + expect(wrapper.find('ProfilePermissionsForm').exists()).toBe(true); wrapper.find('ProfilePermissionsForm').prop<Function>('onClose')(); wrapper.update(); - expect(wrapper.find('ProfilePermissionsForm').exists()).toBeFalsy(); + expect(wrapper.find('ProfilePermissionsForm').exists()).toBe(false); }); it('removes user', () => { diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsGroup-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsGroup-test.tsx index 261882ecb6b..182b1f454b4 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsGroup-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsGroup-test.tsx @@ -53,10 +53,10 @@ it('removes user', async () => { /> ); (wrapper.instance() as ProfilePermissionsGroup).mounted = true; - expect(wrapper.find('SimpleModal').exists()).toBeFalsy(); + expect(wrapper.find('SimpleModal').exists()).toBe(false); click(wrapper.find('DeleteButton')); - expect(wrapper.find('SimpleModal').exists()).toBeTruthy(); + expect(wrapper.find('SimpleModal').exists()).toBe(true); wrapper.find('SimpleModal').prop<Function>('onSubmit')(); expect(removeGroup).toBeCalledWith({ diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsUser-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsUser-test.tsx index 8d2b1f58c84..7d5888bccd7 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsUser-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsUser-test.tsx @@ -46,10 +46,10 @@ it('removes user', async () => { <ProfilePermissionsUser onDelete={onDelete} organization="org" profile={profile} user={user} /> ); (wrapper.instance() as ProfilePermissionsUser).mounted = true; - expect(wrapper.find('SimpleModal').exists()).toBeFalsy(); + expect(wrapper.find('SimpleModal').exists()).toBe(false); click(wrapper.find('DeleteButton')); - expect(wrapper.find('SimpleModal').exists()).toBeTruthy(); + expect(wrapper.find('SimpleModal').exists()).toBe(true); wrapper.find('SimpleModal').prop<Function>('onSubmit')(); expect(removeUser).toBeCalledWith({ diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx index 79cd1f4ed8e..8692f0fc345 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx @@ -131,7 +131,7 @@ it('should load data correctly when hotspot key list is forced', async () => { branch: 'branch-6.7' }); expect(wrapper.state().hotspotKeys).toEqual(hotspotKeys); - expect(wrapper.find(SecurityHotspotsAppRenderer).props().isStaticListOfHotspots).toBeTruthy(); + expect(wrapper.find(SecurityHotspotsAppRenderer).props().isStaticListOfHotspots).toBe(true); // Reset (getSecurityHotspots as jest.Mock).mockClear(); diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/FilterBar-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/FilterBar-test.tsx index da016ade85b..dd123331b6a 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/FilterBar-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/FilterBar-test.tsx @@ -63,12 +63,8 @@ it('should trigger onChange for status', () => { .at(0) .props(); - if (!onChange) { - fail("Select's onChange should be defined"); - } else { - onChange({ value: HotspotStatusFilter.SAFE }); - expect(onChangeFilters).toBeCalledWith({ status: HotspotStatusFilter.SAFE }); - } + onChange!({ value: HotspotStatusFilter.SAFE }); + expect(onChangeFilters).toBeCalledWith({ status: HotspotStatusFilter.SAFE }); }); it('should trigger onChange for self-assigned toggle', () => { @@ -77,12 +73,8 @@ it('should trigger onChange for self-assigned toggle', () => { const { onCheck } = wrapper.find(RadioToggle).props(); - if (!onCheck) { - fail("RadioToggle's onCheck should be defined"); - } else { - onCheck(AssigneeFilterOption.ALL); - expect(onChangeFilters).toBeCalledWith({ assignedToMe: false }); - } + onCheck!(AssigneeFilterOption.ALL); + expect(onChangeFilters).toBeCalledWith({ assignedToMe: false }); }); it('should trigger onChange for leak period', () => { @@ -94,12 +86,8 @@ it('should trigger onChange for leak period', () => { .at(1) .props(); - if (!onChange) { - fail("Select's onChange should be defined"); - } else { - onChange({ value: true }); - expect(onChangeFilters).toBeCalledWith({ sinceLeakPeriod: true }); - } + onChange!({ value: true }); + expect(onChangeFilters).toBeCalledWith({ sinceLeakPeriod: true }); }); function shallowRender(props: Partial<FilterBarProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/settings/components/__tests__/AdditionalCategories-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/__tests__/AdditionalCategories-test.tsx index 3ddd931f29e..65a9f45e9cf 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/__tests__/AdditionalCategories-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/__tests__/AdditionalCategories-test.tsx @@ -39,11 +39,5 @@ it('should not render pull request decoration binding component when the compone c => c.key === PULL_REQUEST_DECORATION_BINDING_CATEGORY ); - if (!category) { - fail('category should be defined'); - } else { - expect( - category.renderComponent({ component: undefined, selectedCategory: '' }) - ).toBeUndefined(); - } + expect(category!.renderComponent({ component: undefined, selectedCategory: '' })).toBeUndefined(); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/__tests__/Languages-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/__tests__/Languages-test.tsx index fdba7965f62..9a8f49e9ed9 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/__tests__/Languages-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/__tests__/Languages-test.tsx @@ -42,12 +42,8 @@ it('should correctly handle a change of the selected language', () => { const { onChange } = wrapper.find(Select).props(); - if (!onChange) { - fail('onChange should be defined'); - } else { - onChange({ label: '', originalValue: 'CoBoL', value: 'cobol' }); - expect(push).toHaveBeenCalledWith(expect.objectContaining({ query: { category: 'CoBoL' } })); - } + onChange!({ label: '', originalValue: 'CoBoL', value: 'cobol' }); + expect(push).toHaveBeenCalledWith(expect.objectContaining({ query: { category: 'CoBoL' } })); }); it('should correctly show the subcategory for a component', () => { diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForBoolean-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForBoolean-test.tsx index 89ce1005e8f..e9c05fbc2e6 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForBoolean-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForBoolean-test.tsx @@ -28,7 +28,7 @@ it('should render Toggle', () => { expect(toggle.length).toBe(1); expect(toggle.prop('name')).toBe('foo'); expect(toggle.prop('value')).toBe(true); - expect(toggle.prop('onChange')).toBeTruthy(); + expect(toggle.prop('onChange')).toBeDefined(); }); it('should render Toggle without value', () => { @@ -38,7 +38,7 @@ it('should render Toggle without value', () => { expect(toggle.length).toBe(1); expect(toggle.prop('name')).toBe('foo'); expect(toggle.prop('value')).toBe(false); - expect(toggle.prop('onChange')).toBeTruthy(); + expect(toggle.prop('onChange')).toBeDefined(); expect(input.find('.note').length).toBe(1); }); @@ -48,7 +48,7 @@ it('should call onChange', () => { const input = shallowRender({ onChange, value: true }); const toggle = input.find('Toggle'); expect(toggle.length).toBe(1); - expect(toggle.prop('onChange')).toBeTruthy(); + expect(toggle.prop('onChange')).toBeDefined(); toggle.prop<Function>('onChange')(false); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForNumber-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForNumber-test.tsx index c08c7bfb349..7188f76a896 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForNumber-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForNumber-test.tsx @@ -31,5 +31,5 @@ it('should render SimpleInput', () => { expect(simpleInput.prop('name')).toBe('foo'); expect(simpleInput.prop('value')).toBe(17); expect(simpleInput.prop('type')).toBe('text'); - expect(simpleInput.prop('onChange')).toBeTruthy(); + expect(simpleInput.prop('onChange')).toBeDefined(); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSingleSelectList-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSingleSelectList-test.tsx index 42cb70a4dd4..2d2e353df79 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSingleSelectList-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSingleSelectList-test.tsx @@ -33,14 +33,14 @@ it('should render Select', () => { { value: 'bar', label: 'bar' }, { value: 'baz', label: 'baz' } ]); - expect(select.prop('onChange')).toBeTruthy(); + expect(select.prop('onChange')).toBeDefined(); }); it('should call onChange', () => { const onChange = jest.fn(); const select = shallowRender({ onChange }).find('Select'); expect(select.length).toBe(1); - expect(select.prop('onChange')).toBeTruthy(); + expect(select.prop('onChange')).toBeDefined(); select.prop<Function>('onChange')({ value: 'baz', label: 'baz' }); expect(onChange).toBeCalledWith('baz'); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForString-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForString-test.tsx index a4228a8ce64..416d9181d5e 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForString-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForString-test.tsx @@ -31,5 +31,5 @@ it('should render SimpleInput', () => { expect(simpleInput.prop('name')).toBe('foo'); expect(simpleInput.prop('value')).toBe('bar'); expect(simpleInput.prop('type')).toBe('text'); - expect(simpleInput.prop('onChange')).toBeTruthy(); + expect(simpleInput.prop('onChange')).toBeDefined(); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForText-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForText-test.tsx index 28e2b2246e3..b9fcd3cc4d9 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForText-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForText-test.tsx @@ -29,14 +29,14 @@ it('should render textarea', () => { expect(textarea.length).toBe(1); expect(textarea.prop('name')).toBe('foo'); expect(textarea.prop('value')).toBe('bar'); - expect(textarea.prop('onChange')).toBeTruthy(); + expect(textarea.prop('onChange')).toBeDefined(); }); it('should call onChange', () => { const onChange = jest.fn(); const textarea = shallowRender({ onChange }).find('textarea'); expect(textarea.length).toBe(1); - expect(textarea.prop('onChange')).toBeTruthy(); + expect(textarea.prop('onChange')).toBeDefined(); change(textarea, 'qux'); expect(onChange).toBeCalledWith('qux'); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/SimpleInput-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/SimpleInput-test.tsx index 9e8674b7559..ecf194cbc95 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/SimpleInput-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/SimpleInput-test.tsx @@ -39,7 +39,7 @@ it('should render input', () => { expect(input.prop('className')).toContain('input-large'); expect(input.prop('name')).toBe('foo'); expect(input.prop('value')).toBe('bar'); - expect(input.prop('onChange')).toBeTruthy(); + expect(input.prop('onChange')).toBeDefined(); }); it('should call onChange', () => { @@ -55,7 +55,7 @@ it('should call onChange', () => { /> ).find('input'); expect(input.length).toBe(1); - expect(input.prop('onChange')).toBeTruthy(); + expect(input.prop('onChange')).toBeDefined(); change(input, 'qux'); expect(onChange).toBeCalledWith('qux'); diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/PRDecorationBinding.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/PRDecorationBinding.tsx index a0fe97c4c29..c311e6a0a33 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/PRDecorationBinding.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/PRDecorationBinding.tsx @@ -107,7 +107,7 @@ export default class PRDecorationBinding extends React.PureComponent<Props, Stat getProjectBinding(project: string): Promise<ProjectAlmBinding | undefined> { return getProjectAlmBinding(project).catch((response: Response) => { if (response && response.status === 404) { - return Promise.resolve(undefined); + return undefined; } return throwGlobalError(response); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-test.tsx index ed59ce74aff..fc6a64ba9df 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-test.tsx @@ -218,7 +218,7 @@ it('should reject submit github settings', async () => { expect.assertions(1); await expect( wrapper.instance().submitProjectAlmBinding(AlmKeys.GitHub, 'github-binding', {}) - ).rejects.toBe(undefined); + ).rejects.toBeUndefined(); }); it('should accept submit github settings', async () => { diff --git a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeIntermediate-test.tsx b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeIntermediate-test.tsx index 4d677e5980b..7f2f17dfa58 100644 --- a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeIntermediate-test.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeIntermediate-test.tsx @@ -50,9 +50,9 @@ it('should display correctly', () => { it('should allow to show and hide intermediates', () => { const wrapper = shallow(<SystemUpgradeIntermediate upgrades={UPGRADES} />); - expect(wrapper.find('.system-upgrade-intermediate').exists()).toBeFalsy(); + expect(wrapper.find('.system-upgrade-intermediate').exists()).toBe(false); click(wrapper.find('ButtonLink')); - expect(wrapper.find('.system-upgrade-intermediate').exists()).toBeTruthy(); + expect(wrapper.find('.system-upgrade-intermediate').exists()).toBe(true); click(wrapper.find('ButtonLink')); - expect(wrapper.find('.system-upgrade-intermediate').exists()).toBeFalsy(); + expect(wrapper.find('.system-upgrade-intermediate').exists()).toBe(false); }); diff --git a/server/sonar-web/src/main/js/apps/tutorials/analyzeProject/__tests__/AnalyzeTutorialSonarCloud-test.tsx b/server/sonar-web/src/main/js/apps/tutorials/analyzeProject/__tests__/AnalyzeTutorialSonarCloud-test.tsx index 11c3e7e81c8..3ed8bb44c5d 100644 --- a/server/sonar-web/src/main/js/apps/tutorials/analyzeProject/__tests__/AnalyzeTutorialSonarCloud-test.tsx +++ b/server/sonar-web/src/main/js/apps/tutorials/analyzeProject/__tests__/AnalyzeTutorialSonarCloud-test.tsx @@ -151,10 +151,10 @@ it('should set tutorial done', () => { const instance = wrapper.instance(); instance.setTutorialDone(false); - expect(wrapper.state('isTutorialDone')).toBeFalsy(); + expect(wrapper.state('isTutorialDone')).toBe(false); instance.setTutorialDone(true); - expect(wrapper.state('isTutorialDone')).toBeTruthy(); + expect(wrapper.state('isTutorialDone')).toBe(true); }); it('should have a spinner', () => { diff --git a/server/sonar-web/src/main/js/apps/tutorials/analyzeProject/configurations/__tests__/ConfigureWithTravis-test.tsx b/server/sonar-web/src/main/js/apps/tutorials/analyzeProject/configurations/__tests__/ConfigureWithTravis-test.tsx index 30e8c1b87cf..e3d27e93f0e 100644 --- a/server/sonar-web/src/main/js/apps/tutorials/analyzeProject/configurations/__tests__/ConfigureWithTravis-test.tsx +++ b/server/sonar-web/src/main/js/apps/tutorials/analyzeProject/configurations/__tests__/ConfigureWithTravis-test.tsx @@ -40,21 +40,21 @@ it('should render correctly', () => { it('should react to EditTravisYmlStep onContinue', () => { const wrapper = shallowRender(); - expect(wrapper.find('EditTravisYmlStep').prop('open') as Boolean).toBeFalsy(); + expect(wrapper.find('EditTravisYmlStep').prop('open') as Boolean).toBe(false); (wrapper.find('EncryptYourTokenStep').prop('onContinue') as Function)(); - expect(wrapper.find('EditTravisYmlStep').prop('open') as Boolean).toBeTruthy(); + expect(wrapper.find('EditTravisYmlStep').prop('open') as Boolean).toBe(true); }); it('should react to EditTravisYmlStep onOpen', () => { const wrapper = shallowRender(); (wrapper.find('EncryptYourTokenStep').prop('onContinue') as Function)(); - expect(wrapper.find('EncryptYourTokenStep').prop('open') as Boolean).toBeFalsy(); + expect(wrapper.find('EncryptYourTokenStep').prop('open') as Boolean).toBe(false); (wrapper.find('EncryptYourTokenStep').prop('onOpen') as Function)(); - expect(wrapper.find('EncryptYourTokenStep').prop('open') as Boolean).toBeTruthy(); + expect(wrapper.find('EncryptYourTokenStep').prop('open') as Boolean).toBe(true); }); function shallowRender(props: Partial<TutorialProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/tutorials/components/commands/BuildWrapper.tsx b/server/sonar-web/src/main/js/apps/tutorials/components/commands/BuildWrapper.tsx index 50efad3c3ba..0ffaf245858 100644 --- a/server/sonar-web/src/main/js/apps/tutorials/components/commands/BuildWrapper.tsx +++ b/server/sonar-web/src/main/js/apps/tutorials/components/commands/BuildWrapper.tsx @@ -53,7 +53,8 @@ export default function BuildWrapper(props: Props) { className="button" download={filenames[props.os]} href={`${getBaseUrl()}/static/cpp/${filenames[props.os]}`} - target="_blank"> + target="_blank" + rel="noopener noreferrer"> {translate('download_verb')} </a> </p> diff --git a/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/AnalysisCommandOtherCI-test.tsx b/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/AnalysisCommandOtherCI-test.tsx index 1c39ec3defd..5b74aefcb03 100644 --- a/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/AnalysisCommandOtherCI-test.tsx +++ b/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/AnalysisCommandOtherCI-test.tsx @@ -70,34 +70,6 @@ it('should render AnalysisCommandCustom correctly', () => { expect(getBuildOptions).toHaveBeenCalled(); }); -// TODO make it work -// it('should execute function when the user interacts with the component', async () => { -// const getBuildOptions = jest.fn().mockReturnValue({ -// maven: RenderCommandForMaven -// }); -// const onDone = jest.fn(); -// const setToken = jest.fn(); -// const wrapper = shallow( -// <AnalysisCommandCommon -// buildType={'maven'} -// component={mockComponent()} -// currentUser={mockLoggedInUser()} -// getBuildOptions={getBuildOptions} -// mode={ProjectAnalysisModes.CI} -// onDone={onDone} -// organization={organization} -// setToken={setToken} -// token={token} -// /> -// ); -// -// (wrapper.find('RenderCommandForMaven').prop('toggleTokenModal') as Function)(); -// await waitAndUpdate(wrapper); -// (wrapper.find('EditTokenModal').prop('onSave') as Function)(); -// -// expect(setToken).toHaveBeenCalledWith(token); -// }); - it('should render RenderCommandForClangOrGCC', () => { const render = (token?: string) => shallow( diff --git a/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/AnalysisCommandTravis-test.tsx b/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/AnalysisCommandTravis-test.tsx index 51d6532061b..02bb2f4800a 100644 --- a/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/AnalysisCommandTravis-test.tsx +++ b/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/AnalysisCommandTravis-test.tsx @@ -48,7 +48,7 @@ it('should render for Clang or GCC', () => { shallowRender('make') .find(RenderCommandForClangOrGCC) .exists() - ).toBeTruthy(); + ).toBe(true); }); it('should render for Gradle', () => { @@ -56,7 +56,7 @@ it('should render for Gradle', () => { shallowRender('gradle') .find(RenderCommandForGradle) .exists() - ).toBeTruthy(); + ).toBe(true); }); it('should render for Maven', () => { @@ -64,7 +64,7 @@ it('should render for Maven', () => { shallowRender('maven') .find(RenderCommandForMaven) .exists() - ).toBeTruthy(); + ).toBe(true); }); it('should render for other', () => { @@ -72,7 +72,7 @@ it('should render for other', () => { shallowRender('other') .find(RenderCommandForOther) .exists() - ).toBeTruthy(); + ).toBe(true); }); it('should render nothing for unsupported build', () => { @@ -80,20 +80,20 @@ it('should render nothing for unsupported build', () => { shallowRender() .find(RenderCommandForOther) .exists() - ).toBeFalsy(); + ).toBe(false); expect( shallowRender('anotherBuild') .find(RenderCommandForOther) .exists() - ).toBeFalsy(); + ).toBe(false); }); it('should render nothing when there is no project key', () => { - expect(shallow(<RenderCommandForClangOrGCC />).html()).toBe(null); - expect(shallow(<RenderCommandForGradle />).html()).toBe(null); - expect(shallow(<RenderCommandForMaven />).html()).toBe(null); - expect(shallow(<RenderCommandForOther />).html()).toBe(null); + expect(shallow(<RenderCommandForClangOrGCC />).html()).toBeNull(); + expect(shallow(<RenderCommandForGradle />).html()).toBeNull(); + expect(shallow(<RenderCommandForMaven />).html()).toBeNull(); + expect(shallow(<RenderCommandForOther />).html()).toBeNull(); }); it('should render the sonarcloud yaml for travis', () => { @@ -101,7 +101,7 @@ it('should render the sonarcloud yaml for travis', () => { expect(getSonarcloudAddonYml('SonarSource')).toMatchSnapshot(); }); -it('should render the sonarcloud yaml for travis', () => { +it('should render the sonarcloud yaml for travis - render', () => { expect(getSonarcloudAddonYmlRender()).toMatchSnapshot(); expect(getSonarcloudAddonYmlRender('SonarSource')).toMatchSnapshot(); }); diff --git a/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/__snapshots__/AnalysisCommandTravis-test.tsx.snap b/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/__snapshots__/AnalysisCommandTravis-test.tsx.snap index 766d1f7633b..28bf95d2bc5 100644 --- a/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/__snapshots__/AnalysisCommandTravis-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/__snapshots__/AnalysisCommandTravis-test.tsx.snap @@ -86,23 +86,7 @@ exports[`should render the requirements for builds 2`] = ` </Fragment> `; -exports[`should render the sonarcloud yaml for travis 1`] = ` -"addons: - sonarcloud: - organization: \\"Add your organization key\\" - token: - secure: \\"**************************\\" # encrypted value of your token" -`; - -exports[`should render the sonarcloud yaml for travis 2`] = ` -"addons: - sonarcloud: - organization: \\"SonarSource\\" - token: - secure: \\"**************************\\" # encrypted value of your token" -`; - -exports[`should render the sonarcloud yaml for travis 3`] = ` +exports[`should render the sonarcloud yaml for travis - render 1`] = ` <React.Fragment> addons: sonarcloud: @@ -119,7 +103,7 @@ exports[`should render the sonarcloud yaml for travis 3`] = ` </React.Fragment> `; -exports[`should render the sonarcloud yaml for travis 4`] = ` +exports[`should render the sonarcloud yaml for travis - render 2`] = ` <React.Fragment> addons: sonarcloud: @@ -135,3 +119,19 @@ exports[`should render the sonarcloud yaml for travis 4`] = ` <br /> </React.Fragment> `; + +exports[`should render the sonarcloud yaml for travis 1`] = ` +"addons: + sonarcloud: + organization: \\"Add your organization key\\" + token: + secure: \\"**************************\\" # encrypted value of your token" +`; + +exports[`should render the sonarcloud yaml for travis 2`] = ` +"addons: + sonarcloud: + organization: \\"SonarSource\\" + token: + secure: \\"**************************\\" # encrypted value of your token" +`; diff --git a/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/__snapshots__/BuildWrapper-test.tsx.snap b/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/__snapshots__/BuildWrapper-test.tsx.snap index 85f98bb085d..4a85e3e3cb8 100644 --- a/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/__snapshots__/BuildWrapper-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/tutorials/components/commands/__tests__/__snapshots__/BuildWrapper-test.tsx.snap @@ -27,6 +27,7 @@ exports[`renders correctly 1`] = ` className="button" download="build-wrapper-win-x86.zip" href="/static/cpp/build-wrapper-win-x86.zip" + rel="noopener noreferrer" target="_blank" > download_verb @@ -62,6 +63,7 @@ exports[`renders correctly 2`] = ` className="button" download="build-wrapper-linux-x86.zip" href="/static/cpp/build-wrapper-linux-x86.zip" + rel="noopener noreferrer" target="_blank" > download_verb @@ -97,6 +99,7 @@ exports[`renders correctly 3`] = ` className="button" download="build-wrapper-macosx-x86.zip" href="/static/cpp/build-wrapper-macosx-x86.zip" + rel="noopener noreferrer" target="_blank" > download_verb diff --git a/server/sonar-web/src/main/js/apps/tutorials/onboarding/__tests__/OrganizationsShortList-test.tsx b/server/sonar-web/src/main/js/apps/tutorials/onboarding/__tests__/OrganizationsShortList-test.tsx index 95a3132a7a8..dbf47fb6307 100644 --- a/server/sonar-web/src/main/js/apps/tutorials/onboarding/__tests__/OrganizationsShortList-test.tsx +++ b/server/sonar-web/src/main/js/apps/tutorials/onboarding/__tests__/OrganizationsShortList-test.tsx @@ -23,7 +23,7 @@ import { mockOrganization } from '../../../../helpers/testMocks'; import OrganizationsShortList, { Props } from '../OrganizationsShortList'; it('should render null with no orgs', () => { - expect(shallowRender().getElement()).toBe(null); + expect(shallowRender().getElement()).toBeNull(); }); it('should render correctly', () => { diff --git a/server/sonar-web/src/main/js/apps/users/__tests__/Header-test.tsx b/server/sonar-web/src/main/js/apps/users/__tests__/Header-test.tsx index 0652ee008c1..eaa448f3932 100644 --- a/server/sonar-web/src/main/js/apps/users/__tests__/Header-test.tsx +++ b/server/sonar-web/src/main/js/apps/users/__tests__/Header-test.tsx @@ -29,7 +29,7 @@ it('should render correctly', () => { it('should open the user creation form', () => { const wrapper = getWrapper(); click(wrapper.find('#users-create')); - expect(wrapper.find('UserForm').exists()).toBeTruthy(); + expect(wrapper.find('UserForm').exists()).toBe(true); }); function getWrapper(props = {}) { diff --git a/server/sonar-web/src/main/js/apps/users/components/__tests__/UserGroups-test.tsx b/server/sonar-web/src/main/js/apps/users/components/__tests__/UserGroups-test.tsx index c21972e1330..366fd665cf3 100644 --- a/server/sonar-web/src/main/js/apps/users/components/__tests__/UserGroups-test.tsx +++ b/server/sonar-web/src/main/js/apps/users/components/__tests__/UserGroups-test.tsx @@ -46,7 +46,7 @@ it('should show all groups', () => { it('should open the groups form', () => { const wrapper = getWrapper(); click(wrapper.find('.js-user-groups')); - expect(wrapper.find('GroupsForm').exists()).toBeTruthy(); + expect(wrapper.find('GroupsForm').exists()).toBe(true); }); function getWrapper(props = {}) { diff --git a/server/sonar-web/src/main/js/apps/users/components/__tests__/UserListItem-test.tsx b/server/sonar-web/src/main/js/apps/users/components/__tests__/UserListItem-test.tsx index 0963216f472..80a3a11a5cf 100644 --- a/server/sonar-web/src/main/js/apps/users/components/__tests__/UserListItem-test.tsx +++ b/server/sonar-web/src/main/js/apps/users/components/__tests__/UserListItem-test.tsx @@ -47,13 +47,13 @@ it('should display a change password button', () => { shallowRender({ organizationsEnabled: true }) .find('UserGroups') .exists() - ).toBeFalsy(); + ).toBe(false); }); it('should open the correct forms', () => { const wrapper = shallowRender(); click(wrapper.find('.js-user-tokens')); - expect(wrapper.find('TokensFormModal').exists()).toBeTruthy(); + expect(wrapper.find('TokensFormModal').exists()).toBe(true); }); function shallowRender(props: Partial<UserListItem['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/App-test.tsx index 7ab47f8ca41..a539729cdbe 100644 --- a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/App-test.tsx @@ -59,7 +59,7 @@ it('should be in loading status', () => { it('should fetch webhooks and display them', async () => { const wrapper = shallow(<App organization={organization} />); - expect(wrapper.state('loading')).toBeTruthy(); + expect(wrapper.state('loading')).toBe(true); await new Promise(setImmediate); expect(searchWebhooks).toHaveBeenCalledWith({ organization: organization.key }); diff --git a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/PageActions-test.tsx b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/PageActions-test.tsx index 77f78e1fc8f..116dbc6c13f 100644 --- a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/PageActions-test.tsx +++ b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/PageActions-test.tsx @@ -38,7 +38,7 @@ it('should display the create form', () => { const onCreate = jest.fn(); const wrapper = getWrapper({ onCreate }); click(wrapper.find('.js-webhook-create')); - expect(wrapper.find('CreateWebhookForm').exists()).toBeTruthy(); + expect(wrapper.find('CreateWebhookForm').exists()).toBe(true); wrapper.find('CreateWebhookForm').prop<Function>('onDone')({ name: 'foo', url: 'http://foo.bar' diff --git a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/WebhookActions-test.tsx b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/WebhookActions-test.tsx index f55272142a2..2299c7c509b 100644 --- a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/WebhookActions-test.tsx +++ b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/WebhookActions-test.tsx @@ -44,7 +44,7 @@ it('should display the update webhook form', () => { const onUpdate = jest.fn(() => Promise.resolve()); const wrapper = getWrapper({ onUpdate }); click(wrapper.find('.js-webhook-update')); - expect(wrapper.find('CreateWebhookForm').exists()).toBeTruthy(); + expect(wrapper.find('CreateWebhookForm').exists()).toBe(true); wrapper.find('CreateWebhookForm').prop<Function>('onDone')({ name: webhook.name, url: webhook.url @@ -56,7 +56,7 @@ it('should display the delete webhook form', () => { const onDelete = jest.fn(() => Promise.resolve()); const wrapper = getWrapper({ onDelete }); click(wrapper.find('.js-webhook-delete')); - expect(wrapper.find('DeleteWebhookForm').exists()).toBeTruthy(); + expect(wrapper.find('DeleteWebhookForm').exists()).toBe(true); wrapper.find('DeleteWebhookForm').prop<Function>('onSubmit')(); expect(onDelete).lastCalledWith(webhook.key); }); @@ -65,7 +65,7 @@ it('should display the deliveries form', () => { const wrapper = getWrapper({ webhook: { ...webhook, latestDelivery: delivery } }); expect(wrapper).toMatchSnapshot(); click(wrapper.find('.js-webhook-deliveries')); - expect(wrapper.find('DeliveriesForm').exists()).toBeTruthy(); + expect(wrapper.find('DeliveriesForm').exists()).toBe(true); }); function getWrapper(props = {}) { diff --git a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/WebhookItemLatestDelivery-test.tsx b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/WebhookItemLatestDelivery-test.tsx index 3bf30d4891c..54cbf1d2364 100644 --- a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/WebhookItemLatestDelivery-test.tsx +++ b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/WebhookItemLatestDelivery-test.tsx @@ -63,5 +63,5 @@ it('should render correctly a failed delivery', () => { it('should display the latest delivery form', () => { const wrapper = shallow(<WebhookItemLatestDelivery webhook={webhook} />); click(wrapper.find('ButtonIcon')); - expect(wrapper.find('LatestDeliveryForm').exists()).toBeTruthy(); + expect(wrapper.find('LatestDeliveryForm').exists()).toBe(true); }); diff --git a/server/sonar-web/src/main/js/components/SourceViewer/helpers/__tests__/duplications-test.ts b/server/sonar-web/src/main/js/components/SourceViewer/helpers/__tests__/duplications-test.ts index 6944be9c6af..1c11aeb8846 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/helpers/__tests__/duplications-test.ts +++ b/server/sonar-web/src/main/js/components/SourceViewer/helpers/__tests__/duplications-test.ts @@ -32,7 +32,7 @@ describe('getDuplicationBlocksForIndex', () => { }); describe('isDuplicationBlockInRemovedComponent', () => { - it('should ', () => { + it('should', () => { expect( isDuplicationBlockInRemovedComponent([ { _ref: '0', from: 2, size: 2 }, diff --git a/server/sonar-web/src/main/js/components/activity-graph/__tests__/utils-test.ts b/server/sonar-web/src/main/js/components/activity-graph/__tests__/utils-test.ts index 06a3fd398f7..d7a342e1860 100644 --- a/server/sonar-web/src/main/js/components/activity-graph/__tests__/utils-test.ts +++ b/server/sonar-web/src/main/js/components/activity-graph/__tests__/utils-test.ts @@ -138,7 +138,7 @@ describe('hasHistoryData', () => { ] } ]) - ).toBeTruthy(); + ).toBe(true); expect( utils.hasHistoryData([ { @@ -157,7 +157,7 @@ describe('hasHistoryData', () => { ] } ]) - ).toBeTruthy(); + ).toBe(true); expect( utils.hasHistoryData([ { @@ -167,7 +167,7 @@ describe('hasHistoryData', () => { data: [{ x: dates.parseDate('2017-04-27T08:21:32.000Z'), y: 2 }] } ]) - ).toBeFalsy(); + ).toBe(false); }); }); diff --git a/server/sonar-web/src/main/js/components/controls/DateRangeInput.tsx b/server/sonar-web/src/main/js/components/controls/DateRangeInput.tsx index 58d7d835597..36ccbe6cd37 100644 --- a/server/sonar-web/src/main/js/components/controls/DateRangeInput.tsx +++ b/server/sonar-web/src/main/js/components/controls/DateRangeInput.tsx @@ -55,7 +55,6 @@ export default class DateRangeInput extends React.PureComponent<Props> { }; handleToChange = (to: Date | undefined) => { - this.setState({ to }); this.props.onChange({ from: this.from, to }); }; diff --git a/server/sonar-web/src/main/js/components/docs/DocTooltip.tsx b/server/sonar-web/src/main/js/components/docs/DocTooltip.tsx index a1cfb5d2150..d3f096a8957 100644 --- a/server/sonar-web/src/main/js/components/docs/DocTooltip.tsx +++ b/server/sonar-web/src/main/js/components/docs/DocTooltip.tsx @@ -34,12 +34,11 @@ interface Props { interface State { content?: string; - open: boolean; } export default class DocTooltip extends React.PureComponent<Props, State> { mounted = false; - state: State = { open: false }; + state: State = {}; componentDidMount() { this.mounted = true; @@ -51,20 +50,12 @@ export default class DocTooltip extends React.PureComponent<Props, State> { }, () => {} ); - document.addEventListener('scroll', this.close, true); } componentWillUnmount() { this.mounted = false; - document.removeEventListener('scroll', this.close, true); } - close = () => { - if (this.mounted) { - this.setState({ open: false }); - } - }; - render() { return this.state.content ? ( <HelpTooltip diff --git a/server/sonar-web/src/main/js/components/docs/__tests__/DocLink-test.tsx b/server/sonar-web/src/main/js/components/docs/__tests__/DocLink-test.tsx index e51e1841ace..71e0e920a24 100644 --- a/server/sonar-web/src/main/js/components/docs/__tests__/DocLink-test.tsx +++ b/server/sonar-web/src/main/js/components/docs/__tests__/DocLink-test.tsx @@ -116,7 +116,7 @@ it('should not render sonarqube admin link on sonarcloud', () => { expect(wrapper.find('SonarQubeAdminLink').dive()).toMatchSnapshot(); }); -it.skip('should render documentation anchor', () => { +it('should render documentation anchor', () => { expect( shallow( <DocLink appState={{ canAdmin: false }} href="#quality-profiles"> diff --git a/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocLink-test.tsx.snap b/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocLink-test.tsx.snap index 06a3ff51156..3b3db3ba938 100644 --- a/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocLink-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/docs/__tests__/__snapshots__/DocLink-test.tsx.snap @@ -24,6 +24,15 @@ exports[`should not render sonarqube link on sonarcloud 1`] = ` </Fragment> `; +exports[`should render documentation anchor 1`] = ` +<a + href="#" + onClick={[Function]} +> + link text +</a> +`; + exports[`should render documentation link 1`] = ` <Link onlyActiveOnIndex={false} diff --git a/server/sonar-web/src/main/js/components/facet/__tests__/ListStyleFacet-test.tsx b/server/sonar-web/src/main/js/components/facet/__tests__/ListStyleFacet-test.tsx index b0a8bfae528..3ad271764c4 100644 --- a/server/sonar-web/src/main/js/components/facet/__tests__/ListStyleFacet-test.tsx +++ b/server/sonar-web/src/main/js/components/facet/__tests__/ListStyleFacet-test.tsx @@ -214,7 +214,7 @@ function identity(str: string) { function checkInitialState(wrapper: ShallowWrapper) { expect(wrapper.state('query')).toBe(''); - expect(wrapper.state('searchResults')).toBe(undefined); + expect(wrapper.state('searchResults')).toBeUndefined(); expect(wrapper.state('searching')).toBe(false); expect(wrapper.state('searchResultsCounts')).toEqual({}); expect(wrapper.state('showFullList')).toBe(false); diff --git a/server/sonar-web/src/main/js/components/facet/__tests__/MultipleSelectionHint-test.tsx b/server/sonar-web/src/main/js/components/facet/__tests__/MultipleSelectionHint-test.tsx index 768d13d90fb..e8794c85bfc 100644 --- a/server/sonar-web/src/main/js/components/facet/__tests__/MultipleSelectionHint-test.tsx +++ b/server/sonar-web/src/main/js/components/facet/__tests__/MultipleSelectionHint-test.tsx @@ -38,9 +38,9 @@ it('should render for windows', () => { }); it('should not render when there is not selection', () => { - expect(shallow(<MultipleSelectionHint options={3} values={0} />).type()).toBe(null); + expect(shallow(<MultipleSelectionHint options={3} values={0} />).type()).toBeNull(); }); it('should not render when there are not enough options', () => { - expect(shallow(<MultipleSelectionHint options={1} values={1} />).type()).toBe(null); + expect(shallow(<MultipleSelectionHint options={1} values={1} />).type()).toBeNull(); }); diff --git a/server/sonar-web/src/main/js/components/hoc/__tests__/whenLoggedIn-test.tsx b/server/sonar-web/src/main/js/components/hoc/__tests__/whenLoggedIn-test.tsx index e20ba928f55..7f5ccf8318e 100644 --- a/server/sonar-web/src/main/js/components/hoc/__tests__/whenLoggedIn-test.tsx +++ b/server/sonar-web/src/main/js/components/hoc/__tests__/whenLoggedIn-test.tsx @@ -41,7 +41,7 @@ it('should render for logged in user', () => { it('should not render for anonymous user', () => { const wrapper = shallowRender(false); - expect(getRenderedType(wrapper)).toBe(null); + expect(getRenderedType(wrapper)).toBeNull(); expect(handleRequiredAuthentication).toBeCalled(); }); diff --git a/server/sonar-web/src/main/js/helpers/__tests__/almIntegrations-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/almIntegrations-test.ts index 714749f88e7..4b2b94a155e 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/almIntegrations-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/almIntegrations-test.ts @@ -37,19 +37,19 @@ it('#getAlmMembersUrl', () => { }); it('#isBitbucket', () => { - expect(isBitbucket('bitbucket')).toBeTruthy(); - expect(isBitbucket('bitbucketcloud')).toBeTruthy(); - expect(isBitbucket('github')).toBeFalsy(); + expect(isBitbucket('bitbucket')).toBe(true); + expect(isBitbucket('bitbucketcloud')).toBe(true); + expect(isBitbucket('github')).toBe(false); }); it('#isGithub', () => { - expect(isGithub('github')).toBeTruthy(); - expect(isGithub('bitbucket')).toBeFalsy(); + expect(isGithub('github')).toBe(true); + expect(isGithub('bitbucket')).toBe(false); }); it('#isVSTS', () => { - expect(isVSTS('microsoft')).toBeTruthy(); - expect(isVSTS('github')).toBeFalsy(); + expect(isVSTS('microsoft')).toBe(true); + expect(isVSTS('github')).toBe(false); }); it('#sanitizeAlmId', () => { diff --git a/server/sonar-web/src/main/js/helpers/__tests__/branches-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/branches-test.ts index ecc2f9a845e..a2045f338c8 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/branches-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/branches-test.ts @@ -97,27 +97,27 @@ describe('#isSameBranchLike', () => { const foo = mockBranch({ name: 'foo' }); const foo1 = mockBranch({ name: 'foo-1' }); const pr = mockPullRequest(); - expect(isSameBranchLike(main, pr)).toBeFalsy(); - expect(isSameBranchLike(main, foo1)).toBeFalsy(); - expect(isSameBranchLike(main, foo)).toBeFalsy(); - expect(isSameBranchLike(pr, foo1)).toBeFalsy(); - expect(isSameBranchLike(pr, foo)).toBeFalsy(); - expect(isSameBranchLike(foo1, foo)).toBeFalsy(); + expect(isSameBranchLike(main, pr)).toBe(false); + expect(isSameBranchLike(main, foo1)).toBe(false); + expect(isSameBranchLike(main, foo)).toBe(false); + expect(isSameBranchLike(pr, foo1)).toBe(false); + expect(isSameBranchLike(pr, foo)).toBe(false); + expect(isSameBranchLike(foo1, foo)).toBe(false); }); it('compares pull requests', () => { expect( isSameBranchLike(mockPullRequest({ key: '1234' }), mockPullRequest({ key: '1234' })) - ).toBeTruthy(); + ).toBe(true); expect( isSameBranchLike(mockPullRequest({ key: '1234' }), mockPullRequest({ key: '5678' })) - ).toBeFalsy(); + ).toBe(false); }); it('compares branches', () => { - expect(isSameBranchLike(mockBranch({ name: 'foo' }), mockBranch({ name: 'foo' }))).toBeTruthy(); - expect(isSameBranchLike(mockBranch({ name: 'foo' }), mockBranch({ name: 'foo' }))).toBeTruthy(); - expect(isSameBranchLike(mockBranch({ name: 'foo' }), mockBranch({ name: 'bar' }))).toBeFalsy(); - expect(isSameBranchLike(mockBranch({ name: 'foo' }), mockBranch({ name: 'bar' }))).toBeFalsy(); + expect(isSameBranchLike(mockBranch({ name: 'foo' }), mockBranch({ name: 'foo' }))).toBe(true); + expect(isSameBranchLike(mockBranch({ name: 'foo' }), mockBranch({ name: 'foo' }))).toBe(true); + expect(isSameBranchLike(mockBranch({ name: 'foo' }), mockBranch({ name: 'bar' }))).toBe(false); + expect(isSameBranchLike(mockBranch({ name: 'foo' }), mockBranch({ name: 'bar' }))).toBe(false); }); }); diff --git a/server/sonar-web/src/main/js/helpers/__tests__/markdown-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/markdown-test.ts index dddfbf79beb..65c9f56dd4d 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/markdown-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/markdown-test.ts @@ -163,7 +163,7 @@ Duis sagittis semper sapien nec tempor. Nullam vehicula nisi vitae nisi interdum expect(filterContent(content)).toMatchSnapshot(); }); -it.only('should not break when conditional tags are misused', () => { +it('should not break when conditional tags are misused', () => { const originalConsoleError = console.error; console.error = jest.fn(); diff --git a/server/sonar-web/src/main/js/helpers/__tests__/organizations-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/organizations-test.ts index 76c8774ed1a..b95574c53a0 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/organizations-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/organizations-test.ts @@ -32,25 +32,25 @@ const loggedOut = { isLoggedIn: false }; describe('isCurrentUserMemberOf', () => { it('should be a member', () => { - expect(isCurrentUserMemberOf(loggedIn, adminOrg, [])).toBeTruthy(); - expect(isCurrentUserMemberOf(loggedIn, org, [org])).toBeTruthy(); + expect(isCurrentUserMemberOf(loggedIn, adminOrg, [])).toBe(true); + expect(isCurrentUserMemberOf(loggedIn, org, [org])).toBe(true); }); it('should not be a member', () => { - expect(isCurrentUserMemberOf(loggedIn, undefined, [])).toBeFalsy(); - expect(isCurrentUserMemberOf(loggedIn, org, [])).toBeFalsy(); - expect(isCurrentUserMemberOf(loggedIn, org, [randomOrg])).toBeFalsy(); - expect(isCurrentUserMemberOf(loggedOut, org, [org])).toBeFalsy(); + expect(isCurrentUserMemberOf(loggedIn, undefined, [])).toBe(false); + expect(isCurrentUserMemberOf(loggedIn, org, [])).toBe(false); + expect(isCurrentUserMemberOf(loggedIn, org, [randomOrg])).toBe(false); + expect(isCurrentUserMemberOf(loggedOut, org, [org])).toBe(false); }); }); describe('hasPrivateAccess', () => { it('should have access', () => { - expect(hasPrivateAccess(loggedIn, randomOrg, [])).toBeTruthy(); - expect(hasPrivateAccess(loggedIn, org, [org])).toBeTruthy(); + expect(hasPrivateAccess(loggedIn, randomOrg, [])).toBe(true); + expect(hasPrivateAccess(loggedIn, org, [org])).toBe(true); }); it('should not have access', () => { - expect(hasPrivateAccess(loggedIn, org, [])).toBeFalsy(); + expect(hasPrivateAccess(loggedIn, org, [])).toBe(false); }); }); diff --git a/server/sonar-web/src/main/js/store/__tests__/organizations-test.ts b/server/sonar-web/src/main/js/store/__tests__/organizations-test.ts index 0fd442e2f43..1ce00ff7a54 100644 --- a/server/sonar-web/src/main/js/store/__tests__/organizations-test.ts +++ b/server/sonar-web/src/main/js/store/__tests__/organizations-test.ts @@ -89,7 +89,7 @@ describe('Selectors', () => { const foo = { key: 'foo', name: 'Foo' }; const state = { ...state0, byKey: { foo } }; expect(getOrganizationByKey(state, 'foo')).toBe(foo); - expect(getOrganizationByKey(state, 'bar')).toBeFalsy(); + expect(getOrganizationByKey(state, 'bar')).toBeUndefined(); }); it('getMyOrganizations', () => { diff --git a/server/sonar-web/src/main/js/store/__tests__/users-test.tsx b/server/sonar-web/src/main/js/store/__tests__/users-test.tsx index 3b6abcc8dfa..b5d5f9eb1d0 100644 --- a/server/sonar-web/src/main/js/store/__tests__/users-test.tsx +++ b/server/sonar-web/src/main/js/store/__tests__/users-test.tsx @@ -95,21 +95,21 @@ describe('getters', () => { const john = mockUser({ login: 'john' }); const state = createState({ currentUser, usersByLogin: { jane, john } }); - test('getCurrentUser', () => { + it('getCurrentUser', () => { expect(getCurrentUser(state)).toBe(currentUser); }); - test('getCurrentUserSetting', () => { + it('getCurrentUserSetting', () => { expect(getCurrentUserSetting(state, 'notifications.optOut')).toBe('1'); expect(getCurrentUserSetting(state, 'notifications.readDate')).toBeUndefined(); }); - test('getUserByLogin', () => { + it('getUserByLogin', () => { expect(getUserByLogin(state, 'jane')).toBe(jane); expect(getUserByLogin(state, 'steve')).toBeUndefined(); }); - test('getUsersByLogins', () => { + it('getUsersByLogins', () => { expect(getUsersByLogins(state, ['jane', 'john'])).toEqual([jane, john]); }); }); |