1
- import { provideStore } from '@ngxs/store' ;
1
+ import { Store } from '@ngxs/store' ;
2
2
3
3
import { TranslatePipe , TranslateService } from '@ngx-translate/core' ;
4
- import { MockPipe , MockProviders } from 'ng-mocks' ;
4
+ import { MockPipe , MockProvider , MockProviders } from 'ng-mocks' ;
5
5
6
6
import { DialogService , DynamicDialogRef } from 'primeng/dynamicdialog' ;
7
7
8
- import { Subject } from 'rxjs' ;
8
+ import { of , Subject } from 'rxjs' ;
9
9
10
10
import { provideHttpClient } from '@angular/common/http' ;
11
11
import { provideHttpClientTesting } from '@angular/common/http/testing' ;
12
12
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
13
13
import { provideNoopAnimations } from '@angular/platform-browser/animations' ;
14
14
15
+ import { AccountSettingsService } from '@osf/features/settings/account-settings/services' ;
16
+ import { AccountSettingsSelectors } from '@osf/features/settings/account-settings/store' ;
17
+ import { MOCK_STORE } from '@shared/mocks' ;
15
18
import { ToastService } from '@shared/services' ;
16
19
17
- import { AccountSettingsState } from '../../store/account-settings.state' ;
18
20
import { CancelDeactivationComponent } from '../cancel-deactivation/cancel-deactivation.component' ;
19
21
import { DeactivationWarningComponent } from '../deactivation-warning/deactivation-warning.component' ;
20
22
@@ -26,15 +28,47 @@ describe('DeactivateAccountComponent', () => {
26
28
let dialogService : DialogService ;
27
29
let translateService : TranslateService ;
28
30
31
+ const MOCK_ACCOUNT_SETTINGS = {
32
+ twoFactorEnabled : false ,
33
+ twoFactorConfirmed : false ,
34
+ subscribeOsfGeneralEmail : false ,
35
+ subscribeOsfHelpEmail : false ,
36
+ deactivationRequested : false ,
37
+ contactedDeactivation : false ,
38
+ secret : '' ,
39
+ } ;
40
+
29
41
beforeEach ( async ( ) => {
42
+ const store = MOCK_STORE ;
43
+
44
+ store . selectSignal . mockImplementation ( ( selector ) => {
45
+ if ( selector === AccountSettingsSelectors . getAccountSettings ) {
46
+ return ( ) => MOCK_ACCOUNT_SETTINGS ;
47
+ }
48
+
49
+ if ( selector === AccountSettingsSelectors . getEmails ) {
50
+ return ( ) => [ ] ;
51
+ }
52
+
53
+ if ( selector === AccountSettingsSelectors . getRegions ) {
54
+ return ( ) => [ ] ;
55
+ }
56
+
57
+ return ( ) => null ;
58
+ } ) ;
59
+
60
+ store . dispatch . mockImplementation ( ( ) => {
61
+ return of ( ) ;
62
+ } ) ;
63
+
30
64
await TestBed . configureTestingModule ( {
31
65
imports : [ DeactivateAccountComponent , MockPipe ( TranslatePipe ) ] ,
32
66
providers : [
33
67
provideNoopAnimations ( ) ,
34
- provideStore ( [ AccountSettingsState ] ) ,
68
+ MockProvider ( Store , store ) ,
35
69
provideHttpClient ( ) ,
36
70
provideHttpClientTesting ( ) ,
37
- MockProviders ( DynamicDialogRef , DialogService , TranslateService , ToastService ) ,
71
+ MockProviders ( DynamicDialogRef , DialogService , TranslateService , ToastService , AccountSettingsService ) ,
38
72
] ,
39
73
} ) . compileComponents ( ) ;
40
74
0 commit comments