Skip to content

Commit 46b1787

Browse files
committed
fix(tests): add new tests and changes for existing behavior
1 parent 537bf24 commit 46b1787

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

src/app/features/settings/notifications/notifications.component.spec.ts

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
import { Store } from '@ngxs/store';
22

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

66
import { of } from 'rxjs';
77

88
import { provideHttpClient } from '@angular/common/http';
99
import { provideHttpClientTesting } from '@angular/common/http/testing';
1010
import { signal } from '@angular/core';
1111
import { ComponentFixture, TestBed } from '@angular/core/testing';
12-
import { FormBuilder, ReactiveFormsModule } from '@angular/forms';
12+
import { FormBuilder } from '@angular/forms';
1313

1414
import { UserSelectors } from '@osf/core/store/user';
15-
import { LoaderService, ToastService } from '@osf/shared/services';
16-
import { SubscriptionEvent, SubscriptionFrequency } from '@shared/enums';
15+
import { InfoIconComponent } from '@osf/shared/components/info-icon/info-icon.component';
16+
import { SubHeaderComponent } from '@osf/shared/components/sub-header/sub-header.component';
17+
import { SubscriptionEvent } from '@osf/shared/enums/subscriptions/subscription-event.enum';
18+
import { SubscriptionFrequency } from '@osf/shared/enums/subscriptions/subscription-frequency.enum';
19+
import { LoaderService } from '@osf/shared/services/loader.service';
20+
import { ToastService } from '@osf/shared/services/toast.service';
1721

1822
import { AccountSettings } from '../account-settings/models';
1923
import { AccountSettingsSelectors } from '../account-settings/store';
2024

2125
import { NotificationsComponent } from './notifications.component';
2226
import { NotificationSubscriptionSelectors } from './store';
2327

24-
import { MOCK_STORE, MOCK_USER, TranslateServiceMock } from '@testing/mocks';
28+
import { MOCK_USER } from '@testing/mocks/data.mock';
29+
import { MOCK_STORE } from '@testing/mocks/mock-store.mock';
30+
import { TranslateServiceMock } from '@testing/mocks/translate.service.mock';
2531
import { ToastServiceMockBuilder } from '@testing/providers/toast-provider.mock';
2632

2733
describe('NotificationsComponent', () => {
@@ -35,13 +41,19 @@ describe('NotificationsComponent', () => {
3541
subscribeOsfHelpEmail: false,
3642
};
3743

44+
// new_pending_submissions → global_reviews
45+
// files_updated → global_file_updated
3846
const mockNotificationSubscriptions = [
39-
{ id: 'id1', event: SubscriptionEvent.GlobalMentions, frequency: SubscriptionFrequency.Daily },
4047
{
41-
id: 'id2',
42-
event: SubscriptionEvent.GlobalMentions,
48+
id: 'osf_new_pending_submissions',
49+
event: 'new_pending_submissions',
4350
frequency: SubscriptionFrequency.Instant,
4451
},
52+
{
53+
id: 'cuzg4_global_file_updated',
54+
event: 'files_updated',
55+
frequency: SubscriptionFrequency.Daily,
56+
},
4557
];
4658

4759
beforeEach(async () => {
@@ -71,10 +83,14 @@ describe('NotificationsComponent', () => {
7183
return signal(null);
7284
});
7385

74-
MOCK_STORE.dispatch.mockImplementation(() => of());
86+
MOCK_STORE.dispatch.mockReturnValue(of({}));
7587

7688
await TestBed.configureTestingModule({
77-
imports: [NotificationsComponent, MockPipe(TranslatePipe), ReactiveFormsModule],
89+
imports: [
90+
NotificationsComponent,
91+
...MockComponents(InfoIconComponent, SubHeaderComponent),
92+
MockPipe(TranslatePipe),
93+
],
7894
providers: [
7995
provideHttpClient(),
8096
provideHttpClientTesting(),
@@ -106,9 +122,9 @@ describe('NotificationsComponent', () => {
106122

107123
return signal(null);
108124
});
109-
component.emailPreferencesFormSubmit();
110125

111-
expect(loaderService.hide).not.toHaveBeenCalled();
126+
component.emailPreferencesFormSubmit();
127+
expect(loaderService.hide).toHaveBeenCalledTimes(1);
112128
});
113129

114130
it('should handle subscription completion correctly', () => {
@@ -126,11 +142,17 @@ describe('NotificationsComponent', () => {
126142
it('should call dispatch only once per subscription change', () => {
127143
const mockDispatch = jest.fn().mockReturnValue(of({}));
128144
MOCK_STORE.dispatch.mockImplementation(mockDispatch);
129-
const event = SubscriptionEvent.GlobalMentions;
130-
const frequency = SubscriptionFrequency.Daily;
131145

132-
component.onSubscriptionChange(event, frequency);
146+
component.onSubscriptionChange(SubscriptionEvent.GlobalFileUpdated, SubscriptionFrequency.Daily);
133147

134148
expect(mockDispatch).toHaveBeenCalledTimes(1);
135149
});
150+
151+
it('should default to API value', () => {
152+
const subs = component.notificationSubscriptionsForm.value;
153+
154+
expect(subs.global_reviews).toBe(SubscriptionFrequency.Instant);
155+
156+
expect(subs.global_file_updated).toBe(SubscriptionFrequency.Daily);
157+
});
136158
});

0 commit comments

Comments
 (0)