2022-03-17 16:25:57 +08:00
|
|
|
/*
|
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { mocked } from 'jest-mock';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
|
|
|
|
import '../../../skinned-sdk';
|
|
|
|
import LeftPanelLiveShareWarning from '../../../../src/components/views/beacon/LeftPanelLiveShareWarning';
|
|
|
|
import { OwnBeaconStore, OwnBeaconStoreEvent } from '../../../../src/stores/OwnBeaconStore';
|
|
|
|
import { flushPromises } from '../../../test-utils';
|
|
|
|
|
|
|
|
jest.mock('../../../../src/stores/OwnBeaconStore', () => {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
|
|
const EventEmitter = require("events");
|
|
|
|
class MockOwnBeaconStore extends EventEmitter {
|
|
|
|
public hasLiveBeacons = jest.fn().mockReturnValue(false);
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
// @ts-ignore
|
|
|
|
...jest.requireActual('../../../../src/stores/OwnBeaconStore'),
|
|
|
|
OwnBeaconStore: {
|
|
|
|
instance: new MockOwnBeaconStore() as unknown as OwnBeaconStore,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
describe('<LeftPanelLiveShareWarning />', () => {
|
|
|
|
const defaultProps = {};
|
|
|
|
const getComponent = (props = {}) =>
|
|
|
|
mount(<LeftPanelLiveShareWarning {...defaultProps} {...props} />);
|
|
|
|
|
|
|
|
it('renders nothing when user has no live beacons', () => {
|
|
|
|
const component = getComponent();
|
|
|
|
expect(component.html()).toBe(null);
|
|
|
|
});
|
|
|
|
|
2022-03-29 00:46:39 +08:00
|
|
|
describe('when user has live location monitor', () => {
|
2022-03-17 16:25:57 +08:00
|
|
|
beforeEach(() => {
|
2022-03-29 00:46:39 +08:00
|
|
|
mocked(OwnBeaconStore.instance).isMonitoringLiveLocation = true;
|
2022-03-17 16:25:57 +08:00
|
|
|
});
|
|
|
|
it('renders correctly when not minimized', () => {
|
|
|
|
const component = getComponent();
|
|
|
|
expect(component).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly when minimized', () => {
|
|
|
|
const component = getComponent({ isMinimized: true });
|
|
|
|
expect(component).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes itself when user stops having live beacons', async () => {
|
|
|
|
const component = getComponent({ isMinimized: true });
|
|
|
|
// started out rendered
|
|
|
|
expect(component.html()).toBeTruthy();
|
|
|
|
|
2022-03-29 00:46:39 +08:00
|
|
|
mocked(OwnBeaconStore.instance).isMonitoringLiveLocation = false;
|
|
|
|
OwnBeaconStore.instance.emit(OwnBeaconStoreEvent.MonitoringLivePosition);
|
2022-03-17 16:25:57 +08:00
|
|
|
|
|
|
|
await flushPromises();
|
|
|
|
component.setProps({});
|
|
|
|
|
|
|
|
expect(component.html()).toBe(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|