LLS: error handling on stopping beacon (#8406)
* shared stopping error state for timeline, maxi and room warnign Signed-off-by: Kerry Archibald <kerrya@element.io> * check for stopping errors in roomlist share warning Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io> * test stopping errors in OwnBeaconStore Signed-off-by: Kerry Archibald <kerrya@element.io> * update LeftPanelLiveShareWarning tests for stopping errors Signed-off-by: Kerry Archibald <kerrya@element.io> * reinstate try/catch for stopping beacons in create Signed-off-by: Kerry Archibald <kerrya@element.io> * remove unnecessary and buggy beacon stopping on creation Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
parent
1bceeb244c
commit
472222c195
8 changed files with 213 additions and 49 deletions
|
@ -18,7 +18,7 @@ import React from 'react';
|
|||
import { mocked } from 'jest-mock';
|
||||
import { mount } from 'enzyme';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { Beacon } from 'matrix-js-sdk/src/matrix';
|
||||
import { Beacon, BeaconIdentifier } from 'matrix-js-sdk/src/matrix';
|
||||
|
||||
import LeftPanelLiveShareWarning from '../../../../src/components/views/beacon/LeftPanelLiveShareWarning';
|
||||
import { OwnBeaconStore, OwnBeaconStoreEvent } from '../../../../src/stores/OwnBeaconStore';
|
||||
|
@ -33,6 +33,7 @@ jest.mock('../../../../src/stores/OwnBeaconStore', () => {
|
|||
public getLiveBeaconIdsWithLocationPublishError = jest.fn().mockReturnValue([]);
|
||||
public getBeaconById = jest.fn();
|
||||
public getLiveBeaconIds = jest.fn().mockReturnValue([]);
|
||||
public readonly beaconUpdateErrors = new Map<BeaconIdentifier, Error>();
|
||||
}
|
||||
return {
|
||||
// @ts-ignore
|
||||
|
@ -59,6 +60,8 @@ describe('<LeftPanelLiveShareWarning />', () => {
|
|||
beforeEach(() => {
|
||||
jest.spyOn(global.Date, 'now').mockReturnValue(now);
|
||||
jest.spyOn(dispatcher, 'dispatch').mockClear().mockImplementation(() => { });
|
||||
|
||||
OwnBeaconStore.instance.beaconUpdateErrors.clear();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
|
@ -191,5 +194,55 @@ describe('<LeftPanelLiveShareWarning />', () => {
|
|||
|
||||
expect(component.html()).toBe(null);
|
||||
});
|
||||
|
||||
describe('stopping errors', () => {
|
||||
it('renders stopping error', () => {
|
||||
OwnBeaconStore.instance.beaconUpdateErrors.set(beacon2.identifier, new Error('error'));
|
||||
const component = getComponent();
|
||||
expect(component.text()).toEqual('An error occurred while stopping your live location');
|
||||
});
|
||||
|
||||
it('starts rendering stopping error on beaconUpdateError emit', () => {
|
||||
const component = getComponent();
|
||||
// no error
|
||||
expect(component.text()).toEqual('You are sharing your live location');
|
||||
|
||||
act(() => {
|
||||
OwnBeaconStore.instance.beaconUpdateErrors.set(beacon2.identifier, new Error('error'));
|
||||
OwnBeaconStore.instance.emit(OwnBeaconStoreEvent.BeaconUpdateError, beacon2.identifier, true);
|
||||
});
|
||||
|
||||
expect(component.text()).toEqual('An error occurred while stopping your live location');
|
||||
});
|
||||
|
||||
it('renders stopping error when beacons have stopping and location errors', () => {
|
||||
mocked(OwnBeaconStore.instance).getLiveBeaconIdsWithLocationPublishError.mockReturnValue(
|
||||
[beacon1.identifier],
|
||||
);
|
||||
OwnBeaconStore.instance.beaconUpdateErrors.set(beacon2.identifier, new Error('error'));
|
||||
const component = getComponent();
|
||||
expect(component.text()).toEqual('An error occurred while stopping your live location');
|
||||
});
|
||||
|
||||
it('goes to room of latest beacon with stopping error when clicked', () => {
|
||||
mocked(OwnBeaconStore.instance).getLiveBeaconIdsWithLocationPublishError.mockReturnValue(
|
||||
[beacon1.identifier],
|
||||
);
|
||||
OwnBeaconStore.instance.beaconUpdateErrors.set(beacon2.identifier, new Error('error'));
|
||||
const component = getComponent();
|
||||
const dispatchSpy = jest.spyOn(dispatcher, 'dispatch');
|
||||
|
||||
act(() => {
|
||||
component.simulate('click');
|
||||
});
|
||||
|
||||
expect(dispatchSpy).toHaveBeenCalledWith({
|
||||
action: Action.ViewRoom,
|
||||
metricsTrigger: undefined,
|
||||
// stopping error beacon's room
|
||||
room_id: beacon2.roomId,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue