diff options
author | Kevin Silva <kevin.silva@sonarsource.com> | 2023-02-20 15:08:48 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-02-21 20:03:00 +0000 |
commit | 5af56eda84b62f4602578d195207cd108da0487a (patch) | |
tree | b9467690a4b56428a6094bb0a9ac4cdd4d6d5e87 | |
parent | 1f43862c86e1680ad6185323c819b07bd559b5d8 (diff) | |
download | sonarqube-5af56eda84b62f4602578d195207cd108da0487a.tar.gz sonarqube-5af56eda84b62f4602578d195207cd108da0487a.zip |
SONAR-18458 React Testing Library for Security Hotspot - As any user
58 files changed, 196 insertions, 11248 deletions
diff --git a/server/sonar-web/src/main/js/api/mocks/SecurityHotspotServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/SecurityHotspotServiceMock.ts index 8149070f1d0..d4729ef47b9 100644 --- a/server/sonar-web/src/main/js/api/mocks/SecurityHotspotServiceMock.ts +++ b/server/sonar-web/src/main/js/api/mocks/SecurityHotspotServiceMock.ts @@ -17,10 +17,11 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { cloneDeep, pick, range, times } from 'lodash'; -import { mockHotspot, mockRawHotspot } from '../../helpers/mocks/security-hotspots'; +import { cloneDeep, range, times } from 'lodash'; +import { mockHotspot, mockRawHotspot, mockStandards } from '../../helpers/mocks/security-hotspots'; import { mockSourceLine } from '../../helpers/mocks/sources'; -import { mockRuleDetails } from '../../helpers/testMocks'; +import { getStandards } from '../../helpers/security-standard'; +import { mockPaging, mockRuleDetails, mockUser } from '../../helpers/testMocks'; import { BranchParameters } from '../../types/branch-like'; import { Hotspot, @@ -34,28 +35,31 @@ import { getRuleDetails } from '../rules'; import { assignSecurityHotspot, getSecurityHotspotDetails, + getSecurityHotspotList, getSecurityHotspots, + setSecurityHotspotStatus, } from '../security-hotspots'; +import { searchUsers } from '../users'; const NUMBER_OF_LINES = 20; const MAX_END_RANGE = 10; export default class SecurityHotspotServiceMock { hotspots: Hotspot[] = []; - rawHotspotKey: string[] = []; nextAssignee: string | undefined; constructor() { this.reset(); - (getMeasures as jest.Mock).mockImplementation(this.handleGetMeasures); - (getSecurityHotspots as jest.Mock).mockImplementation(this.handleGetSecurityHotspots); - (getSecurityHotspotDetails as jest.Mock).mockImplementation( - this.handleGetSecurityHotspotDetails - ); - (assignSecurityHotspot as jest.Mock).mockImplementation(this.handleAssignSecurityHotspot); - (getRuleDetails as jest.Mock).mockResolvedValue({ rule: mockRuleDetails() }); - (getSources as jest.Mock).mockResolvedValue( + jest.mocked(getMeasures).mockImplementation(this.handleGetMeasures); + jest.mocked(getSecurityHotspots).mockImplementation(this.handleGetSecurityHotspots); + jest.mocked(getSecurityHotspotDetails).mockImplementation(this.handleGetSecurityHotspotDetails); + jest.mocked(getSecurityHotspotList).mockImplementation(this.handleGetSecurityHotspotList); + jest.mocked(assignSecurityHotspot).mockImplementation(this.handleAssignSecurityHotspot); + jest.mocked(setSecurityHotspotStatus).mockImplementation(this.handleSetSecurityHotspotStatus); + jest.mocked(searchUsers).mockImplementation(this.handleSearchUsers); + jest.mocked(getRuleDetails).mockResolvedValue({ rule: mockRuleDetails() }); + jest.mocked(getSources).mockResolvedValue( times(NUMBER_OF_LINES, (n) => mockSourceLine({ line: n, @@ -63,6 +67,7 @@ export default class SecurityHotspotServiceMock { }) ) ); + jest.mocked(getStandards).mockImplementation(this.handleGetStandards); } handleGetSources = (data: { key: string; from?: number; to?: number } & BranchParameters) => { @@ -71,6 +76,47 @@ export default class SecurityHotspotServiceMock { ); }; + handleGetStandards = () => { + return Promise.resolve(mockStandards()); + }; + + handleSetSecurityHotspotStatus = () => { + return Promise.resolve(); + }; + + handleSearchUsers = () => { + return this.reply({ + users: [ + mockUser({ name: 'User John' }), + mockUser({ name: 'User Doe' }), + mockUser({ name: 'User Foo' }), + ], + paging: mockPaging(), + }); + }; + + handleGetSecurityHotspotList = () => { + return this.reply({ + paging: mockPaging(), + hotspots: [mockRawHotspot({ assignee: 'John Doe' })], + components: [ + { + key: 'guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed:index.php', + qualifier: 'FIL', + name: 'index.php', + longName: 'index.php', + path: 'index.php', + }, + { + key: 'guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed', + qualifier: 'TRK', + name: 'benflix', + longName: 'benflix', + }, + ], + }); + }; + handleGetSecurityHotspots = ( data: { projectKey: string; @@ -83,8 +129,8 @@ export default class SecurityHotspotServiceMock { } & BranchParameters ) => { return this.reply({ - paging: { pageIndex: 1, pageSize: data.ps, total: this.hotspots.length }, - hotspots: this.hotspots.map((hotspot) => pick(hotspot, this.rawHotspotKey)), + paging: mockPaging({ pageIndex: 1, pageSize: data.ps, total: this.hotspots.length }), + hotspots: this.mockRawHotspots(data.onlyMine), components: [ { key: 'guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed:index.php', @@ -103,6 +149,16 @@ export default class SecurityHotspotServiceMock { }); }; + mockRawHotspots = (onlyMine: boolean | undefined) => { + if (onlyMine) { + return []; + } + return [ + mockRawHotspot({ assignee: 'John Doe', key: 'test-1' }), + mockRawHotspot({ assignee: 'John Doe', key: 'test-2' }), + ]; + }; + handleGetSecurityHotspotDetails = (securityHotspotKey: string) => { const hotspot = this.hotspots.find((h) => h.key === securityHotspotKey); @@ -121,25 +177,26 @@ export default class SecurityHotspotServiceMock { this.nextAssignee = undefined; } + hotspot.canChangeStatus = true; + return this.reply(hotspot); }; handleGetMeasures = () => { return this.reply([ { - component: { - key: 'guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed', - name: 'benflix', - qualifier: 'TRK', - measures: [{ metric: 'security_hotspots_reviewed', value: '0.0', bestValue: false }], - }, + key: 'guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed', + name: 'benflix', + qualifier: 'TRK', + metric: 'security_hotspots_reviewed', + measures: [{ metric: 'security_hotspots_reviewed', value: '0.0', bestValue: false }], }, ]); }; handleAssignSecurityHotspot = (_: string, data: HotspotAssignRequest) => { this.nextAssignee = data.assignee; - return this.reply({}); + return Promise.resolve(); }; reply<T>(response: T): Promise<T> { @@ -147,10 +204,13 @@ export default class SecurityHotspotServiceMock { } reset = () => { - this.rawHotspotKey = Object.keys(mockRawHotspot()); this.hotspots = [ - mockHotspot({ key: '1', status: HotspotStatus.TO_REVIEW }), - mockHotspot({ key: '2', status: HotspotStatus.TO_REVIEW }), + mockHotspot({ key: 'test-1', status: HotspotStatus.TO_REVIEW }), + mockHotspot({ + key: 'test-2', + status: HotspotStatus.TO_REVIEW, + message: "'2' is a magic number.", + }), ]; }; } diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx index a9ba25fb5cb..719c8aecaec 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx @@ -21,8 +21,12 @@ import { screen, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import React from 'react'; import { Route } from 'react-router-dom'; +import selectEvent from 'react-select-event'; import { byRole, byTestId, byText } from 'testing-library-selector'; import SecurityHotspotServiceMock from '../../../api/mocks/SecurityHotspotServiceMock'; +import { getSecurityHotspots, setSecurityHotspotStatus } from '../../../api/security-hotspots'; +import { searchUsers } from '../../../api/users'; +import { mockMainBranch } from '../../../helpers/mocks/branch-like'; import { mockComponent } from '../../../helpers/mocks/component'; import { mockLoggedInUser } from '../../../helpers/testMocks'; import { renderAppWithComponentContext } from '../../../helpers/testReactTestingUtils'; @@ -32,14 +36,30 @@ jest.mock('../../../api/measures'); jest.mock('../../../api/security-hotspots'); jest.mock('../../../api/rules'); jest.mock('../../../api/components'); +jest.mock('../../../helpers/security-standard'); +jest.mock('../../../api/users'); const ui = { + inputAssignee: byRole('searchbox', { name: 'hotspots.assignee.select_user' }), selectStatusButton: byRole('button', { name: 'hotspots.status.select_status', }), editAssigneeButton: byRole('button', { name: 'hotspots.assignee.change_user', }), + filterAssigneeToMe: byRole('button', { + name: 'hotspot.filters.assignee.assigned_to_me', + }), + filterSeeAll: byRole('button', { name: 'hotspot.filters.assignee.all' }), + filterByStatus: byRole('combobox', { name: 'hotspot.filters.status' }), + filterByPeriod: byRole('combobox', { name: 'hotspot.filters.period' }), + noHotspotForFilter: byText('hotspots.no_hotspots_for_filters.title'), + selectStatus: byRole('button', { name: 'hotspots.status.select_status' }), + toReviewStatus: byText('hotspots.status_option.TO_REVIEW'), + changeStatus: byRole('button', { name: 'hotspots.status.change_status' }), + hotspotTitle: (name: string | RegExp) => byRole('heading', { name }), + hotspotStatus: byRole('heading', { name: 'status: hotspots.status_option.FIXED' }), + hotpostListTitle: byRole('heading', { name: 'hotspots.list_title.TO_REVIEW.2' }), activeAssignee: byTestId('assignee-name'), successGlobalMessage: byRole('status'), currentUserSelectionItem: byText('foo'), @@ -56,19 +76,105 @@ afterEach(() => { handler.reset(); }); -it('should self-assign hotspot', async () => { +it('should be able to self-assign a hotspot', async () => { const user = userEvent.setup(); renderSecurityHotspotsApp(); expect(await ui.activeAssignee.find()).toHaveTextContent('John Doe'); - await user.click(await ui.editAssigneeButton.find()); + await user.click(ui.editAssigneeButton.get()); await user.click(ui.currentUserSelectionItem.get()); expect(ui.successGlobalMessage.get()).toHaveTextContent(`hotspots.assign.success.foo`); expect(ui.activeAssignee.get()).toHaveTextContent('foo'); }); +it('should be able to search for a user on the assignee', async () => { + const user = userEvent.setup(); + renderSecurityHotspotsApp(); + + await user.click(await ui.editAssigneeButton.find()); + await user.click(ui.inputAssignee.get()); + + await user.keyboard('User'); + + expect(searchUsers).toHaveBeenLastCalledWith({ q: 'User' }); + await user.keyboard('{ArrowDown}{Enter}'); + expect(ui.successGlobalMessage.get()).toHaveTextContent(`hotspots.assign.success.User John`); +}); + +it('should be able to filter the hotspot list', async () => { + const user = userEvent.setup(); + renderSecurityHotspotsApp(); + + expect(await ui.hotpostListTitle.find()).toBeInTheDocument(); + + await user.click(ui.filterAssigneeToMe.get()); + expect(ui.noHotspotForFilter.get()).toBeInTheDocument(); + await selectEvent.select(ui.filterByStatus.get(), ['hotspot.filters.status.to_review']); + + expect(getSecurityHotspots).toHaveBeenLastCalledWith({ + inNewCodePeriod: false, + onlyMine: true, + p: 1, + projectKey: 'guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed', + ps: 500, + resolution: undefined, + status: 'TO_REVIEW', + }); + + await selectEvent.select(ui.filterByPeriod.get(), ['hotspot.filters.period.since_leak_period']); + + expect(getSecurityHotspots).toHaveBeenLastCalledWith({ + inNewCodePeriod: true, + onlyMine: true, + p: 1, + projectKey: 'guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed', + ps: 500, + resolution: undefined, + status: 'TO_REVIEW', + }); + + await user.click(ui.filterSeeAll.get()); + + expect(ui.hotpostListTitle.get()).toBeInTheDocument(); +}); + +it('should be able to navigate the hotspot list with keyboard', async () => { + const user = userEvent.setup(); + renderSecurityHotspotsApp(); + + await user.keyboard('{ArrowDown}'); + expect(await ui.hotspotTitle(/'2' is a magic number./).find()).toBeInTheDocument(); + await user.keyboard('{ArrowUp}'); + expect(await ui.hotspotTitle(/'3' is a magic number./).find()).toBeInTheDocument(); +}); + +it('should be able to change the status of a hotspot', async () => { + const user = userEvent.setup(); + const comment = 'COMMENT-TEXT'; + + renderSecurityHotspotsApp(); + + expect(await ui.selectStatus.find()).toBeInTheDocument(); + + await user.click(ui.selectStatus.get()); + await user.click(ui.toReviewStatus.get()); + + await user.click(screen.getByRole('textbox', { name: 'hotspots.status.add_comment' })); + await user.keyboard(comment); + + await user.click(ui.changeStatus.get()); + + expect(setSecurityHotspotStatus).toHaveBeenLastCalledWith('test-1', { + comment: 'COMMENT-TEXT', + resolution: undefined, + status: 'TO_REVIEW', + }); + + expect(ui.hotspotStatus.get()).toBeInTheDocument(); +}); + it('should remember the comment when toggling change status panel for the same security hotspot', async () => { const user = userEvent.setup(); renderSecurityHotspotsApp(); @@ -86,7 +192,7 @@ it('should remember the comment when toggling change status panel for the same s // Check panel is closed expect(ui.panel.query()).not.toBeInTheDocument(); - await user.click(await ui.selectStatusButton.find()); + await user.click(ui.selectStatusButton.get()); expect(await screen.findByText(comment)).toBeInTheDocument(); }); @@ -103,7 +209,7 @@ function renderSecurityHotspotsApp(navigateTo?: string) { }), }, { - branchLikes: [], + branchLike: mockMainBranch(), onBranchesChange: jest.fn(), onComponentChange: jest.fn(), component: mockComponent({ 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 deleted file mode 100644 index 7b0fbfa3c84..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx +++ /dev/null @@ -1,474 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { getMeasures } from '../../../api/measures'; -import { getSecurityHotspotList, getSecurityHotspots } from '../../../api/security-hotspots'; -import { KeyboardKeys } from '../../../helpers/keycodes'; -import { mockBranch, mockPullRequest } from '../../../helpers/mocks/branch-like'; -import { mockComponent } from '../../../helpers/mocks/component'; -import { mockRawHotspot, mockStandards } from '../../../helpers/mocks/security-hotspots'; -import { getStandards } from '../../../helpers/security-standard'; -import { - mockCurrentUser, - mockFlowLocation, - mockLocation, - mockLoggedInUser, -} from '../../../helpers/testMocks'; -import { mockEvent, waitAndUpdate } from '../../../helpers/testUtils'; -import { SecurityStandard } from '../../../types/security'; -import { - HotspotResolution, - HotspotStatus, - HotspotStatusFilter, -} from '../../../types/security-hotspots'; -import { SecurityHotspotsApp } from '../SecurityHotspotsApp'; -import SecurityHotspotsAppRenderer from '../SecurityHotspotsAppRenderer'; - -beforeEach(() => { - jest.clearAllMocks(); -}); - -jest.mock('../../../api/measures', () => ({ - getMeasures: jest.fn().mockResolvedValue([]), -})); - -jest.mock('../../../api/security-hotspots', () => ({ - getSecurityHotspots: jest.fn().mockResolvedValue({ hotspots: [], paging: { total: 0 } }), - getSecurityHotspotList: jest.fn().mockResolvedValue({ hotspots: [], rules: [] }), -})); - -jest.mock('../../../helpers/security-standard', () => ({ - getStandards: jest.fn().mockResolvedValue({ sonarsourceSecurity: { cat1: { title: 'cat 1' } } }), -})); - -jest.mock('../../../helpers/scrolling', () => ({ - scrollToElement: jest.fn(), -})); - -const branch = mockBranch(); - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); -}); - -it('should load data correctly', async () => { - const hotspots = [mockRawHotspot()]; - (getSecurityHotspots as jest.Mock).mockResolvedValue({ - hotspots, - paging: { - total: 1, - }, - }); - (getMeasures as jest.Mock).mockResolvedValue([{ value: '86.6' }]); - - const wrapper = shallowRender(); - - expect(wrapper.state().loading).toBe(true); - expect(wrapper.state().loadingMeasure).toBe(true); - - expect(getStandards).toHaveBeenCalled(); - expect(getSecurityHotspots).toHaveBeenCalledWith( - expect.objectContaining({ - branch: branch.name, - }) - ); - expect(getMeasures).toHaveBeenCalledWith( - expect.objectContaining({ - branch: branch.name, - }) - ); - - await waitAndUpdate(wrapper); - - expect(wrapper.state().loading).toBe(false); - expect(wrapper.state().hotspots).toEqual(hotspots); - expect(wrapper.state().selectedHotspot).toBe(hotspots[0]); - expect(wrapper.state().standards).toEqual({ - sonarsourceSecurity: { - cat1: { title: 'cat 1' }, - }, - }); - expect(wrapper.state().loadingMeasure).toBe(false); - expect(wrapper.state().hotspotsReviewedMeasure).toBe('86.6'); -}); - -it('should handle category request', () => { - (getStandards as jest.Mock).mockResolvedValue(mockStandards()); - (getMeasures as jest.Mock).mockResolvedValue([{ value: '86.6' }]); - - shallowRender({ - location: mockLocation({ query: { [SecurityStandard.OWASP_TOP10]: 'a1' } }), - }); - - expect(getSecurityHotspots).toHaveBeenCalledWith( - expect.objectContaining({ [SecurityStandard.OWASP_TOP10]: 'a1' }) - ); -}); - -it('should handle cwe request', () => { - (getStandards as jest.Mock).mockResolvedValue(mockStandards()); - (getMeasures as jest.Mock).mockResolvedValue([{ value: '86.6' }]); - - shallowRender({ - location: mockLocation({ query: { [SecurityStandard.CWE]: '1004' } }), - }); - - expect(getSecurityHotspots).toHaveBeenCalledWith( - expect.objectContaining({ [SecurityStandard.CWE]: '1004' }) - ); -}); - -it('should handle file request', () => { - (getStandards as jest.Mock).mockResolvedValue(mockStandards()); - (getMeasures as jest.Mock).mockResolvedValue([{ value: '86.6' }]); - - const filepath = 'src/path/to/file.java'; - - shallowRender({ - location: mockLocation({ query: { files: filepath } }), - }); - - expect(getSecurityHotspots).toHaveBeenCalledWith(expect.objectContaining({ files: filepath })); -}); - -it('should load data correctly when hotspot key list is forced', async () => { - const hotspots = [ - mockRawHotspot({ key: 'test1' }), - mockRawHotspot({ key: 'test2' }), - mockRawHotspot({ key: 'test3' }), - ]; - const hotspotKeys = hotspots.map((h) => h.key); - (getSecurityHotspotList as jest.Mock).mockResolvedValueOnce({ - hotspots, - }); - - const location = mockLocation({ query: { hotspots: hotspotKeys.join() } }); - const wrapper = shallowRender({ - location, - }); - - await waitAndUpdate(wrapper); - expect(getSecurityHotspotList).toHaveBeenCalledWith(hotspotKeys, { - projectKey: 'my-project', - branch: 'branch-6.7', - }); - expect(wrapper.state().hotspotKeys).toEqual(hotspotKeys); - expect(wrapper.find(SecurityHotspotsAppRenderer).props().isStaticListOfHotspots).toBe(true); - - // Reset - (getSecurityHotspots as jest.Mock).mockClear(); - (getSecurityHotspotList as jest.Mock).mockClear(); - - // Simulate a new location - wrapper.setProps({ - location: { ...location, query: { ...location.query, hotspots: undefined } }, - }); - await waitAndUpdate(wrapper); - expect(wrapper.state().hotspotKeys).toBeUndefined(); - expect(getSecurityHotspotList).not.toHaveBeenCalled(); - expect(getSecurityHotspots).toHaveBeenCalled(); -}); - -it('should set "leakperiod" filter according to context (branchlike & location query)', () => { - expect(shallowRender().state().filters.inNewCodePeriod).toBe(false); - expect(shallowRender({ branchLike: mockPullRequest() }).state().filters.inNewCodePeriod).toBe( - true - ); - expect( - shallowRender({ location: mockLocation({ query: { inNewCodePeriod: 'true' } }) }).state() - .filters.inNewCodePeriod - ).toBe(true); -}); - -it('should set "assigned to me" filter according to context (logged in & explicit location query)', () => { - const wrapper = shallowRender(); - expect(wrapper.state().filters.assignedToMe).toBe(false); - - wrapper.setProps({ location: mockLocation({ query: { assignedToMe: 'true' } }) }); - expect(wrapper.state().filters.assignedToMe).toBe(false); - - expect(shallowRender({ currentUser: mockLoggedInUser() }).state().filters.assignedToMe).toBe( - false - ); - expect( - shallowRender({ - location: mockLocation({ query: { assignedToMe: 'true' } }), - currentUser: mockLoggedInUser(), - }).state().filters.assignedToMe - ).toBe(true); -}); - -it('should handle loading more', async () => { - const hotspots = [mockRawHotspot({ key: '1' }), mockRawHotspot({ key: '2' })]; - const hotspots2 = [mockRawHotspot({ key: '3' }), mockRawHotspot({ key: '4' })]; - (getSecurityHotspots as jest.Mock) - .mockResolvedValueOnce({ - hotspots, - paging: { total: 5 }, - }) - .mockResolvedValueOnce({ - hotspots: hotspots2, - paging: { total: 5 }, - }); - - const wrapper = shallowRender(); - - await waitAndUpdate(wrapper); - - wrapper.instance().handleLoadMore(); - - expect(wrapper.state().loadingMore).toBe(true); - expect(getSecurityHotspots).toHaveBeenCalledTimes(2); - - await waitAndUpdate(wrapper); - - expect(wrapper.state().loadingMore).toBe(false); - expect(wrapper.state().hotspotsPageIndex).toBe(2); - expect(wrapper.state().hotspotsTotal).toBe(5); - expect(wrapper.state().hotspots).toHaveLength(4); -}); - -it('should handle hotspot update', async () => { - const key = 'hotspotKey'; - const hotspots = [mockRawHotspot(), mockRawHotspot({ key })]; - const fetchBranchStatusMock = jest.fn(); - const branchLike = mockPullRequest(); - const componentKey = 'test'; - - (getSecurityHotspots as jest.Mock).mockResolvedValueOnce({ - hotspots, - paging: { pageIndex: 1, total: 1252 }, - }); - - let wrapper = shallowRender(); - await waitAndUpdate(wrapper); - wrapper.setState({ hotspotsPageIndex: 2 }); - - jest.clearAllMocks(); - (getSecurityHotspots as jest.Mock) - .mockResolvedValueOnce({ - hotspots: [mockRawHotspot()], - paging: { pageIndex: 1, total: 1251 }, - }) - .mockResolvedValueOnce({ - hotspots: [mockRawHotspot()], - paging: { pageIndex: 2, total: 1251 }, - }); - - const selectedHotspotIndex = wrapper - .state() - .hotspots.findIndex((h) => h.key === wrapper.state().selectedHotspot?.key); - - await wrapper.find(SecurityHotspotsAppRenderer).props().onUpdateHotspot(key); - - expect(getSecurityHotspots).toHaveBeenCalledTimes(2); - - expect(wrapper.state().hotspots).toHaveLength(2); - expect(wrapper.state().hotspotsPageIndex).toBe(2); - expect(wrapper.state().hotspotsTotal).toBe(1251); - expect( - wrapper.state().hotspots.findIndex((h) => h.key === wrapper.state().selectedHotspot?.key) - ).toBe(selectedHotspotIndex); - - expect(getMeasures).toHaveBeenCalled(); - - (getSecurityHotspots as jest.Mock).mockResolvedValueOnce({ - hotspots, - paging: { pageIndex: 1, total: 1252 }, - }); - - wrapper = shallowRender({ - branchLike, - fetchBranchStatus: fetchBranchStatusMock, - component: mockComponent({ key: componentKey }), - }); - await wrapper.find(SecurityHotspotsAppRenderer).props().onUpdateHotspot(key); - expect(fetchBranchStatusMock).toHaveBeenCalledWith(branchLike, componentKey); -}); - -it('should handle status filter change', async () => { - const hotspots = [mockRawHotspot({ key: 'key1' })]; - const hotspots2 = [mockRawHotspot({ key: 'key2' })]; - (getSecurityHotspots as jest.Mock) - .mockResolvedValueOnce({ hotspots, paging: { total: 1 } }) - .mockResolvedValueOnce({ hotspots: hotspots2, paging: { total: 1 } }) - .mockResolvedValueOnce({ hotspots: [], paging: { total: 0 } }); - - const wrapper = shallowRender(); - - expect(getSecurityHotspots).toHaveBeenCalledWith( - expect.objectContaining({ status: HotspotStatus.TO_REVIEW, resolution: undefined }) - ); - - await waitAndUpdate(wrapper); - - expect(getMeasures).toHaveBeenCalledTimes(1); - - // Set filter to SAFE: - wrapper.instance().handleChangeFilters({ status: HotspotStatusFilter.SAFE }); - expect(getMeasures).toHaveBeenCalledTimes(1); - - expect(getSecurityHotspots).toHaveBeenCalledWith( - expect.objectContaining({ status: HotspotStatus.REVIEWED, resolution: HotspotResolution.SAFE }) - ); - - await waitAndUpdate(wrapper); - - expect(wrapper.state().hotspots[0]).toBe(hotspots2[0]); - - // Set filter to FIXED (use the other method to check this one): - wrapper.instance().handleChangeStatusFilter(HotspotStatusFilter.FIXED); - - expect(getSecurityHotspots).toHaveBeenCalledWith( - expect.objectContaining({ status: HotspotStatus.REVIEWED, resolution: HotspotResolution.FIXED }) - ); - - await waitAndUpdate(wrapper); - - expect(wrapper.state().hotspots).toHaveLength(0); -}); - -it('should handle leakPeriod filter change', async () => { - const hotspots = [mockRawHotspot({ key: 'key1' })]; - const hotspots2 = [mockRawHotspot({ key: 'key2' })]; - (getSecurityHotspots as jest.Mock) - .mockResolvedValueOnce({ hotspots, paging: { total: 1 } }) - .mockResolvedValueOnce({ hotspots: hotspots2, paging: { total: 1 } }) - .mockResolvedValueOnce({ hotspots: [], paging: { total: 0 } }); - - const wrapper = shallowRender(); - - expect(getSecurityHotspots).toHaveBeenCalledWith( - expect.objectContaining({ status: HotspotStatus.TO_REVIEW, resolution: undefined }) - ); - - await waitAndUpdate(wrapper); - - expect(getMeasures).toHaveBeenCalledTimes(1); - - wrapper.instance().handleChangeFilters({ inNewCodePeriod: true }); - - expect(getMeasures).toHaveBeenCalledTimes(2); - expect(getSecurityHotspots).toHaveBeenCalledWith( - expect.objectContaining({ inNewCodePeriod: true }) - ); -}); - -it('should handle hotspot click', () => { - const wrapper = shallowRender(); - const selectedHotspot = mockRawHotspot(); - wrapper.instance().handleHotspotClick(selectedHotspot); - - expect(wrapper.instance().state.selectedHotspotLocationIndex).toBeUndefined(); - expect(wrapper.instance().state.selectedHotspot).toEqual(selectedHotspot); -}); - -it('should handle secondary location click', () => { - const wrapper = shallowRender(); - wrapper.instance().handleLocationClick(0); - expect(wrapper.instance().state.selectedHotspotLocationIndex).toEqual(0); - - wrapper.instance().handleLocationClick(1); - expect(wrapper.instance().state.selectedHotspotLocationIndex).toEqual(1); - - wrapper.instance().handleLocationClick(1); - expect(wrapper.instance().state.selectedHotspotLocationIndex).toBeUndefined(); - - wrapper.setState({ selectedHotspotLocationIndex: 2 }); - wrapper.instance().handleLocationClick(); - expect(wrapper.instance().state.selectedHotspotLocationIndex).toBeUndefined(); -}); - -describe('keyboard navigation', () => { - const hotspots = [ - mockRawHotspot({ key: 'k1' }), - mockRawHotspot({ key: 'k2' }), - mockRawHotspot({ key: 'k3' }), - ]; - const flowsData = { - flows: [{ locations: [mockFlowLocation(), mockFlowLocation(), mockFlowLocation()] }], - }; - const hotspotsForLocation = mockRawHotspot(flowsData); - - (getSecurityHotspots as jest.Mock).mockResolvedValueOnce({ hotspots, paging: { total: 3 } }); - - const wrapper = shallowRender(); - - it.each([ - ['selecting next', 0, 1, 1], - ['selecting previous', 1, -1, 0], - ['selecting previous, non-existent', 0, -1, 0], - ['selecting next, non-existent', 2, 1, 2], - ['jumping down', 0, 18, 2], - ['jumping up', 2, -18, 0], - ['none selected', 4, -2, 4], - ])('should work when %s', (_, start, shift, expected) => { - wrapper.setState({ selectedHotspot: hotspots[start] }); - wrapper.instance().selectNeighboringHotspot(shift); - - expect(wrapper.state().selectedHotspot).toBe(hotspots[expected]); - }); - - it.each([ - ['selecting next locations when nothing is selected', undefined, 0], - ['selecting next locations', 0, 1], - ['selecting next locations, non-existent', 2, undefined], - ])('should work when %s', (_, start, expected) => { - wrapper.setState({ selectedHotspotLocationIndex: start, selectedHotspot: hotspotsForLocation }); - wrapper.instance().handleKeyDown(mockEvent({ altKey: true, key: KeyboardKeys.DownArrow })); - - expect(wrapper.state().selectedHotspotLocationIndex).toBe(expected); - }); - - it.each([ - ['selecting previous locations when nothing is selected', undefined, undefined], - ['selecting previous locations', 1, 0], - ['selecting previous locations, non-existent', 0, undefined], - ])('should work when %s', (_, start, expected) => { - wrapper.setState({ selectedHotspotLocationIndex: start, selectedHotspot: hotspotsForLocation }); - wrapper.instance().handleKeyDown(mockEvent({ altKey: true, key: KeyboardKeys.UpArrow })); - - expect(wrapper.state().selectedHotspotLocationIndex).toBe(expected); - }); - - it('should not change location index when locations are empty', () => { - wrapper.setState({ selectedHotspotLocationIndex: undefined, selectedHotspot: hotspots[0] }); - - wrapper.instance().handleKeyDown(mockEvent({ altKey: true, key: KeyboardKeys.UpArrow })); - expect(wrapper.state().selectedHotspotLocationIndex).toBeUndefined(); - - wrapper.instance().handleKeyDown(mockEvent({ altKey: true, key: KeyboardKeys.DownArrow })); - expect(wrapper.state().selectedHotspotLocationIndex).toBeUndefined(); - }); -}); - -function shallowRender(props: Partial<SecurityHotspotsApp['props']> = {}) { - return shallow<SecurityHotspotsApp>( - <SecurityHotspotsApp - fetchBranchStatus={jest.fn()} - branchLike={branch} - component={mockComponent()} - currentUser={mockCurrentUser()} - location={mockLocation()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsAppRenderer-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsAppRenderer-test.tsx deleted file mode 100644 index 1e0594d62cb..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsAppRenderer-test.tsx +++ /dev/null @@ -1,154 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 React from 'react'; -import ScreenPositionHelper from '../../../components/common/ScreenPositionHelper'; -import { mockComponent } from '../../../helpers/mocks/component'; -import { mockRawHotspot, mockStandards } from '../../../helpers/mocks/security-hotspots'; -import { scrollToElement } from '../../../helpers/scrolling'; -import { SecurityStandard } from '../../../types/security'; -import { HotspotStatusFilter } from '../../../types/security-hotspots'; -import SecurityHotspotsAppRenderer, { - SecurityHotspotsAppRendererProps, -} from '../SecurityHotspotsAppRenderer'; - -jest.mock('../../../helpers/scrolling', () => ({ - scrollToElement: jest.fn(), -})); - -jest.mock('../../../components/common/ScreenPositionHelper'); - -beforeEach(() => { - jest.clearAllMocks(); -}); - -jest.mock('react', () => { - return { - ...jest.requireActual('react'), - useRef: jest.fn(), - useEffect: jest.fn(), - }; -}); - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); - expect( - shallowRender({ - filters: { - assignedToMe: true, - inNewCodePeriod: false, - status: HotspotStatusFilter.TO_REVIEW, - }, - }) - ).toMatchSnapshot('no hotspots with filters'); - expect(shallowRender({ loading: true })).toMatchSnapshot('loading'); -}); - -it('should render correctly with hotspots', () => { - const hotspots = [mockRawHotspot({ key: 'h1' }), mockRawHotspot({ key: 'h2' })]; - expect(shallowRender({ hotspots, hotspotsTotal: 2 })).toMatchSnapshot(); - expect( - shallowRender({ hotspots, hotspotsTotal: 3, selectedHotspot: mockRawHotspot({ key: 'h2' }) }) - .find(ScreenPositionHelper) - .dive() - ).toMatchSnapshot(); -}); - -it('should render correctly when filtered by category or cwe', () => { - const hotspots = [mockRawHotspot({ key: 'h1' }), mockRawHotspot({ key: 'h2' })]; - - expect( - shallowRender({ filterByCWE: '327', hotspots, hotspotsTotal: 2, selectedHotspot: hotspots[0] }) - .find(ScreenPositionHelper) - .dive() - ).toMatchSnapshot('cwe'); - expect( - shallowRender({ - filterByCategory: { category: 'a1', standard: SecurityStandard.OWASP_TOP10 }, - hotspots, - hotspotsTotal: 2, - selectedHotspot: hotspots[0], - }) - .find(ScreenPositionHelper) - .dive() - ).toMatchSnapshot('category'); -}); - -describe('side effect', () => { - const fakeElement = document.createElement('span'); - const fakeParent = document.createElement('div'); - - beforeEach(() => { - (React.useEffect as jest.Mock).mockImplementationOnce((f) => f()); - jest.spyOn(document, 'querySelector').mockImplementationOnce(() => fakeElement); - (React.useRef as jest.Mock).mockImplementationOnce(() => ({ current: fakeParent })); - }); - - it('should trigger scrolling', () => { - shallowRender({ selectedHotspot: mockRawHotspot() }); - - expect(scrollToElement).toHaveBeenCalledWith( - fakeElement, - expect.objectContaining({ parent: fakeParent }) - ); - }); - - it('should not trigger scrolling if no selected hotspot', () => { - shallowRender(); - expect(scrollToElement).not.toHaveBeenCalled(); - }); - - it('should not trigger scrolling if no parent', () => { - const mockUseRef = React.useRef as jest.Mock; - mockUseRef.mockReset(); - mockUseRef.mockImplementationOnce(() => ({ current: null })); - shallowRender({ selectedHotspot: mockRawHotspot() }); - expect(scrollToElement).not.toHaveBeenCalled(); - }); -}); - -function shallowRender(props: Partial<SecurityHotspotsAppRendererProps> = {}) { - return shallow( - <SecurityHotspotsAppRenderer - component={mockComponent()} - filters={{ - assignedToMe: false, - inNewCodePeriod: false, - status: HotspotStatusFilter.TO_REVIEW, - }} - hotspots={[]} - hotspotsTotal={0} - isStaticListOfHotspots={true} - loading={false} - loadingMeasure={false} - loadingMore={false} - onChangeFilters={jest.fn()} - onHotspotClick={jest.fn()} - onLoadMore={jest.fn()} - onSwitchStatusFilter={jest.fn()} - onUpdateHotspot={jest.fn()} - onLocationClick={jest.fn()} - securityCategories={{}} - selectedHotspot={undefined} - standards={mockStandards()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsApp-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsApp-test.tsx.snap deleted file mode 100644 index 6c80b807c45..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsApp-test.tsx.snap +++ /dev/null @@ -1,68 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -<SecurityHotspotsAppRenderer - branchLike={ - { - "analysisDate": "2018-01-01", - "excludedFromPurge": true, - "isMain": false, - "name": "branch-6.7", - } - } - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - filters={ - { - "assignedToMe": false, - "inNewCodePeriod": false, - "status": "TO_REVIEW", - } - } - hotspots={[]} - hotspotsTotal={0} - isStaticListOfHotspots={false} - loading={true} - loadingMeasure={true} - loadingMore={false} - onChangeFilters={[Function]} - onHotspotClick={[Function]} - onLoadMore={[Function]} - onLocationClick={[Function]} - onSwitchStatusFilter={[Function]} - onUpdateHotspot={[Function]} - securityCategories={{}} - standards={ - { - "cwe": {}, - "owaspAsvs-4.0": {}, - "owaspTop10": {}, - "owaspTop10-2021": {}, - "pciDss-3.2": {}, - "pciDss-4.0": {}, - "sansTop25": {}, - "sonarsourceSecurity": {}, - } - } -/> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap deleted file mode 100644 index fa4d05d80fa..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/__snapshots__/SecurityHotspotsAppRenderer-test.tsx.snap +++ /dev/null @@ -1,617 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -<div - id="security_hotspots" -> - <Suggestions - suggestions="security_hotspots" - /> - <Helmet - defer={true} - encodeSpecialCharacters={true} - prioritizeSeoTags={false} - title="hotspots.page" - /> - <A11ySkipTarget - anchor="security_hotspots_main" - /> - <withCurrentUserContext(FilterBar) - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - filters={ - { - "assignedToMe": false, - "inNewCodePeriod": false, - "status": "TO_REVIEW", - } - } - isStaticListOfHotspots={true} - loadingMeasure={false} - onBranch={false} - onChangeFilters={[MockFunction]} - /> - <EmptyHotspotsPage - filterByFile={false} - filtered={false} - isStaticListOfHotspots={true} - /> -</div> -`; - -exports[`should render correctly when filtered by category or cwe: category 1`] = ` -<div - className="layout-page-side" - style={ - { - "top": 0, - } - } -> - <div - className="layout-page-side-inner" - > - <HotspotSimpleList - filterByCategory={ - { - "category": "a1", - "standard": "owaspTop10", - } - } - hotspots={ - [ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h1", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - }, - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - }, - ] - } - hotspotsTotal={2} - loadingMore={false} - onHotspotClick={[MockFunction]} - onLoadMore={[MockFunction]} - onLocationClick={[MockFunction]} - selectedHotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h1", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - standards={ - { - "cwe": { - "1004": { - "title": "Sensitive Cookie Without 'HttpOnly' Flag", - }, - "unknown": { - "title": "No CWE associated", - }, - }, - "owaspAsvs-4.0": { - "1": { - "title": "New OWASP ASVS cat 1", - }, - }, - "owaspTop10": { - "a1": { - "title": "Injection", - }, - "a2": { - "title": "Broken Authentication", - }, - "a3": { - "title": "Sensitive Data Exposure", - }, - }, - "owaspTop10-2021": { - "a1": { - "title": "Injection", - }, - "a2": { - "title": "Broken Authentication", - }, - "a3": { - "title": "Sensitive Data Exposure", - }, - }, - "pciDss-3.2": { - "1": { - "title": " Install and maintain a firewall configuration to protect cardholder data", - }, - }, - "pciDss-4.0": { - "2": { - "title": "This is useless...", - }, - }, - "sansTop25": { - "insecure-interaction": { - "title": "Insecure Interaction Between Components", - }, - "porous-defenses": { - "title": "Porous Defenses", - }, - "risky-resource": { - "title": "Risky Resource Management", - }, - }, - "sonarsourceSecurity": { - "buffer-overflow": { - "title": "Buffer Overflow", - }, - "rce": { - "title": "Code Injection (RCE)", - }, - "sql-injection": { - "title": "SQL Injection", - }, - }, - } - } - /> - </div> -</div> -`; - -exports[`should render correctly when filtered by category or cwe: cwe 1`] = ` -<div - className="layout-page-side" - style={ - { - "top": 0, - } - } -> - <div - className="layout-page-side-inner" - > - <HotspotSimpleList - filterByCWE="327" - hotspots={ - [ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h1", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - }, - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - }, - ] - } - hotspotsTotal={2} - loadingMore={false} - onHotspotClick={[MockFunction]} - onLoadMore={[MockFunction]} - onLocationClick={[MockFunction]} - selectedHotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h1", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - standards={ - { - "cwe": { - "1004": { - "title": "Sensitive Cookie Without 'HttpOnly' Flag", - }, - "unknown": { - "title": "No CWE associated", - }, - }, - "owaspAsvs-4.0": { - "1": { - "title": "New OWASP ASVS cat 1", - }, - }, - "owaspTop10": { - "a1": { - "title": "Injection", - }, - "a2": { - "title": "Broken Authentication", - }, - "a3": { - "title": "Sensitive Data Exposure", - }, - }, - "owaspTop10-2021": { - "a1": { - "title": "Injection", - }, - "a2": { - "title": "Broken Authentication", - }, - "a3": { - "title": "Sensitive Data Exposure", - }, - }, - "pciDss-3.2": { - "1": { - "title": " Install and maintain a firewall configuration to protect cardholder data", - }, - }, - "pciDss-4.0": { - "2": { - "title": "This is useless...", - }, - }, - "sansTop25": { - "insecure-interaction": { - "title": "Insecure Interaction Between Components", - }, - "porous-defenses": { - "title": "Porous Defenses", - }, - "risky-resource": { - "title": "Risky Resource Management", - }, - }, - "sonarsourceSecurity": { - "buffer-overflow": { - "title": "Buffer Overflow", - }, - "rce": { - "title": "Code Injection (RCE)", - }, - "sql-injection": { - "title": "SQL Injection", - }, - }, - } - } - /> - </div> -</div> -`; - -exports[`should render correctly with hotspots 1`] = ` -<div - id="security_hotspots" -> - <Suggestions - suggestions="security_hotspots" - /> - <Helmet - defer={true} - encodeSpecialCharacters={true} - prioritizeSeoTags={false} - title="hotspots.page" - /> - <A11ySkipTarget - anchor="security_hotspots_main" - /> - <withCurrentUserContext(FilterBar) - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - filters={ - { - "assignedToMe": false, - "inNewCodePeriod": false, - "status": "TO_REVIEW", - } - } - isStaticListOfHotspots={true} - loadingMeasure={false} - onBranch={false} - onChangeFilters={[MockFunction]} - /> - <EmptyHotspotsPage - filterByFile={false} - filtered={false} - isStaticListOfHotspots={true} - /> -</div> -`; - -exports[`should render correctly with hotspots 2`] = ` -<div - className="layout-page-side" - style={ - { - "top": 0, - } - } -> - <div - className="layout-page-side-inner" - > - <HotspotList - hotspots={ - [ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h1", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - }, - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - }, - ] - } - hotspotsTotal={3} - isStaticListOfHotspots={true} - loadingMore={false} - onHotspotClick={[MockFunction]} - onLoadMore={[MockFunction]} - onLocationClick={[MockFunction]} - securityCategories={{}} - selectedHotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - statusFilter="TO_REVIEW" - /> - </div> -</div> -`; - -exports[`should render correctly: loading 1`] = ` -<div - id="security_hotspots" -> - <Suggestions - suggestions="security_hotspots" - /> - <Helmet - defer={true} - encodeSpecialCharacters={true} - prioritizeSeoTags={false} - title="hotspots.page" - /> - <A11ySkipTarget - anchor="security_hotspots_main" - /> - <withCurrentUserContext(FilterBar) - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - filters={ - { - "assignedToMe": false, - "inNewCodePeriod": false, - "status": "TO_REVIEW", - } - } - isStaticListOfHotspots={true} - loadingMeasure={false} - onBranch={false} - onChangeFilters={[MockFunction]} - /> - <div - className="layout-page" - > - <div - className="layout-page-side-inner" - > - <DeferredSpinner - className="big-spacer-top" - /> - </div> - </div> -</div> -`; - -exports[`should render correctly: no hotspots with filters 1`] = ` -<div - id="security_hotspots" -> - <Suggestions - suggestions="security_hotspots" - /> - <Helmet - defer={true} - encodeSpecialCharacters={true} - prioritizeSeoTags={false} - title="hotspots.page" - /> - <A11ySkipTarget - anchor="security_hotspots_main" - /> - <withCurrentUserContext(FilterBar) - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - filters={ - { - "assignedToMe": true, - "inNewCodePeriod": false, - "status": "TO_REVIEW", - } - } - isStaticListOfHotspots={true} - loadingMeasure={false} - onBranch={false} - onChangeFilters={[MockFunction]} - /> - <EmptyHotspotsPage - filterByFile={false} - filtered={true} - isStaticListOfHotspots={true} - /> -</div> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotHeader.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotHeader.tsx index ce2e7940a0a..07dacf5f64e 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotHeader.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotHeader.tsx @@ -37,9 +37,9 @@ export function HotspotHeader(props: HotspotHeaderProps) { return ( <div className="huge-spacer-bottom hotspot-header"> <div className="display-flex-column big-spacer-bottom"> - <div className="big text-bold"> + <h2 className="big text-bold"> <IssueMessageHighlighting message={message} messageFormattings={messageFormattings} /> - </div> + </h2> <div className="spacer-top"> <span className="note padded-right">{rule.name}</span> <Link className="small" to={getRuleUrl(rule.key)} target="_blank"> diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/EmptyHotspotsPage-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/EmptyHotspotsPage-test.tsx deleted file mode 100644 index 38fffee404e..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/EmptyHotspotsPage-test.tsx +++ /dev/null @@ -1,40 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 EmptyHotspotsPage, { EmptyHotspotsPageProps } from '../EmptyHotspotsPage'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); - expect(shallowRender({ filtered: true })).toMatchSnapshot('filtered'); - expect(shallowRender({ isStaticListOfHotspots: true })).toMatchSnapshot('keys'); - expect(shallowRender({ filterByFile: true })).toMatchSnapshot('file'); -}); - -function shallowRender(props: Partial<EmptyHotspotsPageProps> = {}) { - return shallow( - <EmptyHotspotsPage - filtered={false} - filterByFile={false} - isStaticListOfHotspots={false} - {...props} - /> - ); -} 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 deleted file mode 100644 index 7318feaa0cd..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/FilterBar-test.tsx +++ /dev/null @@ -1,99 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 ButtonToggle from '../../../../components/controls/ButtonToggle'; -import Select from '../../../../components/controls/Select'; -import { mockComponent } from '../../../../helpers/mocks/component'; -import { mockCurrentUser, mockLoggedInUser } from '../../../../helpers/testMocks'; -import { ComponentQualifier } from '../../../../types/component'; -import { HotspotStatusFilter } from '../../../../types/security-hotspots'; -import { AssigneeFilterOption, FilterBar, FilterBarProps } from '../FilterBar'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot('anonymous'); - expect(shallowRender({ currentUser: mockLoggedInUser() })).toMatchSnapshot('logged-in'); - expect(shallowRender({ onBranch: false })).toMatchSnapshot('on Pull request'); - expect(shallowRender({ hotspotsReviewedMeasure: '23.30' })).toMatchSnapshot( - 'with hotspots reviewed measure' - ); - expect( - shallowRender({ - currentUser: mockLoggedInUser(), - component: mockComponent({ qualifier: ComponentQualifier.Application }), - }) - ).toMatchSnapshot('non-project'); -}); - -it('should render correctly when the list of hotspot is static', () => { - const wrapper = shallowRender({ - isStaticListOfHotspots: true, - }); - expect(wrapper).toMatchSnapshot(); -}); - -it('should trigger onChange for status', () => { - const onChangeFilters = jest.fn(); - const wrapper = shallowRender({ onChangeFilters }); - - const { onChange } = wrapper.find(Select).at(0).props(); - - onChange({ value: HotspotStatusFilter.SAFE }); - expect(onChangeFilters).toHaveBeenCalledWith({ status: HotspotStatusFilter.SAFE }); -}); - -it('should trigger onChange for self-assigned toggle', () => { - const onChangeFilters = jest.fn(); - const wrapper = shallowRender({ currentUser: mockLoggedInUser(), onChangeFilters }); - - const { onCheck } = wrapper.find(ButtonToggle).props(); - - onCheck(AssigneeFilterOption.ALL); - expect(onChangeFilters).toHaveBeenCalledWith({ assignedToMe: false }); -}); - -it('should trigger onChange for leak period', () => { - const onChangeFilters = jest.fn(); - const wrapper = shallowRender({ onChangeFilters }); - - const { onChange } = wrapper.find(Select).at(1).props(); - - onChange({ value: true }); - expect(onChangeFilters).toHaveBeenCalledWith({ inNewCodePeriod: true }); -}); - -function shallowRender(props: Partial<FilterBarProps> = {}) { - return shallow( - <FilterBar - component={mockComponent()} - currentUser={mockCurrentUser()} - filters={{ - assignedToMe: false, - inNewCodePeriod: false, - status: HotspotStatusFilter.TO_REVIEW, - }} - isStaticListOfHotspots={false} - loadingMeasure={false} - onBranch={true} - onChangeFilters={jest.fn()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotCategory-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotCategory-test.tsx deleted file mode 100644 index 3517dd1c106..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotCategory-test.tsx +++ /dev/null @@ -1,82 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { mockRawHotspot } from '../../../../helpers/mocks/security-hotspots'; -import HotspotCategory, { HotspotCategoryProps } from '../HotspotCategory'; - -it('should render correctly', () => { - expect(shallowRender().type()).toBeNull(); -}); - -it('should render correctly with hotspots', () => { - const securityCategory = 'command-injection'; - const hotspots = [ - mockRawHotspot({ key: 'h1', securityCategory }), - mockRawHotspot({ key: 'h2', securityCategory }), - ]; - expect(shallowRender({ hotspots })).toMatchSnapshot(); - expect(shallowRender({ hotspots, expanded: false })).toMatchSnapshot('collapsed'); - expect( - shallowRender({ categoryKey: securityCategory, hotspots, selectedHotspot: hotspots[0] }) - ).toMatchSnapshot('contains selected'); - expect(shallowRender({ hotspots, isLastAndIncomplete: true })).toMatchSnapshot( - 'lastAndIncomplete' - ); -}); - -it('should handle collapse and expand', () => { - const onToggleExpand = jest.fn(); - - const categoryKey = 'xss-injection'; - - const wrapper = shallowRender({ - categoryKey, - expanded: true, - hotspots: [mockRawHotspot()], - onToggleExpand, - }); - - wrapper.find('.hotspot-category-header').simulate('click'); - - expect(onToggleExpand).toHaveBeenCalledWith(categoryKey, false); - - wrapper.setProps({ expanded: false }); - wrapper.find('.hotspot-category-header').simulate('click'); - - expect(onToggleExpand).toHaveBeenCalledWith(categoryKey, true); -}); - -function shallowRender(props: Partial<HotspotCategoryProps> = {}) { - return shallow( - <HotspotCategory - categoryKey="xss-injection" - expanded={true} - hotspots={[]} - onHotspotClick={jest.fn()} - onToggleExpand={jest.fn()} - selectedHotspot={mockRawHotspot()} - title="Class Injection" - isLastAndIncomplete={false} - onLocationClick={jest.fn()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotCommentPopup-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotCommentPopup-test.tsx deleted file mode 100644 index 4e81f39822b..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotCommentPopup-test.tsx +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { Button, ResetButtonLink } from '../../../../components/controls/buttons'; -import HotspotCommentPopup, { HotspotCommentPopupProps } from '../HotspotCommentPopup'; - -it('should render correclty', () => { - const wrapper = shallowRender(); - expect(wrapper).toMatchSnapshot(); -}); - -it('should trigger update comment', () => { - const props = { - onCommentEditSubmit: jest.fn(), - }; - const wrapper = shallowRender(props); - wrapper.find('textarea').simulate('change', { target: { value: 'foo' } }); - wrapper.find(Button).simulate('click'); - - expect(props.onCommentEditSubmit).toHaveBeenCalledWith('foo'); -}); - -it('should trigger cancel update comment', () => { - const props = { - onCancelEdit: jest.fn(), - }; - const wrapper = shallowRender(props); - wrapper.find(ResetButtonLink).simulate('click'); - - expect(props.onCancelEdit).toHaveBeenCalledTimes(1); -}); - -function shallowRender(props?: Partial<HotspotCommentPopupProps>) { - return shallow( - <HotspotCommentPopup - markdownComment="test" - onCancelEdit={jest.fn()} - onCommentEditSubmit={jest.fn()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotHeader-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotHeader-test.tsx deleted file mode 100644 index a1295913719..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotHeader-test.tsx +++ /dev/null @@ -1,42 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 React from 'react'; -import { mockHotspot } from '../../../../helpers/mocks/security-hotspots'; -import { HotspotStatusOption } from '../../../../types/security-hotspots'; -import { HotspotHeader, HotspotHeaderProps } from '../HotspotHeader'; -import Status from '../status/Status'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); -}); - -it('correctly propagates the status change', () => { - const onUpdateHotspot = jest.fn(); - const wrapper = shallowRender({ onUpdateHotspot }); - - wrapper.find(Status).props().onStatusChange(HotspotStatusOption.FIXED); - - expect(onUpdateHotspot).toHaveBeenCalledWith(true, HotspotStatusOption.FIXED); -}); - -function shallowRender(props: Partial<HotspotHeaderProps> = {}) { - return shallow(<HotspotHeader hotspot={mockHotspot()} onUpdateHotspot={jest.fn()} {...props} />); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotList-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotList-test.tsx deleted file mode 100644 index ef075366be2..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotList-test.tsx +++ /dev/null @@ -1,127 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { mockRawHotspot } from '../../../../helpers/mocks/security-hotspots'; -import { addSideBarClass, removeSideBarClass } from '../../../../helpers/pages'; -import { waitAndUpdate } from '../../../../helpers/testUtils'; -import { HotspotStatusFilter, RiskExposure } from '../../../../types/security-hotspots'; -import HotspotList from '../HotspotList'; - -jest.mock('../../../../helpers/pages', () => ({ - addSideBarClass: jest.fn(), - removeSideBarClass: jest.fn(), -})); - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); - expect(shallowRender({ loadingMore: true })).toMatchSnapshot(); -}); - -it('should add/remove sidebar classes', async () => { - const wrapper = shallowRender(); - - await waitAndUpdate(wrapper); - - expect(addSideBarClass).toHaveBeenCalled(); - - wrapper.unmount(); - - expect(removeSideBarClass).toHaveBeenCalled(); -}); - -it('should render correctly when the list of hotspot is static', () => { - expect(shallowRender({ isStaticListOfHotspots: true })).toMatchSnapshot(); -}); - -const hotspots = [ - mockRawHotspot({ key: 'h1', securityCategory: 'cat2' }), - mockRawHotspot({ key: 'h2', securityCategory: 'cat1' }), - mockRawHotspot({ - key: 'h3', - securityCategory: 'cat1', - vulnerabilityProbability: RiskExposure.MEDIUM, - }), - mockRawHotspot({ - key: 'h4', - securityCategory: 'cat1', - vulnerabilityProbability: RiskExposure.MEDIUM, - }), - mockRawHotspot({ - key: 'h5', - securityCategory: 'cat2', - vulnerabilityProbability: RiskExposure.MEDIUM, - }), -]; - -it('should render correctly with hotspots', () => { - expect(shallowRender({ hotspots, hotspotsTotal: hotspots.length })).toMatchSnapshot( - 'no pagination' - ); - expect(shallowRender({ hotspots, hotspotsTotal: 7 })).toMatchSnapshot('pagination'); -}); - -it('should update expanded categories correctly', () => { - const wrapper = shallowRender({ hotspots, selectedHotspot: hotspots[0] }); - - expect(wrapper.state().expandedCategories).toEqual({ cat2: true }); - - wrapper.setProps({ selectedHotspot: hotspots[1] }); - - expect(wrapper.state().expandedCategories).toEqual({ cat1: true, cat2: true }); -}); - -it('should update grouped hotspots when the list changes', () => { - const wrapper = shallowRender({ hotspots, selectedHotspot: hotspots[0] }); - - wrapper.setProps({ hotspots: [mockRawHotspot()] }); - - expect(wrapper.state().groupedHotspots).toHaveLength(1); - expect(wrapper.state().groupedHotspots[0].categories).toHaveLength(1); - expect(wrapper.state().groupedHotspots[0].categories[0].hotspots).toHaveLength(1); -}); - -it('should expand the categories for which the location is selected', () => { - const wrapper = shallowRender({ hotspots, selectedHotspot: hotspots[0] }); - - wrapper.setState({ expandedCategories: { cat1: true, cat2: false } }); - - wrapper.setProps({ selectedHotspotLocation: 1 }); - - expect(wrapper.state().expandedCategories).toEqual({ cat1: true, cat2: true }); -}); - -function shallowRender(props: Partial<HotspotList['props']> = {}) { - return shallow<HotspotList>( - <HotspotList - hotspots={[]} - hotspotsTotal={0} - isStaticListOfHotspots={false} - loadingMore={false} - onHotspotClick={jest.fn()} - onLoadMore={jest.fn()} - onLocationClick={jest.fn()} - securityCategories={{}} - selectedHotspot={mockRawHotspot({ key: 'h2' })} - statusFilter={HotspotStatusFilter.TO_REVIEW} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotListItem-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotListItem-test.tsx deleted file mode 100644 index e81e47a4dc4..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotListItem-test.tsx +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { mockRawHotspot } from '../../../../helpers/mocks/security-hotspots'; -import HotspotListItem, { HotspotListItemProps } from '../HotspotListItem'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); - expect(shallowRender({ selected: true })).toMatchSnapshot(); -}); - -it('should handle click', () => { - const hotspot = mockRawHotspot({ key: 'hotspotKey' }); - const onClick = jest.fn(); - const wrapper = shallowRender({ hotspot, onClick }); - - wrapper.simulate('click'); - - expect(onClick).toHaveBeenCalledWith(hotspot); -}); - -it('should handle click on the title', () => { - const hotspot = mockRawHotspot({ key: 'hotspotKey' }); - const onLocationClick = jest.fn(); - const wrapper = shallowRender({ hotspot, onLocationClick, selected: true }); - - wrapper.find('div.cursor-pointer').simulate('click'); - - expect(onLocationClick).toHaveBeenCalledWith(); -}); - -function shallowRender(props: Partial<HotspotListItemProps> = {}) { - return shallow( - <HotspotListItem - hotspot={mockRawHotspot()} - onClick={jest.fn()} - onLocationClick={jest.fn} - selected={false} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotOpenInIdeButton-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotOpenInIdeButton-test.tsx deleted file mode 100644 index f8b02ea5189..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotOpenInIdeButton-test.tsx +++ /dev/null @@ -1,82 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { Button } from '../../../../components/controls/buttons'; -import * as sonarlint from '../../../../helpers/sonarlint'; -import HotspotOpenInIdeButton from '../HotspotOpenInIdeButton'; - -jest.mock('../../../../helpers/sonarlint'); - -describe('HotspotOpenInIdeButton', () => { - beforeEach(jest.resetAllMocks); - - it('should render correctly', async () => { - const projectKey = 'my-project:key'; - const hotspotKey = 'AXWsgE9RpggAQesHYfwm'; - const port = 42001; - - const wrapper = shallow( - <HotspotOpenInIdeButton projectKey={projectKey} hotspotKey={hotspotKey} /> - ); - expect(wrapper).toMatchSnapshot(); - - (sonarlint.probeSonarLintServers as jest.Mock).mockResolvedValue([ - { port, ideName: 'BlueJ IDE', description: 'Hello World' }, - ]); - (sonarlint.openHotspot as jest.Mock).mockResolvedValue(null); - - wrapper.find(Button).simulate('click'); - - await new Promise(setImmediate); - expect(sonarlint.openHotspot).toHaveBeenCalledWith(port, projectKey, hotspotKey); - }); - - it('should gracefully handle zero IDE detected', async () => { - const wrapper = shallow(<HotspotOpenInIdeButton projectKey="polop" hotspotKey="palap" />); - (sonarlint.probeSonarLintServers as jest.Mock).mockResolvedValue([]); - wrapper.find(Button).simulate('click'); - - await new Promise(setImmediate); - expect(sonarlint.openHotspot).not.toHaveBeenCalled(); - }); - - it('should handle several IDE', async () => { - const projectKey = 'my-project:key'; - const hotspotKey = 'AXWsgE9RpggAQesHYfwm'; - const port1 = 42000; - const port2 = 42001; - - const wrapper = shallow( - <HotspotOpenInIdeButton projectKey={projectKey} hotspotKey={hotspotKey} /> - ); - expect(wrapper).toMatchSnapshot(); - - (sonarlint.probeSonarLintServers as jest.Mock).mockResolvedValue([ - { port: port1, ideName: 'BlueJ IDE', description: 'Hello World' }, - { port: port2, ideName: 'Arduino IDE', description: 'Blink' }, - ]); - - wrapper.find(Button).simulate('click'); - - await new Promise(setImmediate); - expect(wrapper).toMatchSnapshot('dropdown open'); - }); -}); diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotOpenInIdeOverlay-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotOpenInIdeOverlay-test.tsx deleted file mode 100644 index 4208234a040..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotOpenInIdeOverlay-test.tsx +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { HotspotOpenInIdeOverlay } from '../HotspotOpenInIdeOverlay'; - -it('should render nothing with fewer than 2 IDE', () => { - const onIdeSelected = jest.fn(); - expect( - shallow(<HotspotOpenInIdeOverlay ides={[]} onIdeSelected={onIdeSelected} />).type() - ).toBeNull(); - expect( - shallow( - <HotspotOpenInIdeOverlay - ides={[{ port: 0, ideName: 'Polop', description: 'Plouf' }]} - onIdeSelected={onIdeSelected} - /> - ).type() - ).toBeNull(); -}); - -it('should render menu and select the right IDE', () => { - const onIdeSelected = jest.fn(); - const ide1 = { port: 0, ideName: 'Polop', description: 'Plouf' }; - const ide2 = { port: 1, ideName: 'Foo', description: '' }; - const wrapper = shallow( - <HotspotOpenInIdeOverlay ides={[ide1, ide2]} onIdeSelected={onIdeSelected} /> - ); - expect(wrapper).toMatchSnapshot(); - - wrapper.find('a').last().simulate('click'); - expect(onIdeSelected).toHaveBeenCalledWith(ide2); -}); diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotPrimaryLocationBox-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotPrimaryLocationBox-test.tsx deleted file mode 100644 index 17739630d51..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotPrimaryLocationBox-test.tsx +++ /dev/null @@ -1,107 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 React from 'react'; -import { ButtonLink } from '../../../../components/controls/buttons'; -import { mockHotspot, mockHotspotRule } from '../../../../helpers/mocks/security-hotspots'; -import { mockCurrentUser, mockLoggedInUser } from '../../../../helpers/testMocks'; -import { RiskExposure } from '../../../../types/security-hotspots'; -import { - HotspotPrimaryLocationBox, - HotspotPrimaryLocationBoxProps, -} from '../HotspotPrimaryLocationBox'; - -jest.mock('react', () => { - return { - ...jest.requireActual('react'), - useRef: jest.fn(), - useEffect: jest.fn(), - }; -}); - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot('User logged in'); - expect(shallowRender({ currentUser: mockCurrentUser() })).toMatchSnapshot('User not logged in '); -}); - -it.each([[RiskExposure.HIGH], [RiskExposure.MEDIUM], [RiskExposure.LOW]])( - 'should indicate risk exposure: %s', - (vulnerabilityProbability) => { - const wrapper = shallowRender({ - hotspot: mockHotspot({ rule: mockHotspotRule({ vulnerabilityProbability }) }), - }); - - expect(wrapper.hasClass(`hotspot-risk-exposure-${vulnerabilityProbability}`)).toBe(true); - } -); - -it('should handle click', () => { - const onCommentClick = jest.fn(); - const wrapper = shallowRender({ onCommentClick }); - - wrapper.find(ButtonLink).simulate('click'); - - expect(onCommentClick).toHaveBeenCalled(); -}); - -it('should scroll on load if no secondary locations selected', () => { - const node = document.createElement('div'); - (React.useRef as jest.Mock).mockImplementationOnce(() => ({ current: node })); - (React.useEffect as jest.Mock).mockImplementationOnce((f) => f()); - - const scroll = jest.fn(); - shallowRender({ scroll }); - - expect(scroll).toHaveBeenCalled(); -}); - -it('should not scroll on load if a secondary location is selected', () => { - const node = document.createElement('div'); - (React.useRef as jest.Mock).mockImplementationOnce(() => ({ current: node })); - (React.useEffect as jest.Mock).mockImplementationOnce((f) => f()); - - const scroll = jest.fn(); - shallowRender({ scroll, secondaryLocationSelected: true }); - - expect(scroll).not.toHaveBeenCalled(); -}); - -it('should not scroll on load if node is not defined', () => { - (React.useRef as jest.Mock).mockImplementationOnce(() => ({ current: undefined })); - (React.useEffect as jest.Mock).mockImplementationOnce((f) => f()); - - const scroll = jest.fn(); - shallowRender({ scroll }); - - expect(scroll).not.toHaveBeenCalled(); -}); - -function shallowRender(props: Partial<HotspotPrimaryLocationBoxProps> = {}) { - return shallow( - <HotspotPrimaryLocationBox - currentUser={mockLoggedInUser()} - hotspot={mockHotspot()} - onCommentClick={jest.fn()} - scroll={jest.fn()} - secondaryLocationSelected={false} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotReviewHistory-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotReviewHistory-test.tsx deleted file mode 100644 index 791de003a18..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotReviewHistory-test.tsx +++ /dev/null @@ -1,152 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 React from 'react'; -import { Button, EditButton } from '../../../../components/controls/buttons'; -import Dropdown, { DropdownOverlay } from '../../../../components/controls/Dropdown'; -import Toggler from '../../../../components/controls/Toggler'; -import { mockIssueChangelog } from '../../../../helpers/mocks/issues'; -import { mockHotspot, mockHotspotComment } from '../../../../helpers/mocks/security-hotspots'; -import { mockUser } from '../../../../helpers/testMocks'; -import HotspotCommentPopup from '../HotspotCommentPopup'; -import HotspotReviewHistory, { HotspotReviewHistoryProps } from '../HotspotReviewHistory'; - -jest.mock('react', () => { - return { - ...jest.requireActual('react'), - useState: jest.fn().mockImplementation(() => ['', jest.fn()]), - }; -}); - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot('default'); - expect(shallowRender({ showFullHistory: true })).toMatchSnapshot('show full list'); - expect(shallowRender({ showFullHistory: true }).find(Toggler).props().overlay).toMatchSnapshot( - 'edit comment overlay' - ); - expect(shallowRender({ showFullHistory: true }).find(Dropdown).props().overlay).toMatchSnapshot( - 'delete comment overlay' - ); -}); - -it('should correctly handle comment updating', () => { - return new Promise<void>((resolve, reject) => { - const setEditedCommentKey = jest.fn(); - (React.useState as jest.Mock).mockImplementationOnce(() => ['', setEditedCommentKey]); - - const onEditComment = jest.fn(); - const wrapper = shallowRender({ onEditComment, showFullHistory: true }); - - // Closing the Toggler sets the edited key back to an empty string. - wrapper.find(Toggler).at(0).props().onRequestClose(); - expect(setEditedCommentKey).toHaveBeenCalledWith(''); - - const editOnClick = wrapper.find(EditButton).at(0).props().onClick; - if (!editOnClick) { - reject(); - return; - } - - // Clicking on the EditButton correctly flags the comment for editing. - editOnClick(); - expect(setEditedCommentKey).toHaveBeenLastCalledWith('comment-1'); - - // Cancelling an edit sets the edited key back to an empty string - const dropdownOverlay = shallow( - wrapper.find(Toggler).at(0).props().overlay as React.ReactElement<DropdownOverlay> - ); - dropdownOverlay.find(HotspotCommentPopup).props().onCancelEdit(); - expect(setEditedCommentKey).toHaveBeenLastCalledWith(''); - - // Updating the comment sets the edited key back to an empty string, and calls the - // prop to update the comment value. - dropdownOverlay.find(HotspotCommentPopup).props().onCommentEditSubmit('comment'); - expect(onEditComment).toHaveBeenLastCalledWith('comment-1', 'comment'); - expect(setEditedCommentKey).toHaveBeenLastCalledWith(''); - expect(setEditedCommentKey).toHaveBeenCalledTimes(4); - - resolve(); - }); -}); - -it('should correctly handle comment deleting', () => { - return new Promise<void>((resolve, reject) => { - const setEditedCommentKey = jest.fn(); - (React.useState as jest.Mock).mockImplementationOnce(() => ['', setEditedCommentKey]); - - const onDeleteComment = jest.fn(); - const wrapper = shallowRender({ onDeleteComment, showFullHistory: true }); - - // Opening the deletion Dropdown sets the edited key back to an empty string. - const dropdownOnOpen = wrapper.find(Dropdown).at(0).props().onOpen; - if (!dropdownOnOpen) { - reject(); - return; - } - dropdownOnOpen(); - expect(setEditedCommentKey).toHaveBeenLastCalledWith(''); - - // Confirming deletion calls the prop to delete the comment. - const dropdownOverlay = shallow( - wrapper.find(Dropdown).at(0).props().overlay as React.ReactElement<HTMLDivElement> - ); - const deleteButtonOnClick = dropdownOverlay.find(Button).props().onClick; - if (!deleteButtonOnClick) { - reject(); - return; - } - - deleteButtonOnClick(); - expect(onDeleteComment).toHaveBeenCalledWith('comment-1'); - - resolve(); - }); -}); - -function shallowRender(props?: Partial<HotspotReviewHistoryProps>) { - return shallow( - <HotspotReviewHistory - hotspot={mockHotspot({ - creationDate: '2018-09-01', - changelog: [ - mockIssueChangelog(), - mockIssueChangelog({ - creationDate: '2018-10-12', - }), - ], - comment: [ - mockHotspotComment({ - key: 'comment-1', - updatable: true, - }), - mockHotspotComment({ key: 'comment-2', user: mockUser({ name: undefined }) }), - mockHotspotComment({ key: 'comment-3', user: mockUser({ active: false }) }), - mockHotspotComment({ key: 'comment-4' }), - mockHotspotComment({ key: 'comment-5' }), - ], - })} - onDeleteComment={jest.fn()} - onEditComment={jest.fn()} - onShowFullHistory={jest.fn()} - showFullHistory={false} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotReviewHistoryAndComments-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotReviewHistoryAndComments-test.tsx deleted file mode 100644 index 22abda84f2f..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotReviewHistoryAndComments-test.tsx +++ /dev/null @@ -1,121 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { - commentSecurityHotspot, - deleteSecurityHotspotComment, - editSecurityHotspotComment, -} from '../../../../api/security-hotspots'; -import { mockHotspot } from '../../../../helpers/mocks/security-hotspots'; -import { mockCurrentUser } from '../../../../helpers/testMocks'; -import { waitAndUpdate } from '../../../../helpers/testUtils'; -import { isLoggedIn } from '../../../../types/users'; -import HotspotReviewHistory from '../HotspotReviewHistory'; -import HotspotReviewHistoryAndComments from '../HotspotReviewHistoryAndComments'; - -jest.mock('../../../../api/security-hotspots', () => ({ - commentSecurityHotspot: jest.fn().mockResolvedValue({}), - deleteSecurityHotspotComment: jest.fn().mockResolvedValue({}), - editSecurityHotspotComment: jest.fn().mockResolvedValue({}), -})); - -jest.mock('../../../../types/users', () => ({ isLoggedIn: jest.fn(() => true) })); - -it('should render correctly', () => { - const wrapper = shallowRender(); - expect(wrapper).toMatchSnapshot(); -}); - -it('should render correctly without user', () => { - (isLoggedIn as any as jest.Mock<boolean, [boolean]>).mockReturnValueOnce(false); - const wrapper = shallowRender(); - expect(wrapper).toMatchSnapshot(); -}); - -it('should submit comment', async () => { - const mockApi = commentSecurityHotspot as jest.Mock; - const hotspot = mockHotspot(); - const wrapper = shallowRender({ hotspot }); - mockApi.mockClear(); - wrapper.instance().setState({ comment: 'Comment' }); - - wrapper.find('#hotspot-comment-box-submit').simulate('click'); - await waitAndUpdate(wrapper); - - expect(mockApi).toHaveBeenCalledWith(hotspot.key, 'Comment'); - expect(wrapper.state().comment).toBe(''); - expect(wrapper.instance().props.onCommentUpdate).toHaveBeenCalledTimes(1); -}); - -it('should change comment', () => { - const wrapper = shallowRender(); - wrapper.instance().setState({ comment: 'Comment' }); - wrapper.find('textarea').simulate('change', { target: { value: 'Foo' } }); - - expect(wrapper.state().comment).toBe('Foo'); -}); - -it('should reset on change hotspot', () => { - const wrapper = shallowRender(); - wrapper.setState({ comment: 'NOP' }); - wrapper.setProps({ hotspot: mockHotspot({ key: 'other-hotspot' }) }); - - expect(wrapper.state().comment).toBe(''); -}); - -it('should delete comment', async () => { - const wrapper = shallowRender(); - - wrapper.find(HotspotReviewHistory).simulate('deleteComment', 'me1'); - await waitAndUpdate(wrapper); - - expect(deleteSecurityHotspotComment).toHaveBeenCalledWith('me1'); - expect(wrapper.instance().props.onCommentUpdate).toHaveBeenCalledTimes(1); -}); - -it('should edit comment', async () => { - const wrapper = shallowRender(); - - wrapper.find(HotspotReviewHistory).simulate('editComment', 'me1', 'new'); - await waitAndUpdate(wrapper); - - expect(editSecurityHotspotComment).toHaveBeenCalledWith('me1', 'new'); - expect(wrapper.instance().props.onCommentUpdate).toHaveBeenCalledTimes(1); -}); - -it('should correctly toggle the show full history state', () => { - const wrapper = shallowRender(); - expect(wrapper.state().showFullHistory).toBe(false); - wrapper.find(HotspotReviewHistory).props().onShowFullHistory(); - expect(wrapper.state().showFullHistory).toBe(true); -}); - -function shallowRender(props?: Partial<HotspotReviewHistoryAndComments['props']>) { - return shallow<HotspotReviewHistoryAndComments>( - <HotspotReviewHistoryAndComments - commentTextRef={React.createRef()} - currentUser={mockCurrentUser()} - hotspot={mockHotspot()} - onCommentUpdate={jest.fn()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSimpleList-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSimpleList-test.tsx deleted file mode 100644 index 7ed9e70744d..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSimpleList-test.tsx +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { mockRawHotspot } from '../../../../helpers/mocks/security-hotspots'; -import { addSideBarClass, removeSideBarClass } from '../../../../helpers/pages'; -import { waitAndUpdate } from '../../../../helpers/testUtils'; -import { SecurityStandard } from '../../../../types/security'; -import HotspotSimpleList, { HotspotSimpleListProps } from '../HotspotSimpleList'; - -jest.mock('../../../../helpers/pages', () => ({ - addSideBarClass: jest.fn(), - removeSideBarClass: jest.fn(), -})); - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot('filter by category'); - expect(shallowRender({ filterByCategory: undefined, filterByCWE: '327' })).toMatchSnapshot( - 'filter by cwe' - ); - expect(shallowRender({ filterByCWE: '327' })).toMatchSnapshot('filter by both'); - expect(shallowRender({ filterByFile: 'src/apps/something/main.ts' })).toMatchSnapshot( - 'filter by file' - ); -}); - -it('should add/remove sidebar classes', async () => { - const wrapper = shallowRender(); - - await waitAndUpdate(wrapper); - - expect(addSideBarClass).toHaveBeenCalled(); - - wrapper.unmount(); - - expect(removeSideBarClass).toHaveBeenCalled(); -}); - -function shallowRender(props: Partial<HotspotSimpleListProps> = {}) { - const hotspots = [mockRawHotspot({ key: 'h1' }), mockRawHotspot({ key: 'h2' })]; - - return shallow( - <HotspotSimpleList - filterByCategory={{ standard: SecurityStandard.OWASP_TOP10, category: 'a1' }} - hotspots={hotspots} - hotspotsTotal={2} - loadingMore={false} - onHotspotClick={jest.fn()} - onLoadMore={jest.fn()} - onLocationClick={jest.fn()} - selectedHotspot={hotspots[0]} - standards={{ - cwe: { 327: { title: 'Use of a Broken or Risky Cryptographic Algorithm' } }, - owaspTop10: { - a1: { title: 'A1 - SQL Injection' }, - a3: { title: 'A3 - Sensitive Data Exposure' }, - }, - 'owaspTop10-2021': { - a1: { title: 'A1 - SQL Injection' }, - a3: { title: 'A3 - Sensitive Data Exposure' }, - }, - sansTop25: {}, - sonarsourceSecurity: {}, - 'pciDss-3.2': {}, - 'pciDss-4.0': {}, - 'owaspAsvs-4.0': {}, - }} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainer-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainer-test.tsx deleted file mode 100644 index ccc25e4f5e2..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainer-test.tsx +++ /dev/null @@ -1,221 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { range } from 'lodash'; -import * as React from 'react'; -import { getSources } from '../../../../api/components'; -import { mockBranch } from '../../../../helpers/mocks/branch-like'; -import { mockComponent } from '../../../../helpers/mocks/component'; -import { mockHotspot, mockHotspotComponent } from '../../../../helpers/mocks/security-hotspots'; -import { mockSourceLine } from '../../../../helpers/mocks/sources'; -import { mockFlowLocation } from '../../../../helpers/testMocks'; -import { waitAndUpdate } from '../../../../helpers/testUtils'; -import { ComponentQualifier } from '../../../../types/component'; -import HotspotSnippetContainer from '../HotspotSnippetContainer'; -import HotspotSnippetContainerRenderer from '../HotspotSnippetContainerRenderer'; - -jest.mock('../../../../api/components', () => ({ - getSources: jest.fn().mockResolvedValue([]), -})); - -jest.mock('../../../../helpers/scrolling', () => ({ - scrollToElement: jest.fn(), -})); - -beforeEach(() => jest.clearAllMocks()); - -const branch = mockBranch(); - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); -}); - -it('should load sources on mount', async () => { - (getSources as jest.Mock).mockResolvedValueOnce( - range(1, 25).map((line) => mockSourceLine({ line })) - ); - - const hotspot = mockHotspot({ - project: mockHotspotComponent({ branch: branch.name, qualifier: ComponentQualifier.Project }), - textRange: { startLine: 10, endLine: 11, startOffset: 0, endOffset: 12 }, - flows: [ - { - locations: [ - mockFlowLocation({ - textRange: { startLine: 8, endLine: 8, startOffset: 0, endOffset: 1 }, - }), - mockFlowLocation({ - textRange: { startLine: 13, endLine: 13, startOffset: 0, endOffset: 1 }, - }), - ], - }, - ], - }); - - const wrapper = shallowRender({ hotspot }); - - await waitAndUpdate(wrapper); - - expect(getSources).toHaveBeenCalledWith( - expect.objectContaining({ - key: hotspot.component.key, - branch: branch.name, - from: 1, - to: 24, - }) - ); - expect(wrapper.state().lastLine).toBeUndefined(); - expect(wrapper.state().sourceLines).toHaveLength(23); -}); - -it('should handle load sources failure', async () => { - (getSources as jest.Mock).mockRejectedValueOnce(null); - - const wrapper = shallowRender(); - - await waitAndUpdate(wrapper); - - expect(getSources).toHaveBeenCalled(); - expect(wrapper.state().loading).toBe(false); - expect(wrapper.state().lastLine).toBeUndefined(); - expect(wrapper.state().sourceLines).toHaveLength(0); -}); - -it('should not load sources on mount when the hotspot is not associated to any loc', async () => { - const hotspot = mockHotspot({ - line: undefined, - textRange: undefined, - }); - - const wrapper = shallowRender({ hotspot }); - - await waitAndUpdate(wrapper); - - expect(getSources).not.toHaveBeenCalled(); - expect(wrapper.state().lastLine).toBeUndefined(); - expect(wrapper.state().sourceLines).toHaveLength(0); -}); - -it('should handle end-of-file on mount', async () => { - (getSources as jest.Mock).mockResolvedValueOnce( - range(5, 15).map((line) => mockSourceLine({ line })) - ); - - const hotspot = mockHotspot({ - textRange: { startLine: 10, endLine: 11, startOffset: 0, endOffset: 12 }, - }); - - const wrapper = shallowRender({ hotspot }); - - await waitAndUpdate(wrapper); - - expect(getSources).toHaveBeenCalled(); - expect(wrapper.state().lastLine).toBe(14); - expect(wrapper.state().sourceLines).toHaveLength(10); -}); - -describe('Expansion', () => { - beforeEach(() => { - (getSources as jest.Mock).mockResolvedValueOnce( - range(10, 32).map((line) => mockSourceLine({ line })) - ); - }); - - const hotspot = mockHotspot({ - project: mockHotspotComponent({ branch: branch.name, qualifier: ComponentQualifier.Project }), - textRange: { startLine: 20, endLine: 21, startOffset: 0, endOffset: 12 }, - }); - - it('up should work', async () => { - (getSources as jest.Mock).mockResolvedValueOnce( - range(1, 10).map((line) => mockSourceLine({ line })) - ); - - const wrapper = shallowRender({ hotspot }); - await waitAndUpdate(wrapper); - - wrapper.find(HotspotSnippetContainerRenderer).props().onExpandBlock('up'); - - await waitAndUpdate(wrapper); - - expect(getSources).toHaveBeenCalledWith( - expect.objectContaining({ - branch: branch.name, - }) - ); - expect(wrapper.state().sourceLines).toHaveLength(31); - }); - - it('down should work', async () => { - (getSources as jest.Mock).mockResolvedValueOnce( - // lastLine + expand + extra for EOF check + range end is excluded - // 31 + 50 + 1 + 1 - range(32, 83).map((line) => mockSourceLine({ line })) - ); - - const wrapper = shallowRender({ hotspot }); - await waitAndUpdate(wrapper); - - wrapper.find(HotspotSnippetContainerRenderer).props().onExpandBlock('down'); - - await waitAndUpdate(wrapper); - - expect(wrapper.state().lastLine).toBeUndefined(); - expect(wrapper.state().sourceLines).toHaveLength(72); - }); - - it('down should work and handle EOF', async () => { - (getSources as jest.Mock).mockResolvedValueOnce( - // lastLine + expand + extra for EOF check + range end is excluded - 1 to trigger end-of-file - // 26 + 50 + 1 + 1 - 1 - range(27, 77).map((line) => mockSourceLine({ line })) - ); - - const wrapper = shallowRender({ hotspot }); - await waitAndUpdate(wrapper); - - wrapper.find(HotspotSnippetContainerRenderer).props().onExpandBlock('down'); - - await waitAndUpdate(wrapper); - - expect(wrapper.state().lastLine).toBe(76); - expect(wrapper.state().sourceLines).toHaveLength(72); - }); -}); - -it('should handle symbol click', () => { - const wrapper = shallowRender(); - const symbols = ['symbol']; - wrapper.find(HotspotSnippetContainerRenderer).props().onSymbolClick(symbols); - expect(wrapper.state().highlightedSymbols).toBe(symbols); -}); - -function shallowRender(props?: Partial<HotspotSnippetContainer['props']>) { - return shallow<HotspotSnippetContainer>( - <HotspotSnippetContainer - branchLike={branch} - component={mockComponent()} - hotspot={mockHotspot()} - onCommentButtonClick={jest.fn()} - onLocationSelect={jest.fn()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainerRenderer-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainerRenderer-test.tsx deleted file mode 100644 index cd01b0ca4c1..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainerRenderer-test.tsx +++ /dev/null @@ -1,177 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 React, { RefObject } from 'react'; -import { mockMainBranch } from '../../../../helpers/mocks/branch-like'; -import { mockComponent } from '../../../../helpers/mocks/component'; -import { mockHotspot } from '../../../../helpers/mocks/security-hotspots'; -import { mockSourceLine, mockSourceViewerFile } from '../../../../helpers/mocks/sources'; -import { scrollToElement } from '../../../../helpers/scrolling'; -import SnippetViewer from '../../../issues/crossComponentSourceViewer/SnippetViewer'; -import HotspotSnippetContainerRenderer, { - animateExpansion, - getScrollHandler, - HotspotSnippetContainerRendererProps, -} from '../HotspotSnippetContainerRenderer'; - -jest.mock('../../../../helpers/scrolling', () => ({ - scrollToElement: jest.fn(), -})); - -beforeEach(() => { - jest.spyOn(React, 'useMemo').mockImplementationOnce((f) => f()); -}); - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); - expect(shallowRender({ sourceLines: [mockSourceLine()] })).toMatchSnapshot('with sourcelines'); -}); - -it('should render a HotspotPrimaryLocationBox', () => { - const wrapper = shallowRender({ - hotspot: mockHotspot({ line: 42 }), - sourceLines: [mockSourceLine()], - }); - - const { renderAdditionalChildInLine } = wrapper.find(SnippetViewer).props(); - - expect(renderAdditionalChildInLine!(mockSourceLine({ line: 10 }))).toBeUndefined(); - expect(renderAdditionalChildInLine!(mockSourceLine({ line: 42 }))).not.toBeUndefined(); -}); - -it('should render correctly when secondary location is selected', () => { - const wrapper = shallowRender({ - selectedHotspotLocation: 1, - }); - expect(wrapper).toMatchSnapshot('with selected hotspot location'); -}); - -describe('scrolling', () => { - beforeAll(() => { - jest.useFakeTimers(); - }); - - afterAll(() => { - jest.useRealTimers(); - }); - - beforeEach(() => { - jest.clearAllMocks(); - }); - - it('should scroll to element if parent is defined', () => { - const ref: RefObject<HTMLDivElement> = { - current: document.createElement('div'), - }; - - const scrollHandler = getScrollHandler(ref); - - const targetElement = document.createElement('div'); - - scrollHandler(targetElement); - jest.runAllTimers(); - - expect(scrollToElement).toHaveBeenCalled(); - }); - - it('should not scroll if parent is undefined', () => { - const ref: RefObject<HTMLDivElement> = { - current: null, - }; - - const scrollHandler = getScrollHandler(ref); - - const targetElement = document.createElement('div'); - - scrollHandler(targetElement); - jest.runAllTimers(); - - expect(scrollToElement).not.toHaveBeenCalled(); - }); -}); - -describe('expand', () => { - it('should work as expected', async () => { - jest.useFakeTimers(); - const onExpandBlock = jest.fn().mockResolvedValue({}); - - const scrollableNode = document.createElement('div'); - scrollableNode.scrollTo = jest.fn(); - const ref: RefObject<HTMLDivElement> = { - current: scrollableNode, - }; - - jest.spyOn(React, 'useRef').mockReturnValue(ref); - - const snippet = document.createElement('div'); - const table = document.createElement('table'); - snippet.appendChild(table); - scrollableNode.querySelector = jest.fn().mockReturnValue(snippet); - - jest - .spyOn(table, 'getBoundingClientRect') - .mockReturnValueOnce({ height: 42 } as DOMRect) - .mockReturnValueOnce({ height: 99 } as DOMRect) - .mockReturnValueOnce({ height: 99 } as DOMRect) - .mockReturnValueOnce({ height: 112 } as DOMRect); - - await animateExpansion(ref, onExpandBlock, 'up'); - expect(onExpandBlock).toHaveBeenCalledWith('up'); - - expect(snippet).toHaveStyle({ maxHeight: '42px' }); - expect(table).toHaveStyle({ marginTop: '-57px' }); - - jest.advanceTimersByTime(100); - - expect(snippet).toHaveStyle({ maxHeight: '99px' }); - expect(table).toHaveStyle({ marginTop: '0px' }); - - expect(scrollableNode.scrollTo).not.toHaveBeenCalled(); - - jest.runAllTimers(); - - await animateExpansion(ref, onExpandBlock, 'down'); - expect(onExpandBlock).toHaveBeenCalledWith('down'); - expect(snippet).toHaveStyle({ maxHeight: '112px' }); - - jest.useRealTimers(); - }); -}); - -function shallowRender(props?: Partial<HotspotSnippetContainerRendererProps>) { - return shallow( - <HotspotSnippetContainerRenderer - branchLike={mockMainBranch()} - highlightedSymbols={[]} - hotspot={mockHotspot()} - loading={false} - locations={{}} - onCommentButtonClick={jest.fn()} - onExpandBlock={jest.fn()} - onSymbolClick={jest.fn()} - secondaryLocations={[]} - sourceLines={[]} - sourceViewerFile={mockSourceViewerFile()} - component={mockComponent()} - onLocationSelect={jest.fn()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetHeader-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetHeader-test.tsx deleted file mode 100644 index a1a77d6c72d..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetHeader-test.tsx +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 React from 'react'; -import { mockComponent } from '../../../../helpers/mocks/component'; -import { mockHotspot } from '../../../../helpers/mocks/security-hotspots'; -import { mockCurrentUser, mockLoggedInUser } from '../../../../helpers/testMocks'; -import { ComponentQualifier } from '../../../../types/component'; -import { HotspotSnippetHeader, HotspotSnippetHeaderProps } from '../HotspotSnippetHeader'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot('user not logged in'); - expect(shallowRender({ currentUser: mockLoggedInUser() })).toMatchSnapshot('user logged in'); - expect( - shallowRender({ - currentUser: mockLoggedInUser(), - component: mockComponent({ qualifier: ComponentQualifier.Application }), - }) - ).toMatchSnapshot('user logged in with project Name'); -}); - -function shallowRender(props: Partial<HotspotSnippetHeaderProps> = {}) { - return shallow( - <HotspotSnippetHeader - hotspot={mockHotspot()} - currentUser={mockCurrentUser()} - component={mockComponent()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewer-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewer-test.tsx deleted file mode 100644 index 9ce369d647c..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewer-test.tsx +++ /dev/null @@ -1,188 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { clone } from 'lodash'; -import * as React from 'react'; -import { getRuleDetails } from '../../../../api/rules'; -import { getSecurityHotspotDetails } from '../../../../api/security-hotspots'; -import { mockComponent } from '../../../../helpers/mocks/component'; -import { scrollToElement } from '../../../../helpers/scrolling'; -import { mockRuleDetails } from '../../../../helpers/testMocks'; -import { waitAndUpdate } from '../../../../helpers/testUtils'; -import { HotspotStatusOption } from '../../../../types/security-hotspots'; -import { RuleDescriptionSections } from '../../../coding-rules/rule'; -import HotspotViewer from '../HotspotViewer'; -import HotspotViewerRenderer from '../HotspotViewerRenderer'; - -const hotspotKey = 'hotspot-key'; - -jest.mock('../../../../api/security-hotspots', () => ({ - getSecurityHotspotDetails: jest - .fn() - .mockResolvedValue({ id: `I am a detailled hotspot`, rule: {} }), -})); - -jest.mock('../../../../api/rules', () => ({ - getRuleDetails: jest.fn().mockResolvedValue({ rule: { descriptionSections: [] } }), -})); - -jest.mock('../../../../helpers/scrolling', () => ({ - scrollToElement: jest.fn(), -})); - -it('should render correctly', async () => { - const wrapper = shallowRender(); - expect(wrapper).toMatchSnapshot(); - - await waitAndUpdate(wrapper); - - expect(wrapper).toMatchSnapshot(); - expect(getSecurityHotspotDetails).toHaveBeenCalledWith(hotspotKey); - - const newHotspotKey = `new-${hotspotKey}`; - wrapper.setProps({ hotspotKey: newHotspotKey }); - - await waitAndUpdate(wrapper); - expect(getSecurityHotspotDetails).toHaveBeenCalledWith(newHotspotKey); -}); - -it('should render fetch rule details', async () => { - (getRuleDetails as jest.Mock).mockResolvedValueOnce({ - rule: mockRuleDetails({ - descriptionSections: [ - { - key: RuleDescriptionSections.ASSESS_THE_PROBLEM, - content: 'assess', - }, - { - key: RuleDescriptionSections.ROOT_CAUSE, - content: 'cause', - }, - { - key: RuleDescriptionSections.HOW_TO_FIX, - content: 'how', - }, - ], - }), - }); - const wrapper = shallowRender(); - await waitAndUpdate(wrapper); - - expect(wrapper.state().ruleDescriptionSections).toStrictEqual([ - { - key: RuleDescriptionSections.ASSESS_THE_PROBLEM, - content: 'assess', - }, - { - key: RuleDescriptionSections.ROOT_CAUSE, - content: 'cause', - }, - { - key: RuleDescriptionSections.HOW_TO_FIX, - content: 'how', - }, - ]); -}); - -it('should refresh hotspot list on status update', () => { - const onUpdateHotspot = jest.fn(); - const wrapper = shallowRender({ onUpdateHotspot }); - wrapper.find(HotspotViewerRenderer).props().onUpdateHotspot(true); - expect(onUpdateHotspot).toHaveBeenCalled(); -}); - -it('should store last status selected when updating a hotspot status', () => { - const wrapper = shallowRender(); - - expect(wrapper.state().lastStatusChangedTo).toBeUndefined(); - wrapper.find(HotspotViewerRenderer).props().onUpdateHotspot(true, HotspotStatusOption.FIXED); - expect(wrapper.state().lastStatusChangedTo).toBe(HotspotStatusOption.FIXED); -}); - -it('should correctly propagate a request to switch the status filter', () => { - const onSwitchStatusFilter = jest.fn(); - const wrapper = shallowRender({ onSwitchStatusFilter }); - - wrapper.instance().handleSwitchFilterToStatusOfUpdatedHotspot(); - expect(onSwitchStatusFilter).not.toHaveBeenCalled(); - - wrapper.setState({ lastStatusChangedTo: HotspotStatusOption.FIXED }); - wrapper.instance().handleSwitchFilterToStatusOfUpdatedHotspot(); - expect(onSwitchStatusFilter).toHaveBeenCalledWith(HotspotStatusOption.FIXED); -}); - -it('should correctly close the success modal', () => { - const wrapper = shallowRender(); - wrapper.setState({ showStatusUpdateSuccessModal: true }); - wrapper.instance().handleCloseStatusUpdateSuccessModal(); - expect(wrapper.state().showStatusUpdateSuccessModal).toBe(false); -}); - -it('should NOT refresh hotspot list on assignee/comment updates', () => { - const onUpdateHotspot = jest.fn(); - const wrapper = shallowRender({ onUpdateHotspot }); - wrapper.find(HotspotViewerRenderer).props().onUpdateHotspot(); - expect(onUpdateHotspot).not.toHaveBeenCalled(); -}); - -it('should scroll to comment form', () => { - const wrapper = shallowRender(); - const mockTextRef = { - current: { focus: jest.fn() }, - } as any as React.RefObject<HTMLTextAreaElement>; - wrapper.instance().commentTextRef = mockTextRef; - - wrapper.find(HotspotViewerRenderer).simulate('showCommentForm'); - - expect(mockTextRef.current?.focus).toHaveBeenCalled(); - expect(scrollToElement).toHaveBeenCalledWith(mockTextRef.current, expect.anything()); -}); - -it('should reset loading even on fetch error', async () => { - const mockGetHostpot = getSecurityHotspotDetails as jest.Mock; - mockGetHostpot.mockRejectedValueOnce({}); - - const wrapper = shallowRender(); - await waitAndUpdate(wrapper); - - expect(wrapper.state().loading).toBe(false); -}); - -it('should keep state on unmoint', () => { - const wrapper = shallowRender(); - wrapper.instance().componentWillUnmount(); - const prevState = clone(wrapper.state()); - - wrapper.find(HotspotViewerRenderer).simulate('updateHotspot'); - expect(wrapper.state()).toStrictEqual(prevState); -}); - -function shallowRender(props?: Partial<HotspotViewer['props']>) { - return shallow<HotspotViewer>( - <HotspotViewer - component={mockComponent()} - hotspotKey={hotspotKey} - onSwitchStatusFilter={jest.fn()} - onUpdateHotspot={jest.fn()} - onLocationClick={jest.fn()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewerRenderer-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewerRenderer-test.tsx deleted file mode 100644 index 53008469164..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewerRenderer-test.tsx +++ /dev/null @@ -1,71 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { mockComponent } from '../../../../helpers/mocks/component'; -import { mockHotspot } from '../../../../helpers/mocks/security-hotspots'; -import { mockCurrentUser, mockUser } from '../../../../helpers/testMocks'; -import { HotspotStatusOption } from '../../../../types/security-hotspots'; -import { HotspotViewerRenderer, HotspotViewerRendererProps } from '../HotspotViewerRenderer'; - -jest.mock('../../../../helpers/users', () => ({ isLoggedIn: jest.fn(() => true) })); - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot('default'); - expect(shallowRender({ showStatusUpdateSuccessModal: true })).toMatchSnapshot( - 'show success modal' - ); - expect(shallowRender({ hotspot: undefined })).toMatchSnapshot('no hotspot'); - expect(shallowRender({ hotspot: mockHotspot({ assignee: undefined }) })).toMatchSnapshot( - 'unassigned' - ); - expect( - shallowRender({ hotspot: mockHotspot({ assigneeUser: mockUser({ active: false }) }) }) - ).toMatchSnapshot('deleted assignee'); - expect( - shallowRender({ - hotspot: mockHotspot({ - assigneeUser: mockUser({ name: undefined, login: 'assignee_login' }), - }), - }) - ).toMatchSnapshot('assignee without name'); - expect(shallowRender()).toMatchSnapshot('anonymous user'); -}); - -function shallowRender(props?: Partial<HotspotViewerRendererProps>) { - return shallow( - <HotspotViewerRenderer - component={mockComponent()} - commentTextRef={React.createRef()} - currentUser={mockCurrentUser()} - hotspot={mockHotspot()} - hotspotsReviewedMeasure="75" - lastStatusChangedTo={HotspotStatusOption.FIXED} - loading={false} - onCloseStatusUpdateSuccessModal={jest.fn()} - onSwitchFilterToStatusOfUpdatedHotspot={jest.fn()} - onShowCommentForm={jest.fn()} - onUpdateHotspot={jest.fn()} - showStatusUpdateSuccessModal={false} - onLocationClick={jest.fn()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewerTabs-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewerTabs-test.tsx deleted file mode 100644 index d5648c16dd4..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewerTabs-test.tsx +++ /dev/null @@ -1,210 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { mount, shallow } from 'enzyme'; -import * as React from 'react'; -import BoxedTabs, { BoxedTabsProps } from '../../../../components/controls/BoxedTabs'; -import { KeyboardKeys } from '../../../../helpers/keycodes'; -import { mockHotspot } from '../../../../helpers/mocks/security-hotspots'; -import { mockUser } from '../../../../helpers/testMocks'; -import { mockEvent } from '../../../../helpers/testUtils'; -import { RuleDescriptionSections } from '../../../coding-rules/rule'; -import HotspotViewerTabs, { TabKeys } from '../HotspotViewerTabs'; - -const originalAddEventListener = window.addEventListener; -const originalRemoveEventListener = window.removeEventListener; - -beforeEach(() => { - Object.defineProperty(window, 'addEventListener', { - value: jest.fn(), - }); - Object.defineProperty(window, 'removeEventListener', { - value: jest.fn(), - }); -}); - -afterEach(() => { - Object.defineProperty(window, 'addEventListener', { - value: originalAddEventListener, - }); - Object.defineProperty(window, 'removeEventListener', { - value: originalRemoveEventListener, - }); -}); - -it('should render correctly', () => { - const wrapper = shallowRender(); - expect(wrapper).toMatchSnapshot('risk'); - - const onSelect: (tab: TabKeys) => void = wrapper.find(BoxedTabs).prop('onSelect'); - - onSelect(TabKeys.VulnerabilityDescription); - expect(wrapper).toMatchSnapshot('vulnerability'); - - onSelect(TabKeys.FixRecommendation); - expect(wrapper).toMatchSnapshot('fix'); - - expect( - shallowRender({ - hotspot: mockHotspot({ - creationDate: undefined, - }), - ruleDescriptionSections: undefined, - }) - .find<BoxedTabsProps<string>>(BoxedTabs) - .props().tabs - ).toHaveLength(1); - - expect( - shallowRender({ - hotspot: mockHotspot({ - comment: [ - { - createdAt: '2019-01-01', - htmlText: '<strong>test</strong>', - key: 'comment-key', - login: 'me', - markdown: '*test*', - updatable: false, - user: mockUser(), - }, - ], - }), - }) - ).toMatchSnapshot('with comments or changelog element'); -}); - -it('should filter empty tab', () => { - const count = shallowRender({ - hotspot: mockHotspot(), - }).state().tabs.length; - - expect( - shallowRender({ - ruleDescriptionSections: [ - { - key: RuleDescriptionSections.ROOT_CAUSE, - content: 'cause', - }, - { - key: RuleDescriptionSections.HOW_TO_FIX, - content: 'how', - }, - ], - }).state().tabs.length - ).toBe(count - 1); -}); - -it('should select first tab on hotspot update', () => { - const wrapper = shallowRender(); - const onSelect: (tab: TabKeys) => void = wrapper.find(BoxedTabs).prop('onSelect'); - - onSelect(TabKeys.VulnerabilityDescription); - expect(wrapper.state().currentTab.key).toBe(TabKeys.VulnerabilityDescription); - wrapper.setProps({ hotspot: mockHotspot({ key: 'new_key' }) }); - expect(wrapper.state().currentTab.key).toBe(TabKeys.Code); -}); - -it('should select first tab when hotspot location is selected and is not undefined', () => { - const wrapper = shallowRender(); - const onSelect: (tab: TabKeys) => void = wrapper.find(BoxedTabs).prop('onSelect'); - - onSelect(TabKeys.VulnerabilityDescription); - expect(wrapper.state().currentTab.key).toBe(TabKeys.VulnerabilityDescription); - - wrapper.setProps({ selectedHotspotLocation: 1 }); - expect(wrapper.state().currentTab.key).toBe(TabKeys.Code); - - onSelect(TabKeys.VulnerabilityDescription); - expect(wrapper.state().currentTab.key).toBe(TabKeys.VulnerabilityDescription); - - wrapper.setProps({ selectedHotspotLocation: undefined }); - expect(wrapper.state().currentTab.key).toBe(TabKeys.VulnerabilityDescription); -}); - -describe('keyboard navigation', () => { - const tabList = [ - TabKeys.Code, - TabKeys.RiskDescription, - TabKeys.VulnerabilityDescription, - TabKeys.FixRecommendation, - ]; - const wrapper = shallowRender(); - - it.each([ - ['selecting next', 0, KeyboardKeys.RightArrow, 1], - ['selecting previous', 1, KeyboardKeys.LeftArrow, 0], - ['selecting previous, non-existent', 0, KeyboardKeys.LeftArrow, 0], - ['selecting next, non-existent', 3, KeyboardKeys.RightArrow, 3], - ])('should work when %s', (_, start, key, expected) => { - wrapper.setState({ currentTab: wrapper.state().tabs[start] }); - wrapper.instance().handleKeyboardNavigation(mockEvent({ key })); - - expect(wrapper.state().currentTab.key).toBe(tabList[expected]); - }); -}); - -it("shouldn't navigate when ctrl or command are pressed with up and down", () => { - const wrapper = mount<HotspotViewerTabs>( - <HotspotViewerTabs codeTabContent={<div>CodeTabContent</div>} hotspot={mockHotspot()} /> - ); - - wrapper.setState({ currentTab: wrapper.state().tabs[0] }); - wrapper - .instance() - .handleKeyboardNavigation(mockEvent({ key: KeyboardKeys.LeftArrow, metaKey: true })); - - expect(wrapper.state().currentTab.key).toBe(TabKeys.Code); -}); - -it('should navigate when up and down key are pressed', () => { - const wrapper = mount<HotspotViewerTabs>( - <HotspotViewerTabs codeTabContent={<div>CodeTabContent</div>} hotspot={mockHotspot()} /> - ); - - expect(window.addEventListener).toHaveBeenCalled(); - - wrapper.unmount(); - - expect(window.removeEventListener).toHaveBeenCalled(); -}); - -function shallowRender(props?: Partial<HotspotViewerTabs['props']>) { - return shallow<HotspotViewerTabs>( - <HotspotViewerTabs - codeTabContent={<div>CodeTabContent</div>} - hotspot={mockHotspot()} - ruleDescriptionSections={[ - { - key: RuleDescriptionSections.ASSESS_THE_PROBLEM, - content: 'assess', - }, - { - key: RuleDescriptionSections.ROOT_CAUSE, - content: 'cause', - }, - { - key: RuleDescriptionSections.HOW_TO_FIX, - content: 'how', - }, - ]} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/StatusUpdateSuccessModal-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/StatusUpdateSuccessModal-test.tsx deleted file mode 100644 index 41f9085202d..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/StatusUpdateSuccessModal-test.tsx +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { HotspotStatusOption } from '../../../../types/security-hotspots'; -import StatusUpdateSuccessModal, { - StatusUpdateSuccessModalProps, -} from '../StatusUpdateSuccessModal'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot('default'); - expect(shallowRender({ lastStatusChangedTo: HotspotStatusOption.TO_REVIEW })).toMatchSnapshot( - 'opening hotspots again' - ); - expect(shallowRender({ lastStatusChangedTo: undefined }).type()).toBeNull(); -}); - -function shallowRender(props: Partial<StatusUpdateSuccessModalProps> = {}) { - return shallow<StatusUpdateSuccessModalProps>( - <StatusUpdateSuccessModal - onClose={jest.fn()} - lastStatusChangedTo={HotspotStatusOption.FIXED} - onSwitchFilterToStatusOfUpdatedHotspot={jest.fn()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/EmptyHotspotsPage-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/EmptyHotspotsPage-test.tsx.snap deleted file mode 100644 index 0a01522c9a7..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/EmptyHotspotsPage-test.tsx.snap +++ /dev/null @@ -1,105 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -<div - className="display-flex-column display-flex-center huge-spacer-top" -> - <img - alt="hotspots.page" - className="huge-spacer-top" - height={100} - src="/images/hotspot-large.svg" - /> - <h1 - className="huge-spacer-top" - > - hotspots.no_hotspots.title - </h1> - <div - className="abs-width-400 text-center big-spacer-top" - > - hotspots.no_hotspots.description - </div> - <withAppStateContext(DocLink) - className="big-spacer-top" - to="/user-guide/security-hotspots/" - > - hotspots.learn_more - </withAppStateContext(DocLink)> -</div> -`; - -exports[`should render correctly: file 1`] = ` -<div - className="display-flex-column display-flex-center huge-spacer-top" -> - <img - alt="hotspots.page" - className="huge-spacer-top" - height={100} - src="/images/hotspot-large.svg" - /> - <h1 - className="huge-spacer-top" - > - hotspots.no_hotspots_for_file.title - </h1> - <div - className="abs-width-400 text-center big-spacer-top" - > - hotspots.no_hotspots_for_file.description - </div> - <withAppStateContext(DocLink) - className="big-spacer-top" - to="/user-guide/security-hotspots/" - > - hotspots.learn_more - </withAppStateContext(DocLink)> -</div> -`; - -exports[`should render correctly: filtered 1`] = ` -<div - className="display-flex-column display-flex-center huge-spacer-top" -> - <img - alt="hotspots.page" - className="huge-spacer-top" - height={100} - src="/images/filter-large.svg" - /> - <h1 - className="huge-spacer-top" - > - hotspots.no_hotspots_for_filters.title - </h1> - <div - className="abs-width-400 text-center big-spacer-top" - > - hotspots.no_hotspots_for_filters.description - </div> -</div> -`; - -exports[`should render correctly: keys 1`] = ` -<div - className="display-flex-column display-flex-center huge-spacer-top" -> - <img - alt="hotspots.page" - className="huge-spacer-top" - height={100} - src="/images/hotspot-large.svg" - /> - <h1 - className="huge-spacer-top" - > - hotspots.no_hotspots_for_keys.title - </h1> - <div - className="abs-width-400 text-center big-spacer-top" - > - hotspots.no_hotspots_for_keys.description - </div> -</div> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/FilterBar-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/FilterBar-test.tsx.snap deleted file mode 100644 index 91edea01d57..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/FilterBar-test.tsx.snap +++ /dev/null @@ -1,589 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly when the list of hotspot is static 1`] = ` -<div - className="filter-bar-outer" -> - <div - className="filter-bar" - > - <div - className="filter-bar-inner display-flex-center" - > - <ForwardRef(Link) - to={ - { - "pathname": "/security_hotspots", - "search": "?id=my-project", - } - } - > - hotspot.filters.show_all - </ForwardRef(Link)> - </div> - </div> -</div> -`; - -exports[`should render correctly: anonymous 1`] = ` -<div - className="filter-bar-outer" -> - <div - className="filter-bar" - > - <div - className="filter-bar-inner display-flex-center" - > - <div - className="display-flex-space-between width-100" - > - <div - className="display-flex-center" - > - <h3 - className="huge-spacer-right" - > - hotspot.filters.title - </h3> - <span - className="spacer-right" - > - - status - - </span> - <Select - aria-label="hotspot.filters.status" - className="input-medium big-spacer-right" - isSearchable={false} - onChange={[Function]} - options={ - [ - { - "label": "hotspot.filters.status.to_review", - "value": "TO_REVIEW", - }, - { - "label": "hotspot.filters.status.acknowledged", - "value": "ACKNOWLEDGED", - }, - { - "label": "hotspot.filters.status.fixed", - "value": "FIXED", - }, - { - "label": "hotspot.filters.status.safe", - "value": "SAFE", - }, - ] - } - value={ - { - "label": "hotspot.filters.status.to_review", - "value": "TO_REVIEW", - } - } - /> - <Select - aria-label="hotspot.filters.period" - className="input-medium big-spacer-right" - isSearchable={false} - onChange={[Function]} - options={ - [ - { - "label": "hotspot.filters.period.since_leak_period", - "value": true, - }, - { - "label": "hotspot.filters.period.overall", - "value": false, - }, - ] - } - value={ - { - "label": "hotspot.filters.period.overall", - "value": false, - } - } - /> - </div> - <div - className="display-flex-center" - > - <span - className="little-spacer-right" - > - metric.security_hotspots_reviewed.name - </span> - <HelpTooltip - className="big-spacer-right" - overlay="hotspots.reviewed.tooltip" - /> - <DeferredSpinner - loading={false} - > - <Measure - className="spacer-left huge it__hs-review-percentage" - metricKey="security_hotspots_reviewed" - metricType="PERCENT" - /> - </DeferredSpinner> - </div> - </div> - </div> - </div> -</div> -`; - -exports[`should render correctly: logged-in 1`] = ` -<div - className="filter-bar-outer" -> - <div - className="filter-bar" - > - <div - className="filter-bar-inner display-flex-center" - > - <div - className="display-flex-space-between width-100" - > - <div - className="display-flex-center" - > - <h3 - className="huge-spacer-right" - > - hotspot.filters.title - </h3> - <span - className="huge-spacer-right" - > - <ButtonToggle - onCheck={[Function]} - options={ - [ - { - "label": "hotspot.filters.assignee.assigned_to_me", - "value": "me", - }, - { - "label": "hotspot.filters.assignee.all", - "value": "all", - }, - ] - } - value="all" - /> - </span> - <span - className="spacer-right" - > - - status - - </span> - <Select - aria-label="hotspot.filters.status" - className="input-medium big-spacer-right" - isSearchable={false} - onChange={[Function]} - options={ - [ - { - "label": "hotspot.filters.status.to_review", - "value": "TO_REVIEW", - }, - { - "label": "hotspot.filters.status.acknowledged", - "value": "ACKNOWLEDGED", - }, - { - "label": "hotspot.filters.status.fixed", - "value": "FIXED", - }, - { - "label": "hotspot.filters.status.safe", - "value": "SAFE", - }, - ] - } - value={ - { - "label": "hotspot.filters.status.to_review", - "value": "TO_REVIEW", - } - } - /> - <Select - aria-label="hotspot.filters.period" - className="input-medium big-spacer-right" - isSearchable={false} - onChange={[Function]} - options={ - [ - { - "label": "hotspot.filters.period.since_leak_period", - "value": true, - }, - { - "label": "hotspot.filters.period.overall", - "value": false, - }, - ] - } - value={ - { - "label": "hotspot.filters.period.overall", - "value": false, - } - } - /> - </div> - <div - className="display-flex-center" - > - <span - className="little-spacer-right" - > - metric.security_hotspots_reviewed.name - </span> - <HelpTooltip - className="big-spacer-right" - overlay="hotspots.reviewed.tooltip" - /> - <DeferredSpinner - loading={false} - > - <Measure - className="spacer-left huge it__hs-review-percentage" - metricKey="security_hotspots_reviewed" - metricType="PERCENT" - /> - </DeferredSpinner> - </div> - </div> - </div> - </div> -</div> -`; - -exports[`should render correctly: non-project 1`] = ` -<div - className="filter-bar-outer" -> - <div - className="filter-bar" - > - <div - className="filter-bar-inner display-flex-center" - > - <div - className="display-flex-space-between width-100" - > - <div - className="display-flex-center" - > - <h3 - className="huge-spacer-right" - > - hotspot.filters.title - </h3> - <span - className="huge-spacer-right" - > - <ButtonToggle - onCheck={[Function]} - options={ - [ - { - "label": "hotspot.filters.assignee.assigned_to_me", - "value": "me", - }, - { - "label": "hotspot.filters.assignee.all", - "value": "all", - }, - ] - } - value="all" - /> - </span> - <span - className="spacer-right" - > - - status - - </span> - <Select - aria-label="hotspot.filters.status" - className="input-medium big-spacer-right" - isSearchable={false} - onChange={[Function]} - options={ - [ - { - "label": "hotspot.filters.status.to_review", - "value": "TO_REVIEW", - }, - { - "label": "hotspot.filters.status.acknowledged", - "value": "ACKNOWLEDGED", - }, - { - "label": "hotspot.filters.status.fixed", - "value": "FIXED", - }, - { - "label": "hotspot.filters.status.safe", - "value": "SAFE", - }, - ] - } - value={ - { - "label": "hotspot.filters.status.to_review", - "value": "TO_REVIEW", - } - } - /> - <Select - aria-label="hotspot.filters.period" - className="input-medium big-spacer-right" - isSearchable={false} - onChange={[Function]} - options={ - [ - { - "label": "hotspot.filters.period.since_leak_period", - "value": true, - }, - { - "label": "hotspot.filters.period.overall", - "value": false, - }, - ] - } - value={ - { - "label": "hotspot.filters.period.overall", - "value": false, - } - } - /> - </div> - </div> - </div> - </div> -</div> -`; - -exports[`should render correctly: on Pull request 1`] = ` -<div - className="filter-bar-outer" -> - <div - className="filter-bar" - > - <div - className="filter-bar-inner display-flex-center" - > - <div - className="display-flex-space-between width-100" - > - <div - className="display-flex-center" - > - <h3 - className="huge-spacer-right" - > - hotspot.filters.title - </h3> - <span - className="spacer-right" - > - - status - - </span> - <Select - aria-label="hotspot.filters.status" - className="input-medium big-spacer-right" - isSearchable={false} - onChange={[Function]} - options={ - [ - { - "label": "hotspot.filters.status.to_review", - "value": "TO_REVIEW", - }, - { - "label": "hotspot.filters.status.acknowledged", - "value": "ACKNOWLEDGED", - }, - { - "label": "hotspot.filters.status.fixed", - "value": "FIXED", - }, - { - "label": "hotspot.filters.status.safe", - "value": "SAFE", - }, - ] - } - value={ - { - "label": "hotspot.filters.status.to_review", - "value": "TO_REVIEW", - } - } - /> - </div> - <div - className="display-flex-center" - > - <span - className="little-spacer-right" - > - metric.security_hotspots_reviewed.name - </span> - <HelpTooltip - className="big-spacer-right" - overlay="hotspots.reviewed.tooltip" - /> - <DeferredSpinner - loading={false} - > - <Measure - className="spacer-left huge it__hs-review-percentage" - metricKey="new_security_hotspots_reviewed" - metricType="PERCENT" - /> - </DeferredSpinner> - </div> - </div> - </div> - </div> -</div> -`; - -exports[`should render correctly: with hotspots reviewed measure 1`] = ` -<div - className="filter-bar-outer" -> - <div - className="filter-bar" - > - <div - className="filter-bar-inner display-flex-center" - > - <div - className="display-flex-space-between width-100" - > - <div - className="display-flex-center" - > - <h3 - className="huge-spacer-right" - > - hotspot.filters.title - </h3> - <span - className="spacer-right" - > - - status - - </span> - <Select - aria-label="hotspot.filters.status" - className="input-medium big-spacer-right" - isSearchable={false} - onChange={[Function]} - options={ - [ - { - "label": "hotspot.filters.status.to_review", - "value": "TO_REVIEW", - }, - { - "label": "hotspot.filters.status.acknowledged", - "value": "ACKNOWLEDGED", - }, - { - "label": "hotspot.filters.status.fixed", - "value": "FIXED", - }, - { - "label": "hotspot.filters.status.safe", - "value": "SAFE", - }, - ] - } - value={ - { - "label": "hotspot.filters.status.to_review", - "value": "TO_REVIEW", - } - } - /> - <Select - aria-label="hotspot.filters.period" - className="input-medium big-spacer-right" - isSearchable={false} - onChange={[Function]} - options={ - [ - { - "label": "hotspot.filters.period.since_leak_period", - "value": true, - }, - { - "label": "hotspot.filters.period.overall", - "value": false, - }, - ] - } - value={ - { - "label": "hotspot.filters.period.overall", - "value": false, - } - } - /> - </div> - <div - className="display-flex-center" - > - <span - className="little-spacer-right" - > - metric.security_hotspots_reviewed.name - </span> - <HelpTooltip - className="big-spacer-right" - overlay="hotspots.reviewed.tooltip" - /> - <DeferredSpinner - loading={false} - > - <CoverageRating - value="23.30" - /> - <Measure - className="spacer-left huge it__hs-review-percentage" - metricKey="security_hotspots_reviewed" - metricType="PERCENT" - value="23.30" - /> - </DeferredSpinner> - </div> - </div> - </div> - </div> -</div> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotCategory-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotCategory-test.tsx.snap deleted file mode 100644 index 1389d7b84fc..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotCategory-test.tsx.snap +++ /dev/null @@ -1,282 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly with hotspots 1`] = ` -<div - className="hotspot-category HIGH" -> - <ButtonPlain - aria-expanded={true} - className="hotspot-category-header display-flex-space-between display-flex-center" - onClick={[Function]} - > - <strong - className="flex-1 spacer-right break-word" - > - Class Injection - </strong> - <span> - <span - className="counter-badge" - > - 2 - </span> - <ChevronUpIcon - className="big-spacer-left" - /> - </span> - </ButtonPlain> - <ul> - <li - data-hotspot-key="h1" - key="h1" - > - <HotspotListItem - hotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h1", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - onClick={[MockFunction]} - onLocationClick={[MockFunction]} - selected={false} - /> - </li> - <li - data-hotspot-key="h2" - key="h2" - > - <HotspotListItem - hotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - onClick={[MockFunction]} - onLocationClick={[MockFunction]} - selected={false} - /> - </li> - </ul> -</div> -`; - -exports[`should render correctly with hotspots: collapsed 1`] = ` -<div - className="hotspot-category HIGH" -> - <ButtonPlain - aria-expanded={false} - className="hotspot-category-header display-flex-space-between display-flex-center" - onClick={[Function]} - > - <strong - className="flex-1 spacer-right break-word" - > - Class Injection - </strong> - <span> - <span - className="counter-badge" - > - 2 - </span> - <ChevronDownIcon - className="big-spacer-left" - /> - </span> - </ButtonPlain> -</div> -`; - -exports[`should render correctly with hotspots: contains selected 1`] = ` -<div - className="hotspot-category HIGH" -> - <ButtonPlain - aria-expanded={true} - className="hotspot-category-header display-flex-space-between display-flex-center contains-selected-hotspot" - onClick={[Function]} - > - <strong - className="flex-1 spacer-right break-word" - > - Class Injection - </strong> - <span> - <span - className="counter-badge" - > - 2 - </span> - <ChevronUpIcon - className="big-spacer-left" - /> - </span> - </ButtonPlain> - <ul> - <li - data-hotspot-key="h1" - key="h1" - > - <HotspotListItem - hotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h1", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - onClick={[MockFunction]} - onLocationClick={[MockFunction]} - selected={true} - /> - </li> - <li - data-hotspot-key="h2" - key="h2" - > - <HotspotListItem - hotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - onClick={[MockFunction]} - onLocationClick={[MockFunction]} - selected={false} - /> - </li> - </ul> -</div> -`; - -exports[`should render correctly with hotspots: lastAndIncomplete 1`] = ` -<div - className="hotspot-category HIGH" -> - <ButtonPlain - aria-expanded={true} - className="hotspot-category-header display-flex-space-between display-flex-center" - onClick={[Function]} - > - <strong - className="flex-1 spacer-right break-word" - > - Class Injection - </strong> - <span> - <span - className="counter-badge" - > - 2 - + - </span> - <ChevronUpIcon - className="big-spacer-left" - /> - </span> - </ButtonPlain> - <ul> - <li - data-hotspot-key="h1" - key="h1" - > - <HotspotListItem - hotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h1", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - onClick={[MockFunction]} - onLocationClick={[MockFunction]} - selected={false} - /> - </li> - <li - data-hotspot-key="h2" - key="h2" - > - <HotspotListItem - hotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - onClick={[MockFunction]} - onLocationClick={[MockFunction]} - selected={false} - /> - </li> - </ul> -</div> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotCommentPopup-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotCommentPopup-test.tsx.snap deleted file mode 100644 index b64b02e320e..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotCommentPopup-test.tsx.snap +++ /dev/null @@ -1,40 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correclty 1`] = ` -<div - className="issue-comment-bubble-popup" -> - <div - className="issue-comment-form-text" - > - <textarea - autoFocus={true} - onChange={[Function]} - rows={2} - value="test" - /> - </div> - <div - className="spacer-top display-flex-space-between" - > - <div - className="issue-comment-form-tips" - > - <FormattingTips /> - </div> - <div> - <Button - className="little-spacer-right" - onClick={[Function]} - > - save - </Button> - <ResetButtonLink - onClick={[Function]} - > - cancel - </ResetButtonLink> - </div> - </div> -</div> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotHeader-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotHeader-test.tsx.snap deleted file mode 100644 index 0a10135b3be..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotHeader-test.tsx.snap +++ /dev/null @@ -1,229 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -<div - className="huge-spacer-bottom hotspot-header" -> - <div - className="display-flex-column big-spacer-bottom" - > - <div - className="big text-bold" - > - <IssueMessageHighlighting - message="'3' is a magic number." - /> - </div> - <div - className="spacer-top" - > - <span - className="note padded-right" - > - That rule - </span> - <ForwardRef(Link) - className="small" - target="_blank" - to={ - { - "pathname": "/coding_rules", - "search": "?open=squid%3AS2077&rule_key=squid%3AS2077", - } - } - > - squid:S2077 - </ForwardRef(Link)> - </div> - </div> - <div - className="display-flex-space-between" - > - <withCurrentUserContext(Status) - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onStatusChange={[Function]} - /> - <div - className="display-flex-end" - > - <div - className="display-inline-flex-center it__hs-assignee" - > - <div - className="big-spacer-right" - > - assignee: - </div> - <withCurrentUserContext(Assignee) - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onAssigneeChange={[MockFunction]} - /> - </div> - </div> - </div> -</div> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotList-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotList-test.tsx.snap deleted file mode 100644 index 0a78c398346..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotList-test.tsx.snap +++ /dev/null @@ -1,624 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -<div - className="huge-spacer-bottom" -> - <h1 - className="hotspot-list-header bordered-bottom" - > - <SecurityHotspotIcon - className="spacer-right" - /> - hotspots.list_title.TO_REVIEW.0 - </h1> - <ul - className="big-spacer-bottom big-spacer-top" - /> - <ListFooter - count={0} - loadMore={[MockFunction]} - loading={false} - total={0} - /> -</div> -`; - -exports[`should render correctly 2`] = ` -<div - className="huge-spacer-bottom" -> - <h1 - className="hotspot-list-header bordered-bottom" - > - <SecurityHotspotIcon - className="spacer-right" - /> - hotspots.list_title.TO_REVIEW.0 - </h1> - <ul - className="big-spacer-bottom big-spacer-top" - /> - <ListFooter - count={0} - loading={true} - total={0} - /> -</div> -`; - -exports[`should render correctly when the list of hotspot is static 1`] = ` -<div - className="huge-spacer-bottom" -> - <h1 - className="hotspot-list-header bordered-bottom" - > - <SecurityHotspotIcon - className="spacer-right" - /> - hotspots.list_title.0 - </h1> - <ul - className="big-spacer-bottom big-spacer-top" - /> - <ListFooter - count={0} - loadMore={[MockFunction]} - loading={false} - total={0} - /> -</div> -`; - -exports[`should render correctly with hotspots: no pagination 1`] = ` -<div - className="huge-spacer-bottom" -> - <h1 - className="hotspot-list-header bordered-bottom" - > - <SecurityHotspotIcon - className="spacer-right" - /> - hotspots.list_title.TO_REVIEW.5 - </h1> - <ul - className="big-spacer-bottom big-spacer-top" - > - <li - className="big-spacer-bottom" - key="HIGH" - > - <div - className="hotspot-risk-header little-spacer-left spacer-top spacer-bottom" - > - <span> - hotspots.risk_exposure - : - </span> - <div - className="hotspot-risk-badge spacer-left HIGH" - > - risk_exposure.HIGH - </div> - </div> - <ul> - <li - className="spacer-bottom" - key="cat1" - > - <HotspotCategory - categoryKey="cat1" - hotspots={ - [ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "cat1", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - }, - ] - } - isLastAndIncomplete={false} - onHotspotClick={[MockFunction]} - onLocationClick={[MockFunction]} - onToggleExpand={[Function]} - selectedHotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - title="cat1" - /> - </li> - <li - className="spacer-bottom" - key="cat2" - > - <HotspotCategory - categoryKey="cat2" - hotspots={ - [ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h1", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "cat2", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - }, - ] - } - isLastAndIncomplete={false} - onHotspotClick={[MockFunction]} - onLocationClick={[MockFunction]} - onToggleExpand={[Function]} - selectedHotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - title="cat2" - /> - </li> - </ul> - </li> - <li - className="big-spacer-bottom" - key="MEDIUM" - > - <div - className="hotspot-risk-header little-spacer-left spacer-top spacer-bottom" - > - <span> - hotspots.risk_exposure - : - </span> - <div - className="hotspot-risk-badge spacer-left MEDIUM" - > - risk_exposure.MEDIUM - </div> - </div> - <ul> - <li - className="spacer-bottom" - key="cat1" - > - <HotspotCategory - categoryKey="cat1" - hotspots={ - [ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h3", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "cat1", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "MEDIUM", - }, - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h4", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "cat1", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "MEDIUM", - }, - ] - } - isLastAndIncomplete={false} - onHotspotClick={[MockFunction]} - onLocationClick={[MockFunction]} - onToggleExpand={[Function]} - selectedHotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - title="cat1" - /> - </li> - <li - className="spacer-bottom" - key="cat2" - > - <HotspotCategory - categoryKey="cat2" - hotspots={ - [ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h5", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "cat2", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "MEDIUM", - }, - ] - } - isLastAndIncomplete={false} - onHotspotClick={[MockFunction]} - onLocationClick={[MockFunction]} - onToggleExpand={[Function]} - selectedHotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - title="cat2" - /> - </li> - </ul> - </li> - </ul> - <ListFooter - count={5} - loadMore={[MockFunction]} - loading={false} - total={5} - /> -</div> -`; - -exports[`should render correctly with hotspots: pagination 1`] = ` -<div - className="huge-spacer-bottom" -> - <h1 - className="hotspot-list-header bordered-bottom" - > - <SecurityHotspotIcon - className="spacer-right" - /> - hotspots.list_title.TO_REVIEW.7 - </h1> - <ul - className="big-spacer-bottom big-spacer-top" - > - <li - className="big-spacer-bottom" - key="HIGH" - > - <div - className="hotspot-risk-header little-spacer-left spacer-top spacer-bottom" - > - <span> - hotspots.risk_exposure - : - </span> - <div - className="hotspot-risk-badge spacer-left HIGH" - > - risk_exposure.HIGH - </div> - </div> - <ul> - <li - className="spacer-bottom" - key="cat1" - > - <HotspotCategory - categoryKey="cat1" - hotspots={ - [ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "cat1", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - }, - ] - } - isLastAndIncomplete={false} - onHotspotClick={[MockFunction]} - onLocationClick={[MockFunction]} - onToggleExpand={[Function]} - selectedHotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - title="cat1" - /> - </li> - <li - className="spacer-bottom" - key="cat2" - > - <HotspotCategory - categoryKey="cat2" - hotspots={ - [ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h1", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "cat2", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - }, - ] - } - isLastAndIncomplete={false} - onHotspotClick={[MockFunction]} - onLocationClick={[MockFunction]} - onToggleExpand={[Function]} - selectedHotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - title="cat2" - /> - </li> - </ul> - </li> - <li - className="big-spacer-bottom" - key="MEDIUM" - > - <div - className="hotspot-risk-header little-spacer-left spacer-top spacer-bottom" - > - <span> - hotspots.risk_exposure - : - </span> - <div - className="hotspot-risk-badge spacer-left MEDIUM" - > - risk_exposure.MEDIUM - </div> - </div> - <ul> - <li - className="spacer-bottom" - key="cat1" - > - <HotspotCategory - categoryKey="cat1" - hotspots={ - [ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h3", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "cat1", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "MEDIUM", - }, - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h4", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "cat1", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "MEDIUM", - }, - ] - } - isLastAndIncomplete={false} - onHotspotClick={[MockFunction]} - onLocationClick={[MockFunction]} - onToggleExpand={[Function]} - selectedHotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - title="cat1" - /> - </li> - <li - className="spacer-bottom" - key="cat2" - > - <HotspotCategory - categoryKey="cat2" - hotspots={ - [ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h5", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "cat2", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "MEDIUM", - }, - ] - } - isLastAndIncomplete={true} - onHotspotClick={[MockFunction]} - onLocationClick={[MockFunction]} - onToggleExpand={[Function]} - selectedHotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - title="cat2" - /> - </li> - </ul> - </li> - </ul> - <ListFooter - count={5} - loadMore={[MockFunction]} - loading={false} - total={7} - /> -</div> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotListItem-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotListItem-test.tsx.snap deleted file mode 100644 index c9f80cab22d..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotListItem-test.tsx.snap +++ /dev/null @@ -1,70 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -<ButtonPlain - aria-current={false} - className="hotspot-item" - onClick={[Function]} -> - <div - className="little-spacer-left text-bold" - > - <IssueMessageHighlighting - message="'3' is a magic number." - /> - </div> - <div - className="display-flex-center big-spacer-top" - > - <QualifierIcon - qualifier="FIL" - /> - <div - className="little-spacer-left hotspot-box-filename text-ellipsis" - title="com.github.kevinsawicki.http.HttpRequest" - > - <bdi> - com.github.kevinsawicki.http.HttpRequest - </bdi> - </div> - </div> -</ButtonPlain> -`; - -exports[`should render correctly 2`] = ` -<ButtonPlain - aria-current={true} - className="hotspot-item highlight" - onClick={[Function]} -> - <div - className="little-spacer-left text-bold cursor-pointer" - onClick={[Function]} - > - <IssueMessageHighlighting - message="'3' is a magic number." - /> - </div> - <div - className="display-flex-center big-spacer-top" - > - <QualifierIcon - qualifier="FIL" - /> - <div - className="little-spacer-left hotspot-box-filename text-ellipsis" - title="com.github.kevinsawicki.http.HttpRequest" - > - <bdi> - com.github.kevinsawicki.http.HttpRequest - </bdi> - </div> - </div> - <LocationsList - componentKey="com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest" - locations={[]} - onLocationSelect={[Function]} - showCrossFile={false} - /> -</ButtonPlain> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotOpenInIdeButton-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotOpenInIdeButton-test.tsx.snap deleted file mode 100644 index 6cd6c5e4266..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotOpenInIdeButton-test.tsx.snap +++ /dev/null @@ -1,89 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`HotspotOpenInIdeButton should handle several IDE 1`] = ` -<Toggler - onRequestClose={[Function]} - open={false} - overlay={ - <DropdownOverlay> - <HotspotOpenInIdeOverlay - ides={[]} - onIdeSelected={[Function]} - /> - </DropdownOverlay> - } -> - <Button - onClick={[Function]} - > - hotspots.open_in_ide.open - <DeferredSpinner - className="spacer-left" - loading={false} - /> - </Button> -</Toggler> -`; - -exports[`HotspotOpenInIdeButton should handle several IDE: dropdown open 1`] = ` -<Toggler - onRequestClose={[Function]} - open={true} - overlay={ - <DropdownOverlay> - <HotspotOpenInIdeOverlay - ides={ - [ - { - "description": "Hello World", - "ideName": "BlueJ IDE", - "port": 42000, - }, - { - "description": "Blink", - "ideName": "Arduino IDE", - "port": 42001, - }, - ] - } - onIdeSelected={[Function]} - /> - </DropdownOverlay> - } -> - <Button - onClick={[Function]} - > - hotspots.open_in_ide.open - <DeferredSpinner - className="spacer-left" - loading={false} - /> - </Button> -</Toggler> -`; - -exports[`HotspotOpenInIdeButton should render correctly 1`] = ` -<Toggler - onRequestClose={[Function]} - open={false} - overlay={ - <DropdownOverlay> - <HotspotOpenInIdeOverlay - ides={[]} - onIdeSelected={[Function]} - /> - </DropdownOverlay> - } -> - <Button - onClick={[Function]} - > - hotspots.open_in_ide.open - <DeferredSpinner - className="spacer-left" - loading={false} - /> - </Button> -</Toggler> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotOpenInIdeOverlay-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotOpenInIdeOverlay-test.tsx.snap deleted file mode 100644 index 47edfaa8c8f..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotOpenInIdeOverlay-test.tsx.snap +++ /dev/null @@ -1,28 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render menu and select the right IDE 1`] = ` -<ul - className="menu" -> - <li - key="0" - > - <a - href="#" - onClick={[Function]} - > - Polop - Plouf - </a> - </li> - <li - key="1" - > - <a - href="#" - onClick={[Function]} - > - Foo - </a> - </li> -</ul> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotPrimaryLocationBox-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotPrimaryLocationBox-test.tsx.snap deleted file mode 100644 index 4d3f324977c..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotPrimaryLocationBox-test.tsx.snap +++ /dev/null @@ -1,35 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly: User logged in 1`] = ` -<div - className="hotspot-primary-location display-flex-space-between display-flex-center padded-top padded-bottom big-padded-left big-padded-right hotspot-risk-exposure-HIGH" -> - <div - className="text-bold" - > - <IssueMessageHighlighting - message="'3' is a magic number." - /> - </div> - <ButtonLink - className="nowrap big-spacer-left it__hs-add-comment" - onClick={[MockFunction]} - > - hotspots.comment.open - </ButtonLink> -</div> -`; - -exports[`should render correctly: User not logged in 1`] = ` -<div - className="hotspot-primary-location display-flex-space-between display-flex-center padded-top padded-bottom big-padded-left big-padded-right hotspot-risk-exposure-HIGH" -> - <div - className="text-bold" - > - <IssueMessageHighlighting - message="'3' is a magic number." - /> - </div> -</div> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotReviewHistory-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotReviewHistory-test.tsx.snap deleted file mode 100644 index 98e92766989..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotReviewHistory-test.tsx.snap +++ /dev/null @@ -1,620 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly: default 1`] = ` -<Fragment> - <ul> - <li - className="padded-top padded-bottom" - key="0" - > - <div - className="display-flex-center" - > - <withAppStateContext(Avatar) - className="little-spacer-right" - name="Luke Skywalker" - size={20} - /> - <strong> - Luke Skywalker - </strong> - <span - className="little-spacer-left little-spacer-right" - > - - - </span> - <DateTimeFormatter - date="2018-10-12" - /> - </div> - <div - className="spacer-top" - > - <IssueChangelogDiff - diff={ - { - "key": "assign", - "newValue": "darth.vader", - "oldValue": "luke.skywalker", - } - } - key="0" - /> - </div> - </li> - <li - className="padded-top padded-bottom bordered-top" - key="1" - > - <div - className="display-flex-center" - > - <withAppStateContext(Avatar) - className="little-spacer-right" - name="Luke Skywalker" - size={20} - /> - <strong> - Luke Skywalker - </strong> - <span - className="little-spacer-left little-spacer-right" - > - - - </span> - <DateTimeFormatter - date="2018-10-01" - /> - </div> - <div - className="spacer-top" - > - <IssueChangelogDiff - diff={ - { - "key": "assign", - "newValue": "darth.vader", - "oldValue": "luke.skywalker", - } - } - key="0" - /> - </div> - </li> - <li - className="padded-top padded-bottom bordered-top" - key="2" - > - <div - className="display-flex-center" - > - <withAppStateContext(Avatar) - className="little-spacer-right" - name="John Doe" - size={20} - /> - <strong> - John Doe - </strong> - <span - className="little-spacer-left" - > - hotspots.review_history.comment_added - </span> - <span - className="little-spacer-left little-spacer-right" - > - - - </span> - <DateTimeFormatter - date="2018-09-10" - /> - </div> - <div - className="spacer-top display-flex-space-between" - > - <div - className="markdown" - dangerouslySetInnerHTML={ - { - "__html": "<strong>TEST</strong>", - } - } - /> - </div> - </li> - <li - className="padded-top padded-bottom bordered-top" - key="3" - > - <div - className="display-flex-center" - > - <withAppStateContext(Avatar) - className="little-spacer-right" - name="John Doe" - size={20} - /> - <strong> - John Doe - </strong> - <span - className="little-spacer-left" - > - hotspots.review_history.comment_added - </span> - <span - className="little-spacer-left little-spacer-right" - > - - - </span> - <DateTimeFormatter - date="2018-09-10" - /> - </div> - <div - className="spacer-top display-flex-space-between" - > - <div - className="markdown" - dangerouslySetInnerHTML={ - { - "__html": "<strong>TEST</strong>", - } - } - /> - </div> - </li> - <li - className="padded-top padded-bottom bordered-top" - key="4" - > - <div - className="display-flex-center" - > - <withAppStateContext(Avatar) - className="little-spacer-right" - name="John Doe" - size={20} - /> - <strong> - user.x_deleted.John Doe - </strong> - <span - className="little-spacer-left" - > - hotspots.review_history.comment_added - </span> - <span - className="little-spacer-left little-spacer-right" - > - - - </span> - <DateTimeFormatter - date="2018-09-10" - /> - </div> - <div - className="spacer-top display-flex-space-between" - > - <div - className="markdown" - dangerouslySetInnerHTML={ - { - "__html": "<strong>TEST</strong>", - } - } - /> - </div> - </li> - </ul> - <ButtonLink - className="spacer-top" - onClick={[MockFunction]} - > - show_all - </ButtonLink> -</Fragment> -`; - -exports[`should render correctly: delete comment overlay 1`] = ` -<div - className="padded abs-width-150" -> - <p> - issue.comment.delete_confirm_message - </p> - <Button - className="button-red big-spacer-top pull-right" - onClick={[Function]} - > - delete - </Button> -</div> -`; - -exports[`should render correctly: edit comment overlay 1`] = ` -<DropdownOverlay - placement="bottom-right" -> - <HotspotCommentPopup - markdownComment="*TEST*" - onCancelEdit={[Function]} - onCommentEditSubmit={[Function]} - /> -</DropdownOverlay> -`; - -exports[`should render correctly: show full list 1`] = ` -<Fragment> - <ul> - <li - className="padded-top padded-bottom" - key="0" - > - <div - className="display-flex-center" - > - <withAppStateContext(Avatar) - className="little-spacer-right" - name="Luke Skywalker" - size={20} - /> - <strong> - Luke Skywalker - </strong> - <span - className="little-spacer-left little-spacer-right" - > - - - </span> - <DateTimeFormatter - date="2018-10-12" - /> - </div> - <div - className="spacer-top" - > - <IssueChangelogDiff - diff={ - { - "key": "assign", - "newValue": "darth.vader", - "oldValue": "luke.skywalker", - } - } - key="0" - /> - </div> - </li> - <li - className="padded-top padded-bottom bordered-top" - key="1" - > - <div - className="display-flex-center" - > - <withAppStateContext(Avatar) - className="little-spacer-right" - name="Luke Skywalker" - size={20} - /> - <strong> - Luke Skywalker - </strong> - <span - className="little-spacer-left little-spacer-right" - > - - - </span> - <DateTimeFormatter - date="2018-10-01" - /> - </div> - <div - className="spacer-top" - > - <IssueChangelogDiff - diff={ - { - "key": "assign", - "newValue": "darth.vader", - "oldValue": "luke.skywalker", - } - } - key="0" - /> - </div> - </li> - <li - className="padded-top padded-bottom bordered-top" - key="2" - > - <div - className="display-flex-center" - > - <withAppStateContext(Avatar) - className="little-spacer-right" - name="John Doe" - size={20} - /> - <strong> - John Doe - </strong> - <span - className="little-spacer-left" - > - hotspots.review_history.comment_added - </span> - <span - className="little-spacer-left little-spacer-right" - > - - - </span> - <DateTimeFormatter - date="2018-09-10" - /> - </div> - <div - className="spacer-top display-flex-space-between" - > - <div - className="markdown" - dangerouslySetInnerHTML={ - { - "__html": "<strong>TEST</strong>", - } - } - /> - </div> - </li> - <li - className="padded-top padded-bottom bordered-top" - key="3" - > - <div - className="display-flex-center" - > - <withAppStateContext(Avatar) - className="little-spacer-right" - name="John Doe" - size={20} - /> - <strong> - John Doe - </strong> - <span - className="little-spacer-left" - > - hotspots.review_history.comment_added - </span> - <span - className="little-spacer-left little-spacer-right" - > - - - </span> - <DateTimeFormatter - date="2018-09-10" - /> - </div> - <div - className="spacer-top display-flex-space-between" - > - <div - className="markdown" - dangerouslySetInnerHTML={ - { - "__html": "<strong>TEST</strong>", - } - } - /> - </div> - </li> - <li - className="padded-top padded-bottom bordered-top" - key="4" - > - <div - className="display-flex-center" - > - <withAppStateContext(Avatar) - className="little-spacer-right" - name="John Doe" - size={20} - /> - <strong> - user.x_deleted.John Doe - </strong> - <span - className="little-spacer-left" - > - hotspots.review_history.comment_added - </span> - <span - className="little-spacer-left little-spacer-right" - > - - - </span> - <DateTimeFormatter - date="2018-09-10" - /> - </div> - <div - className="spacer-top display-flex-space-between" - > - <div - className="markdown" - dangerouslySetInnerHTML={ - { - "__html": "<strong>TEST</strong>", - } - } - /> - </div> - </li> - <li - className="padded-top padded-bottom bordered-top" - key="5" - > - <div - className="display-flex-center" - > - <withAppStateContext(Avatar) - className="little-spacer-right" - name="john.doe" - size={20} - /> - <strong> - john.doe - </strong> - <span - className="little-spacer-left" - > - hotspots.review_history.comment_added - </span> - <span - className="little-spacer-left little-spacer-right" - > - - - </span> - <DateTimeFormatter - date="2018-09-10" - /> - </div> - <div - className="spacer-top display-flex-space-between" - > - <div - className="markdown" - dangerouslySetInnerHTML={ - { - "__html": "<strong>TEST</strong>", - } - } - /> - </div> - </li> - <li - className="padded-top padded-bottom bordered-top" - key="6" - > - <div - className="display-flex-center" - > - <withAppStateContext(Avatar) - className="little-spacer-right" - name="John Doe" - size={20} - /> - <strong> - John Doe - </strong> - <span - className="little-spacer-left" - > - hotspots.review_history.comment_added - </span> - <span - className="little-spacer-left little-spacer-right" - > - - - </span> - <DateTimeFormatter - date="2018-09-10" - /> - </div> - <div - className="spacer-top display-flex-space-between" - > - <div - className="markdown" - dangerouslySetInnerHTML={ - { - "__html": "<strong>TEST</strong>", - } - } - /> - <div> - <div - className="dropdown" - > - <Toggler - onRequestClose={[Function]} - open={false} - overlay={ - <DropdownOverlay - placement="bottom-right" - > - <HotspotCommentPopup - markdownComment="*TEST*" - onCancelEdit={[Function]} - onCommentEditSubmit={[Function]} - /> - </DropdownOverlay> - } - > - <EditButton - className="button-small" - onClick={[Function]} - /> - </Toggler> - </div> - <Dropdown - onOpen={[Function]} - overlay={ - <div - className="padded abs-width-150" - > - <p> - issue.comment.delete_confirm_message - </p> - <Button - className="button-red big-spacer-top pull-right" - onClick={[Function]} - > - delete - </Button> - </div> - } - overlayPlacement="bottom-right" - > - <DeleteButton - className="button-small" - /> - </Dropdown> - </div> - </div> - </li> - <li - className="padded-top padded-bottom bordered-top" - key="7" - > - <div - className="display-flex-center" - > - <withAppStateContext(Avatar) - className="little-spacer-right" - name="John Doe" - size={20} - /> - <strong> - John Doe - </strong> - <span - className="little-spacer-left" - > - hotspots.review_history.created - </span> - <span - className="little-spacer-left little-spacer-right" - > - - - </span> - <DateTimeFormatter - date="2018-09-01" - /> - </div> - </li> - </ul> -</Fragment> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotReviewHistoryAndComments-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotReviewHistoryAndComments-test.tsx.snap deleted file mode 100644 index 253103a022e..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotReviewHistoryAndComments-test.tsx.snap +++ /dev/null @@ -1,231 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -<div - className="padded it__hs-review-history" -> - <label - htmlFor="security-hotspot-comment" - > - hotspots.comment.field - </label> - <textarea - className="form-field fixed-width width-100 spacer-bottom" - id="security-hotspot-comment" - onChange={[Function]} - rows={2} - value="" - /> - <div - className="display-flex-space-between display-flex-center " - > - <FormattingTips - className="huge-spacer-bottom" - /> - <div> - <Button - className="huge-spacer-bottom" - id="hotspot-comment-box-submit" - onClick={[Function]} - > - hotspots.comment.submit - </Button> - </div> - </div> - <h2 - className="spacer-top big-spacer-bottom" - > - hotspot.section.activity - </h2> - <HotspotReviewHistory - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onDeleteComment={[Function]} - onEditComment={[Function]} - onShowFullHistory={[Function]} - showFullHistory={false} - /> -</div> -`; - -exports[`should render correctly without user 1`] = ` -<div - className="padded it__hs-review-history" -> - <h2 - className="spacer-top big-spacer-bottom" - > - hotspot.section.activity - </h2> - <HotspotReviewHistory - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onDeleteComment={[Function]} - onEditComment={[Function]} - onShowFullHistory={[Function]} - showFullHistory={false} - /> -</div> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSimpleList-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSimpleList-test.tsx.snap deleted file mode 100644 index bc5b379dbc5..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSimpleList-test.tsx.snap +++ /dev/null @@ -1,389 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly: filter by both 1`] = ` -<div - className="hotspots-list-single-category huge-spacer-bottom" -> - <h1 - className="hotspot-list-header bordered-bottom" - > - <SecurityHotspotIcon - className="spacer-right" - /> - hotspots.list_title.2 - </h1> - <div - className="big-spacer-bottom" - > - <div - className="hotspot-category" - > - <div - className="hotspot-category-header" - > - <strong - className="flex-1 spacer-right break-word" - > - A1 - A1 - SQL Injection - <hr /> - CWE-327 - Use of a Broken or Risky Cryptographic Algorithm - </strong> - </div> - <ul> - <li - data-hotspot-key="h1" - key="h1" - > - <HotspotListItem - hotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h1", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - onClick={[MockFunction]} - onLocationClick={[MockFunction]} - selected={true} - /> - </li> - <li - data-hotspot-key="h2" - key="h2" - > - <HotspotListItem - hotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - onClick={[MockFunction]} - onLocationClick={[MockFunction]} - selected={false} - /> - </li> - </ul> - </div> - </div> - <ListFooter - count={2} - loadMore={[MockFunction]} - loading={false} - total={2} - /> -</div> -`; - -exports[`should render correctly: filter by category 1`] = ` -<div - className="hotspots-list-single-category huge-spacer-bottom" -> - <h1 - className="hotspot-list-header bordered-bottom" - > - <SecurityHotspotIcon - className="spacer-right" - /> - hotspots.list_title.2 - </h1> - <div - className="big-spacer-bottom" - > - <div - className="hotspot-category" - > - <div - className="hotspot-category-header" - > - <strong - className="flex-1 spacer-right break-word" - > - A1 - A1 - SQL Injection - </strong> - </div> - <ul> - <li - data-hotspot-key="h1" - key="h1" - > - <HotspotListItem - hotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h1", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - onClick={[MockFunction]} - onLocationClick={[MockFunction]} - selected={true} - /> - </li> - <li - data-hotspot-key="h2" - key="h2" - > - <HotspotListItem - hotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - onClick={[MockFunction]} - onLocationClick={[MockFunction]} - selected={false} - /> - </li> - </ul> - </div> - </div> - <ListFooter - count={2} - loadMore={[MockFunction]} - loading={false} - total={2} - /> -</div> -`; - -exports[`should render correctly: filter by cwe 1`] = ` -<div - className="hotspots-list-single-category huge-spacer-bottom" -> - <h1 - className="hotspot-list-header bordered-bottom" - > - <SecurityHotspotIcon - className="spacer-right" - /> - hotspots.list_title.2 - </h1> - <div - className="big-spacer-bottom" - > - <div - className="hotspot-category" - > - <div - className="hotspot-category-header" - > - <strong - className="flex-1 spacer-right break-word" - > - CWE-327 - Use of a Broken or Risky Cryptographic Algorithm - </strong> - </div> - <ul> - <li - data-hotspot-key="h1" - key="h1" - > - <HotspotListItem - hotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h1", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - onClick={[MockFunction]} - onLocationClick={[MockFunction]} - selected={true} - /> - </li> - <li - data-hotspot-key="h2" - key="h2" - > - <HotspotListItem - hotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - onClick={[MockFunction]} - onLocationClick={[MockFunction]} - selected={false} - /> - </li> - </ul> - </div> - </div> - <ListFooter - count={2} - loadMore={[MockFunction]} - loading={false} - total={2} - /> -</div> -`; - -exports[`should render correctly: filter by file 1`] = ` -<div - className="hotspots-list-single-category huge-spacer-bottom" -> - <h1 - className="hotspot-list-header bordered-bottom" - > - <SecurityHotspotIcon - className="spacer-right" - /> - hotspots.list_title.2 - </h1> - <div - className="big-spacer-bottom" - > - <div - className="hotspot-category" - > - <div - className="hotspot-category-header" - > - <strong - className="flex-1 spacer-right break-word" - > - <Tooltip - overlay="src/apps/something/main.ts" - > - <span> - <QualifierIcon - className="little-spacer-right" - qualifier="FIL" - /> - main.ts - </span> - </Tooltip> - </strong> - </div> - <ul> - <li - data-hotspot-key="h1" - key="h1" - > - <HotspotListItem - hotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h1", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - onClick={[MockFunction]} - onLocationClick={[MockFunction]} - selected={true} - /> - </li> - <li - data-hotspot-key="h2" - key="h2" - > - <HotspotListItem - hotspot={ - { - "author": "Developer 1", - "component": "com.github.kevinsawicki:http-request:com.github.kevinsawicki.http.HttpRequest", - "creationDate": "2013-05-13T17:55:39+0200", - "key": "h2", - "line": 81, - "message": "'3' is a magic number.", - "project": "com.github.kevinsawicki:http-request", - "resolution": undefined, - "rule": "checkstyle:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck", - "securityCategory": "command-injection", - "status": "TO_REVIEW", - "updateDate": "2013-05-13T17:55:39+0200", - "vulnerabilityProbability": "HIGH", - } - } - onClick={[MockFunction]} - onLocationClick={[MockFunction]} - selected={false} - /> - </li> - </ul> - </div> - </div> - <ListFooter - count={2} - loadMore={[MockFunction]} - loading={false} - total={2} - /> -</div> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetContainer-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetContainer-test.tsx.snap deleted file mode 100644 index 03e59180ae2..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetContainer-test.tsx.snap +++ /dev/null @@ -1,165 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -<HotspotSnippetContainerRenderer - branchLike={ - { - "analysisDate": "2018-01-01", - "excludedFromPurge": true, - "isMain": false, - "name": "branch-6.7", - } - } - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - highlightedSymbols={[]} - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - loading={true} - locations={ - { - "142": [ - { - "from": 26, - "line": 142, - "to": 83, - }, - ], - } - } - onCommentButtonClick={[MockFunction]} - onExpandBlock={[Function]} - onLocationSelect={[MockFunction]} - onSymbolClick={[Function]} - secondaryLocations={ - [ - { - "component": "main.js", - "index": 0, - "text": undefined, - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ] - } - sourceLines={[]} - sourceViewerFile={ - { - "key": "hotspot-component", - "measures": { - "lines": undefined, - }, - "path": "path/to/component", - "project": "hotspot-component", - "projectName": "Hotspot Component", - "q": "FIL", - "uuid": "", - } - } -/> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetContainerRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetContainerRenderer-test.tsx.snap deleted file mode 100644 index 1ace6e7e117..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetContainerRenderer-test.tsx.snap +++ /dev/null @@ -1,528 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -<Fragment> - <p - className="spacer-bottom" - > - hotspots.no_associated_lines - </p> - <withCurrentUserContext(HotspotSnippetHeader) - branchLike={ - { - "analysisDate": "2018-01-01", - "excludedFromPurge": true, - "isMain": true, - "name": "master", - } - } - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - /> - <div - className="hotspot-snippet-container bordered" - > - <DeferredSpinner - className="big-spacer" - loading={false} - /> - </div> -</Fragment> -`; - -exports[`should render correctly when secondary location is selected: with selected hotspot location 1`] = ` -<Fragment> - <p - className="spacer-bottom" - > - hotspots.no_associated_lines - </p> - <withCurrentUserContext(HotspotSnippetHeader) - branchLike={ - { - "analysisDate": "2018-01-01", - "excludedFromPurge": true, - "isMain": true, - "name": "master", - } - } - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - /> - <div - className="hotspot-snippet-container bordered" - > - <DeferredSpinner - className="big-spacer" - loading={false} - /> - </div> -</Fragment> -`; - -exports[`should render correctly: with sourcelines 1`] = ` -<Fragment> - <withCurrentUserContext(HotspotSnippetHeader) - branchLike={ - { - "analysisDate": "2018-01-01", - "excludedFromPurge": true, - "isMain": true, - "name": "master", - } - } - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - /> - <div - className="hotspot-snippet-container bordered" - > - <DeferredSpinner - className="big-spacer" - loading={false} - > - <SnippetViewer - component={ - { - "canMarkAsFavorite": true, - "fav": false, - "key": "project:foo/bar.ts", - "longName": "foo/bar.ts", - "measures": { - "coverage": "85.2", - "duplicationDensity": "1.0", - "issues": "12", - "lines": "56", - }, - "name": "foo/bar.ts", - "path": "foo/bar.ts", - "project": "project", - "projectName": "MyProject", - "q": "FIL", - "uuid": "foo-bar", - } - } - displayLineNumberOptions={false} - displaySCM={false} - expandBlock={[Function]} - handleSymbolClick={[MockFunction]} - highlightedSymbols={[]} - index={0} - issue={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - lastSnippetOfLastGroup={false} - locations={[]} - locationsByLine={{}} - onLocationSelect={[MockFunction]} - renderAdditionalChildInLine={[Function]} - renderDuplicationPopup={[Function]} - snippet={ - [ - { - "code": "<span class="k">import</span> java.util.<span class="sym-9 sym">ArrayList</span>;", - "coverageStatus": "covered", - "coveredConditions": 2, - "duplicated": false, - "isNew": true, - "line": 16, - "scmAuthor": "simon.brandhof@sonarsource.com", - "scmDate": "2018-12-11T10:48:39+0100", - "scmRevision": "80f564becc0c0a1c9abaa006eca83a4fd278c3f0", - }, - ] - } - /> - </DeferredSpinner> - </div> -</Fragment> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetHeader-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetHeader-test.tsx.snap deleted file mode 100644 index 35ff578b6e6..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetHeader-test.tsx.snap +++ /dev/null @@ -1,114 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly: user logged in 1`] = ` -<Styled(div)> - <Styled(div)> - <QualifierIcon - qualifier="FIL" - /> - <span> - path/to/ - component - </span> - <ClipboardIconButton - className="button-link link-no-underline little-spacer-left" - copyValue="path/to/component" - /> - </Styled(div)> - <div - className="dropdown spacer-right flex-0" - > - <HotspotOpenInIdeButton - hotspotKey="01fc972e-2a3c-433e-bcae-0bd7f88f5123" - projectKey="hotspot-component" - /> - </div> - <ClipboardButton - className="flex-0" - copyValue="http://localhost/security_hotspots?id=my-project&hotspots=01fc972e-2a3c-433e-bcae-0bd7f88f5123" - > - <span> - hotspots.get_permalink - </span> - <LinkIcon - className="spacer-left" - /> - </ClipboardButton> -</Styled(div)> -`; - -exports[`should render correctly: user logged in with project Name 1`] = ` -<Styled(div)> - <Styled(div)> - <QualifierIcon - className="little-spacer-right" - qualifier="TRK" - /> - <Styled(span) - className="little-spacer-right" - title="Hotspot Component" - > - Hotspot Component - </Styled(span)> - <QualifierIcon - qualifier="FIL" - /> - <span> - path/to/ - component - </span> - <ClipboardIconButton - className="button-link link-no-underline little-spacer-left" - copyValue="path/to/component" - /> - </Styled(div)> - <div - className="dropdown spacer-right flex-0" - > - <HotspotOpenInIdeButton - hotspotKey="01fc972e-2a3c-433e-bcae-0bd7f88f5123" - projectKey="hotspot-component" - /> - </div> - <ClipboardButton - className="flex-0" - copyValue="http://localhost/security_hotspots?id=my-project&hotspots=01fc972e-2a3c-433e-bcae-0bd7f88f5123" - > - <span> - hotspots.get_permalink - </span> - <LinkIcon - className="spacer-left" - /> - </ClipboardButton> -</Styled(div)> -`; - -exports[`should render correctly: user not logged in 1`] = ` -<Styled(div)> - <Styled(div)> - <QualifierIcon - qualifier="FIL" - /> - <span> - path/to/ - component - </span> - <ClipboardIconButton - className="button-link link-no-underline little-spacer-left" - copyValue="path/to/component" - /> - </Styled(div)> - <ClipboardButton - className="flex-0" - copyValue="http://localhost/security_hotspots?id=my-project&hotspots=01fc972e-2a3c-433e-bcae-0bd7f88f5123" - > - <span> - hotspots.get_permalink - </span> - <LinkIcon - className="spacer-left" - /> - </ClipboardButton> -</Styled(div)> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotViewer-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotViewer-test.tsx.snap deleted file mode 100644 index 3ac04551e1a..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotViewer-test.tsx.snap +++ /dev/null @@ -1,86 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -<withCurrentUserContext(HotspotViewerRenderer) - commentTextRef={ - { - "current": null, - } - } - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - loading={true} - onCloseStatusUpdateSuccessModal={[Function]} - onLocationClick={[MockFunction]} - onShowCommentForm={[Function]} - onSwitchFilterToStatusOfUpdatedHotspot={[Function]} - onUpdateHotspot={[Function]} - showStatusUpdateSuccessModal={false} -/> -`; - -exports[`should render correctly 2`] = ` -<withCurrentUserContext(HotspotViewerRenderer) - commentTextRef={ - { - "current": null, - } - } - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - hotspot={ - { - "id": "I am a detailled hotspot", - "rule": {}, - } - } - loading={false} - onCloseStatusUpdateSuccessModal={[Function]} - onLocationClick={[MockFunction]} - onShowCommentForm={[Function]} - onSwitchFilterToStatusOfUpdatedHotspot={[Function]} - onUpdateHotspot={[Function]} - ruleDescriptionSections={[]} - showStatusUpdateSuccessModal={false} -/> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotViewerRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotViewerRenderer-test.tsx.snap deleted file mode 100644 index b3c5a12ade7..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotViewerRenderer-test.tsx.snap +++ /dev/null @@ -1,2372 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly: anonymous user 1`] = ` -<DeferredSpinner - className="big-spacer-left big-spacer-top" - loading={false} -> - <div - className="big-padded hotspot-content" - > - <HotspotHeader - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onUpdateHotspot={[MockFunction]} - /> - <HotspotViewerTabs - codeTabContent={ - <HotspotSnippetContainer - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onCommentButtonClick={[MockFunction]} - onLocationSelect={[MockFunction]} - /> - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - /> - <HotspotReviewHistoryAndComments - commentTextRef={ - { - "current": null, - } - } - currentUser={ - { - "dismissedNotices": { - "educationPrinciples": false, - }, - "isLoggedIn": false, - } - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onCommentUpdate={[MockFunction]} - /> - </div> -</DeferredSpinner> -`; - -exports[`should render correctly: assignee without name 1`] = ` -<DeferredSpinner - className="big-spacer-left big-spacer-top" - loading={false} -> - <div - className="big-padded hotspot-content" - > - <HotspotHeader - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee_login", - "name": undefined, - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onUpdateHotspot={[MockFunction]} - /> - <HotspotViewerTabs - codeTabContent={ - <HotspotSnippetContainer - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee_login", - "name": undefined, - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onCommentButtonClick={[MockFunction]} - onLocationSelect={[MockFunction]} - /> - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee_login", - "name": undefined, - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - /> - <HotspotReviewHistoryAndComments - commentTextRef={ - { - "current": null, - } - } - currentUser={ - { - "dismissedNotices": { - "educationPrinciples": false, - }, - "isLoggedIn": false, - } - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee_login", - "name": undefined, - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onCommentUpdate={[MockFunction]} - /> - </div> -</DeferredSpinner> -`; - -exports[`should render correctly: default 1`] = ` -<DeferredSpinner - className="big-spacer-left big-spacer-top" - loading={false} -> - <div - className="big-padded hotspot-content" - > - <HotspotHeader - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onUpdateHotspot={[MockFunction]} - /> - <HotspotViewerTabs - codeTabContent={ - <HotspotSnippetContainer - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onCommentButtonClick={[MockFunction]} - onLocationSelect={[MockFunction]} - /> - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - /> - <HotspotReviewHistoryAndComments - commentTextRef={ - { - "current": null, - } - } - currentUser={ - { - "dismissedNotices": { - "educationPrinciples": false, - }, - "isLoggedIn": false, - } - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onCommentUpdate={[MockFunction]} - /> - </div> -</DeferredSpinner> -`; - -exports[`should render correctly: deleted assignee 1`] = ` -<DeferredSpinner - className="big-spacer-left big-spacer-top" - loading={false} -> - <div - className="big-padded hotspot-content" - > - <HotspotHeader - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": false, - "local": true, - "login": "john.doe", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onUpdateHotspot={[MockFunction]} - /> - <HotspotViewerTabs - codeTabContent={ - <HotspotSnippetContainer - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": false, - "local": true, - "login": "john.doe", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onCommentButtonClick={[MockFunction]} - onLocationSelect={[MockFunction]} - /> - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": false, - "local": true, - "login": "john.doe", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - /> - <HotspotReviewHistoryAndComments - commentTextRef={ - { - "current": null, - } - } - currentUser={ - { - "dismissedNotices": { - "educationPrinciples": false, - }, - "isLoggedIn": false, - } - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": false, - "local": true, - "login": "john.doe", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onCommentUpdate={[MockFunction]} - /> - </div> -</DeferredSpinner> -`; - -exports[`should render correctly: no hotspot 1`] = ` -<DeferredSpinner - className="big-spacer-left big-spacer-top" - loading={false} -/> -`; - -exports[`should render correctly: show success modal 1`] = ` -<DeferredSpinner - className="big-spacer-left big-spacer-top" - loading={false} -> - <StatusUpdateSuccessModal - hotspotsReviewedMeasure="75" - lastStatusChangedTo="FIXED" - onClose={[MockFunction]} - onSwitchFilterToStatusOfUpdatedHotspot={[MockFunction]} - /> - <div - className="big-padded hotspot-content" - > - <HotspotHeader - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onUpdateHotspot={[MockFunction]} - /> - <HotspotViewerTabs - codeTabContent={ - <HotspotSnippetContainer - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onCommentButtonClick={[MockFunction]} - onLocationSelect={[MockFunction]} - /> - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - /> - <HotspotReviewHistoryAndComments - commentTextRef={ - { - "current": null, - } - } - currentUser={ - { - "dismissedNotices": { - "educationPrinciples": false, - }, - "isLoggedIn": false, - } - } - hotspot={ - { - "assignee": "assignee", - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onCommentUpdate={[MockFunction]} - /> - </div> -</DeferredSpinner> -`; - -exports[`should render correctly: unassigned 1`] = ` -<DeferredSpinner - className="big-spacer-left big-spacer-top" - loading={false} -> - <div - className="big-padded hotspot-content" - > - <HotspotHeader - hotspot={ - { - "assignee": undefined, - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onUpdateHotspot={[MockFunction]} - /> - <HotspotViewerTabs - codeTabContent={ - <HotspotSnippetContainer - component={ - { - "breadcrumbs": [], - "key": "my-project", - "name": "MyProject", - "qualifier": "TRK", - "qualityGate": { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": [ - { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": [], - } - } - hotspot={ - { - "assignee": undefined, - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onCommentButtonClick={[MockFunction]} - onLocationSelect={[MockFunction]} - /> - } - hotspot={ - { - "assignee": undefined, - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - /> - <HotspotReviewHistoryAndComments - commentTextRef={ - { - "current": null, - } - } - currentUser={ - { - "dismissedNotices": { - "educationPrinciples": false, - }, - "isLoggedIn": false, - } - } - hotspot={ - { - "assignee": undefined, - "assigneeUser": { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - "author": "author", - "authorUser": { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - "canChangeStatus": true, - "changelog": [], - "comment": [], - "component": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "FIL", - }, - "creationDate": "2013-05-13T17:55:41+0200", - "flows": [ - { - "locations": [ - { - "component": "main.js", - "textRange": { - "endLine": 2, - "endOffset": 2, - "startLine": 1, - "startOffset": 1, - }, - }, - ], - }, - ], - "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", - "line": 142, - "message": "'3' is a magic number.", - "project": { - "key": "hotspot-component", - "longName": "Hotspot component long name", - "name": "Hotspot Component", - "path": "path/to/component", - "qualifier": "TRK", - }, - "resolution": "FIXED", - "rule": { - "key": "squid:S2077", - "name": "That rule", - "securityCategory": "sql-injection", - "vulnerabilityProbability": "HIGH", - }, - "status": "REVIEWED", - "textRange": { - "endLine": 142, - "endOffset": 83, - "startLine": 142, - "startOffset": 26, - }, - "updateDate": "2013-05-13T17:55:42+0200", - "users": [ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - }, - { - "active": true, - "local": true, - "login": "author", - "name": "John Doe", - }, - ], - } - } - onCommentUpdate={[MockFunction]} - /> - </div> -</DeferredSpinner> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotViewerTabs-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotViewerTabs-test.tsx.snap deleted file mode 100644 index 3594e0207b1..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotViewerTabs-test.tsx.snap +++ /dev/null @@ -1,355 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly: fix 1`] = ` -<Fragment> - <BoxedTabs - onSelect={[Function]} - selected="fix" - tabs={ - [ - { - "content": <div - className="padded" - > - <div> - CodeTabContent - </div> - </div>, - "key": "code", - "label": "hotspots.tabs.code", - }, - { - "content": <RuleDescription - className="big-padded" - isDefault={true} - sections={ - [ - { - "content": "cause", - "key": "root_cause", - }, - ] - } - />, - "key": "risk", - "label": "hotspots.tabs.risk_description", - }, - { - "content": <RuleDescription - className="big-padded" - isDefault={true} - sections={ - [ - { - "content": "assess", - "key": "assess_the_problem", - }, - ] - } - />, - "key": "vulnerability", - "label": "hotspots.tabs.vulnerability_description", - }, - { - "content": <RuleDescription - className="big-padded" - isDefault={true} - sections={ - [ - { - "content": "how", - "key": "how_to_fix", - }, - ] - } - />, - "key": "fix", - "label": "hotspots.tabs.fix_recommendations", - }, - ] - } - /> - <div - aria-labelledby="tab-fix" - className="bordered huge-spacer-bottom" - id="tabpanel-fix" - role="tabpanel" - > - <RuleDescription - className="big-padded" - isDefault={true} - sections={ - [ - { - "content": "how", - "key": "how_to_fix", - }, - ] - } - /> - </div> -</Fragment> -`; - -exports[`should render correctly: risk 1`] = ` -<Fragment> - <BoxedTabs - onSelect={[Function]} - selected="code" - tabs={ - [ - { - "content": <div - className="padded" - > - <div> - CodeTabContent - </div> - </div>, - "key": "code", - "label": "hotspots.tabs.code", - }, - { - "content": <RuleDescription - className="big-padded" - isDefault={true} - sections={ - [ - { - "content": "cause", - "key": "root_cause", - }, - ] - } - />, - "key": "risk", - "label": "hotspots.tabs.risk_description", - }, - { - "content": <RuleDescription - className="big-padded" - isDefault={true} - sections={ - [ - { - "content": "assess", - "key": "assess_the_problem", - }, - ] - } - />, - "key": "vulnerability", - "label": "hotspots.tabs.vulnerability_description", - }, - { - "content": <RuleDescription - className="big-padded" - isDefault={true} - sections={ - [ - { - "content": "how", - "key": "how_to_fix", - }, - ] - } - />, - "key": "fix", - "label": "hotspots.tabs.fix_recommendations", - }, - ] - } - /> - <div - aria-labelledby="tab-code" - className="bordered huge-spacer-bottom" - id="tabpanel-code" - role="tabpanel" - > - <div - className="padded" - > - <div> - CodeTabContent - </div> - </div> - </div> -</Fragment> -`; - -exports[`should render correctly: vulnerability 1`] = ` -<Fragment> - <BoxedTabs - onSelect={[Function]} - selected="vulnerability" - tabs={ - [ - { - "content": <div - className="padded" - > - <div> - CodeTabContent - </div> - </div>, - "key": "code", - "label": "hotspots.tabs.code", - }, - { - "content": <RuleDescription - className="big-padded" - isDefault={true} - sections={ - [ - { - "content": "cause", - "key": "root_cause", - }, - ] - } - />, - "key": "risk", - "label": "hotspots.tabs.risk_description", - }, - { - "content": <RuleDescription - className="big-padded" - isDefault={true} - sections={ - [ - { - "content": "assess", - "key": "assess_the_problem", - }, - ] - } - />, - "key": "vulnerability", - "label": "hotspots.tabs.vulnerability_description", - }, - { - "content": <RuleDescription - className="big-padded" - isDefault={true} - sections={ - [ - { - "content": "how", - "key": "how_to_fix", - }, - ] - } - />, - "key": "fix", - "label": "hotspots.tabs.fix_recommendations", - }, - ] - } - /> - <div - aria-labelledby="tab-vulnerability" - className="bordered huge-spacer-bottom" - id="tabpanel-vulnerability" - role="tabpanel" - > - <RuleDescription - className="big-padded" - isDefault={true} - sections={ - [ - { - "content": "assess", - "key": "assess_the_problem", - }, - ] - } - /> - </div> -</Fragment> -`; - -exports[`should render correctly: with comments or changelog element 1`] = ` -<Fragment> - <BoxedTabs - onSelect={[Function]} - selected="code" - tabs={ - [ - { - "content": <div - className="padded" - > - <div> - CodeTabContent - </div> - </div>, - "key": "code", - "label": "hotspots.tabs.code", - }, - { - "content": <RuleDescription - className="big-padded" - isDefault={true} - sections={ - [ - { - "content": "cause", - "key": "root_cause", - }, - ] - } - />, - "key": "risk", - "label": "hotspots.tabs.risk_description", - }, - { - "content": <RuleDescription - className="big-padded" - isDefault={true} - sections={ - [ - { - "content": "assess", - "key": "assess_the_problem", - }, - ] - } - />, - "key": "vulnerability", - "label": "hotspots.tabs.vulnerability_description", - }, - { - "content": <RuleDescription - className="big-padded" - isDefault={true} - sections={ - [ - { - "content": "how", - "key": "how_to_fix", - }, - ] - } - />, - "key": "fix", - "label": "hotspots.tabs.fix_recommendations", - }, - ] - } - /> - <div - aria-labelledby="tab-code" - className="bordered huge-spacer-bottom" - id="tabpanel-code" - role="tabpanel" - > - <div - className="padded" - > - <div> - CodeTabContent - </div> - </div> - </div> -</Fragment> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/StatusUpdateSuccessModal-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/StatusUpdateSuccessModal-test.tsx.snap deleted file mode 100644 index 609e8203e5a..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/StatusUpdateSuccessModal-test.tsx.snap +++ /dev/null @@ -1,104 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly: default 1`] = ` -<Modal - contentLabel="hotspots.congratulations" -> - <div - className="modal-head big text-center text-bold" - > - <p> - hotspots.successful_status_change_to_x.hotspots.status_option.FIXED - </p> - </div> - <div - className="modal-body text-center" - > - <FormattedMessage - defaultMessage="hotspots.find_in_status_filter_x" - id="hotspots.successfully_changed_to_x" - values={ - { - "status_label": <strong> - hotspots.status_option.FIXED - </strong>, - } - } - /> - <p - className="spacer-top" - > - <FormattedMessage - defaultMessage="hotspots.x_done_keep_going" - id="hotspots.x_done_keep_going" - values={ - { - "percentage": <strong> - - </strong>, - } - } - /> - </p> - </div> - <div - className="modal-foot modal-foot-clear display-flex-center display-flex-space-between" - > - <ButtonLink - onClick={[MockFunction]} - > - hotspots.see_x_hotspots.hotspots.status_option.FIXED - </ButtonLink> - <Button - className="button padded" - onClick={[MockFunction]} - > - hotspots.continue_to_next_hotspot - </Button> - </div> -</Modal> -`; - -exports[`should render correctly: opening hotspots again 1`] = ` -<Modal - contentLabel="hotspots.update.success" -> - <div - className="modal-head big text-center text-bold" - > - <p> - hotspots.successful_status_change_to_x.hotspots.status_option.TO_REVIEW - </p> - </div> - <div - className="modal-body text-center" - > - <FormattedMessage - defaultMessage="hotspots.find_in_status_filter_x" - id="hotspots.successfully_changed_to_x" - values={ - { - "status_label": <strong> - hotspots.status_option.TO_REVIEW - </strong>, - } - } - /> - </div> - <div - className="modal-foot modal-foot-clear display-flex-center display-flex-space-between" - > - <ButtonLink - onClick={[MockFunction]} - > - hotspots.see_x_hotspots.hotspots.status_option.TO_REVIEW - </ButtonLink> - <Button - className="button padded" - onClick={[MockFunction]} - > - hotspots.continue_to_next_hotspot - </Button> - </div> -</Modal> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/Assignee-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/Assignee-test.tsx deleted file mode 100644 index 094b6f204b8..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/Assignee-test.tsx +++ /dev/null @@ -1,101 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { assignSecurityHotspot } from '../../../../../api/security-hotspots'; -import { addGlobalSuccessMessage } from '../../../../../helpers/globalMessages'; -import { mockHotspot } from '../../../../../helpers/mocks/security-hotspots'; -import { mockCurrentUser, mockUser } from '../../../../../helpers/testMocks'; -import { waitAndUpdate } from '../../../../../helpers/testUtils'; -import { HotspotResolution, HotspotStatus } from '../../../../../types/security-hotspots'; -import { UserActive } from '../../../../../types/users'; -import { Assignee } from '../Assignee'; -import AssigneeRenderer from '../AssigneeRenderer'; - -jest.mock('../../../../../api/security-hotspots', () => ({ - assignSecurityHotspot: jest.fn(), -})); - -jest.mock('../../../../../helpers/globalMessages', () => ({ - addGlobalSuccessMessage: jest.fn(), -})); - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); -}); - -it.each([ - [HotspotStatus.TO_REVIEW, undefined, true], - [HotspotStatus.REVIEWED, HotspotResolution.FIXED, false], - [HotspotStatus.REVIEWED, HotspotResolution.SAFE, false], - [HotspotStatus.REVIEWED, HotspotResolution.ACKNOWLEDGED, true], -])('should allow edition properly', (status, resolution, canEdit) => { - expect( - shallowRender({ hotspot: mockHotspot({ status, resolution }) }) - .find(AssigneeRenderer) - .props().canEdit - ).toBe(canEdit); -}); - -it('should handle edition event correctly', () => { - const wrapper = shallowRender(); - - wrapper.find(AssigneeRenderer).props().onEnterEditionMode(); - expect(wrapper.state().editing).toBe(true); - - wrapper.find(AssigneeRenderer).props().onExitEditionMode(); - expect(wrapper.state().editing).toBe(false); -}); - -it.each([ - ['assign to user', mockUser() as UserActive], - ['unassign', { login: '', name: 'unassigned' } as UserActive], -])('should handle %s event', async (_, user: UserActive) => { - const hotspot = mockHotspot(); - const onAssigneeChange = jest.fn(); - - const wrapper = shallowRender({ hotspot, onAssigneeChange }); - - (assignSecurityHotspot as jest.Mock).mockResolvedValueOnce({}); - wrapper.find(AssigneeRenderer).props().onAssign(user); - - expect(wrapper.state().loading).toBe(true); - expect(assignSecurityHotspot).toHaveBeenCalledWith(hotspot.key, { assignee: user?.login }); - - await waitAndUpdate(wrapper); - - expect(wrapper.state()).toEqual({ - editing: false, - loading: false, - }); - expect(onAssigneeChange).toHaveBeenCalled(); - expect(addGlobalSuccessMessage).toHaveBeenCalled(); -}); - -function shallowRender(props?: Partial<Assignee['props']>) { - return shallow<Assignee>( - <Assignee - currentUser={mockCurrentUser()} - hotspot={mockHotspot()} - onAssigneeChange={jest.fn()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeRenderer-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeRenderer-test.tsx deleted file mode 100644 index a90f2fe97d9..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeRenderer-test.tsx +++ /dev/null @@ -1,81 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { EditButton } from '../../../../../components/controls/buttons'; -import OutsideClickHandler from '../../../../../components/controls/OutsideClickHandler'; -import { mockLoggedInUser, mockUser } from '../../../../../helpers/testMocks'; -import { click } from '../../../../../helpers/testUtils'; -import { UserActive } from '../../../../../types/users'; -import AssigneeRenderer, { AssigneeRendererProps } from '../AssigneeRenderer'; -import AssigneeSelection from '../AssigneeSelection'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot('not editing'); - expect(shallowRender({ editing: true })).toMatchSnapshot('editing'); - expect(shallowRender({ assignee: undefined })).toMatchSnapshot('without current assignee'); - expect(shallowRender({ assignee: mockUser({ active: true }) })).toMatchSnapshot( - 'with active assignee' - ); - - expect(shallowRender({ loggedInUser: undefined }).find(EditButton).length).toBe(0); - expect(shallowRender({ canEdit: false }).find(EditButton).length).toBe(0); - expect( - shallowRender({ editing: true, assignee: mockUser() }).find(AssigneeSelection).props() - .allowCurrentUserSelection - ).toBe(true); -}); - -it('should propagate calls correctly', () => { - const onAssign = jest.fn(); - const onEnterEditionMode = jest.fn(); - const onExitEditionMode = jest.fn(); - const wrapper = shallowRender({ onAssign, onEnterEditionMode, onExitEditionMode }); - - click(wrapper.find(EditButton)); - expect(onEnterEditionMode).toHaveBeenCalled(); - - const newAssignee = mockUser({ login: 'toto' }); - wrapper.setProps({ editing: true }); - wrapper - .find(AssigneeSelection) - .props() - .onSelect(newAssignee as UserActive); - expect(onAssign).toHaveBeenCalledWith(newAssignee); - - wrapper.find(OutsideClickHandler).props().onClickOutside(); - expect(onExitEditionMode).toHaveBeenCalled(); -}); - -function shallowRender(props?: Partial<AssigneeRendererProps>) { - return shallow<AssigneeRendererProps>( - <AssigneeRenderer - assignee={mockLoggedInUser()} - canEdit={true} - editing={false} - loading={false} - loggedInUser={mockLoggedInUser()} - onAssign={jest.fn()} - onEnterEditionMode={jest.fn()} - onExitEditionMode={jest.fn()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeSelection-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeSelection-test.tsx deleted file mode 100644 index cdc2d507d3b..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeSelection-test.tsx +++ /dev/null @@ -1,130 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { searchUsers } from '../../../../../api/users'; -import { KeyboardKeys } from '../../../../../helpers/keycodes'; -import { mockLoggedInUser, mockUser } from '../../../../../helpers/testMocks'; -import { mockEvent, waitAndUpdate } from '../../../../../helpers/testUtils'; -import { UserActive } from '../../../../../types/users'; -import AssigneeSelection from '../AssigneeSelection'; - -jest.mock('../../../../../api/users', () => ({ - searchUsers: jest.fn().mockResolvedValue([]), -})); - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); -}); - -it('should handle keydown', () => { - const suggestedUsers = [ - mockUser({ login: '1' }) as UserActive, - mockUser({ login: '2' }) as UserActive, - mockUser({ login: '3' }) as UserActive, - ]; - - const onSelect = jest.fn(); - const wrapper = shallowRender({ onSelect }); - - wrapper.instance().handleKeyDown(mockKeyboardEvent(KeyboardKeys.UpArrow)); - expect(wrapper.state().highlighted).toEqual({ login: '', name: 'unassigned' }); - - wrapper.setState({ suggestedUsers }); - - // press down to highlight the first - wrapper.instance().handleKeyDown(mockKeyboardEvent(KeyboardKeys.DownArrow)); - expect(wrapper.state().highlighted).toBe(suggestedUsers[0]); - - // press up to loop around to last - wrapper.instance().handleKeyDown(mockKeyboardEvent(KeyboardKeys.UpArrow)); - expect(wrapper.state().highlighted).toBe(suggestedUsers[2]); - - // press down to loop around to first - wrapper.instance().handleKeyDown(mockKeyboardEvent(KeyboardKeys.DownArrow)); - expect(wrapper.state().highlighted).toBe(suggestedUsers[0]); - - // press down highlight the next - wrapper.instance().handleKeyDown(mockKeyboardEvent(KeyboardKeys.DownArrow)); - expect(wrapper.state().highlighted).toBe(suggestedUsers[1]); - - // press enter to select the highlighted user - wrapper.instance().handleKeyDown(mockKeyboardEvent(KeyboardKeys.Enter)); - expect(onSelect).toHaveBeenCalledWith(suggestedUsers[1]); -}); - -it('should handle search', async () => { - const users = [mockUser({ login: '1' }), mockUser({ login: '2' }), mockUser({ login: '3' })]; - (searchUsers as jest.Mock).mockResolvedValueOnce({ users }); - - const onSelect = jest.fn(); - - const wrapper = shallowRender({ onSelect }); - expect(wrapper.state().suggestedUsers.length).toBe(1); - wrapper.instance().handleSearch('j'); - - expect(searchUsers).not.toHaveBeenCalled(); - - wrapper.instance().handleSearch('jo'); - expect(wrapper.state().loading).toBe(true); - expect(searchUsers).toHaveBeenCalledWith({ q: 'jo' }); - - await waitAndUpdate(wrapper); - - expect(wrapper.state().loading).toBe(false); - expect(wrapper.state().suggestedUsers).toHaveLength(4); - - jest.clearAllMocks(); - - wrapper.instance().handleSearch(''); - expect(searchUsers).not.toHaveBeenCalled(); - expect(wrapper.state().suggestedUsers.length).toBe(1); -}); - -it('should allow current user selection', async () => { - const loggedInUser = mockLoggedInUser(); - const users = [mockUser({ login: '1' }), mockUser({ login: '2' }), mockUser({ login: '3' })]; - (searchUsers as jest.Mock).mockResolvedValueOnce({ users }); - - const wrapper = shallowRender({ allowCurrentUserSelection: true, loggedInUser }); - expect(wrapper.state().suggestedUsers[0]).toBe(loggedInUser); - - wrapper.instance().handleSearch('jo'); - await waitAndUpdate(wrapper); - expect(wrapper.state().suggestedUsers).toHaveLength(4); - - wrapper.instance().handleSearch(''); - expect(wrapper.state().suggestedUsers[0]).toBe(loggedInUser); -}); - -function mockKeyboardEvent(key: KeyboardKeys): React.KeyboardEvent { - return mockEvent({ nativeEvent: mockEvent({ key }) }); -} - -function shallowRender(props?: Partial<AssigneeSelection['props']>) { - return shallow<AssigneeSelection>( - <AssigneeSelection - allowCurrentUserSelection={false} - loggedInUser={mockLoggedInUser()} - onSelect={jest.fn()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeSelectionRenderer-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeSelectionRenderer-test.tsx deleted file mode 100644 index c7ce501f9a7..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeSelectionRenderer-test.tsx +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { mockUser } from '../../../../../helpers/testMocks'; -import { UserActive } from '../../../../../types/users'; -import AssigneeSelectionRenderer, { - HotspotAssigneeSelectRendererProps, -} from '../AssigneeSelectionRenderer'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); - expect(shallowRender({ loading: true })).toMatchSnapshot('loading'); - - const highlightedUser = mockUser({ login: 'highlighted' }) as UserActive; - expect( - shallowRender({ - highlighted: highlightedUser, - suggestedUsers: [mockUser() as UserActive, highlightedUser], - }) - ).toMatchSnapshot('open with results'); -}); - -it('should call onSelect when clicked', () => { - const user = mockUser() as UserActive; - const onSelect = jest.fn(); - const wrapper = shallowRender({ - onSelect, - suggestedUsers: [user], - }); - - wrapper.find('li').at(0).simulate('click'); - - expect(onSelect).toHaveBeenCalledWith(user); -}); - -function shallowRender(props?: Partial<HotspotAssigneeSelectRendererProps>) { - return shallow( - <AssigneeSelectionRenderer - loading={false} - onKeyDown={jest.fn()} - onSearch={jest.fn()} - onSelect={jest.fn()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/__snapshots__/Assignee-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/__snapshots__/Assignee-test.tsx.snap deleted file mode 100644 index 56948a75548..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/__snapshots__/Assignee-test.tsx.snap +++ /dev/null @@ -1,20 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -<AssigneeRenderer - assignee={ - { - "active": true, - "local": true, - "login": "assignee", - "name": "John Doe", - } - } - canEdit={false} - editing={false} - loading={false} - onAssign={[Function]} - onEnterEditionMode={[Function]} - onExitEditionMode={[Function]} -/> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/__snapshots__/AssigneeRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/__snapshots__/AssigneeRenderer-test.tsx.snap deleted file mode 100644 index bd08e03f65e..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/__snapshots__/AssigneeRenderer-test.tsx.snap +++ /dev/null @@ -1,98 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly: editing 1`] = ` -<DeferredSpinner - loading={false} -> - <EscKeydownHandler - onKeydown={[MockFunction]} - > - <OutsideClickHandler - onClickOutside={[MockFunction]} - > - <AssigneeSelection - allowCurrentUserSelection={false} - loggedInUser={ - { - "dismissedNotices": { - "educationPrinciples": false, - }, - "groups": [], - "isLoggedIn": true, - "login": "luke", - "name": "Skywalker", - "scmAccounts": [], - } - } - onSelect={[MockFunction]} - /> - </OutsideClickHandler> - </EscKeydownHandler> -</DeferredSpinner> -`; - -exports[`should render correctly: not editing 1`] = ` -<DeferredSpinner - loading={false} -> - <div - className="display-flex-center" - > - <strong - className="nowrap" - data-testid="assignee-name" - > - user.x_deleted.Skywalker - </strong> - <EditButton - aria-label="hotspots.assignee.change_user" - className="spacer-left" - onClick={[MockFunction]} - /> - </div> -</DeferredSpinner> -`; - -exports[`should render correctly: with active assignee 1`] = ` -<DeferredSpinner - loading={false} -> - <div - className="display-flex-center" - > - <strong - className="nowrap" - data-testid="assignee-name" - > - John Doe - </strong> - <EditButton - aria-label="hotspots.assignee.change_user" - className="spacer-left" - onClick={[MockFunction]} - /> - </div> -</DeferredSpinner> -`; - -exports[`should render correctly: without current assignee 1`] = ` -<DeferredSpinner - loading={false} -> - <div - className="display-flex-center" - > - <strong - className="nowrap" - data-testid="assignee-name" - > - unassigned - </strong> - <EditButton - aria-label="hotspots.assignee.change_user" - className="spacer-left" - onClick={[MockFunction]} - /> - </div> -</DeferredSpinner> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/__snapshots__/AssigneeSelection-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/__snapshots__/AssigneeSelection-test.tsx.snap deleted file mode 100644 index 07a704bdaea..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/__snapshots__/AssigneeSelection-test.tsx.snap +++ /dev/null @@ -1,18 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -<AssigneeSelectionRenderer - loading={false} - onKeyDown={[Function]} - onSearch={[Function]} - onSelect={[MockFunction]} - suggestedUsers={ - [ - { - "login": "", - "name": "unassigned", - }, - ] - } -/> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/__snapshots__/AssigneeSelectionRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/__snapshots__/AssigneeSelectionRenderer-test.tsx.snap deleted file mode 100644 index 7d05daab361..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/__snapshots__/AssigneeSelectionRenderer-test.tsx.snap +++ /dev/null @@ -1,96 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -<div - className="dropdown" -> - <div - className="display-flex-center" - > - <SearchBox - autoFocus={true} - onChange={[MockFunction]} - onKeyDown={[MockFunction]} - placeholder="hotspots.assignee.select_user" - /> - </div> - <DropdownOverlay - noPadding={true} - placement="bottom-left" - > - <ul - className="hotspot-assignee-search-results" - /> - </DropdownOverlay> -</div> -`; - -exports[`should render correctly: loading 1`] = ` -<div - className="dropdown" -> - <div - className="display-flex-center" - > - <SearchBox - autoFocus={true} - onChange={[MockFunction]} - onKeyDown={[MockFunction]} - placeholder="hotspots.assignee.select_user" - /> - <DeferredSpinner - className="spacer-left" - /> - </div> -</div> -`; - -exports[`should render correctly: open with results 1`] = ` -<div - className="dropdown" -> - <div - className="display-flex-center" - > - <SearchBox - autoFocus={true} - onChange={[MockFunction]} - onKeyDown={[MockFunction]} - placeholder="hotspots.assignee.select_user" - /> - </div> - <DropdownOverlay - noPadding={true} - placement="bottom-left" - > - <ul - className="hotspot-assignee-search-results" - > - <li - className="padded" - key="john.doe" - onClick={[Function]} - > - <withAppStateContext(Avatar) - className="spacer-right" - name="John Doe" - size={16} - /> - John Doe - </li> - <li - className="padded active" - key="highlighted" - onClick={[Function]} - > - <withAppStateContext(Avatar) - className="spacer-right" - name="John Doe" - size={16} - /> - John Doe - </li> - </ul> - </DropdownOverlay> -</div> -`; diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/status/__tests__/Status-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/status/__tests__/Status-test.tsx deleted file mode 100644 index e7389b9687d..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/status/__tests__/Status-test.tsx +++ /dev/null @@ -1,87 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 * as React from 'react'; -import { mockHotspot } from '../../../../../helpers/mocks/security-hotspots'; -import { mockCurrentUser } from '../../../../../helpers/testMocks'; -import { Status, StatusProps } from '../Status'; - -import { render, screen } from '@testing-library/react'; -import userEvent from '@testing-library/user-event'; -import { setSecurityHotspotStatus } from '../../../../../api/security-hotspots'; -import { HotspotResolution, HotspotStatus } from '../../../../../types/security-hotspots'; - -jest.mock('../../../../../api/security-hotspots', () => ({ - setSecurityHotspotStatus: jest.fn().mockResolvedValue({}), -})); - -it('should properly deal with comment/status/submit events', async () => { - const hotspot = mockHotspot(); - renderStatusSelection({ hotspot }); - const user = userEvent.setup(); - const comment = 'COMMENT-TEXT'; - - await user.click(screen.getByRole('button', { name: 'hotspots.status.select_status' })); - - await user.click( - screen.getByRole('radio', { - name: 'hotspots.status_option.SAFE hotspots.status_option.SAFE.description', - }) - ); - - await user.click(screen.getByRole('textbox')); - await user.keyboard(comment); - - await user.click(screen.getByRole('button', { name: 'hotspots.status.change_status' })); - - expect(setSecurityHotspotStatus).toHaveBeenCalledWith(hotspot.key, { - status: HotspotStatus.REVIEWED, - resolution: HotspotResolution.SAFE, - comment, - }); -}); - -it('should open change status panel correctly', async () => { - renderStatusSelection(); - const user = userEvent.setup(); - expect(screen.queryByTestId('security-hotspot-test')).not.toBeInTheDocument(); - await user.click(screen.getByRole('button', { name: 'hotspots.status.select_status' })); - expect(screen.getByTestId('security-hotspot-test')).toBeInTheDocument(); -}); - -it('should disallow status change for hotspot that are readonly', () => { - renderStatusSelection({ hotspot: mockHotspot({ canChangeStatus: false }) }); - expect(screen.getByRole('button')).toBeDisabled(); -}); - -it('should disallow status change for user that are not logged in', () => { - renderStatusSelection({ currentUser: mockCurrentUser({ isLoggedIn: false }) }); - expect(screen.getByRole('button')).toBeDisabled(); -}); - -function renderStatusSelection(props?: Partial<StatusProps>) { - render( - <Status - currentUser={mockCurrentUser({ isLoggedIn: true })} - hotspot={mockHotspot()} - onStatusChange={jest.fn()} - {...props} - /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/status/__tests__/StatusDescription-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/status/__tests__/StatusDescription-test.tsx deleted file mode 100644 index 98ef2acb208..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/status/__tests__/StatusDescription-test.tsx +++ /dev/null @@ -1,35 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { HotspotStatusOption } from '../../../../../types/security-hotspots'; -import StatusDescription, { StatusDescriptionProps } from '../StatusDescription'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); - expect(shallowRender({ showTitle: true })).toMatchSnapshot('with title'); - expect(shallowRender({ statusInBadge: false })).toMatchSnapshot('without status in badge'); -}); - -function shallowRender(props?: Partial<StatusDescriptionProps>) { - return shallow<StatusDescriptionProps>( - <StatusDescription statusOption={HotspotStatusOption.TO_REVIEW} {...props} /> - ); -} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/status/__tests__/__snapshots__/StatusDescription-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/status/__tests__/__snapshots__/StatusDescription-test.tsx.snap deleted file mode 100644 index c939658a273..00000000000 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/status/__tests__/__snapshots__/StatusDescription-test.tsx.snap +++ /dev/null @@ -1,51 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` -<Styled(div)> - <h3> - <div - className="badge" - > - hotspots.status_option.TO_REVIEW - </div> - </h3> - <div - className="little-spacer-top" - > - hotspots.status_option.TO_REVIEW.description - </div> -</Styled(div)> -`; - -exports[`should render correctly: with title 1`] = ` -<Styled(div)> - <h3> - status: - <div - className="badge" - > - hotspots.status_option.TO_REVIEW - </div> - </h3> - <div - className="little-spacer-top" - > - hotspots.status_option.TO_REVIEW.description - </div> -</Styled(div)> -`; - -exports[`should render correctly: without status in badge 1`] = ` -<Styled(div)> - <h3> - <div> - hotspots.status_option.TO_REVIEW - </div> - </h3> - <div - className="little-spacer-top" - > - hotspots.status_option.TO_REVIEW.description - </div> -</Styled(div)> -`; |