|
| 1 | +import { render, screen, waitFor } from "@testing-library/react"; |
| 2 | +import SonarqubeIssues from "./SonarqubeIssues"; |
| 3 | + |
| 4 | +const issuesResp = { |
| 5 | + total: 3, |
| 6 | + p: 1, |
| 7 | + ps: 100, |
| 8 | + paging: { |
| 9 | + pageIndex: 1, |
| 10 | + pageSize: 100, |
| 11 | + total: 3 |
| 12 | + }, |
| 13 | + effortTotal: 12, |
| 14 | + debtTotal: 12, |
| 15 | + issues: [ |
| 16 | + { |
| 17 | + key: "AZGA0FU2K5CbPgAYf4Pr", |
| 18 | + rule: "typescript:S1854", |
| 19 | + severity: "MAJOR", |
| 20 | + component: "martindstone-org_funrepo:index.tsx", |
| 21 | + project: "martindstone-org_funrepo", |
| 22 | + line: 3, |
| 23 | + hash: "ad1e379169a24735d922555c92f04126", |
| 24 | + textRange: { |
| 25 | + startLine: 3, |
| 26 | + endLine: 3, |
| 27 | + startOffset: 10, |
| 28 | + endOffset: 22 |
| 29 | + }, |
| 30 | + flows: [], |
| 31 | + status: "OPEN", |
| 32 | + message: "Remove this useless assignment to variable \"secretApiKey\".", |
| 33 | + effort: "1min", |
| 34 | + debt: "1min", |
| 35 | + assignee: "martindstone@github", |
| 36 | + |
| 37 | + tags: ["cwe", "unused"], |
| 38 | + creationDate: "2024-08-23T21:54:55+0200", |
| 39 | + updateDate: "2024-08-26T21:21:44+0200", |
| 40 | + type: "CODE_SMELL", |
| 41 | + organization: "martindstone-org", |
| 42 | + cleanCodeAttribute: "LOGICAL", |
| 43 | + cleanCodeAttributeCategory: "INTENTIONAL", |
| 44 | + impacts: [ |
| 45 | + { |
| 46 | + softwareQuality: "MAINTAINABILITY", |
| 47 | + severity: "MEDIUM" |
| 48 | + } |
| 49 | + ], |
| 50 | + issueStatus: "OPEN" |
| 51 | + }, |
| 52 | + { |
| 53 | + key: "AZGA0FU2K5CbPgAYf4Ps", |
| 54 | + rule: "typescript:S1854", |
| 55 | + severity: "MAJOR", |
| 56 | + component: "martindstone-org_funrepo:index.tsx", |
| 57 | + project: "martindstone-org_funrepo", |
| 58 | + line: 6, |
| 59 | + hash: "c50e075544f8218bf672958c96e2b394", |
| 60 | + textRange: { |
| 61 | + startLine: 6, |
| 62 | + endLine: 6, |
| 63 | + startOffset: 10, |
| 64 | + endOffset: 24 |
| 65 | + }, |
| 66 | + flows: [], |
| 67 | + status: "OPEN", |
| 68 | + message: "Remove this useless assignment to variable \"unusedVariable\".", |
| 69 | + effort: "1min", |
| 70 | + debt: "1min", |
| 71 | + assignee: "martindstone@github", |
| 72 | + |
| 73 | + tags: ["cwe", "unused"], |
| 74 | + creationDate: "2024-08-23T21:54:55+0200", |
| 75 | + updateDate: "2024-08-26T17:11:19+0200", |
| 76 | + type: "CODE_SMELL", |
| 77 | + organization: "martindstone-org", |
| 78 | + cleanCodeAttribute: "LOGICAL", |
| 79 | + cleanCodeAttributeCategory: "INTENTIONAL", |
| 80 | + impacts: [ |
| 81 | + { |
| 82 | + softwareQuality: "MAINTAINABILITY", |
| 83 | + severity: "MEDIUM" |
| 84 | + } |
| 85 | + ], |
| 86 | + issueStatus: "OPEN" |
| 87 | + }, |
| 88 | + { |
| 89 | + key: "AZGA0FU2K5CbPgAYf4Pt", |
| 90 | + rule: "typescript:S1862", |
| 91 | + severity: "MAJOR", |
| 92 | + component: "martindstone-org_funrepo:index.tsx", |
| 93 | + project: "martindstone-org_funrepo", |
| 94 | + line: 21, |
| 95 | + hash: "1421bf36954c21103f4a1934e5b63fa4", |
| 96 | + textRange: { |
| 97 | + startLine: 21, |
| 98 | + endLine: 21, |
| 99 | + startOffset: 15, |
| 100 | + endOffset: 26 |
| 101 | + }, |
| 102 | + flows: [ |
| 103 | + { |
| 104 | + locations: [ |
| 105 | + { |
| 106 | + component: "martindstone-org_funrepo:index.tsx", |
| 107 | + textRange: { |
| 108 | + startLine: 19, |
| 109 | + endLine: 19, |
| 110 | + startOffset: 8, |
| 111 | + endOffset: 19 |
| 112 | + }, |
| 113 | + msg: "Covering" |
| 114 | + } |
| 115 | + ] |
| 116 | + } |
| 117 | + ], |
| 118 | + status: "OPEN", |
| 119 | + message: "This condition is covered by the one on line 19", |
| 120 | + effort: "10min", |
| 121 | + debt: "10min", |
| 122 | + assignee: "martindstone@github", |
| 123 | + |
| 124 | + tags: ["pitfall", "unused"], |
| 125 | + creationDate: "2024-08-23T21:54:55+0200", |
| 126 | + updateDate: "2024-08-24T03:12:29+0200", |
| 127 | + type: "BUG", |
| 128 | + organization: "martindstone-org", |
| 129 | + cleanCodeAttribute: "LOGICAL", |
| 130 | + cleanCodeAttributeCategory: "INTENTIONAL", |
| 131 | + impacts: [ |
| 132 | + { |
| 133 | + softwareQuality: "RELIABILITY", |
| 134 | + severity: "MEDIUM" |
| 135 | + } |
| 136 | + ], |
| 137 | + issueStatus: "OPEN" |
| 138 | + } |
| 139 | + ], |
| 140 | + components: [ |
| 141 | + { |
| 142 | + organization: "martindstone-org", |
| 143 | + key: "martindstone-org_funrepo:index.tsx", |
| 144 | + uuid: "AZGA0FJxK5CbPgAYf4Pq", |
| 145 | + enabled: true, |
| 146 | + qualifier: "FIL", |
| 147 | + name: "index.tsx", |
| 148 | + longName: "index.tsx", |
| 149 | + path: "index.tsx" |
| 150 | + } |
| 151 | + ], |
| 152 | + organizations: [ |
| 153 | + { |
| 154 | + key: "martindstone-org", |
| 155 | + name: "martindstone-org" |
| 156 | + } |
| 157 | + ], |
| 158 | + facets: [] |
| 159 | +}; |
| 160 | + |
| 161 | +const serviceYaml = { |
| 162 | + info: { |
| 163 | + "x-cortex-static-analysis": { |
| 164 | + sonarqube: { |
| 165 | + project: "martindstone-org_funrepo", |
| 166 | + }, |
| 167 | + }, |
| 168 | + }, |
| 169 | +}; |
| 170 | + |
| 171 | +describe("Issues", () => { |
| 172 | + it("has Issues", async () => { |
| 173 | + fetchMock.mockIf( |
| 174 | + /^https:\/\/sonarcloud\.io\/api\/issues/, |
| 175 | + async (_req: Request) => { |
| 176 | + return await Promise.resolve(JSON.stringify(issuesResp)); |
| 177 | + } |
| 178 | + ); |
| 179 | + |
| 180 | + render(<SonarqubeIssues entityYaml={serviceYaml} />); |
| 181 | + expect(screen.queryByText("Loading")).toBeInTheDocument(); |
| 182 | + await waitFor(() => { |
| 183 | + expect(screen.queryByText("Loading")).not.toBeInTheDocument(); |
| 184 | + }); |
| 185 | + // expect(screen.queryByText("useless")).toBeInTheDocument(); |
| 186 | + const majorElements = screen.queryAllByText("major"); |
| 187 | + expect(majorElements.length).toEqual(3); |
| 188 | + const commentElements = screen.queryAllByText("Comment"); |
| 189 | + expect(commentElements.length).toBeGreaterThan(0); |
| 190 | + }); |
| 191 | + |
| 192 | + it("has no Issues", async () => { |
| 193 | + fetchMock.mockIf( |
| 194 | + /^https:\/\/sonarcloud\.io\/api\/issues/, |
| 195 | + async (_req: Request) => { |
| 196 | + return await Promise.resolve(JSON.stringify({issues: []})); |
| 197 | + } |
| 198 | + ); |
| 199 | + render(<SonarqubeIssues entityYaml={serviceYaml} />); |
| 200 | + expect(screen.queryByText("Loading")).toBeInTheDocument(); |
| 201 | + |
| 202 | + await waitFor(() => { |
| 203 | + expect(screen.queryByText("Loading")).not.toBeInTheDocument(); |
| 204 | + }); |
| 205 | + expect( |
| 206 | + screen.queryByText( |
| 207 | + "We could not find any Sonarqube issues associated with this entity" |
| 208 | + ) |
| 209 | + ).toBeInTheDocument(); |
| 210 | + }); |
| 211 | +}); |
0 commit comments