2020
2121import { screen } from '@testing-library/react' ;
2222import userEvent from '@testing-library/user-event' ;
23- import { byRole } from '~shared/helpers/testSelector' ;
2423import { ComponentQualifier } from '~shared/types/component' ;
25- import AlmIntegrationsServiceMock from '~sq-server-commons/api/mocks/AlmIntegrationsServiceMock' ;
2624import AlmSettingsServiceMock from '~sq-server-commons/api/mocks/AlmSettingsServiceMock' ;
2725import BranchesServiceMock from '~sq-server-commons/api/mocks/BranchesServiceMock' ;
28- import { mockGitHubRepository } from '~sq-server-commons/helpers/mocks/alm-integrations' ;
29- import { mockProjectAlmBindingResponse } from '~sq-server-commons/helpers/mocks/alm-settings' ;
3026import { mockMainBranch , mockPullRequest } from '~sq-server-commons/helpers/mocks/branch-like' ;
3127import { mockComponent } from '~sq-server-commons/helpers/mocks/component' ;
3228import { mockCurrentUser , mockLoggedInUser } from '~sq-server-commons/helpers/testMocks' ;
@@ -39,29 +35,13 @@ jest.mock('~sq-server-commons/api/favorites', () => ({
3935 addFavorite : jest . fn ( ) . mockResolvedValue ( { } ) ,
4036 removeFavorite : jest . fn ( ) . mockResolvedValue ( { } ) ,
4137} ) ) ;
42- jest . mock ( '~adapters/helpers/users' , ( ) => ( {
43- ...jest . requireActual < typeof import ( '~adapters/helpers/users' ) > ( '~adapters/helpers/users' ) ,
44- useCurrentUser : ( ) => ( { currentUser : mockLoggedInUser ( ) } ) ,
45- } ) ) ;
46-
47- const ui = {
48- bindProjectLink : byRole ( 'link' , { name : 'project_navigation.binding_status.bind' } ) ,
49- bindingLink : byRole ( 'link' , {
50- name : / p r o j e c t _ n a v i g a t i o n .b i n d i n g _ s t a t u s .b o u n d _ t o _ x / ,
51- } ) ,
52- bindingLogo : byRole ( 'img' , {
53- name : / p r o j e c t _ n a v i g a t i o n .b i n d i n g _ s t a t u s .b o u n d _ t o _ x / ,
54- } ) ,
55- } ;
5638
5739const handler = new BranchesServiceMock ( ) ;
5840const almHandler = new AlmSettingsServiceMock ( ) ;
59- const almIntegrationsHandler = new AlmIntegrationsServiceMock ( ) ;
6041
6142beforeEach ( ( ) => {
6243 handler . reset ( ) ;
6344 almHandler . reset ( ) ;
64- almIntegrationsHandler . reset ( ) ;
6545} ) ;
6646
6747it ( 'should render correctly when there is only 1 branch' , async ( ) => {
@@ -128,65 +108,6 @@ it('should show the correct help tooltip when branch support is not enabled', as
128108 ) . toBeInTheDocument ( ) ;
129109} ) ;
130110
131- it ( 'should show "bind project" link when project is not bound and user can bind project' , async ( ) => {
132- renderHeader ( {
133- component : mockComponent ( {
134- breadcrumbs : [ { name : 'project' , key : 'project' , qualifier : ComponentQualifier . Project } ] ,
135- configuration : {
136- showSettings : true ,
137- } ,
138- } ) ,
139- currentUser : mockLoggedInUser ( ) ,
140- } ) ;
141-
142- expect ( await ui . bindProjectLink . find ( ) ) . toBeInTheDocument ( ) ;
143- } ) ;
144-
145- it ( 'should show GitHub logo linking to repository when project is bound to GitHub' , async ( ) => {
146- almIntegrationsHandler . githubRepositories = [
147- mockGitHubRepository ( {
148- url : 'https://github.com/org/repo' ,
149- } ) ,
150- ] ;
151- almHandler . projectsBindings [ 'project-bound' ] = mockProjectAlmBindingResponse ( {
152- key : 'project-bound' ,
153- slug : 'org/repo' ,
154- } ) ;
155- renderHeader ( {
156- component : mockComponent ( {
157- breadcrumbs : [ { name : 'project' , key : 'project' , qualifier : ComponentQualifier . Project } ] ,
158- configuration : {
159- showSettings : true ,
160- } ,
161- key : 'project-bound' ,
162- } ) ,
163- currentUser : mockLoggedInUser ( ) ,
164- } ) ;
165-
166- expect ( await ui . bindingLink . find ( ) ) . toBeInTheDocument ( ) ;
167- } ) ;
168-
169- it ( 'should show GitLab logo (without link) when project is bound to GitLab' , async ( ) => {
170- almHandler . projectsBindings [ 'project-bound' ] = mockProjectAlmBindingResponse ( {
171- alm : AlmKeys . GitLab ,
172- key : 'project-bound' ,
173- slug : 'gitlab-repo' ,
174- } ) ;
175- renderHeader ( {
176- component : mockComponent ( {
177- breadcrumbs : [ { name : 'project' , key : 'project' , qualifier : ComponentQualifier . Project } ] ,
178- configuration : {
179- showSettings : true ,
180- } ,
181- key : 'project-bound' ,
182- } ) ,
183- currentUser : mockLoggedInUser ( ) ,
184- } ) ;
185-
186- expect ( await ui . bindingLogo . find ( ) ) . toBeInTheDocument ( ) ;
187- expect ( ui . bindingLink . query ( ) ) . not . toBeInTheDocument ( ) ;
188- } ) ;
189-
190111
191112function renderHeader (
192113 props ?: Partial < HeaderProps > ,
@@ -197,8 +118,8 @@ function renderHeader(
197118 '/' ,
198119 < Header
199120 component = { mockComponent ( {
200- breadcrumbs : [ { name : 'project' , key : 'project' , qualifier : ComponentQualifier . Project } ] ,
201121 key : 'header-project' ,
122+ breadcrumbs : [ { name : 'project' , key : 'project' , qualifier : ComponentQualifier . Project } ] ,
202123 } ) }
203124 currentUser = { mockCurrentUser ( ) }
204125 { ...props }
0 commit comments