LLS: rename wireError (#8401)

* rename wireError in ownbeaconstore to locationPublishError

Signed-off-by: Kerry Archibald <kerrya@element.io>

* rename getLiveBeaconIdsWithWireError -> getLiveBeaconIdsWithLocationPublishError

Signed-off-by: Kerry Archibald <kerrya@element.io>

* rename wire error variables in components

Signed-off-by: Kerry Archibald <kerrya@element.io>

* new snapshots for new test names

Signed-off-by: Kerry Archibald <kerrya@element.io>

* fix bad capitalisation on onResetLocationPublishError

Signed-off-by: Kerry Archibald <kerrya@element.io>

* missed variable

Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
Kerry 2022-04-25 14:44:18 +02:00 committed by GitHub
parent a3f9123f6c
commit 8c6786bad6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 133 additions and 120 deletions

View file

@ -53,10 +53,10 @@ const LeftPanelLiveShareWarning: React.FC<Props> = ({ isMinimized }) => {
() => OwnBeaconStore.instance.isMonitoringLiveLocation, () => OwnBeaconStore.instance.isMonitoringLiveLocation,
); );
const beaconIdsWithWireError = useEventEmitterState( const beaconIdsWithLocationPublishError = useEventEmitterState(
OwnBeaconStore.instance, OwnBeaconStore.instance,
OwnBeaconStoreEvent.WireError, OwnBeaconStoreEvent.LocationPublishError,
() => OwnBeaconStore.instance.getLiveBeaconIdsWithWireError(), () => OwnBeaconStore.instance.getLiveBeaconIdsWithLocationPublishError(),
); );
const liveBeaconIds = useEventEmitterState( const liveBeaconIds = useEventEmitterState(
@ -65,13 +65,13 @@ const LeftPanelLiveShareWarning: React.FC<Props> = ({ isMinimized }) => {
() => OwnBeaconStore.instance.getLiveBeaconIds(), () => OwnBeaconStore.instance.getLiveBeaconIds(),
); );
const hasWireErrors = !!beaconIdsWithWireError.length; const hasLocationPublishErrors = !!beaconIdsWithLocationPublishError.length;
if (!isMonitoringLiveLocation) { if (!isMonitoringLiveLocation) {
return null; return null;
} }
const relevantBeaconRoomId = chooseBestBeaconRoomId(liveBeaconIds, beaconIdsWithWireError); const relevantBeaconRoomId = chooseBestBeaconRoomId(liveBeaconIds, beaconIdsWithLocationPublishError);
const onWarningClick = relevantBeaconRoomId ? () => { const onWarningClick = relevantBeaconRoomId ? () => {
dispatcher.dispatch<ViewRoomPayload>({ dispatcher.dispatch<ViewRoomPayload>({
@ -81,14 +81,14 @@ const LeftPanelLiveShareWarning: React.FC<Props> = ({ isMinimized }) => {
}); });
} : undefined; } : undefined;
const label = hasWireErrors ? const label = hasLocationPublishErrors ?
_t('An error occured whilst sharing your live location') : _t('An error occured whilst sharing your live location') :
_t('You are sharing your live location'); _t('You are sharing your live location');
return <AccessibleButton return <AccessibleButton
className={classNames('mx_LeftPanelLiveShareWarning', { className={classNames('mx_LeftPanelLiveShareWarning', {
'mx_LeftPanelLiveShareWarning__minimized': isMinimized, 'mx_LeftPanelLiveShareWarning__minimized': isMinimized,
'mx_LeftPanelLiveShareWarning__error': hasWireErrors, 'mx_LeftPanelLiveShareWarning__error': hasLocationPublishErrors,
})} })}
title={isMinimized ? label : undefined} title={isMinimized ? label : undefined}
onClick={onWarningClick} onClick={onWarningClick}

View file

@ -38,15 +38,15 @@ const OwnBeaconStatus: React.FC<Props & HTMLProps<HTMLDivElement>> = ({
beacon, displayStatus, ...rest beacon, displayStatus, ...rest
}) => { }) => {
const { const {
hasWireError, hasLocationPublishError,
hasStopSharingError, hasStopSharingError,
stoppingInProgress, stoppingInProgress,
onStopSharing, onStopSharing,
onResetWireError, onResetLocationPublishError,
} = useOwnLiveBeacons([beacon?.identifier]); } = useOwnLiveBeacons([beacon?.identifier]);
// combine display status with errors that only occur for user's own beacons // combine display status with errors that only occur for user's own beacons
const ownDisplayStatus = hasWireError || hasStopSharingError ? const ownDisplayStatus = hasLocationPublishError || hasStopSharingError ?
BeaconDisplayStatus.Error : BeaconDisplayStatus.Error :
displayStatus; displayStatus;
@ -67,10 +67,10 @@ const OwnBeaconStatus: React.FC<Props & HTMLProps<HTMLDivElement>> = ({
{ _t('Stop') } { _t('Stop') }
</AccessibleButton> </AccessibleButton>
} }
{ hasWireError && <AccessibleButton { hasLocationPublishError && <AccessibleButton
data-test-id='beacon-status-reset-wire-error' data-test-id='beacon-status-reset-wire-error'
kind='link' kind='link'
onClick={onResetWireError} onClick={onResetLocationPublishError}
className='mx_OwnBeaconStatus_button mx_OwnBeaconStatus_destructiveButton' className='mx_OwnBeaconStatus_button mx_OwnBeaconStatus_destructiveButton'
> >
{ _t('Retry') } { _t('Retry') }

View file

@ -28,8 +28,8 @@ import StyledLiveBeaconIcon from './StyledLiveBeaconIcon';
import { Icon as CloseIcon } from '../../../../res/img/image-view/close.svg'; import { Icon as CloseIcon } from '../../../../res/img/image-view/close.svg';
import LiveTimeRemaining from './LiveTimeRemaining'; import LiveTimeRemaining from './LiveTimeRemaining';
const getLabel = (hasWireError: boolean, hasStopSharingError: boolean): string => { const getLabel = (hasLocationPublishError: boolean, hasStopSharingError: boolean): string => {
if (hasWireError) { if (hasLocationPublishError) {
return _t('An error occured whilst sharing your live location, please try again'); return _t('An error occured whilst sharing your live location, please try again');
} }
if (hasStopSharingError) { if (hasStopSharingError) {
@ -45,22 +45,22 @@ interface RoomLiveShareWarningInnerProps {
const RoomLiveShareWarningInner: React.FC<RoomLiveShareWarningInnerProps> = ({ liveBeaconIds, roomId }) => { const RoomLiveShareWarningInner: React.FC<RoomLiveShareWarningInnerProps> = ({ liveBeaconIds, roomId }) => {
const { const {
onStopSharing, onStopSharing,
onResetWireError, onResetLocationPublishError,
beacon, beacon,
stoppingInProgress, stoppingInProgress,
hasStopSharingError, hasStopSharingError,
hasWireError, hasLocationPublishError,
} = useOwnLiveBeacons(liveBeaconIds); } = useOwnLiveBeacons(liveBeaconIds);
if (!beacon) { if (!beacon) {
return null; return null;
} }
const hasError = hasStopSharingError || hasWireError; const hasError = hasStopSharingError || hasLocationPublishError;
const onButtonClick = () => { const onButtonClick = () => {
if (hasWireError) { if (hasLocationPublishError) {
onResetWireError(); onResetLocationPublishError();
} else { } else {
onStopSharing(); onStopSharing();
} }
@ -72,7 +72,7 @@ const RoomLiveShareWarningInner: React.FC<RoomLiveShareWarningInnerProps> = ({ l
<StyledLiveBeaconIcon className="mx_RoomLiveShareWarning_icon" withError={hasError} /> <StyledLiveBeaconIcon className="mx_RoomLiveShareWarning_icon" withError={hasError} />
<span className="mx_RoomLiveShareWarning_label"> <span className="mx_RoomLiveShareWarning_label">
{ getLabel(hasWireError, hasStopSharingError) } { getLabel(hasLocationPublishError, hasStopSharingError) }
</span> </span>
{ stoppingInProgress && { stoppingInProgress &&
@ -90,7 +90,7 @@ const RoomLiveShareWarningInner: React.FC<RoomLiveShareWarningInnerProps> = ({ l
> >
{ hasError ? _t('Retry') : _t('Stop sharing') } { hasError ? _t('Retry') : _t('Stop sharing') }
</AccessibleButton> </AccessibleButton>
{ hasWireError && <AccessibleButton { hasLocationPublishError && <AccessibleButton
data-test-id='room-live-share-wire-error-close-button' data-test-id='room-live-share-wire-error-close-button'
title={_t('Stop sharing and close')} title={_t('Stop sharing and close')}
element='button' element='button'

View file

@ -50,7 +50,7 @@ const isOwnBeacon = (beacon: Beacon, userId: string): boolean => beacon.beaconIn
export enum OwnBeaconStoreEvent { export enum OwnBeaconStoreEvent {
LivenessChange = 'OwnBeaconStore.LivenessChange', LivenessChange = 'OwnBeaconStore.LivenessChange',
MonitoringLivePosition = 'OwnBeaconStore.MonitoringLivePosition', MonitoringLivePosition = 'OwnBeaconStore.MonitoringLivePosition',
WireError = 'WireError', LocationPublishError = 'LocationPublishError',
} }
const MOVING_UPDATE_INTERVAL = 2000; const MOVING_UPDATE_INTERVAL = 2000;
@ -60,7 +60,7 @@ const BAIL_AFTER_CONSECUTIVE_ERROR_COUNT = 2;
type OwnBeaconStoreState = { type OwnBeaconStoreState = {
beacons: Map<BeaconIdentifier, Beacon>; beacons: Map<BeaconIdentifier, Beacon>;
beaconWireErrors: Map<string, Beacon>; beaconLocationPublishErrorCounts: Map<BeaconIdentifier, number>;
beaconsByRoomId: Map<Room['roomId'], Set<BeaconIdentifier>>; beaconsByRoomId: Map<Room['roomId'], Set<BeaconIdentifier>>;
liveBeaconIds: BeaconIdentifier[]; liveBeaconIds: BeaconIdentifier[];
}; };
@ -98,7 +98,7 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
* Counts consecutive wire errors per beacon * Counts consecutive wire errors per beacon
* Reset on successful publish of location * Reset on successful publish of location
*/ */
public readonly beaconWireErrorCounts = new Map<BeaconIdentifier, number>(); public readonly beaconLocationPublishErrorCounts = new Map<BeaconIdentifier, number>();
/** /**
* ids of live beacons * ids of live beacons
* ordered by creation time descending * ordered by creation time descending
@ -143,7 +143,7 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
this.beacons.clear(); this.beacons.clear();
this.beaconsByRoomId.clear(); this.beaconsByRoomId.clear();
this.liveBeaconIds = []; this.liveBeaconIds = [];
this.beaconWireErrorCounts.clear(); this.beaconLocationPublishErrorCounts.clear();
} }
protected async onReady(): Promise<void> { protected async onReady(): Promise<void> {
@ -168,8 +168,8 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
* Some live beacon has a wire error * Some live beacon has a wire error
* Optionally filter by room * Optionally filter by room
*/ */
public hasWireErrors = (roomId?: string): boolean => { public hasLocationPublishErrors = (roomId?: string): boolean => {
return this.getLiveBeaconIds(roomId).some(this.beaconHasWireError); return this.getLiveBeaconIds(roomId).some(this.beaconHasLocationPublishError);
}; };
/** /**
@ -177,12 +177,12 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
* past the allowed consecutive failure count (BAIL_AFTER_CONSECUTIVE_ERROR_COUNT) * past the allowed consecutive failure count (BAIL_AFTER_CONSECUTIVE_ERROR_COUNT)
* Then consider it to have an error * Then consider it to have an error
*/ */
public beaconHasWireError = (beaconId: string): boolean => { public beaconHasLocationPublishError = (beaconId: string): boolean => {
return this.beaconWireErrorCounts.get(beaconId) >= BAIL_AFTER_CONSECUTIVE_ERROR_COUNT; return this.beaconLocationPublishErrorCounts.get(beaconId) >= BAIL_AFTER_CONSECUTIVE_ERROR_COUNT;
}; };
public resetWireError = (beaconId: string): void => { public resetLocationPublishError = (beaconId: string): void => {
this.incrementBeaconWireErrorCount(beaconId, false); this.incrementBeaconLocationPublishErrorCount(beaconId, false);
// always publish to all live beacons together // always publish to all live beacons together
// instead of just one that was changed // instead of just one that was changed
@ -198,8 +198,8 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
return this.liveBeaconIds.filter(beaconId => this.beaconsByRoomId.get(roomId)?.has(beaconId)); return this.liveBeaconIds.filter(beaconId => this.beaconsByRoomId.get(roomId)?.has(beaconId));
}; };
public getLiveBeaconIdsWithWireError = (roomId?: string): string[] => { public getLiveBeaconIdsWithLocationPublishError = (roomId?: string): string[] => {
return this.getLiveBeaconIds(roomId).filter(this.beaconHasWireError); return this.getLiveBeaconIds(roomId).filter(this.beaconHasLocationPublishError);
}; };
public getBeaconById = (beaconId: string): Beacon | undefined => { public getBeaconById = (beaconId: string): Beacon | undefined => {
@ -300,7 +300,7 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
* Live beacon ids that do not have wire errors * Live beacon ids that do not have wire errors
*/ */
private get healthyLiveBeaconIds() { private get healthyLiveBeaconIds() {
return this.liveBeaconIds.filter(beaconId => !this.beaconHasWireError(beaconId)); return this.liveBeaconIds.filter(beaconId => !this.beaconHasLocationPublishError(beaconId));
} }
private initialiseBeaconState = () => { private initialiseBeaconState = () => {
@ -546,10 +546,10 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
const content = makeBeaconContent(geoUri, timestamp, beacon.beaconInfoId); const content = makeBeaconContent(geoUri, timestamp, beacon.beaconInfoId);
try { try {
await this.matrixClient.sendEvent(beacon.roomId, M_BEACON.name, content); await this.matrixClient.sendEvent(beacon.roomId, M_BEACON.name, content);
this.incrementBeaconWireErrorCount(beacon.identifier, false); this.incrementBeaconLocationPublishErrorCount(beacon.identifier, false);
} catch (error) { } catch (error) {
logger.error(error); logger.error(error);
this.incrementBeaconWireErrorCount(beacon.identifier, true); this.incrementBeaconLocationPublishErrorCount(beacon.identifier, true);
} }
}; };
@ -559,22 +559,22 @@ export class OwnBeaconStore extends AsyncStoreWithClient<OwnBeaconStoreState> {
* - increment count for beacon when is error * - increment count for beacon when is error
* - emit if beacon error count crossed threshold * - emit if beacon error count crossed threshold
*/ */
private incrementBeaconWireErrorCount = (beaconId: string, isError: boolean): void => { private incrementBeaconLocationPublishErrorCount = (beaconId: string, isError: boolean): void => {
const hadError = this.beaconHasWireError(beaconId); const hadError = this.beaconHasLocationPublishError(beaconId);
if (isError) { if (isError) {
// increment error count // increment error count
this.beaconWireErrorCounts.set( this.beaconLocationPublishErrorCounts.set(
beaconId, beaconId,
(this.beaconWireErrorCounts.get(beaconId) ?? 0) + 1, (this.beaconLocationPublishErrorCounts.get(beaconId) ?? 0) + 1,
); );
} else { } else {
// clear any error count // clear any error count
this.beaconWireErrorCounts.delete(beaconId); this.beaconLocationPublishErrorCounts.delete(beaconId);
} }
if (this.beaconHasWireError(beaconId) !== hadError) { if (this.beaconHasLocationPublishError(beaconId) !== hadError) {
this.emit(OwnBeaconStoreEvent.WireError, beaconId); this.emit(OwnBeaconStoreEvent.LocationPublishError, beaconId);
} }
}; };
} }

View file

@ -24,10 +24,10 @@ import { sortBeaconsByLatestExpiry } from "./duration";
type LiveBeaconsState = { type LiveBeaconsState = {
beacon?: Beacon; beacon?: Beacon;
onStopSharing?: () => void; onStopSharing?: () => void;
onResetWireError?: () => void; onResetLocationPublishError?: () => void;
stoppingInProgress?: boolean; stoppingInProgress?: boolean;
hasStopSharingError?: boolean; hasStopSharingError?: boolean;
hasWireError?: boolean; hasLocationPublishError?: boolean;
}; };
/** /**
@ -41,11 +41,11 @@ export const useOwnLiveBeacons = (liveBeaconIds: BeaconIdentifier[]): LiveBeacon
const [stoppingInProgress, setStoppingInProgress] = useState(false); const [stoppingInProgress, setStoppingInProgress] = useState(false);
const [error, setError] = useState<Error>(); const [error, setError] = useState<Error>();
const hasWireError = useEventEmitterState( const hasLocationPublishError = useEventEmitterState(
OwnBeaconStore.instance, OwnBeaconStore.instance,
OwnBeaconStoreEvent.WireError, OwnBeaconStoreEvent.LocationPublishError,
() => () =>
liveBeaconIds.some(OwnBeaconStore.instance.beaconHasWireError), liveBeaconIds.some(OwnBeaconStore.instance.beaconHasLocationPublishError),
); );
// reset stopping in progress on change in live ids // reset stopping in progress on change in live ids
@ -72,16 +72,16 @@ export const useOwnLiveBeacons = (liveBeaconIds: BeaconIdentifier[]): LiveBeacon
} }
}; };
const onResetWireError = () => { const onResetLocationPublishError = () => {
liveBeaconIds.map(beaconId => OwnBeaconStore.instance.resetWireError(beaconId)); liveBeaconIds.map(beaconId => OwnBeaconStore.instance.resetLocationPublishError(beaconId));
}; };
return { return {
onStopSharing, onStopSharing,
onResetWireError, onResetLocationPublishError,
beacon, beacon,
stoppingInProgress, stoppingInProgress,
hasWireError, hasLocationPublishError,
hasStopSharingError: !!error, hasStopSharingError: !!error,
}; };
}; };

View file

@ -30,7 +30,7 @@ jest.mock('../../../../src/stores/OwnBeaconStore', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires // eslint-disable-next-line @typescript-eslint/no-var-requires
const EventEmitter = require("events"); const EventEmitter = require("events");
class MockOwnBeaconStore extends EventEmitter { class MockOwnBeaconStore extends EventEmitter {
public getLiveBeaconIdsWithWireError = jest.fn().mockReturnValue([]); public getLiveBeaconIdsWithLocationPublishError = jest.fn().mockReturnValue([]);
public getBeaconById = jest.fn(); public getBeaconById = jest.fn();
public getLiveBeaconIds = jest.fn().mockReturnValue([]); public getLiveBeaconIds = jest.fn().mockReturnValue([]);
} }
@ -96,7 +96,7 @@ describe('<LeftPanelLiveShareWarning />', () => {
beforeEach(() => { beforeEach(() => {
mocked(OwnBeaconStore.instance).isMonitoringLiveLocation = true; mocked(OwnBeaconStore.instance).isMonitoringLiveLocation = true;
mocked(OwnBeaconStore.instance).getLiveBeaconIdsWithWireError.mockReturnValue([]); mocked(OwnBeaconStore.instance).getLiveBeaconIdsWithLocationPublishError.mockReturnValue([]);
mocked(OwnBeaconStore.instance).getLiveBeaconIds.mockReturnValue([beacon2.identifier, beacon1.identifier]); mocked(OwnBeaconStore.instance).getLiveBeaconIds.mockReturnValue([beacon2.identifier, beacon1.identifier]);
}); });
@ -126,14 +126,18 @@ describe('<LeftPanelLiveShareWarning />', () => {
expect(component).toMatchSnapshot(); expect(component).toMatchSnapshot();
}); });
it('renders wire error', () => { it('renders location publish error', () => {
mocked(OwnBeaconStore.instance).getLiveBeaconIdsWithWireError.mockReturnValue([beacon1.identifier]); mocked(OwnBeaconStore.instance).getLiveBeaconIdsWithLocationPublishError.mockReturnValue(
[beacon1.identifier],
);
const component = getComponent(); const component = getComponent();
expect(component).toMatchSnapshot(); expect(component).toMatchSnapshot();
}); });
it('goes to room of latest beacon with wire error when clicked', () => { it('goes to room of latest beacon with location publish error when clicked', () => {
mocked(OwnBeaconStore.instance).getLiveBeaconIdsWithWireError.mockReturnValue([beacon1.identifier]); mocked(OwnBeaconStore.instance).getLiveBeaconIdsWithLocationPublishError.mockReturnValue(
[beacon1.identifier],
);
const component = getComponent(); const component = getComponent();
const dispatchSpy = jest.spyOn(dispatcher, 'dispatch'); const dispatchSpy = jest.spyOn(dispatcher, 'dispatch');
@ -150,7 +154,9 @@ describe('<LeftPanelLiveShareWarning />', () => {
}); });
it('goes back to default style when wire errors are cleared', () => { it('goes back to default style when wire errors are cleared', () => {
mocked(OwnBeaconStore.instance).getLiveBeaconIdsWithWireError.mockReturnValue([beacon1.identifier]); mocked(OwnBeaconStore.instance).getLiveBeaconIdsWithLocationPublishError.mockReturnValue(
[beacon1.identifier],
);
const component = getComponent(); const component = getComponent();
// error mode // error mode
expect(component.find('.mx_LeftPanelLiveShareWarning').at(0).text()).toEqual( expect(component.find('.mx_LeftPanelLiveShareWarning').at(0).text()).toEqual(
@ -158,8 +164,8 @@ describe('<LeftPanelLiveShareWarning />', () => {
); );
act(() => { act(() => {
mocked(OwnBeaconStore.instance).getLiveBeaconIdsWithWireError.mockReturnValue([]); mocked(OwnBeaconStore.instance).getLiveBeaconIdsWithLocationPublishError.mockReturnValue([]);
OwnBeaconStore.instance.emit(OwnBeaconStoreEvent.WireError, 'abc'); OwnBeaconStore.instance.emit(OwnBeaconStoreEvent.LocationPublishError, 'abc');
}); });
component.setProps({}); component.setProps({});

View file

@ -94,12 +94,12 @@ describe('<OwnBeaconStatus />', () => {
expect(component.find('AccessibleButton').length).toBeFalsy(); expect(component.find('AccessibleButton').length).toBeFalsy();
}); });
describe('with wire error', () => { describe('with location publish error', () => {
it('renders in error mode', () => { it('renders in error mode', () => {
const displayStatus = BeaconDisplayStatus.Active; const displayStatus = BeaconDisplayStatus.Active;
mocked(useOwnLiveBeacons).mockReturnValue({ mocked(useOwnLiveBeacons).mockReturnValue({
hasWireError: true, hasLocationPublishError: true,
onResetWireError: jest.fn(), onResetLocationPublishError: jest.fn(),
}); });
const component = getComponent({ displayStatus, beacon: defaultBeacon }); const component = getComponent({ displayStatus, beacon: defaultBeacon });
expect(component.text()).toContain('Live location error'); expect(component.text()).toContain('Live location error');
@ -107,19 +107,19 @@ describe('<OwnBeaconStatus />', () => {
expect(findByTestId(component, 'beacon-status-reset-wire-error').length).toBeTruthy(); expect(findByTestId(component, 'beacon-status-reset-wire-error').length).toBeTruthy();
}); });
it('retry button resets wire error', () => { it('retry button resets location publish error', () => {
const displayStatus = BeaconDisplayStatus.Active; const displayStatus = BeaconDisplayStatus.Active;
const onResetWireError = jest.fn(); const onResetLocationPublishError = jest.fn();
mocked(useOwnLiveBeacons).mockReturnValue({ mocked(useOwnLiveBeacons).mockReturnValue({
hasWireError: true, hasLocationPublishError: true,
onResetWireError, onResetLocationPublishError,
}); });
const component = getComponent({ displayStatus, beacon: defaultBeacon }); const component = getComponent({ displayStatus, beacon: defaultBeacon });
act(() => { act(() => {
findByTestId(component, 'beacon-status-reset-wire-error').at(0).simulate('click'); findByTestId(component, 'beacon-status-reset-wire-error').at(0).simulate('click');
}); });
expect(onResetWireError).toHaveBeenCalled(); expect(onResetLocationPublishError).toHaveBeenCalled();
}); });
}); });
@ -127,7 +127,7 @@ describe('<OwnBeaconStatus />', () => {
it('renders in error mode', () => { it('renders in error mode', () => {
const displayStatus = BeaconDisplayStatus.Active; const displayStatus = BeaconDisplayStatus.Active;
mocked(useOwnLiveBeacons).mockReturnValue({ mocked(useOwnLiveBeacons).mockReturnValue({
hasWireError: false, hasLocationPublishError: false,
hasStopSharingError: true, hasStopSharingError: true,
onStopSharing: jest.fn(), onStopSharing: jest.fn(),
}); });

View file

@ -110,7 +110,7 @@ describe('<RoomLiveShareWarning />', () => {
}); });
afterEach(async () => { afterEach(async () => {
jest.spyOn(OwnBeaconStore.instance, 'beaconHasWireError').mockRestore(); jest.spyOn(OwnBeaconStore.instance, 'beaconHasLocationPublishError').mockRestore();
await resetAsyncStoreWithClient(OwnBeaconStore.instance); await resetAsyncStoreWithClient(OwnBeaconStore.instance);
}); });
@ -328,27 +328,32 @@ describe('<RoomLiveShareWarning />', () => {
}); });
}); });
describe('with wire errors', () => { describe('with location publish errors', () => {
it('displays wire error when mounted with wire errors', async () => { it('displays location publish error when mounted with location publish errors', async () => {
const wireErrorSpy = jest.spyOn(OwnBeaconStore.instance, 'beaconHasWireError') const locationPublishErrorSpy = jest.spyOn(OwnBeaconStore.instance, 'beaconHasLocationPublishError')
.mockReturnValue(true); .mockReturnValue(true);
const component = getComponent({ roomId: room2Id }); const component = getComponent({ roomId: room2Id });
expect(component).toMatchSnapshot(); expect(component).toMatchSnapshot();
expect(wireErrorSpy).toHaveBeenCalledWith( expect(locationPublishErrorSpy).toHaveBeenCalledWith(
getBeaconInfoIdentifier(room2Beacon1), 0, [getBeaconInfoIdentifier(room2Beacon1)], getBeaconInfoIdentifier(room2Beacon1), 0, [getBeaconInfoIdentifier(room2Beacon1)],
); );
}); });
it('displays wire error when wireError event is emitted and beacons have errors', async () => { it(
const wireErrorSpy = jest.spyOn(OwnBeaconStore.instance, 'beaconHasWireError') 'displays location publish error when locationPublishError event is emitted' +
' and beacons have errors',
async () => {
const locationPublishErrorSpy = jest.spyOn(OwnBeaconStore.instance, 'beaconHasLocationPublishError')
.mockReturnValue(false); .mockReturnValue(false);
const component = getComponent({ roomId: room2Id }); const component = getComponent({ roomId: room2Id });
// update mock and emit event // update mock and emit event
act(() => { act(() => {
wireErrorSpy.mockReturnValue(true); locationPublishErrorSpy.mockReturnValue(true);
OwnBeaconStore.instance.emit(OwnBeaconStoreEvent.WireError, getBeaconInfoIdentifier(room2Beacon1)); OwnBeaconStore.instance.emit(
OwnBeaconStoreEvent.LocationPublishError, getBeaconInfoIdentifier(room2Beacon1),
);
}); });
component.setProps({}); component.setProps({});
@ -360,14 +365,16 @@ describe('<RoomLiveShareWarning />', () => {
}); });
it('stops displaying wire error when errors are cleared', async () => { it('stops displaying wire error when errors are cleared', async () => {
const wireErrorSpy = jest.spyOn(OwnBeaconStore.instance, 'beaconHasWireError') const locationPublishErrorSpy = jest.spyOn(OwnBeaconStore.instance, 'beaconHasLocationPublishError')
.mockReturnValue(true); .mockReturnValue(true);
const component = getComponent({ roomId: room2Id }); const component = getComponent({ roomId: room2Id });
// update mock and emit event // update mock and emit event
act(() => { act(() => {
wireErrorSpy.mockReturnValue(false); locationPublishErrorSpy.mockReturnValue(false);
OwnBeaconStore.instance.emit(OwnBeaconStoreEvent.WireError, getBeaconInfoIdentifier(room2Beacon1)); OwnBeaconStore.instance.emit(
OwnBeaconStoreEvent.LocationPublishError, getBeaconInfoIdentifier(room2Beacon1),
);
}); });
component.setProps({}); component.setProps({});
@ -378,9 +385,9 @@ describe('<RoomLiveShareWarning />', () => {
expect(findByTestId(component, 'room-live-share-wire-error-close-button').length).toBeFalsy(); expect(findByTestId(component, 'room-live-share-wire-error-close-button').length).toBeFalsy();
}); });
it('clicking retry button resets wire errors', async () => { it('clicking retry button resets location publish errors', async () => {
jest.spyOn(OwnBeaconStore.instance, 'beaconHasWireError').mockReturnValue(true); jest.spyOn(OwnBeaconStore.instance, 'beaconHasLocationPublishError').mockReturnValue(true);
const resetErrorSpy = jest.spyOn(OwnBeaconStore.instance, 'resetWireError'); const resetErrorSpy = jest.spyOn(OwnBeaconStore.instance, 'resetLocationPublishError');
const component = getComponent({ roomId: room2Id }); const component = getComponent({ roomId: room2Id });
@ -392,7 +399,7 @@ describe('<RoomLiveShareWarning />', () => {
}); });
it('clicking close button stops beacons', async () => { it('clicking close button stops beacons', async () => {
jest.spyOn(OwnBeaconStore.instance, 'beaconHasWireError').mockReturnValue(true); jest.spyOn(OwnBeaconStore.instance, 'beaconHasLocationPublishError').mockReturnValue(true);
const stopBeaconSpy = jest.spyOn(OwnBeaconStore.instance, 'stopBeacon'); const stopBeaconSpy = jest.spyOn(OwnBeaconStore.instance, 'stopBeacon');
const component = getComponent({ roomId: room2Id }); const component = getComponent({ roomId: room2Id });

View file

@ -52,7 +52,7 @@ exports[`<LeftPanelLiveShareWarning /> when user has live location monitor rende
</LeftPanelLiveShareWarning> </LeftPanelLiveShareWarning>
`; `;
exports[`<LeftPanelLiveShareWarning /> when user has live location monitor renders wire error 1`] = ` exports[`<LeftPanelLiveShareWarning /> when user has live location monitor renders location publish error 1`] = `
<LeftPanelLiveShareWarning> <LeftPanelLiveShareWarning>
<AccessibleButton <AccessibleButton
className="mx_LeftPanelLiveShareWarning mx_LeftPanelLiveShareWarning__error" className="mx_LeftPanelLiveShareWarning mx_LeftPanelLiveShareWarning__error"

View file

@ -6,7 +6,7 @@ exports[`<RoomLiveShareWarning /> when user has live beacons and geolocation is
exports[`<RoomLiveShareWarning /> when user has live beacons and geolocation is available stopping beacons displays error when stop sharing fails 1`] = `"<div class=\\"mx_RoomLiveShareWarning\\"><div class=\\"mx_StyledLiveBeaconIcon mx_RoomLiveShareWarning_icon mx_StyledLiveBeaconIcon_error\\"></div><span class=\\"mx_RoomLiveShareWarning_label\\">An error occurred while stopping your live location, please try again</span><button data-test-id=\\"room-live-share-primary-button\\" role=\\"button\\" tabindex=\\"0\\" class=\\"mx_AccessibleButton mx_RoomLiveShareWarning_stopButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_danger\\">Retry</button></div>"`; exports[`<RoomLiveShareWarning /> when user has live beacons and geolocation is available stopping beacons displays error when stop sharing fails 1`] = `"<div class=\\"mx_RoomLiveShareWarning\\"><div class=\\"mx_StyledLiveBeaconIcon mx_RoomLiveShareWarning_icon mx_StyledLiveBeaconIcon_error\\"></div><span class=\\"mx_RoomLiveShareWarning_label\\">An error occurred while stopping your live location, please try again</span><button data-test-id=\\"room-live-share-primary-button\\" role=\\"button\\" tabindex=\\"0\\" class=\\"mx_AccessibleButton mx_RoomLiveShareWarning_stopButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_danger\\">Retry</button></div>"`;
exports[`<RoomLiveShareWarning /> when user has live beacons and geolocation is available with wire errors displays wire error when mounted with wire errors 1`] = ` exports[`<RoomLiveShareWarning /> when user has live beacons and geolocation is available with location publish errors displays location publish error when mounted with location publish errors 1`] = `
<RoomLiveShareWarning <RoomLiveShareWarning
roomId="$room2:server.org" roomId="$room2:server.org"
> >

View file

@ -987,9 +987,9 @@ describe('OwnBeaconStore', () => {
// called for each position from watchPosition // called for each position from watchPosition
expect(mockClient.sendEvent).toHaveBeenCalledTimes(5); expect(mockClient.sendEvent).toHaveBeenCalledTimes(5);
expect(store.beaconHasWireError(getBeaconInfoIdentifier(alicesRoom1BeaconInfo))).toBe(false); expect(store.beaconHasLocationPublishError(getBeaconInfoIdentifier(alicesRoom1BeaconInfo))).toBe(false);
expect(store.getLiveBeaconIdsWithWireError()).toEqual([]); expect(store.getLiveBeaconIdsWithLocationPublishError()).toEqual([]);
expect(store.hasWireErrors()).toBe(false); expect(store.hasLocationPublishErrors()).toBe(false);
}); });
it('continues publishing positions when a beacon fails intermittently', async () => { it('continues publishing positions when a beacon fails intermittently', async () => {
@ -1015,10 +1015,10 @@ describe('OwnBeaconStore', () => {
// called for each position from watchPosition // called for each position from watchPosition
expect(mockClient.sendEvent).toHaveBeenCalledTimes(5); expect(mockClient.sendEvent).toHaveBeenCalledTimes(5);
expect(store.beaconHasWireError(getBeaconInfoIdentifier(alicesRoom1BeaconInfo))).toBe(false); expect(store.beaconHasLocationPublishError(getBeaconInfoIdentifier(alicesRoom1BeaconInfo))).toBe(false);
expect(store.hasWireErrors()).toBe(false); expect(store.hasLocationPublishErrors()).toBe(false);
expect(emitSpy).not.toHaveBeenCalledWith( expect(emitSpy).not.toHaveBeenCalledWith(
OwnBeaconStoreEvent.WireError, getBeaconInfoIdentifier(alicesRoom1BeaconInfo), OwnBeaconStoreEvent.LocationPublishError, getBeaconInfoIdentifier(alicesRoom1BeaconInfo),
); );
}); });
@ -1038,20 +1038,20 @@ describe('OwnBeaconStore', () => {
// only two allowed failures // only two allowed failures
expect(mockClient.sendEvent).toHaveBeenCalledTimes(2); expect(mockClient.sendEvent).toHaveBeenCalledTimes(2);
expect(store.beaconHasWireError(getBeaconInfoIdentifier(alicesRoom1BeaconInfo))).toBe(true); expect(store.beaconHasLocationPublishError(getBeaconInfoIdentifier(alicesRoom1BeaconInfo))).toBe(true);
expect(store.getLiveBeaconIdsWithWireError()).toEqual( expect(store.getLiveBeaconIdsWithLocationPublishError()).toEqual(
[getBeaconInfoIdentifier(alicesRoom1BeaconInfo)], [getBeaconInfoIdentifier(alicesRoom1BeaconInfo)],
); );
expect(store.getLiveBeaconIdsWithWireError(room1Id)).toEqual( expect(store.getLiveBeaconIdsWithLocationPublishError(room1Id)).toEqual(
[getBeaconInfoIdentifier(alicesRoom1BeaconInfo)], [getBeaconInfoIdentifier(alicesRoom1BeaconInfo)],
); );
expect(store.hasWireErrors()).toBe(true); expect(store.hasLocationPublishErrors()).toBe(true);
expect(emitSpy).toHaveBeenCalledWith( expect(emitSpy).toHaveBeenCalledWith(
OwnBeaconStoreEvent.WireError, getBeaconInfoIdentifier(alicesRoom1BeaconInfo), OwnBeaconStoreEvent.LocationPublishError, getBeaconInfoIdentifier(alicesRoom1BeaconInfo),
); );
}); });
it('restarts publishing a beacon after resetting wire error', async () => { it('restarts publishing a beacon after resetting location publish error', async () => {
// always fails to send events // always fails to send events
mockClient.sendEvent.mockRejectedValue(new Error('oups')); mockClient.sendEvent.mockRejectedValue(new Error('oups'));
makeRoomsWithStateEvents([ makeRoomsWithStateEvents([
@ -1067,18 +1067,18 @@ describe('OwnBeaconStore', () => {
// only two allowed failures // only two allowed failures
expect(mockClient.sendEvent).toHaveBeenCalledTimes(2); expect(mockClient.sendEvent).toHaveBeenCalledTimes(2);
expect(store.beaconHasWireError(getBeaconInfoIdentifier(alicesRoom1BeaconInfo))).toBe(true); expect(store.beaconHasLocationPublishError(getBeaconInfoIdentifier(alicesRoom1BeaconInfo))).toBe(true);
expect(store.hasWireErrors()).toBe(true); expect(store.hasLocationPublishErrors()).toBe(true);
expect(store.hasWireErrors(room1Id)).toBe(true); expect(store.hasLocationPublishErrors(room1Id)).toBe(true);
expect(emitSpy).toHaveBeenCalledWith( expect(emitSpy).toHaveBeenCalledWith(
OwnBeaconStoreEvent.WireError, getBeaconInfoIdentifier(alicesRoom1BeaconInfo), OwnBeaconStoreEvent.LocationPublishError, getBeaconInfoIdentifier(alicesRoom1BeaconInfo),
); );
// reset emitSpy mock counts to asser on wireError again // reset emitSpy mock counts to assert on locationPublishError again
emitSpy.mockClear(); emitSpy.mockClear();
store.resetWireError(getBeaconInfoIdentifier(alicesRoom1BeaconInfo)); store.resetLocationPublishError(getBeaconInfoIdentifier(alicesRoom1BeaconInfo));
expect(store.beaconHasWireError(getBeaconInfoIdentifier(alicesRoom1BeaconInfo))).toBe(false); expect(store.beaconHasLocationPublishError(getBeaconInfoIdentifier(alicesRoom1BeaconInfo))).toBe(false);
// 2 more positions from watchPosition in this period // 2 more positions from watchPosition in this period
await advanceAndFlushPromises(10000); await advanceAndFlushPromises(10000);
@ -1086,7 +1086,7 @@ describe('OwnBeaconStore', () => {
// 2 from before, 2 new ones // 2 from before, 2 new ones
expect(mockClient.sendEvent).toHaveBeenCalledTimes(4); expect(mockClient.sendEvent).toHaveBeenCalledTimes(4);
expect(emitSpy).toHaveBeenCalledWith( expect(emitSpy).toHaveBeenCalledWith(
OwnBeaconStoreEvent.WireError, getBeaconInfoIdentifier(alicesRoom1BeaconInfo), OwnBeaconStoreEvent.LocationPublishError, getBeaconInfoIdentifier(alicesRoom1BeaconInfo),
); );
}); });
}); });