From 6b9a6544d4974909e05179b4480f9184102afab9 Mon Sep 17 00:00:00 2001 From: stanislavh Date: Wed, 15 Feb 2023 10:25:20 +0100 Subject: [PATCH] SONAR-14640 Add sonar.projectName scanner parameter in tutorials --- .../src/main/js/api/mocks/UserTokensMock.ts | 5 +- .../BranchAnalysisStepContent.tsx | 1 + .../__tests__/AzurePipelinesTutorial-it.tsx | 5 +- .../AzurePipelinesTutorial-it.tsx.snap | 8 +- .../commands/AnalysisCommand.tsx | 7 +- .../azure-pipelines/commands/JavaGradle.tsx | 4 +- .../azure-pipelines/commands/JavaMaven.tsx | 4 +- .../commands/PrepareAnalysisCommand.tsx | 7 +- .../bitbucket-pipelines/AnalysisCommand.tsx | 14 +- .../bitbucket-pipelines/PreambuleYaml.tsx | 2 +- .../AnalysisCommand-test.tsx.snap | 4 +- .../__snapshots__/PreambuleYaml-test.tsx.snap | 1 + .../bitbucket-pipelines/commands/Maven.ts | 5 +- .../github-action/commands/Gradle.tsx | 2 +- .../github-action/commands/JavaMaven.tsx | 6 +- .../__snapshots__/Gradle-test.tsx.snap | 2 + .../__snapshots__/JavaMaven-test.tsx.snap | 4 +- .../tutorials/gitlabci/GitLabCITutorial.tsx | 1 - .../tutorials/gitlabci/YmlFileStep.tsx | 11 +- .../gitlabci/__tests__/YmlFileStep-test.tsx | 1 - .../GitLabCITutorial-test.tsx.snap | 1 - .../gitlabci/commands/PipeCommand.tsx | 9 +- .../commands/__tests__/PipeCommand-test.tsx | 2 + .../__snapshots__/PipeCommand-test.tsx.snap | 4 +- .../jenkins/buildtool-steps/Gradle.tsx | 2 +- .../jenkins/buildtool-steps/Maven.tsx | 6 +- .../__snapshots__/Gradle-test.tsx.snap | 1 + .../__snapshots__/Maven-test.tsx.snap | 2 +- .../components/tutorials/other/TokenStep.tsx | 6 +- .../other/__tests__/BuildToolForm-test.tsx | 54 -- .../other/__tests__/DoneNextSteps-test.tsx | 34 - .../other/__tests__/OtherTutorial-it.tsx | 165 +++++ .../other/__tests__/OtherTutorial-test.tsx | 56 -- .../__tests__/ProjectAnalysisStep-test.tsx | 39 - .../other/__tests__/TokenStep-test.tsx | 106 --- .../__snapshots__/BuildToolForm-test.tsx.snap | 172 ----- .../__snapshots__/DoneNextSteps-test.tsx.snap | 85 --- .../__snapshots__/OtherTutorial-it.tsx.snap | 132 ++++ .../__snapshots__/OtherTutorial-test.tsx.snap | 71 -- .../ProjectAnalysisStep-test.tsx.snap | 13 - .../__snapshots__/TokenStep-test.tsx.snap | 693 ------------------ .../tutorials/other/commands/JavaGradle.tsx | 1 + .../tutorials/other/commands/JavaMaven.tsx | 1 + .../__snapshots__/JavaGradle-test.tsx.snap | 1 + .../__snapshots__/JavaMaven-test.tsx.snap | 1 + .../js/components/tutorials/test-utils.ts | 25 + .../src/main/js/components/tutorials/utils.ts | 3 +- .../resources/org/sonar/l10n/core.properties | 1 + 48 files changed, 406 insertions(+), 1374 deletions(-) delete mode 100644 server/sonar-web/src/main/js/components/tutorials/other/__tests__/BuildToolForm-test.tsx delete mode 100644 server/sonar-web/src/main/js/components/tutorials/other/__tests__/DoneNextSteps-test.tsx create mode 100644 server/sonar-web/src/main/js/components/tutorials/other/__tests__/OtherTutorial-it.tsx delete mode 100644 server/sonar-web/src/main/js/components/tutorials/other/__tests__/OtherTutorial-test.tsx delete mode 100644 server/sonar-web/src/main/js/components/tutorials/other/__tests__/ProjectAnalysisStep-test.tsx delete mode 100644 server/sonar-web/src/main/js/components/tutorials/other/__tests__/TokenStep-test.tsx delete mode 100644 server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/BuildToolForm-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/DoneNextSteps-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/OtherTutorial-it.tsx.snap delete mode 100644 server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/OtherTutorial-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/ProjectAnalysisStep-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/TokenStep-test.tsx.snap diff --git a/server/sonar-web/src/main/js/api/mocks/UserTokensMock.ts b/server/sonar-web/src/main/js/api/mocks/UserTokensMock.ts index 347e6733ba3..4c6de69c5d9 100644 --- a/server/sonar-web/src/main/js/api/mocks/UserTokensMock.ts +++ b/server/sonar-web/src/main/js/api/mocks/UserTokensMock.ts @@ -22,9 +22,6 @@ import { mockUserToken } from '../../helpers/mocks/token'; import { NewUserToken, TokenType, UserToken } from '../../types/token'; import { generateToken, getTokens, revokeToken } from '../user-tokens'; -const RANDOM_RADIX = 36; -const RANDOM_PREFIX = 2; - const defaultTokens = [ mockUserToken({ name: 'local-scanner', @@ -77,7 +74,7 @@ export default class UserTokensMock { type, projectKey, isExpired: false, - token: Math.random().toString(RANDOM_RADIX).slice(RANDOM_PREFIX), + token: `generatedtoken${this.tokens.length}`, createdAt: '2022-04-04T04:04:04+0000', expirationDate, }; diff --git a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/BranchAnalysisStepContent.tsx b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/BranchAnalysisStepContent.tsx index d4d6c83708a..8b74202c41e 100644 --- a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/BranchAnalysisStepContent.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/BranchAnalysisStepContent.tsx @@ -62,6 +62,7 @@ export function BranchAnalysisStepContent(props: BranchesAnalysisStepProps) { onStepValidationChange={onStepValidationChange} buildTool={buildTechnology} projectKey={component.key} + projectName={component.name} /> ); diff --git a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/__tests__/AzurePipelinesTutorial-it.tsx b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/__tests__/AzurePipelinesTutorial-it.tsx index 234a84bebbb..ed24e8b5b7f 100644 --- a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/__tests__/AzurePipelinesTutorial-it.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/__tests__/AzurePipelinesTutorial-it.tsx @@ -27,6 +27,7 @@ import { mockLanguage, mockLoggedInUser } from '../../../../helpers/testMocks'; import { renderApp, RenderContext } from '../../../../helpers/testReactTestingUtils'; import { Permissions } from '../../../../types/permissions'; import { TokenType } from '../../../../types/token'; +import { getCopyToClipboardValue } from '../../test-utils'; import { OSs } from '../../types'; import AzurePipelinesTutorial, { AzurePipelinesTutorialProps } from '../AzurePipelinesTutorial'; @@ -250,7 +251,3 @@ async function clickButton(user: UserEvent, name: string, context?: HTMLElement) async function goToNextStep(user: UserEvent) { await clickButton(user, 'continue'); } - -function getCopyToClipboardValue(i = 0, name = 'copy_to_clipboard') { - return screen.getAllByRole('button', { name })[i].getAttribute('data-clipboard-text'); -} diff --git a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/__tests__/__snapshots__/AzurePipelinesTutorial-it.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/__tests__/__snapshots__/AzurePipelinesTutorial-it.tsx.snap index f02fe7b9621..cba7e2bcd12 100644 --- a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/__tests__/__snapshots__/AzurePipelinesTutorial-it.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/__tests__/__snapshots__/AzurePipelinesTutorial-it.tsx.snap @@ -31,12 +31,16 @@ exports[`should render correctly and allow navigating between the different step "# Additional properties that will be passed to the scanner, # Put one key=value per line, example: # sonar.exclusions=**/*.bin -sonar.projectKey=foo" +sonar.projectKey=foo +sonar.projectName=MyProject +" `; exports[`should render correctly and allow navigating between the different steps: maven, copy additional properties 1`] = ` "# Additional properties that will be passed to the scanner, # Put one key=value per line, example: # sonar.exclusions=**/*.bin -sonar.projectKey=foo" +sonar.projectKey=foo +sonar.projectName=MyProject +" `; diff --git a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/AnalysisCommand.tsx b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/AnalysisCommand.tsx index 31db342133b..9b2078e5941 100644 --- a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/AnalysisCommand.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/AnalysisCommand.tsx @@ -27,12 +27,13 @@ import Other from './Other'; export interface AnalysisCommandProps { projectKey: string; + projectName: string; buildTool?: BuildTools; onStepValidationChange: (isValid: boolean) => void; } export default function AnalysisCommand(props: AnalysisCommandProps) { - const { buildTool, projectKey } = props; + const { buildTool, projectKey, projectName } = props; React.useEffect(() => { if (buildTool && buildTool !== BuildTools.CFamily) { @@ -45,10 +46,10 @@ export default function AnalysisCommand(props: AnalysisCommandProps) { } switch (buildTool) { case BuildTools.Maven: - return ; + return ; case BuildTools.Gradle: - return ; + return ; case BuildTools.DotNet: return ; diff --git a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/JavaGradle.tsx b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/JavaGradle.tsx index 4ad6263d34e..5e098e2a243 100644 --- a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/JavaGradle.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/JavaGradle.tsx @@ -28,10 +28,11 @@ import PublishSteps from './PublishSteps'; export interface JavaGradleProps { projectKey: string; + projectName: string; } export default function JavaGradle(props: JavaGradleProps) { - const { projectKey } = props; + const { projectKey, projectName } = props; return ( <> @@ -46,6 +47,7 @@ export default function JavaGradle(props: JavaGradleProps) { buildTool={BuildTools.Gradle} kind={PrepareType.JavaMavenGradle} projectKey={projectKey} + projectName={projectName} /> diff --git a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/JavaMaven.tsx b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/JavaMaven.tsx index 3ef4d3847a0..a7e7f9941bf 100644 --- a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/JavaMaven.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/JavaMaven.tsx @@ -28,10 +28,11 @@ import PublishSteps from './PublishSteps'; export interface JavaMavenProps { projectKey: string; + projectName: string; } export default function JavaMaven(props: JavaMavenProps) { - const { projectKey } = props; + const { projectKey, projectName } = props; return ( <> @@ -45,6 +46,7 @@ export default function JavaMaven(props: JavaMavenProps) { buildTool={BuildTools.Gradle} kind={PrepareType.JavaMavenGradle} projectKey={projectKey} + projectName={projectName} /> diff --git a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/PrepareAnalysisCommand.tsx b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/PrepareAnalysisCommand.tsx index cc7f878b1d1..dc6e5975f2f 100644 --- a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/PrepareAnalysisCommand.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/PrepareAnalysisCommand.tsx @@ -35,17 +35,20 @@ export interface PrepareAnalysisCommandProps { buildTool: BuildTools; kind: PrepareType; projectKey: string; + projectName?: string; } export default function PrepareAnalysisCommand(props: PrepareAnalysisCommandProps) { - const { buildTool, kind, projectKey } = props; + const { buildTool, kind, projectKey, projectName } = props; const ADDITIONAL_PROPERTY = 'sonar.cfamily.build-wrapper-output=bw-output'; const MAVEN_GRADLE_PROPS_SNIPPET = `# Additional properties that will be passed to the scanner, # Put one key=value per line, example: # sonar.exclusions=**/*.bin -sonar.projectKey=${projectKey}`; +sonar.projectKey=${projectKey} +sonar.projectName=${projectName} +`; return (
    diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/AnalysisCommand.tsx b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/AnalysisCommand.tsx index 80a5189645e..3998cb59bcc 100644 --- a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/AnalysisCommand.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/AnalysisCommand.tsx @@ -41,7 +41,12 @@ export interface AnalysisCommandProps extends WithAvailableFeaturesProps { } const YamlTemplate: Dictionary< - (branchesEnabled?: boolean, mainBranchName?: string, projectKey?: string) => string + ( + branchesEnabled?: boolean, + mainBranchName?: string, + projectKey?: string, + projectName?: string + ) => string > = { [BuildTools.Gradle]: gradleExample, [BuildTools.Maven]: mavenExample, @@ -58,7 +63,12 @@ export function AnalysisCommand(props: AnalysisCommandProps) { return null; } - const yamlTemplate = YamlTemplate[buildTool](branchSupportEnabled, mainBranchName, component.key); + const yamlTemplate = YamlTemplate[buildTool]( + branchSupportEnabled, + mainBranchName, + component.key, + component.name + ); return ( <> diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/PreambuleYaml.tsx b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/PreambuleYaml.tsx index 55e1d3f0380..d54087fa9f1 100644 --- a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/PreambuleYaml.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/PreambuleYaml.tsx @@ -51,7 +51,7 @@ export function PreambuleYaml(props: PreambuleYamlProps) { sq: org.sonarqube, }} /> - + ); case BuildTools.CFamily: diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/AnalysisCommand-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/AnalysisCommand-test.tsx.snap index 2b454e96ca6..ac895b8390a 100644 --- a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/AnalysisCommand-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/AnalysisCommand-test.tsx.snap @@ -402,7 +402,7 @@ definitions: - maven - sonar script: - - mvn verify sonar:sonar -Dsonar.projectKey=my-project + - mvn verify sonar:sonar -Dsonar.projectKey=my-project -Dsonar.projectName='MyProject' caches: sonar: ~/.sonar @@ -457,7 +457,7 @@ definitions: - maven - sonar script: - - mvn verify sonar:sonar -Dsonar.projectKey=my-project + - mvn verify sonar:sonar -Dsonar.projectKey=my-project -Dsonar.projectName='MyProject' caches: sonar: ~/.sonar diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/PreambuleYaml-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/PreambuleYaml-test.tsx.snap index 267f1b54a7a..f4662e442ec 100644 --- a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/PreambuleYaml-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/PreambuleYaml-test.tsx.snap @@ -64,6 +64,7 @@ exports[`should render correctly for gradle 1`] = ` sonar { properties { property "sonar.projectKey", "my-project" + property "sonar.projectName", "MyProject" } }" /> diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Maven.ts b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Maven.ts index e67693b0138..16f1b7a920b 100644 --- a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Maven.ts +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Maven.ts @@ -20,7 +20,8 @@ export default function mavenExample( branchesEnabled: boolean, mainBranchName: string, - projectKey: string + projectKey: string, + projectName: string ) { return `image: maven:3-openjdk-11 @@ -32,7 +33,7 @@ definitions: - maven - sonar script: - - mvn verify sonar:sonar -Dsonar.projectKey=${projectKey} + - mvn verify sonar:sonar -Dsonar.projectKey=${projectKey} -Dsonar.projectName='${projectName}' caches: sonar: ~/.sonar diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Gradle.tsx b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Gradle.tsx index 17874ed23f8..7d1a8247e21 100644 --- a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Gradle.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/Gradle.tsx @@ -79,7 +79,7 @@ export default function Gradle(props: GradleProps) { sq: org.sonarqube, }} /> - + void; } -function mavenYamlSteps(projectKey: string) { +function mavenYamlSteps(projectKey: string, projectName: string) { return ` - name: Set up JDK 11 uses: actions/setup-java@v1 @@ -54,7 +54,7 @@ function mavenYamlSteps(projectKey: string) { GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }} - run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=${projectKey}`; + run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=${projectKey} -Dsonar.projectName='${projectName}'`; } export default function JavaMaven(props: JavaMavenProps) { @@ -67,7 +67,7 @@ export default function JavaMaven(props: JavaMavenProps) { mainBranchName, !!branchesEnabled, GITHUB_ACTIONS_RUNS_ON_LINUX, - mavenYamlSteps(component.key) + mavenYamlSteps(component.key, component.name) )} /> diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/__tests__/__snapshots__/Gradle-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/__tests__/__snapshots__/Gradle-test.tsx.snap index 10bac0a5d7a..c57af2d85a5 100644 --- a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/__tests__/__snapshots__/Gradle-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/__tests__/__snapshots__/Gradle-test.tsx.snap @@ -36,6 +36,7 @@ exports[`should render correctly 1`] = ` sonar { properties { property "sonar.projectKey", "my-project" + property "sonar.projectName", "MyProject" } }" /> @@ -124,6 +125,7 @@ exports[`should render correctly: without branch enabled 1`] = ` sonar { properties { property "sonar.projectKey", "my-project" + property "sonar.projectName", "MyProject" } }" /> diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/__tests__/__snapshots__/JavaMaven-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/__tests__/__snapshots__/JavaMaven-test.tsx.snap index c26604e439e..4b5b2b2a6db 100644 --- a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/__tests__/__snapshots__/JavaMaven-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/__tests__/__snapshots__/JavaMaven-test.tsx.snap @@ -42,7 +42,7 @@ jobs: GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }} - run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=my-project" + run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=my-project -Dsonar.projectName='MyProject'" /> setStep(Steps.ALL_SET)} onOpen={() => setStep(Steps.YML)} open={step === Steps.YML} - projectKey={component.key} /> void; onOpen: () => void; open: boolean; - projectKey: string; mainBranchName: string; } @@ -51,13 +50,14 @@ const mavenSnippet = () => ` true `; -const gradleSnippet = (key: string) => `plugins { +const gradleSnippet = (key: string, name: string) => `plugins { id "org.sonarqube" version "${GRADLE_SCANNER_VERSION}" } sonar { properties { property "sonar.projectKey", "${key}" + property "sonar.projectName", "${name}" property "sonar.qualitygate.wait", true } }`; @@ -81,7 +81,7 @@ const filenameForBuildTool = { }; export function YmlFileStep(props: YmlFileStepProps) { - const { open, finished, projectKey, mainBranchName, hasCLanguageFeature, component } = props; + const { open, finished, mainBranchName, hasCLanguageFeature, component } = props; const branchSupportEnabled = props.hasFeature(Feature.BranchSupport); const [buildTool, setBuildTool] = React.useState(); @@ -130,7 +130,7 @@ export function YmlFileStep(props: YmlFileStepProps) { ), }} /> - + )} {buildTool && ( @@ -159,7 +159,8 @@ export function YmlFileStep(props: YmlFileStepProps) { buildTool={buildTool} branchesEnabled={branchSupportEnabled} mainBranchName={mainBranchName} - projectKey={projectKey} + projectKey={component.key} + projectName={component.name} />

    diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/YmlFileStep-test.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/YmlFileStep-test.tsx index 27f622a5614..ecb14c207c9 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/YmlFileStep-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/YmlFileStep-test.tsx @@ -36,7 +36,6 @@ function shallowRender(props: Partial = {}) { component={mockComponent()} hasFeature={jest.fn().mockReturnValue(true)} open={true} - projectKey="test" finished={true} mainBranchName="main" onDone={jest.fn()} diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-test.tsx.snap index 43c6bf6c5bd..ce506bca402 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-test.tsx.snap @@ -80,7 +80,6 @@ exports[`should render correctly 1`] = ` onDone={[Function]} onOpen={[Function]} open={false} - projectKey="my-project" /> 'gradle sonar' }, [BuildTools.Maven]: { image: 'maven:3.6.3-jdk-11', - script: (projectKey: string) => ` - - mvn verify sonar:sonar -Dsonar.projectKey=${projectKey}`, + script: (projectKey: string, projectName: string) => ` + - mvn verify sonar:sonar -Dsonar.projectKey=${projectKey} -Dsonar.projectName='${projectName}'`, }, [BuildTools.DotNet]: { image: 'mcr.microsoft.com/dotnet/core/sdk:latest', @@ -57,7 +58,7 @@ const BUILD_TOOL_SPECIFIC = { }; export default function PipeCommand(props: PipeCommandProps) { - const { projectKey, branchesEnabled, buildTool, mainBranchName } = props; + const { projectKey, branchesEnabled, buildTool, mainBranchName, projectName } = props; let command: string; if (buildTool === BuildTools.CFamily) { command = `image: @@ -108,7 +109,7 @@ sonarqube-check: key: "\${CI_JOB_NAME}" paths: - .sonar/cache - script: ${script(projectKey)} + script: ${script(projectKey, projectName)} allow_failure: true rules: ${onlyBlock} diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommand-test.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommand-test.tsx index e4befcf613f..1715a1fc1cb 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommand-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommand-test.tsx @@ -36,6 +36,7 @@ it.each([ branchesEnabled={true} mainBranchName="main" projectKey="test" + projectName="Test Project" /> ) ).toMatchSnapshot('branches enabled'); @@ -46,6 +47,7 @@ it.each([ branchesEnabled={true} mainBranchName="main" projectKey="test" + projectName="Test Project" /> ) ).toMatchSnapshot('branches not enabled'); diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommand-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommand-test.tsx.snap index 607b06e2437..b079bcadbc1 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommand-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommand-test.tsx.snap @@ -195,7 +195,7 @@ exports[`should render correctly for maven: branches enabled 1`] = ` paths: - .sonar/cache script: - - mvn verify sonar:sonar -Dsonar.projectKey=test + - mvn verify sonar:sonar -Dsonar.projectKey=test -Dsonar.projectName='Test Project' allow_failure: true rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' @@ -219,7 +219,7 @@ exports[`should render correctly for maven: branches not enabled 1`] = ` paths: - .sonar/cache script: - - mvn verify sonar:sonar -Dsonar.projectKey=test + - mvn verify sonar:sonar -Dsonar.projectKey=test -Dsonar.projectName='Test Project' allow_failure: true rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' diff --git a/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/Gradle.tsx b/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/Gradle.tsx index ca2267f64e1..478ae99d2dd 100644 --- a/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/Gradle.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/Gradle.tsx @@ -45,7 +45,7 @@ export default function Gradle(props: LanguageProps) { filename="build.gradle" translationKey="onboarding.tutorial.with.jenkins.jenkinsfile.gradle.step2" /> - + diff --git a/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/Maven.tsx b/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/Maven.tsx index 1287fb24877..b35210eeb2c 100644 --- a/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/Maven.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/Maven.tsx @@ -22,7 +22,7 @@ import FinishButton from '../../components/FinishButton'; import { LanguageProps } from '../JenkinsfileStep'; import CreateJenkinsfileBulletPoint from './CreateJenkinsfileBulletPoint'; -function jenkinsfileSnippet(projectKey: string) { +function jenkinsfileSnippet(projectKey: string, projectName: string) { return `node { stage('SCM') { checkout scm @@ -30,7 +30,7 @@ function jenkinsfileSnippet(projectKey: string) { stage('SonarQube Analysis') { def mvn = tool 'Default Maven'; withSonarQubeEnv() { - sh "\${mvn}/bin/mvn clean verify sonar:sonar -Dsonar.projectKey=${projectKey}" + sh "\${mvn}/bin/mvn clean verify sonar:sonar -Dsonar.projectKey=${projectKey} -Dsonar.projectName='${projectName}'" } } }`; @@ -41,7 +41,7 @@ export default function Maven({ component, onDone }: LanguageProps) { <> diff --git a/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/__tests__/__snapshots__/Gradle-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/__tests__/__snapshots__/Gradle-test.tsx.snap index b35f87d237e..b231c344316 100644 --- a/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/__tests__/__snapshots__/Gradle-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/__tests__/__snapshots__/Gradle-test.tsx.snap @@ -17,6 +17,7 @@ exports[`should render correctly 1`] = ` sonar { properties { property "sonar.projectKey", "my-project" + property "sonar.projectName", "MyProject" } }" /> diff --git a/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/__tests__/__snapshots__/Maven-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/__tests__/__snapshots__/Maven-test.tsx.snap index 6b438876f92..185cf0bacfd 100644 --- a/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/__tests__/__snapshots__/Maven-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/__tests__/__snapshots__/Maven-test.tsx.snap @@ -11,7 +11,7 @@ exports[`should render correctly 1`] = ` stage('SonarQube Analysis') { def mvn = tool 'Default Maven'; withSonarQubeEnv() { - sh "\${mvn}/bin/mvn clean verify sonar:sonar -Dsonar.projectKey=my-project" + sh "\${mvn}/bin/mvn clean verify sonar:sonar -Dsonar.projectKey=my-project -Dsonar.projectName='MyProject'" } } }" diff --git a/server/sonar-web/src/main/js/components/tutorials/other/TokenStep.tsx b/server/sonar-web/src/main/js/components/tutorials/other/TokenStep.tsx index 44d942e5a49..dd1e30b8d7a 100644 --- a/server/sonar-web/src/main/js/components/tutorials/other/TokenStep.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/other/TokenStep.tsx @@ -323,7 +323,11 @@ export default class TokenStep extends React.PureComponent { {loading ? ( ) : ( - + )} ) : ( diff --git a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/BuildToolForm-test.tsx b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/BuildToolForm-test.tsx deleted file mode 100644 index 1f0a889d305..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/BuildToolForm-test.tsx +++ /dev/null @@ -1,54 +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 { BuildTools, OSs } from '../../types'; -import { BuildToolForm } from '../BuildToolForm'; - -it('renders correctly', () => { - expect(shallowRender()).toMatchSnapshot('default'); - expect(shallowRender({ hasCLanguageFeature: false })).toMatchSnapshot('without C'); - expect(shallowRender().setState({ config: { buildTool: BuildTools.Maven } })).toMatchSnapshot( - 'with "maven" selected' - ); - expect(shallowRender().setState({ config: { buildTool: BuildTools.Other } })).toMatchSnapshot( - 'with "other" selected' - ); -}); - -it('correctly calls the onDone prop', () => { - const onDone = jest.fn(); - const wrapper = shallowRender({ onDone }); - - wrapper.instance().handleBuildToolChange(BuildTools.Gradle); - expect(onDone).toHaveBeenCalledWith(expect.objectContaining({ buildTool: BuildTools.Gradle })); - - wrapper.setState({ config: { buildTool: BuildTools.Other } }); - wrapper.instance().handleOSChange(OSs.Windows); - expect(onDone).toHaveBeenCalledWith( - expect.objectContaining({ os: OSs.Windows, buildTool: BuildTools.Other }) - ); -}); - -function shallowRender(props: Partial = {}) { - return shallow( - - ); -} diff --git a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/DoneNextSteps-test.tsx b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/DoneNextSteps-test.tsx deleted file mode 100644 index b31e34d19e0..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/DoneNextSteps-test.tsx +++ /dev/null @@ -1,34 +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 DoneNextSteps, { DoneNextStepsProps } from '../DoneNextSteps'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot('default'); - expect( - shallowRender({ component: mockComponent({ configuration: { showSettings: true } }) }) - ).toMatchSnapshot('project admin'); -}); - -function shallowRender(props: Partial = {}) { - return shallow(); -} diff --git a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/OtherTutorial-it.tsx b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/OtherTutorial-it.tsx new file mode 100644 index 00000000000..d7c7133c872 --- /dev/null +++ b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/OtherTutorial-it.tsx @@ -0,0 +1,165 @@ +/* + * 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 userEvent from '@testing-library/user-event'; +import React from 'react'; +import selectEvent from 'react-select-event'; +import { byRole, byText } from 'testing-library-selector'; +import UserTokensMock from '../../../../api/mocks/UserTokensMock'; +import { mockComponent } from '../../../../helpers/mocks/component'; +import { mockLanguage, mockLoggedInUser } from '../../../../helpers/testMocks'; +import { renderApp, RenderContext } from '../../../../helpers/testReactTestingUtils'; +import { getCopyToClipboardValue, getTutorialBuildButtons } from '../../test-utils'; +import OtherTutorial from '../OtherTutorial'; + +jest.mock('../../../../api/user-tokens'); + +jest.mock('../../../../api/settings', () => ({ + getAllValues: jest.fn().mockResolvedValue([]), +})); + +const tokenMock = new UserTokensMock(); + +afterEach(() => { + tokenMock.reset(); +}); + +const ui = { + provideTokenTitle: byRole('heading', { name: 'onboarding.token.header' }), + runAnalysisTitle: byRole('heading', { name: 'onboarding.analysis.header' }), + generateTokenRadio: byRole('radio', { name: 'onboarding.token.generate.PROJECT_ANALYSIS_TOKEN' }), + existingTokenRadio: byRole('radio', { name: 'onboarding.token.use_existing_token' }), + tokenNameInput: byRole('textbox', { name: 'onboarding.token.name.label' }), + expiresInSelect: byRole('combobox', { name: '' }), + generateTokenButton: byRole('button', { name: 'onboarding.token.generate' }), + deleteTokenButton: byRole('button', { name: 'onboarding.token.delete' }), + tokenValueInput: byRole('textbox', { name: 'onboarding.token.use_existing_token.label' }), + invalidTokenValueMessage: byText('onboarding.token.invalid_format'), + continueButton: byRole('button', { name: 'continue' }), + ...getTutorialBuildButtons(), +}; + +it('should generate/delete a new token or use existing one', async () => { + const user = userEvent.setup(); + renderOtherTutorial(); + + // Verify that pages is rendered and includes 2 steps + expect(await ui.provideTokenTitle.find()).toBeInTheDocument(); + expect(ui.runAnalysisTitle.get()).toBeInTheDocument(); + + // Generating token + user.type(ui.tokenNameInput.get(), 'Testing token'); + await selectEvent.select(ui.expiresInSelect.get(), 'users.tokens.expiration.365'); + await user.click(ui.generateTokenButton.get()); + + expect(ui.continueButton.get()).toBeEnabled(); + + // Deleting generated token & switchning to existing one + await user.click(ui.deleteTokenButton.get()); + + await user.click(ui.existingTokenRadio.get()); + await user.type(ui.tokenValueInput.get(), 'INVALID TOKEN VALUE'); + expect(ui.invalidTokenValueMessage.get()).toBeInTheDocument(); + + user.clear(ui.tokenValueInput.get()); + await user.type(ui.tokenValueInput.get(), 'validtokenvalue'); + expect(ui.continueButton.get()).toBeEnabled(); + + // navigate to 'Run analysis' step + await user.click(ui.continueButton.get()); + expect(ui.describeBuildTitle.get()).toBeInTheDocument(); + + // navigate to previous step + await user.click(ui.provideTokenTitle.get()); + expect(ui.continueButton.get()).toBeEnabled(); +}); + +it('can choose build tools and copy provided settings', async () => { + const user = userEvent.setup(); + renderOtherTutorial(); + + await user.click(ui.generateTokenButton.get()); + await user.click(ui.continueButton.get()); + + // Maven + await user.click(ui.mavenBuildButton.get()); + expect(getCopyToClipboardValue()).toMatchSnapshot('maven: execute scanner'); + + // Gradle + await user.click(ui.gradleBuildButton.get()); + expect(getCopyToClipboardValue()).toMatchSnapshot('gradle: sonarqube plugin'); + expect(getCopyToClipboardValue(1)).toMatchSnapshot('gradle: execute scanner'); + + // Dotnet - Core + await user.click(ui.dotnetBuildButton.get()); + expect(getCopyToClipboardValue()).toMatchSnapshot('dotnet core: install scanner globally'); + expect(getCopyToClipboardValue(1)).toMatchSnapshot('dotnet core: execute command 1'); + expect(getCopyToClipboardValue(2)).toMatchSnapshot('dotnet core: execute command 2'); + expect(getCopyToClipboardValue(3)).toMatchSnapshot('dotnet core: execute command 3'); + + // Dotnet - Framework + await user.click(ui.dotnetFrameworkButton.get()); + expect(getCopyToClipboardValue()).toMatchSnapshot('dotnet framework: execute command 1'); + expect(getCopyToClipboardValue(1)).toMatchSnapshot('dotnet framework: execute command 2'); + expect(getCopyToClipboardValue(2)).toMatchSnapshot('dotnet framework: execute command 3'); + + // C Family - Linux + await user.click(ui.cFamilyBuildButton.get()); + await user.click(ui.linuxButton.get()); + expect(getCopyToClipboardValue()).toMatchSnapshot('cfamily linux: execute build wrapper'); + expect(getCopyToClipboardValue(1)).toMatchSnapshot('cfamily linux: execute scanner'); + + // C Family - Windows + await user.click(ui.windowsButton.get()); + expect(getCopyToClipboardValue()).toMatchSnapshot('cfamily windows: execute build wrapper'); + expect(getCopyToClipboardValue(1)).toMatchSnapshot('cfamily windows: execute scanner'); + + // C Family - MacOS + await user.click(ui.macosButton.get()); + expect(getCopyToClipboardValue()).toMatchSnapshot('cfamily macos: execute build wrapper'); + expect(getCopyToClipboardValue(1)).toMatchSnapshot('cfamily macos: execute scanner'); + + // Other - Linux + await user.click(ui.otherBuildButton.get()); + await user.click(ui.linuxButton.get()); + expect(getCopyToClipboardValue()).toMatchSnapshot('other linux: execute scanner'); + + // Other - Windows + await user.click(ui.windowsButton.get()); + expect(getCopyToClipboardValue()).toMatchSnapshot('other windows: execute scanner'); + + // Other - MacOS + await user.click(ui.macosButton.get()); + expect(getCopyToClipboardValue()).toMatchSnapshot('other macos: execute scanner'); +}); + +function renderOtherTutorial({ + languages = { c: mockLanguage({ key: 'c' }) }, +}: RenderContext = {}) { + return renderApp( + '/', + , + { languages } + ); +} diff --git a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/OtherTutorial-test.tsx b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/OtherTutorial-test.tsx deleted file mode 100644 index 0983f0edb83..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/OtherTutorial-test.tsx +++ /dev/null @@ -1,56 +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 { mockLoggedInUser } from '../../../../helpers/testMocks'; -import OtherTutorial from '../OtherTutorial'; -import ProjectAnalysisStep from '../ProjectAnalysisStep'; -import TokenStep from '../TokenStep'; - -it('renders correctly', () => { - expect(shallowRender()).toMatchSnapshot('default'); -}); - -it('allows to navigate between steps', () => { - const wrapper = shallowRender(); - const instance = wrapper.instance(); - - expect(wrapper.find(TokenStep).props().open).toBe(true); - - instance.handleTokenDone('foo'); - expect(wrapper.find(TokenStep).props().open).toBe(false); - expect(wrapper.find(ProjectAnalysisStep).props().open).toBe(true); - - instance.handleTokenOpen(); - expect(wrapper.find(TokenStep).props().open).toBe(true); - expect(wrapper.find(ProjectAnalysisStep).props().open).toBe(false); -}); - -function shallowRender(props: Partial = {}) { - return shallow( - - ); -} diff --git a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/ProjectAnalysisStep-test.tsx b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/ProjectAnalysisStep-test.tsx deleted file mode 100644 index 1cabe5f6dcd..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/ProjectAnalysisStep-test.tsx +++ /dev/null @@ -1,39 +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 ProjectAnalysisStep from '../ProjectAnalysisStep'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); -}); - -function shallowRender() { - return shallow( - - ); -} diff --git a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/TokenStep-test.tsx b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/TokenStep-test.tsx deleted file mode 100644 index e9de063739f..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/TokenStep-test.tsx +++ /dev/null @@ -1,106 +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 { getTokens } from '../../../../api/user-tokens'; -import { mockLoggedInUser } from '../../../../helpers/testMocks'; -import { change, click, submit, waitAndUpdate } from '../../../../helpers/testUtils'; -import TokenStep from '../TokenStep'; - -jest.mock('../../../../api/user-tokens', () => ({ - getTokens: jest.fn().mockResolvedValue([{ name: 'foo' }]), - generateToken: jest.fn().mockResolvedValue({ token: 'abcd1234' }), - revokeToken: jest.fn().mockResolvedValue(null), -})); - -jest.mock('../../../../api/settings', () => { - return { - ...jest.requireActual('../../../../api/settings'), - getAllValues: jest.fn().mockResolvedValue([ - { - key: 'sonar.auth.token.max.allowed.lifetime', - value: 'No expiration', - }, - ]), - }; -}); - -it('sets an initial token name', async () => { - (getTokens as jest.Mock).mockResolvedValueOnce([{ name: 'fôo' }]); - const wrapper = shallowRender({ initialTokenName: 'fôo' }); - await waitAndUpdate(wrapper); - expect(wrapper.dive().find('input').props().value).toBe('fôo 1'); -}); - -it('generates token', async () => { - const wrapper = shallowRender(); - await waitAndUpdate(wrapper); - expect(wrapper.dive()).toMatchSnapshot(); - change(wrapper.dive().find('input'), 'my token'); - submit(wrapper.dive().find('form')); - expect(wrapper.dive()).toMatchSnapshot(); // spinner - await waitAndUpdate(wrapper); - expect(wrapper.dive()).toMatchSnapshot(); -}); - -it('revokes token', async () => { - const wrapper = shallowRender(); - await new Promise(setImmediate); - wrapper.setState({ token: 'abcd1234', tokenName: 'my token' }); - expect(wrapper.dive()).toMatchSnapshot(); - (wrapper.dive().find('DeleteButton').prop('onClick') as Function)(); - wrapper.update(); - expect(wrapper.dive()).toMatchSnapshot(); // spinner - await waitAndUpdate(wrapper); - expect(wrapper.dive()).toMatchSnapshot(); -}); - -it('continues', async () => { - const onContinue = jest.fn(); - const wrapper = shallowRender({ onContinue }); - await new Promise(setImmediate); - wrapper.setState({ token: 'abcd1234', tokenName: 'my token' }); - click(wrapper.dive().find('[className="js-continue"]')); - expect(onContinue).toHaveBeenCalledWith('abcd1234'); -}); - -it('uses existing token', async () => { - const onContinue = jest.fn(); - const wrapper = shallowRender({ onContinue }); - await new Promise(setImmediate); - wrapper.setState({ existingToken: 'abcd1234', selection: 'use-existing' }); - click(wrapper.dive().find('[className="js-continue"]')); - expect(onContinue).toHaveBeenCalledWith('abcd1234'); -}); - -function shallowRender(props: Partial = {}) { - return shallow( - - ); -} diff --git a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/BuildToolForm-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/BuildToolForm-test.tsx.snap deleted file mode 100644 index ed38c39ba37..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/BuildToolForm-test.tsx.snap +++ /dev/null @@ -1,172 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`renders correctly: default 1`] = ` - -

    -

    - onboarding.build -

    - -
    - -`; - -exports[`renders correctly: with "maven" selected 1`] = ` - -
    -

    - onboarding.build -

    - -
    -
    -`; - -exports[`renders correctly: with "other" selected 1`] = ` - -
    -

    - onboarding.build -

    - -
    - -
    -`; - -exports[`renders correctly: without C 1`] = ` - -
    -

    - onboarding.build -

    - -
    -
    -`; diff --git a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/DoneNextSteps-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/DoneNextSteps-test.tsx.snap deleted file mode 100644 index b7363c4bb3e..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/DoneNextSteps-test.tsx.snap +++ /dev/null @@ -1,85 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly: default 1`] = ` - -
    -

    - - onboarding.analysis.auto_refresh_after_analysis.done - - - onboarding.analysis.auto_refresh_after_analysis.auto_refresh -

    -

    - onboarding.analysis.auto_refresh_after_analysis.set_up_pr_deco_and_ci -

    -

    - - onboarding.analysis.auto_refresh_after_analysis.check_these_links.branches - , - "link_pr_analysis": - onboarding.analysis.auto_refresh_after_analysis.check_these_links.pr_analysis - , - } - } - /> -

    -
    -`; - -exports[`should render correctly: project admin 1`] = ` - -
    -

    - - onboarding.analysis.auto_refresh_after_analysis.done - - - onboarding.analysis.auto_refresh_after_analysis.auto_refresh -

    -

    - onboarding.analysis.auto_refresh_after_analysis.set_up_pr_deco_and_ci.admin -

    -

    - - onboarding.analysis.auto_refresh_after_analysis.check_these_links.branches - , - "link_pr_analysis": - onboarding.analysis.auto_refresh_after_analysis.check_these_links.pr_analysis - , - } - } - /> -

    -
    -`; diff --git a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/OtherTutorial-it.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/OtherTutorial-it.tsx.snap new file mode 100644 index 00000000000..eb2ecbd5bde --- /dev/null +++ b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/OtherTutorial-it.tsx.snap @@ -0,0 +1,132 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`can choose build tools and copy provided settings: cfamily linux: execute build wrapper 1`] = ` +"curl --create-dirs -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip http://localhost:9000/static/cpp/build-wrapper-linux-x86.zip +unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/ +export PATH=$HOME/.sonar/build-wrapper-linux-x86:$PATH +" +`; + +exports[`can choose build tools and copy provided settings: cfamily linux: execute scanner 1`] = ` +"export SONAR_SCANNER_VERSION=4.7.0.2747 +export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux +curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip +unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ +export PATH=$SONAR_SCANNER_HOME/bin:$PATH +export SONAR_SCANNER_OPTS="-server" +" +`; + +exports[`can choose build tools and copy provided settings: cfamily macos: execute build wrapper 1`] = ` +"curl --create-dirs -sSLo $HOME/.sonar/build-wrapper-macosx-x86.zip http://localhost:9000/static/cpp/build-wrapper-macosx-x86.zip +unzip -o $HOME/.sonar/build-wrapper-macosx-x86.zip -d $HOME/.sonar/ +export PATH=$HOME/.sonar/build-wrapper-macosx-x86:$PATH +" +`; + +exports[`can choose build tools and copy provided settings: cfamily macos: execute scanner 1`] = ` +"export SONAR_SCANNER_VERSION=4.7.0.2747 +export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-macosx +curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-macosx.zip +unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ +export PATH=$SONAR_SCANNER_HOME/bin:$PATH +export SONAR_SCANNER_OPTS="-server" +" +`; + +exports[`can choose build tools and copy provided settings: cfamily windows: execute build wrapper 1`] = ` +"$env:SONAR_DIRECTORY = [System.IO.Path]::Combine($(get-location).Path,".sonar") +rm "$env:SONAR_DIRECTORY/build-wrapper-win-x86" -Force -Recurse -ErrorAction SilentlyContinue +New-Item -path $env:SONAR_DIRECTORY/build-wrapper-win-x86 -type directory +(New-Object System.Net.WebClient).DownloadFile("http://localhost:9000/static/cpp/build-wrapper-win-x86.zip", "$env:SONAR_DIRECTORY/build-wrapper-win-x86.zip") +Add-Type -AssemblyName System.IO.Compression.FileSystem +[System.IO.Compression.ZipFile]::ExtractToDirectory("$env:SONAR_DIRECTORY/build-wrapper-win-x86.zip", "$env:SONAR_DIRECTORY") +$env:Path += ";$env:SONAR_DIRECTORY/build-wrapper-win-x86" +" +`; + +exports[`can choose build tools and copy provided settings: cfamily windows: execute scanner 1`] = ` +"$env:SONAR_SCANNER_VERSION = "4.7.0.2747" +$env:SONAR_DIRECTORY = [System.IO.Path]::Combine($(get-location).Path,".sonar") +$env:SONAR_SCANNER_HOME = "$env:SONAR_DIRECTORY/sonar-scanner-$env:SONAR_SCANNER_VERSION-windows" +rm $env:SONAR_SCANNER_HOME -Force -Recurse -ErrorAction SilentlyContinue +New-Item -path $env:SONAR_SCANNER_HOME -type directory +(New-Object System.Net.WebClient).DownloadFile("https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$env:SONAR_SCANNER_VERSION-windows.zip", "$env:SONAR_DIRECTORY/sonar-scanner.zip") +Add-Type -AssemblyName System.IO.Compression.FileSystem +[System.IO.Compression.ZipFile]::ExtractToDirectory("$env:SONAR_DIRECTORY/sonar-scanner.zip", "$env:SONAR_DIRECTORY") +rm ./.sonar/sonar-scanner.zip -Force -ErrorAction SilentlyContinue +$env:Path += ";$env:SONAR_SCANNER_HOME/bin" +$env:SONAR_SCANNER_OPTS="-server" +" +`; + +exports[`can choose build tools and copy provided settings: dotnet core: execute command 1 1`] = `"dotnet sonarscanner begin /k:"my-project" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="generatedtoken2""`; + +exports[`can choose build tools and copy provided settings: dotnet core: execute command 2 1`] = `"dotnet build"`; + +exports[`can choose build tools and copy provided settings: dotnet core: execute command 3 1`] = `"dotnet sonarscanner end /d:sonar.login="generatedtoken2""`; + +exports[`can choose build tools and copy provided settings: dotnet core: install scanner globally 1`] = `"dotnet tool install --global dotnet-sonarscanner"`; + +exports[`can choose build tools and copy provided settings: dotnet framework: execute command 1 1`] = `"SonarScanner.MSBuild.exe begin /k:"my-project" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="generatedtoken2""`; + +exports[`can choose build tools and copy provided settings: dotnet framework: execute command 2 1`] = `"MsBuild.exe /t:Rebuild"`; + +exports[`can choose build tools and copy provided settings: dotnet framework: execute command 3 1`] = `"SonarScanner.MSBuild.exe end /d:sonar.login="generatedtoken2""`; + +exports[`can choose build tools and copy provided settings: gradle: execute scanner 1`] = ` +"./gradlew sonar \\ + -Dsonar.projectKey=my-project \\ + -Dsonar.projectName='MyProject' \\ + -Dsonar.host.url=http://localhost:9000 \\ + -Dsonar.login=generatedtoken2" +`; + +exports[`can choose build tools and copy provided settings: gradle: sonarqube plugin 1`] = ` +"plugins { + id "org.sonarqube" version "3.5.0.2730" +}" +`; + +exports[`can choose build tools and copy provided settings: maven: execute scanner 1`] = ` +"mvn clean verify sonar:sonar \\ + -Dsonar.projectKey=my-project \\ + -Dsonar.projectName='MyProject' \\ + -Dsonar.host.url=http://localhost:9000 \\ + -Dsonar.login=generatedtoken2" +`; + +exports[`can choose build tools and copy provided settings: other linux: execute scanner 1`] = ` +"export SONAR_SCANNER_VERSION=4.7.0.2747 +export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux +curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip +unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ +export PATH=$SONAR_SCANNER_HOME/bin:$PATH +export SONAR_SCANNER_OPTS="-server" +" +`; + +exports[`can choose build tools and copy provided settings: other macos: execute scanner 1`] = ` +"export SONAR_SCANNER_VERSION=4.7.0.2747 +export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-macosx +curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-macosx.zip +unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ +export PATH=$SONAR_SCANNER_HOME/bin:$PATH +export SONAR_SCANNER_OPTS="-server" +" +`; + +exports[`can choose build tools and copy provided settings: other windows: execute scanner 1`] = ` +"$env:SONAR_SCANNER_VERSION = "4.7.0.2747" +$env:SONAR_DIRECTORY = [System.IO.Path]::Combine($(get-location).Path,".sonar") +$env:SONAR_SCANNER_HOME = "$env:SONAR_DIRECTORY/sonar-scanner-$env:SONAR_SCANNER_VERSION-windows" +rm $env:SONAR_SCANNER_HOME -Force -Recurse -ErrorAction SilentlyContinue +New-Item -path $env:SONAR_SCANNER_HOME -type directory +(New-Object System.Net.WebClient).DownloadFile("https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$env:SONAR_SCANNER_VERSION-windows.zip", "$env:SONAR_DIRECTORY/sonar-scanner.zip") +Add-Type -AssemblyName System.IO.Compression.FileSystem +[System.IO.Compression.ZipFile]::ExtractToDirectory("$env:SONAR_DIRECTORY/sonar-scanner.zip", "$env:SONAR_DIRECTORY") +rm ./.sonar/sonar-scanner.zip -Force -ErrorAction SilentlyContinue +$env:Path += ";$env:SONAR_SCANNER_HOME/bin" +$env:SONAR_SCANNER_OPTS="-server" +" +`; diff --git a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/OtherTutorial-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/OtherTutorial-test.tsx.snap deleted file mode 100644 index 5caa5c39114..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/OtherTutorial-test.tsx.snap +++ /dev/null @@ -1,71 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`renders correctly: default 1`] = ` - -
    -

    - onboarding.project_analysis.header -

    -

    - -

    -
    - - -
    -`; diff --git a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/ProjectAnalysisStep-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/ProjectAnalysisStep-test.tsx.snap deleted file mode 100644 index 81839635ad0..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/ProjectAnalysisStep-test.tsx.snap +++ /dev/null @@ -1,13 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` - -`; diff --git a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/TokenStep-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/TokenStep-test.tsx.snap deleted file mode 100644 index 183856aaea4..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/__snapshots__/TokenStep-test.tsx.snap +++ /dev/null @@ -1,693 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`generates token 1`] = ` -
    -
    - 1 -
    -
    -

    - onboarding.token.header -

    -
    -
    -
    -
    -
    - - onboarding.token.generate.PROJECT_ANALYSIS_TOKEN - -
    -
    -
    - - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    -