@@ -7,10 +7,12 @@ import { MemoryRouter, Route, Switch } from 'react-router-dom'
7
7
8
8
import config , { DEFAULT_GH_APP } from 'config'
9
9
10
+ import { eventTracker } from 'services/events/events'
10
11
import { useImage } from 'services/image'
11
12
12
13
import ContextSwitcher from './ContextSwitcher'
13
14
15
+ vi . mock ( 'services/events/events' )
14
16
vi . mock ( 'services/image' )
15
17
const mocks = vi . hoisted ( ( ) => ( {
16
18
useIntersection : vi . fn ( ) ,
@@ -713,6 +715,66 @@ describe('ContextSwitcher', () => {
713
715
} )
714
716
} )
715
717
718
+ describe ( 'when install gh app button is clicked' , ( ) => {
719
+ it ( 'tracks a Button Clicked event' , async ( ) => {
720
+ const { user } = setup ( )
721
+ render (
722
+ < ContextSwitcher
723
+ activeContext = { {
724
+ username : 'laudna' ,
725
+ avatarUrl : 'http://127.0.0.1/avatar-url' ,
726
+ } }
727
+ contexts = { [
728
+ {
729
+ owner : {
730
+ username : 'laudna' ,
731
+ avatarUrl : 'http://127.0.0.1/avatar-url' ,
732
+ } ,
733
+ pageName : 'provider' ,
734
+ } ,
735
+ {
736
+ owner : {
737
+ username : 'spotify' ,
738
+ avatarUrl : 'http://127.0.0.1/avatar-url' ,
739
+ } ,
740
+ pageName : 'owner' ,
741
+ } ,
742
+ {
743
+ owner : {
744
+ username : 'codecov' ,
745
+ avatarUrl : 'http://127.0.0.1/avatar-url' ,
746
+ } ,
747
+ pageName : 'owner' ,
748
+ } ,
749
+ ] }
750
+ currentUser = { {
751
+ defaultOrgUsername : 'codecov' ,
752
+ } }
753
+ src = "imageUrl"
754
+ isLoading = { false }
755
+ error = { null }
756
+ /> ,
757
+ {
758
+ wrapper : wrapper ( ) ,
759
+ }
760
+ )
761
+
762
+ const button = await screen . findByRole ( 'button' , { expanded : false } )
763
+ await user . click ( button )
764
+
765
+ const appButton = await screen . findByText ( 'Install Codecov GitHub app' )
766
+ await user . click ( appButton )
767
+
768
+ expect ( eventTracker ( ) . track ) . toHaveBeenCalledWith ( {
769
+ type : 'Button Clicked' ,
770
+ properties : {
771
+ buttonType : 'Install GitHub App' ,
772
+ buttonLocation : 'Org selector' ,
773
+ } ,
774
+ } )
775
+ } )
776
+ } )
777
+
716
778
describe ( 'when on self-hosted' , ( ) => {
717
779
beforeEach ( ( ) => {
718
780
config . IS_SELF_HOSTED = true
0 commit comments