aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/api/mocks/ComponentsServiceMock.ts
diff options
context:
space:
mode:
authorstanislavh <stanislav.honcharov@sonarsource.com>2023-04-13 14:10:07 +0200
committersonartech <sonartech@sonarsource.com>2023-04-14 20:02:47 +0000
commit2768a0aefc190bfa923110a1371c5eeef223ebb0 (patch)
tree8f9999030b1be7d0d997aa551080d9c5d403e6b2 /server/sonar-web/src/main/js/api/mocks/ComponentsServiceMock.ts
parentdb8375a594fd1da6cabae829169fcbb177495432 (diff)
downloadsonarqube-2768a0aefc190bfa923110a1371c5eeef223ebb0.tar.gz
sonarqube-2768a0aefc190bfa923110a1371c5eeef223ebb0.zip
SONAR-18435 Migrate Project Key to RTl
Diffstat (limited to 'server/sonar-web/src/main/js/api/mocks/ComponentsServiceMock.ts')
-rw-r--r--server/sonar-web/src/main/js/api/mocks/ComponentsServiceMock.ts29
1 files changed, 20 insertions, 9 deletions
diff --git a/server/sonar-web/src/main/js/api/mocks/ComponentsServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/ComponentsServiceMock.ts
index ba345fe6d08..359292c3f7e 100644
--- a/server/sonar-web/src/main/js/api/mocks/ComponentsServiceMock.ts
+++ b/server/sonar-web/src/main/js/api/mocks/ComponentsServiceMock.ts
@@ -42,6 +42,7 @@ import {
SourceViewerFile,
} from '../../types/types';
import {
+ changeKey,
getChildren,
getComponentData,
getComponentForSourceViewer,
@@ -387,15 +388,16 @@ export default class ComponentsServiceMock {
this.components = cloneDeep(this.defaultComponents);
this.sourceFiles = cloneDeep(this.defaultSourceFiles);
- (getComponentTree as jest.Mock).mockImplementation(this.handleGetComponentTree);
- (getChildren as jest.Mock).mockImplementation(this.handleGetChildren);
- (getTree as jest.Mock).mockImplementation(this.handleGetTree);
- (getComponentData as jest.Mock).mockImplementation(this.handleGetComponentData);
- (getComponentForSourceViewer as jest.Mock).mockImplementation(
- this.handleGetComponentForSourceViewer
- );
- (getDuplications as jest.Mock).mockImplementation(this.handleGetDuplications);
- (getSources as jest.Mock).mockImplementation(this.handleGetSources);
+ jest.mocked(getComponentTree).mockImplementation(this.handleGetComponentTree);
+ jest.mocked(getChildren).mockImplementation(this.handleGetChildren);
+ jest.mocked(getTree).mockImplementation(this.handleGetTree);
+ jest.mocked(getComponentData).mockImplementation(this.handleGetComponentData);
+ jest
+ .mocked(getComponentForSourceViewer)
+ .mockImplementation(this.handleGetComponentForSourceViewer);
+ jest.mocked(getDuplications).mockImplementation(this.handleGetDuplications);
+ jest.mocked(getSources).mockImplementation(this.handleGetSources);
+ jest.mocked(changeKey).mockImplementation(this.handleChangeKey);
}
findComponentTree = (key: string, from?: ComponentTree): ComponentTree | undefined => {
@@ -625,6 +627,15 @@ export default class ComponentsServiceMock {
return this.reply(lines.slice(from - 1, to));
};
+ handleChangeKey = (data: { from: string; to: string }) => {
+ const treeItem = this.components.find(({ component }) => component.key === data.from);
+ if (treeItem) {
+ treeItem.component.key = data.to;
+ return this.reply(undefined);
+ }
+ return Promise.reject({ status: 404, message: 'Component not found' });
+ };
+
reply<T>(response: T): Promise<T> {
return Promise.resolve(cloneDeep(response));
}