Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit da13c47

Browse files
committed
Test that it all works
1 parent 4c652a7 commit da13c47

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

test/components/views/settings/Notifications-test.tsx

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ limitations under the License.
1313
*/
1414

1515
import React from 'react';
16-
import { mount } from 'enzyme';
16+
import { mount, ReactWrapper } from 'enzyme';
1717
import { IPushRule, IPushRules, RuleId, IPusher } from 'matrix-js-sdk/src/matrix';
1818
import { IThreepid, ThreepidMedium } from 'matrix-js-sdk/src/@types/threepids';
1919
import { act } from 'react-dom/test-utils';
@@ -23,16 +23,11 @@ import SettingsStore from "../../../../src/settings/SettingsStore";
2323
import { StandardActions } from '../../../../src/notifications/StandardActions';
2424
import { getMockClientWithEventEmitter } from '../../../test-utils';
2525

26-
jest.mock('../../../../src/settings/SettingsStore', () => ({
27-
monitorSetting: jest.fn(),
28-
getValue: jest.fn(),
29-
setValue: jest.fn(),
30-
}));
31-
3226
// don't pollute test output with error logs from mock rejections
3327
jest.mock("matrix-js-sdk/src/logger");
3428

35-
jest.useRealTimers();
29+
// Avoid indirectly importing any eagerly created stores that would require extra setup
30+
jest.mock("../../../../src/Notifier");
3631

3732
const masterRule = {
3833
actions: ["dont_notify"],
@@ -81,21 +76,13 @@ describe('<Notifications />', () => {
8176
mockClient.getPushers.mockClear().mockResolvedValue({ pushers: [] });
8277
mockClient.getThreePids.mockClear().mockResolvedValue({ threepids: [] });
8378
mockClient.setPusher.mockClear().mockResolvedValue({});
84-
85-
(SettingsStore.getValue as jest.Mock).mockClear().mockReturnValue(true);
86-
(SettingsStore.setValue as jest.Mock).mockClear().mockResolvedValue(true);
8779
});
8880

8981
it('renders spinner while loading', () => {
9082
const component = getComponent();
9183
expect(component.find('.mx_Spinner').length).toBeTruthy();
9284
});
9385

94-
it('renders error message when fetching push rules fails', async () => {
95-
mockClient.getPushRules.mockRejectedValue({});
96-
const component = await getComponentAndWait();
97-
expect(findByTestId(component, 'error-message').length).toBeTruthy();
98-
});
9986
it('renders error message when fetching push rules fails', async () => {
10087
mockClient.getPushRules.mockRejectedValue({});
10188
const component = await getComponentAndWait();
@@ -221,17 +208,24 @@ describe('<Notifications />', () => {
221208
});
222209
});
223210

224-
it('sets settings value on toggle click', async () => {
211+
it('toggles and sets settings correctly', async () => {
225212
const component = await getComponentAndWait();
213+
let audioNotifsToggle: ReactWrapper;
226214

227-
const audioNotifsToggle = findByTestId(component, 'notif-setting-audioNotificationsEnabled')
228-
.find('div[role="switch"]');
215+
const update = () => {
216+
audioNotifsToggle = findByTestId(component, 'notif-setting-audioNotificationsEnabled')
217+
.find('div[role="switch"]');
218+
};
219+
update();
229220

230-
await act(async () => {
231-
audioNotifsToggle.simulate('click');
232-
});
221+
expect(audioNotifsToggle.getDOMNode<HTMLElement>().getAttribute("aria-checked")).toEqual("true");
222+
expect(SettingsStore.getValue("audioNotificationsEnabled")).toEqual(true);
223+
224+
act(() => { audioNotifsToggle.simulate('click'); });
225+
update();
233226

234-
expect(SettingsStore.setValue).toHaveBeenCalledWith('audioNotificationsEnabled', null, "device", false);
227+
expect(audioNotifsToggle.getDOMNode<HTMLElement>().getAttribute("aria-checked")).toEqual("false");
228+
expect(SettingsStore.getValue("audioNotificationsEnabled")).toEqual(false);
235229
});
236230
});
237231

0 commit comments

Comments
 (0)