aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/api/mocks
diff options
context:
space:
mode:
authorMathieu Suen <mathieu.suen@sonarsource.com>2024-11-25 17:40:30 +0100
committersonartech <sonartech@sonarsource.com>2024-11-29 20:03:07 +0000
commitf86cc04663f914d952562845f6cba41cafefe2f0 (patch)
treec6fd287891f344a091aa028ed2cd001fefd083e9 /server/sonar-web/src/main/js/api/mocks
parent2c496d7199d58ce76f1ec513220bde1127c68358 (diff)
downloadsonarqube-f86cc04663f914d952562845f6cba41cafefe2f0.tar.gz
sonarqube-f86cc04663f914d952562845f6cba41cafefe2f0.zip
SONAR-23619 Adjust the project info page to display AI code assurance status
Diffstat (limited to 'server/sonar-web/src/main/js/api/mocks')
-rw-r--r--server/sonar-web/src/main/js/api/mocks/AiCodeAssuredServiceMock.ts17
-rw-r--r--server/sonar-web/src/main/js/api/mocks/MeasuresServiceMock.ts34
2 files changed, 29 insertions, 22 deletions
diff --git a/server/sonar-web/src/main/js/api/mocks/AiCodeAssuredServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/AiCodeAssuredServiceMock.ts
index da0a0668abe..825b48c2ea9 100644
--- a/server/sonar-web/src/main/js/api/mocks/AiCodeAssuredServiceMock.ts
+++ b/server/sonar-web/src/main/js/api/mocks/AiCodeAssuredServiceMock.ts
@@ -18,22 +18,29 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { isProjectAiCodeAssured } from '../ai-code-assurance';
+import { AiCodeAssuranceStatus, getProjectAiCodeAssuranceStatus } from '../ai-code-assurance';
jest.mock('../ai-code-assurance');
+export const PROJECT_WITH_AI_ASSURED_QG = 'Sonar AI way';
+export const PROJECT_WITHOUT_AI_ASSURED_QG = 'Sonar way';
+
export class AiCodeAssuredServiceMock {
noAiProject = 'no-ai';
constructor() {
- jest.mocked(isProjectAiCodeAssured).mockImplementation(this.handleProjectAiGeneratedCode);
+ jest
+ .mocked(getProjectAiCodeAssuranceStatus)
+ .mockImplementation(this.handleProjectAiGeneratedCode);
}
handleProjectAiGeneratedCode = (project: string) => {
- if (project === this.noAiProject) {
- return Promise.resolve(false);
+ if (project === PROJECT_WITH_AI_ASSURED_QG) {
+ return Promise.resolve(AiCodeAssuranceStatus.AI_CODE_ASSURED);
+ } else if (project === PROJECT_WITHOUT_AI_ASSURED_QG) {
+ return Promise.resolve(AiCodeAssuranceStatus.CONTAINS_AI_CODE);
}
- return Promise.resolve(true);
+ return Promise.resolve(AiCodeAssuranceStatus.NONE);
};
reset() {
diff --git a/server/sonar-web/src/main/js/api/mocks/MeasuresServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/MeasuresServiceMock.ts
index 19f1b585379..55316ab652c 100644
--- a/server/sonar-web/src/main/js/api/mocks/MeasuresServiceMock.ts
+++ b/server/sonar-web/src/main/js/api/mocks/MeasuresServiceMock.ts
@@ -35,20 +35,20 @@ const defaultMeasures = mockFullMeasureData(defaultComponents, mockIssuesList())
const defaultPeriod = mockPeriod();
export class MeasuresServiceMock {
- #components: ComponentTree;
- #measures: MeasureRecords;
- #period: Period;
+ components: ComponentTree;
+ measures: MeasureRecords;
+ period: Period;
reset: () => void;
constructor(components?: ComponentTree, measures?: MeasureRecords, period?: Period) {
- this.#components = components ?? cloneDeep(defaultComponents);
- this.#measures = measures ?? cloneDeep(defaultMeasures);
- this.#period = period ?? cloneDeep(defaultPeriod);
+ this.components = components ?? cloneDeep(defaultComponents);
+ this.measures = measures ?? cloneDeep(defaultMeasures);
+ this.period = period ?? cloneDeep(defaultPeriod);
this.reset = () => {
- this.#components = components ?? cloneDeep(defaultComponents);
- this.#measures = measures ?? cloneDeep(defaultMeasures);
- this.#period = period ?? cloneDeep(defaultPeriod);
+ this.components = components ?? cloneDeep(defaultComponents);
+ this.measures = measures ?? cloneDeep(defaultMeasures);
+ this.period = period ?? cloneDeep(defaultPeriod);
};
jest.mocked(getMeasures).mockImplementation(this.handleGetMeasures);
@@ -58,19 +58,19 @@ export class MeasuresServiceMock {
}
registerComponentMeasures = (measures: MeasureRecords) => {
- this.#measures = measures;
+ this.measures = measures;
};
deleteComponentMeasure = (componentKey: string, measureKey: MetricKey) => {
- delete this.#measures[componentKey][measureKey];
+ delete this.measures[componentKey][measureKey];
};
getComponentMeasures = () => {
- return this.#measures;
+ return this.measures;
};
setComponents = (components: ComponentTree) => {
- this.#components = components;
+ this.components = components;
};
findComponentTree = (key: string, from?: ComponentTree): ComponentTree => {
@@ -81,7 +81,7 @@ export class MeasuresServiceMock {
return node.children.find((child) => recurse(child));
};
- const tree = recurse(from ?? this.#components);
+ const tree = recurse(from ?? this.components);
if (!tree) {
throw new Error(`Couldn't find component tree for key ${key}`);
}
@@ -90,8 +90,8 @@ export class MeasuresServiceMock {
};
filterMeasures = (componentKey: string, metricKeys: string[]) => {
- return this.#measures[componentKey]
- ? Object.values(this.#measures[componentKey]).filter(({ metric }) =>
+ return this.measures[componentKey]
+ ? Object.values(this.measures[componentKey]).filter(({ metric }) =>
metricKeys.includes(metric),
)
: [];
@@ -124,7 +124,7 @@ export class MeasuresServiceMock {
...component,
measures,
},
- period: this.#period,
+ period: this.period,
metrics,
});
};