mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-12 17:01:10 +03:00
14653d1378
* add mocking helpers for platform peg Signed-off-by: Kerry Archibald <kerrya@element.io> * basic working live duration dropdown Signed-off-by: Kerry Archibald <kerrya@element.io> * add duration format utility Signed-off-by: Kerry Archibald <kerrya@element.io> * add duration dropdown to live location picker Signed-off-by: Kerry Archibald <kerrya@element.io> * adjust style to allow overflow and variable height chin Signed-off-by: Kerry Archibald <kerrya@element.io> * tidy comments Signed-off-by: Kerry Archibald <kerrya@element.io> * arrow fn change Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io>
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
/*
|
|
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 { MethodKeysOf, mocked, MockedObject } from "jest-mock";
|
|
|
|
import BasePlatform from "../../src/BasePlatform";
|
|
import PlatformPeg from "../../src/PlatformPeg";
|
|
|
|
// doesn't implement abstract
|
|
// @ts-ignore
|
|
class MockPlatform extends BasePlatform {
|
|
constructor(platformMocks: Partial<Record<MethodKeysOf<BasePlatform>, unknown>>) {
|
|
super();
|
|
Object.assign(this, platformMocks);
|
|
}
|
|
}
|
|
/**
|
|
* Mock Platform Peg
|
|
* Creates a mock BasePlatform class
|
|
* spys on PlatformPeg.get and returns mock platform
|
|
* @returns MockPlatform instance
|
|
*/
|
|
export const mockPlatformPeg = (
|
|
platformMocks: Partial<Record<MethodKeysOf<BasePlatform>, unknown>> = {},
|
|
): MockedObject<BasePlatform> => {
|
|
const mockPlatform = new MockPlatform(platformMocks);
|
|
jest.spyOn(PlatformPeg, 'get').mockReturnValue(mockPlatform);
|
|
return mocked(mockPlatform);
|
|
};
|
|
|
|
export const unmockPlatformPeg = () => {
|
|
jest.spyOn(PlatformPeg, 'get').mockRestore();
|
|
};
|