Display push toggle for web sessions (MSC3890) (#9327)
This commit is contained in:
parent
e15ef9f3de
commit
c3bfb6e4a9
8 changed files with 166 additions and 33 deletions
|
@ -33,7 +33,7 @@ describe('<DeviceDetails />', () => {
|
|||
isLoading: false,
|
||||
onSignOutDevice: jest.fn(),
|
||||
saveDeviceName: jest.fn(),
|
||||
setPusherEnabled: jest.fn(),
|
||||
setPushNotifications: jest.fn(),
|
||||
supportsMSC3881: true,
|
||||
};
|
||||
|
||||
|
@ -157,6 +157,27 @@ describe('<DeviceDetails />', () => {
|
|||
|
||||
fireEvent.click(checkbox);
|
||||
|
||||
expect(defaultProps.setPusherEnabled).toHaveBeenCalledWith(device.device_id, !enabled);
|
||||
expect(defaultProps.setPushNotifications).toHaveBeenCalledWith(device.device_id, !enabled);
|
||||
});
|
||||
|
||||
it('changes the local notifications settings status when clicked', () => {
|
||||
const device = {
|
||||
...baseDevice,
|
||||
};
|
||||
|
||||
const enabled = false;
|
||||
|
||||
const { getByTestId } = render(getComponent({
|
||||
device,
|
||||
localNotificationSettings: {
|
||||
is_silenced: !enabled,
|
||||
},
|
||||
isSigningOut: true,
|
||||
}));
|
||||
|
||||
const checkbox = getByTestId('device-detail-push-notification-checkbox');
|
||||
fireEvent.click(checkbox);
|
||||
|
||||
expect(defaultProps.setPushNotifications).toHaveBeenCalledWith(device.device_id, !enabled);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -45,9 +45,10 @@ describe('<FilteredDeviceList />', () => {
|
|||
onDeviceExpandToggle: jest.fn(),
|
||||
onSignOutDevices: jest.fn(),
|
||||
saveDeviceName: jest.fn(),
|
||||
setPusherEnabled: jest.fn(),
|
||||
setPushNotifications: jest.fn(),
|
||||
expandedDeviceIds: [],
|
||||
signingOutDeviceIds: [],
|
||||
localNotificationSettings: new Map(),
|
||||
devices: {
|
||||
[unverifiedNoMetadata.device_id]: unverifiedNoMetadata,
|
||||
[verifiedNoMetadata.device_id]: verifiedNoMetadata,
|
||||
|
|
|
@ -22,7 +22,13 @@ import { logger } from 'matrix-js-sdk/src/logger';
|
|||
import { DeviceTrustLevel } from 'matrix-js-sdk/src/crypto/CrossSigning';
|
||||
import { VerificationRequest } from 'matrix-js-sdk/src/crypto/verification/request/VerificationRequest';
|
||||
import { sleep } from 'matrix-js-sdk/src/utils';
|
||||
import { IMyDevice, PUSHER_DEVICE_ID, PUSHER_ENABLED } from 'matrix-js-sdk/src/matrix';
|
||||
import {
|
||||
IMyDevice,
|
||||
LOCAL_NOTIFICATION_SETTINGS_PREFIX,
|
||||
MatrixEvent,
|
||||
PUSHER_DEVICE_ID,
|
||||
PUSHER_ENABLED,
|
||||
} from 'matrix-js-sdk/src/matrix';
|
||||
|
||||
import SessionManagerTab from '../../../../../../src/components/views/settings/tabs/user/SessionManagerTab';
|
||||
import MatrixClientContext from '../../../../../../src/contexts/MatrixClientContext';
|
||||
|
@ -71,6 +77,8 @@ describe('<SessionManagerTab />', () => {
|
|||
doesServerSupportUnstableFeature: jest.fn().mockResolvedValue(true),
|
||||
getPushers: jest.fn(),
|
||||
setPusher: jest.fn(),
|
||||
getAccountData: jest.fn(),
|
||||
setLocalNotificationSettings: jest.fn(),
|
||||
});
|
||||
|
||||
const defaultProps = {};
|
||||
|
@ -114,6 +122,19 @@ describe('<SessionManagerTab />', () => {
|
|||
[PUSHER_ENABLED.name]: true,
|
||||
})],
|
||||
});
|
||||
|
||||
mockClient.getAccountData
|
||||
.mockReset()
|
||||
.mockImplementation(eventType => {
|
||||
if (eventType.startsWith(LOCAL_NOTIFICATION_SETTINGS_PREFIX.name)) {
|
||||
return new MatrixEvent({
|
||||
type: eventType,
|
||||
content: {
|
||||
is_silenced: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('renders spinner while devices load', () => {
|
||||
|
@ -333,7 +354,6 @@ describe('<SessionManagerTab />', () => {
|
|||
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
|
||||
mockCrossSigningInfo.checkDeviceTrust
|
||||
.mockImplementation((_userId, { deviceId }) => {
|
||||
console.log('hhh', deviceId);
|
||||
if (deviceId === alicesDevice.device_id) {
|
||||
return new DeviceTrustLevel(true, true, false, false);
|
||||
}
|
||||
|
@ -363,7 +383,6 @@ describe('<SessionManagerTab />', () => {
|
|||
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
|
||||
mockCrossSigningInfo.checkDeviceTrust
|
||||
.mockImplementation((_userId, { deviceId }) => {
|
||||
console.log('hhh', deviceId);
|
||||
if (deviceId === alicesDevice.device_id) {
|
||||
return new DeviceTrustLevel(true, true, false, false);
|
||||
}
|
||||
|
@ -702,4 +721,28 @@ describe('<SessionManagerTab />', () => {
|
|||
|
||||
expect(mockClient.setPusher).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("lets you change the local notification settings state", async () => {
|
||||
const { getByTestId } = render(getComponent());
|
||||
|
||||
await act(async () => {
|
||||
await flushPromisesWithFakeTimers();
|
||||
});
|
||||
|
||||
toggleDeviceDetails(getByTestId, alicesDevice.device_id);
|
||||
|
||||
// device details are expanded
|
||||
expect(getByTestId(`device-detail-${alicesDevice.device_id}`)).toBeTruthy();
|
||||
expect(getByTestId('device-detail-push-notification')).toBeTruthy();
|
||||
|
||||
const checkbox = getByTestId('device-detail-push-notification-checkbox');
|
||||
|
||||
expect(checkbox).toBeTruthy();
|
||||
fireEvent.click(checkbox);
|
||||
|
||||
expect(mockClient.setLocalNotificationSettings).toHaveBeenCalledWith(
|
||||
alicesDevice.device_id,
|
||||
{ is_silenced: true },
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue