123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- /*
- * 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 { waitFor } from '@testing-library/react';
- import React from 'react';
- import { Outlet, Route } from 'react-router-dom';
- import BranchesServiceMock from '../../api/mocks/BranchesServiceMock';
- import ComponentsServiceMock from '../../api/mocks/ComponentsServiceMock';
- import IssuesServiceMock from '../../api/mocks/IssuesServiceMock';
- import { mockComponent } from '../../helpers/mocks/component';
- import { mockCurrentUser } from '../../helpers/testMocks';
- import { renderApp, renderAppWithComponentContext } from '../../helpers/testReactTestingUtils';
- import { byLabelText, byPlaceholderText, byRole, byTestId } from '../../helpers/testSelector';
- import {
- CleanCodeAttributeCategory,
- SoftwareImpactSeverity,
- SoftwareQuality,
- } from '../../types/clean-code-taxonomy';
- import { Component } from '../../types/types';
- import { NoticeType } from '../../types/users';
- import IssuesApp from './components/IssuesApp';
- import { projectIssuesRoutes } from './routes';
-
- export const issuesHandler = new IssuesServiceMock();
- export const componentsHandler = new ComponentsServiceMock();
- export const branchHandler = new BranchesServiceMock();
-
- export const ui = {
- loading: byLabelText('loading'),
- issuePageHeadering: byRole('heading', { level: 1, name: 'issues.page' }),
- issueItemAction1: byRole('link', { name: 'Issue with no location message' }),
- issueItemAction2: byRole('link', { name: 'FlowIssue' }),
- issueItemAction3: byRole('link', { name: 'Issue on file' }),
- issueItemAction4: byRole('link', { name: 'Fix this' }),
- issueItemAction5: byRole('link', { name: 'Fix that' }),
- issueItemAction6: byRole('link', { name: 'Second issue' }),
- issueItemAction7: byRole('link', { name: 'Issue with tags' }),
- issueItemAction8: byRole('link', { name: 'Issue on page 2' }),
-
- issueItems: byRole('region'),
-
- issueItem1: byRole('region', { name: 'Issue with no location message' }),
- issueItem2: byRole('region', { name: 'FlowIssue' }),
- issueItem3: byRole('region', { name: 'Issue on file' }),
- issueItem4: byRole('region', { name: 'Fix this' }),
- issueItem5: byRole('region', { name: 'Fix that' }),
- issueItem6: byRole('region', { name: 'Second issue' }),
- issueItem7: byRole('region', { name: 'Issue with tags' }),
- issueItem8: byRole('region', { name: 'Issue on page 2' }),
- projectIssueItem6: byRole('button', { name: 'Second issue', exact: false }),
-
- assigneeFacet: byRole('button', { name: 'issues.facet.assignees' }),
- authorFacet: byRole('button', { name: 'issues.facet.authors' }),
- codeVariantsFacet: byRole('button', { name: 'issues.facet.codeVariants' }),
- creationDateFacet: byRole('button', { name: 'issues.facet.createdAt' }),
- languageFacet: byRole('button', { name: 'issues.facet.languages' }),
- projectFacet: byRole('button', { name: 'issues.facet.projects' }),
- resolutionFacet: byRole('button', { name: 'issues.facet.resolutions' }),
- ruleFacet: byRole('button', { name: 'issues.facet.rules' }),
- scopeFacet: byRole('button', { name: 'issues.facet.scopes' }),
- issueStatusFacet: byRole('button', { name: 'issues.facet.issueStatuses' }),
- tagFacet: byRole('button', { name: 'issues.facet.tags' }),
- typeFacet: byRole('button', { name: 'issues.facet.types' }),
- cleanCodeAttributeCategoryFacet: byRole('button', {
- name: 'issues.facet.cleanCodeAttributeCategories',
- }),
- softwareQualityFacet: byRole('button', {
- name: 'issues.facet.impactSoftwareQualities',
- }),
- severityFacet: byRole('button', { name: 'issues.facet.impactSeverities' }),
-
- clearCodeCategoryFacet: byTestId('clear-issues.facet.cleanCodeAttributeCategories'),
- clearSoftwareQualityFacet: byTestId('clear-issues.facet.impactSoftwareQualities'),
- clearAssigneeFacet: byTestId('clear-issues.facet.assignees'),
- clearAuthorFacet: byTestId('clear-issues.facet.authors'),
- clearCodeVariantsFacet: byTestId('clear-issues.facet.codeVariants'),
- clearCreationDateFacet: byTestId('clear-issues.facet.createdAt'),
- clearIssueTypeFacet: byTestId('clear-issues.facet.types'),
- clearProjectFacet: byTestId('clear-issues.facet.projects'),
- clearResolutionFacet: byTestId('clear-issues.facet.resolutions'),
- clearRuleFacet: byTestId('clear-issues.facet.rules'),
- clearScopeFacet: byTestId('clear-issues.facet.scopes'),
- clearSeverityFacet: byTestId('clear-issues.facet.impactSeverities'),
- clearIssueStatusFacet: byTestId('clear-issues.facet.issueStatuses'),
- clearTagFacet: byTestId('clear-issues.facet.tags'),
-
- responsibleCategoryFilter: byRole('checkbox', {
- name: `issue.clean_code_attribute_category.${CleanCodeAttributeCategory.Responsible}`,
- }),
- consistentCategoryFilter: byRole('checkbox', {
- name: `issue.clean_code_attribute_category.${CleanCodeAttributeCategory.Consistent}`,
- }),
- softwareQualityMaintainabilityFilter: byRole('checkbox', {
- name: `software_quality.${SoftwareQuality.Maintainability}`,
- }),
- codeSmellIssueTypeFilter: byRole('checkbox', { name: 'issue.type.CODE_SMELL' }),
- confirmedStatusFilter: byRole('checkbox', { name: 'issue.issue_status.CONFIRMED' }),
- fixedResolutionFilter: byRole('checkbox', { name: 'issue.resolution.FIXED' }),
- mainScopeFilter: byRole('checkbox', { name: 'issue.scope.MAIN' }),
- mediumSeverityFilter: byRole('checkbox', { name: `severity.${SoftwareImpactSeverity.Medium}` }),
- openStatusFilter: byRole('checkbox', { name: 'issue.issue_status.OPEN' }),
- vulnerabilityIssueTypeFilter: byRole('checkbox', { name: 'issue.type.VULNERABILITY' }),
-
- bulkChangeComment: byRole('textbox', { name: /issue_bulk_change.resolution_comment/ }),
-
- clearAllFilters: byRole('button', { name: 'clear_all_filters' }),
-
- dateInputMonthSelect: byTestId('month-select'),
- dateInputYearSelect: byTestId('year-select'),
-
- authorFacetSearch: byPlaceholderText('search.search_for_authors'),
- inNewCodeFilter: byRole('checkbox', { name: 'issues.new_code' }),
- languageFacetList: byRole('group', { name: 'issues.facet.languages' }),
- ruleFacetList: byRole('group', { name: 'issues.facet.rules' }),
- ruleFacetSearch: byPlaceholderText('search.search_for_rules'),
- tagFacetSearch: byPlaceholderText('search.search_for_tags'),
-
- guidePopup: byRole('alertdialog'),
- };
-
- export async function waitOnDataLoaded() {
- await waitFor(() => {
- expect(ui.loading.query()).not.toBeInTheDocument();
- });
- }
-
- export function renderIssueApp(
- currentUser = mockCurrentUser({ dismissedNotices: { [NoticeType.ISSUE_GUIDE]: true } }),
- ) {
- renderApp('issues', <IssuesApp />, { currentUser });
- }
-
- export function renderProjectIssuesApp(
- navigateTo?: string,
- overrides?: Partial<Component>,
- currentUser = mockCurrentUser({ dismissedNotices: { [NoticeType.ISSUE_GUIDE]: true } }),
- ) {
- renderAppWithComponentContext(
- 'project/issues',
- () => (
- <Route
- element={
- <div data-guiding-id="issue-5">
- <Outlet />
- </div>
- }
- >
- {projectIssuesRoutes()}
- </Route>
- ),
- { navigateTo, currentUser },
- { component: mockComponent(overrides) },
- );
- }
|