diff options
author | Kevin Silva <kevin.silva@sonarsource.com> | 2022-12-01 17:46:44 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-12-07 20:02:57 +0000 |
commit | ce5964a9d875a72814e20c81db3782c9fbc35926 (patch) | |
tree | d08ed3b8426220d7a628c17374aa4a4d8dfe39b1 /server/sonar-web/src/main/js/api | |
parent | f235dcec41d3fad489d16318bb59b8869f064ac0 (diff) | |
download | sonarqube-ce5964a9d875a72814e20c81db3782c9fbc35926.tar.gz sonarqube-ce5964a9d875a72814e20c81db3782c9fbc35926.zip |
SONAR-17615 Add RTL test for 'project/create' Azure pages and remove the enzyme tests
Diffstat (limited to 'server/sonar-web/src/main/js/api')
-rw-r--r-- | server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts | 72 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/api/mocks/AlmSettingsServiceMock.ts | 2 |
2 files changed, 71 insertions, 3 deletions
diff --git a/server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts index 337a739873b..3ab27ae48af 100644 --- a/server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts +++ b/server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts @@ -18,24 +18,38 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import { cloneDeep } from 'lodash'; -import { mockGitlabProject } from '../../helpers/mocks/alm-integrations'; -import { GitlabProject } from '../../types/alm-integration'; +import { + mockAzureProject, + mockAzureRepository, + mockGitlabProject, +} from '../../helpers/mocks/alm-integrations'; +import { AzureProject, AzureRepository, GitlabProject } from '../../types/alm-integration'; import { checkPersonalAccessTokenIsValid, + getAzureProjects, + getAzureRepositories, getGithubClientId, getGithubOrganizations, getGitlabProjects, + importAzureRepository, + searchAzureRepositories, setAlmPersonalAccessToken, } from '../alm-integrations'; +import { ProjectBase } from '../components'; export default class AlmIntegrationsServiceMock { almInstancePATMap: { [key: string]: boolean } = {}; gitlabProjects: GitlabProject[]; + azureProjects: AzureProject[]; + azureRepositories: AzureRepository[]; defaultAlmInstancePATMap: { [key: string]: boolean } = { 'conf-final-1': false, 'conf-final-2': true, 'conf-github-1': false, 'conf-github-2': true, + 'conf-azure-1': false, + 'conf-azure-2': true, + 'config-reject': false, }; defaultGitlabProjects: GitlabProject[] = [ @@ -49,6 +63,16 @@ export default class AlmIntegrationsServiceMock { mockGitlabProject({ name: 'Gitlab project 3', id: '3' }), ]; + defaultAzureProjects: AzureProject[] = [ + mockAzureProject({ name: 'Azure project', description: 'Description project 1' }), + mockAzureProject({ name: 'Azure project 2', description: 'Description project 2' }), + ]; + + defaultAzureRepositories: AzureRepository[] = [ + mockAzureRepository({ sqProjectKey: 'random' }), + mockAzureRepository({ name: 'Azure repo 2' }), + ]; + defaultOrganizations = { paging: { pageIndex: 1, @@ -66,6 +90,8 @@ export default class AlmIntegrationsServiceMock { constructor() { this.almInstancePATMap = cloneDeep(this.defaultAlmInstancePATMap); this.gitlabProjects = cloneDeep(this.defaultGitlabProjects); + this.azureProjects = cloneDeep(this.defaultAzureProjects); + this.azureRepositories = cloneDeep(this.defaultAzureRepositories); (checkPersonalAccessTokenIsValid as jest.Mock).mockImplementation( this.checkPersonalAccessTokenIsValid ); @@ -73,6 +99,10 @@ export default class AlmIntegrationsServiceMock { (getGitlabProjects as jest.Mock).mockImplementation(this.getGitlabProjects); (getGithubClientId as jest.Mock).mockImplementation(this.getGithubClientId); (getGithubOrganizations as jest.Mock).mockImplementation(this.getGithubOrganizations); + (getAzureProjects as jest.Mock).mockImplementation(this.getAzureProjects); + (getAzureRepositories as jest.Mock).mockImplementation(this.getAzureRepositories); + (searchAzureRepositories as jest.Mock).mockImplementation(this.searchAzureRepositories); + (importAzureRepository as jest.Mock).mockImplementation(this.importAzureRepository); } checkPersonalAccessTokenIsValid = (conf: string) => { @@ -84,13 +114,48 @@ export default class AlmIntegrationsServiceMock { return Promise.resolve(); }; + getAzureProjects = (): Promise<{ projects: AzureProject[] }> => { + return Promise.resolve({ projects: this.azureProjects }); + }; + + getAzureRepositories = (): Promise<{ repositories: AzureRepository[] }> => { + return Promise.resolve({ + repositories: this.azureRepositories, + }); + }; + + searchAzureRepositories = (): Promise<{ repositories: AzureRepository[] }> => { + return Promise.resolve({ + repositories: this.azureRepositories, + }); + }; + + setSearchAzureRepositories = (azureRepositories: AzureRepository[]) => { + this.azureRepositories = azureRepositories; + }; + + importAzureRepository = (): Promise<{ project: ProjectBase }> => { + return Promise.resolve({ + project: { + key: 'key', + name: 'name', + qualifier: 'qualifier', + visibility: 'private', + }, + }); + }; + + setAzureProjects = (azureProjects: AzureProject[]) => { + this.azureProjects = azureProjects; + }; + getGitlabProjects = () => { return Promise.resolve({ projects: this.gitlabProjects, projectsPaging: { pageIndex: 1, pageSize: 30, - total: 3, + total: this.gitlabProjects.length, }, }); }; @@ -110,5 +175,6 @@ export default class AlmIntegrationsServiceMock { reset = () => { this.almInstancePATMap = cloneDeep(this.defaultAlmInstancePATMap); this.gitlabProjects = cloneDeep(this.defaultGitlabProjects); + this.azureRepositories = cloneDeep(this.defaultAzureRepositories); }; } diff --git a/server/sonar-web/src/main/js/api/mocks/AlmSettingsServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/AlmSettingsServiceMock.ts index d42e24c6570..c5e32cb41f0 100644 --- a/server/sonar-web/src/main/js/api/mocks/AlmSettingsServiceMock.ts +++ b/server/sonar-web/src/main/js/api/mocks/AlmSettingsServiceMock.ts @@ -29,6 +29,8 @@ export default class AlmSettingsServiceMock { mockAlmSettingsInstance({ key: 'conf-final-2', alm: AlmKeys.GitLab }), mockAlmSettingsInstance({ key: 'conf-github-1', alm: AlmKeys.GitHub, url: 'url' }), mockAlmSettingsInstance({ key: 'conf-github-2', alm: AlmKeys.GitHub, url: 'url' }), + mockAlmSettingsInstance({ key: 'conf-azure-1', alm: AlmKeys.Azure, url: 'url' }), + mockAlmSettingsInstance({ key: 'conf-azure-2', alm: AlmKeys.Azure, url: 'url' }), ]; constructor() { |