Skip to content

Commit 9e53559

Browse files
committed
test(deactivate-account): fixed tests with mock store and account settings
1 parent 313d413 commit 9e53559

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

src/app/features/settings/account-settings/components/deactivate-account/deactivate-account.component.spec.ts

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import { provideStore } from '@ngxs/store';
1+
import { Store } from '@ngxs/store';
22

33
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
4-
import { MockPipe, MockProviders } from 'ng-mocks';
4+
import { MockPipe, MockProvider, MockProviders } from 'ng-mocks';
55

66
import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
77

8-
import { Subject } from 'rxjs';
8+
import { of, Subject } from 'rxjs';
99

1010
import { provideHttpClient } from '@angular/common/http';
1111
import { provideHttpClientTesting } from '@angular/common/http/testing';
1212
import { ComponentFixture, TestBed } from '@angular/core/testing';
1313
import { provideNoopAnimations } from '@angular/platform-browser/animations';
1414

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';
1518
import { ToastService } from '@shared/services';
1619

17-
import { AccountSettingsState } from '../../store/account-settings.state';
1820
import { CancelDeactivationComponent } from '../cancel-deactivation/cancel-deactivation.component';
1921
import { DeactivationWarningComponent } from '../deactivation-warning/deactivation-warning.component';
2022

@@ -26,15 +28,47 @@ describe('DeactivateAccountComponent', () => {
2628
let dialogService: DialogService;
2729
let translateService: TranslateService;
2830

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+
2941
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+
3064
await TestBed.configureTestingModule({
3165
imports: [DeactivateAccountComponent, MockPipe(TranslatePipe)],
3266
providers: [
3367
provideNoopAnimations(),
34-
provideStore([AccountSettingsState]),
68+
MockProvider(Store, store),
3569
provideHttpClient(),
3670
provideHttpClientTesting(),
37-
MockProviders(DynamicDialogRef, DialogService, TranslateService, ToastService),
71+
MockProviders(DynamicDialogRef, DialogService, TranslateService, ToastService, AccountSettingsService),
3872
],
3973
}).compileComponents();
4074

0 commit comments

Comments
 (0)