Apply prettier formatting

This commit is contained in:
Michael Weimann 2022-12-12 12:24:14 +01:00
parent 1cac306093
commit 526645c791
No known key found for this signature in database
GPG key ID: 53F535A266BB9584
1576 changed files with 65385 additions and 62478 deletions

View file

@ -18,15 +18,12 @@ import { MatrixEvent } from "matrix-js-sdk/src/matrix";
import BasePlatform from "../../../src/BasePlatform";
import { IConfigOptions } from "../../../src/IConfigOptions";
import {
getDeviceClientInformation,
recordClientInformation,
} from "../../../src/utils/device/clientInformation";
import { getDeviceClientInformation, recordClientInformation } from "../../../src/utils/device/clientInformation";
import { getMockClientWithEventEmitter } from "../../test-utils";
describe('recordClientInformation()', () => {
const deviceId = 'my-device-id';
const version = '1.2.3';
describe("recordClientInformation()", () => {
const deviceId = "my-device-id";
const version = "1.2.3";
const isElectron = window.electron;
const mockClient = getMockClientWithEventEmitter({
@ -35,8 +32,8 @@ describe('recordClientInformation()', () => {
});
const sdkConfig: IConfigOptions = {
brand: 'Test Brand',
element_call: { url: '', use_exclusively: false, brand: "Element Call" },
brand: "Test Brand",
element_call: { url: "", use_exclusively: false, brand: "Element Call" },
};
const platform = {
@ -53,45 +50,31 @@ describe('recordClientInformation()', () => {
window.electron = isElectron;
});
it('saves client information without url for electron clients', async () => {
it("saves client information without url for electron clients", async () => {
window.electron = true;
await recordClientInformation(
mockClient,
sdkConfig,
platform,
);
await recordClientInformation(mockClient, sdkConfig, platform);
expect(mockClient.setAccountData).toHaveBeenCalledWith(
`io.element.matrix_client_information.${deviceId}`,
{
name: sdkConfig.brand,
version,
url: undefined,
},
);
expect(mockClient.setAccountData).toHaveBeenCalledWith(`io.element.matrix_client_information.${deviceId}`, {
name: sdkConfig.brand,
version,
url: undefined,
});
});
it('saves client information with url for non-electron clients', async () => {
await recordClientInformation(
mockClient,
sdkConfig,
platform,
);
it("saves client information with url for non-electron clients", async () => {
await recordClientInformation(mockClient, sdkConfig, platform);
expect(mockClient.setAccountData).toHaveBeenCalledWith(
`io.element.matrix_client_information.${deviceId}`,
{
name: sdkConfig.brand,
version,
url: 'localhost',
},
);
expect(mockClient.setAccountData).toHaveBeenCalledWith(`io.element.matrix_client_information.${deviceId}`, {
name: sdkConfig.brand,
version,
url: "localhost",
});
});
});
describe('getDeviceClientInformation()', () => {
const deviceId = 'my-device-id';
describe("getDeviceClientInformation()", () => {
const deviceId = "my-device-id";
const mockClient = getMockClientWithEventEmitter({
getAccountData: jest.fn(),
@ -101,19 +84,17 @@ describe('getDeviceClientInformation()', () => {
jest.resetAllMocks();
});
it('returns an empty object when no event exists for the device', () => {
it("returns an empty object when no event exists for the device", () => {
expect(getDeviceClientInformation(mockClient, deviceId)).toEqual({});
expect(mockClient.getAccountData).toHaveBeenCalledWith(
`io.element.matrix_client_information.${deviceId}`,
);
expect(mockClient.getAccountData).toHaveBeenCalledWith(`io.element.matrix_client_information.${deviceId}`);
});
it('returns client information for the device', () => {
it("returns client information for the device", () => {
const eventContent = {
name: 'Element Web',
version: '1.2.3',
url: 'test.com',
name: "Element Web",
version: "1.2.3",
url: "test.com",
};
const event = new MatrixEvent({
type: `io.element.matrix_client_information.${deviceId}`,
@ -123,13 +104,13 @@ describe('getDeviceClientInformation()', () => {
expect(getDeviceClientInformation(mockClient, deviceId)).toEqual(eventContent);
});
it('excludes values with incorrect types', () => {
it("excludes values with incorrect types", () => {
const eventContent = {
extraField: 'hello',
name: 'Element Web',
extraField: "hello",
name: "Element Web",
// wrong format
version: { value: '1.2.3' },
url: 'test.com',
version: { value: "1.2.3" },
url: "test.com",
};
const event = new MatrixEvent({
type: `io.element.matrix_client_information.${deviceId}`,
@ -143,4 +124,3 @@ describe('getDeviceClientInformation()', () => {
});
});
});

View file

@ -26,7 +26,7 @@ const makeDeviceExtendedInfo = (
deviceType,
deviceModel,
deviceOperatingSystem,
client: clientName && [clientName, clientVersion].filter(Boolean).join(' '),
client: clientName && [clientName, clientVersion].filter(Boolean).join(" "),
});
/* eslint-disable max-len */
@ -66,7 +66,7 @@ const IOS_EXPECTED_RESULT = [
];
const DESKTOP_UA = [
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) ElementNightly/2022091301 Chrome/104.0.5112.102" +
" Electron/20.1.1 Safari/537.36",
" Electron/20.1.1 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) ElementNightly/2022091301 Chrome/104.0.5112.102 Electron/20.1.1 Safari/537.36",
];
const DESKTOP_EXPECTED_RESULT = [
@ -98,7 +98,6 @@ const WEB_EXPECTED_RESULT = [
makeDeviceExtendedInfo(DeviceType.Web, "Apple iPad", "iOS", "Mobile Safari", "8.0"),
makeDeviceExtendedInfo(DeviceType.Web, "Apple iPhone", "iOS", "Mobile Safari", "8.0"),
makeDeviceExtendedInfo(DeviceType.Web, "Samsung SM-G973U", "Android", "Chrome", "69.0.3497.100"),
];
const MISC_UA = [
@ -119,8 +118,8 @@ const MISC_EXPECTED_RESULT = [
];
/* eslint-disable max-len */
describe('parseUserAgent()', () => {
it('returns deviceType unknown when user agent is falsy', () => {
describe("parseUserAgent()", () => {
it("returns deviceType unknown when user agent is falsy", () => {
expect(parseUserAgent(undefined)).toEqual({
deviceType: DeviceType.Unknown,
});
@ -132,17 +131,15 @@ describe('parseUserAgent()', () => {
const testCases: TestCase[] = userAgents.map((userAgent, index) => [userAgent, results[index]]);
describe(platform, () => {
it.each(
testCases,
)('Parses user agent correctly - %s', (userAgent, expectedResult) => {
it.each(testCases)("Parses user agent correctly - %s", (userAgent, expectedResult) => {
expect(parseUserAgent(userAgent)).toEqual(expectedResult);
});
});
};
testPlatform('Android', ANDROID_UA, ANDROID_EXPECTED_RESULT);
testPlatform('iOS', IOS_UA, IOS_EXPECTED_RESULT);
testPlatform('Desktop', DESKTOP_UA, DESKTOP_EXPECTED_RESULT);
testPlatform('Web', WEB_UA, WEB_EXPECTED_RESULT);
testPlatform('Misc', MISC_UA, MISC_EXPECTED_RESULT);
testPlatform("Android", ANDROID_UA, ANDROID_EXPECTED_RESULT);
testPlatform("iOS", IOS_UA, IOS_EXPECTED_RESULT);
testPlatform("Desktop", DESKTOP_UA, DESKTOP_EXPECTED_RESULT);
testPlatform("Web", WEB_UA, WEB_EXPECTED_RESULT);
testPlatform("Misc", MISC_UA, MISC_EXPECTED_RESULT);
});

View file

@ -21,12 +21,12 @@ import {
snoozeBulkUnverifiedDeviceReminder,
} from "../../../src/utils/device/snoozeBulkUnverifiedDeviceReminder";
const SNOOZE_KEY = 'mx_snooze_bulk_unverified_device_nag';
const SNOOZE_KEY = "mx_snooze_bulk_unverified_device_nag";
describe('snooze bulk unverified device nag', () => {
const localStorageSetSpy = jest.spyOn(localStorage.__proto__, 'setItem');
const localStorageGetSpy = jest.spyOn(localStorage.__proto__, 'getItem');
const localStorageRemoveSpy = jest.spyOn(localStorage.__proto__, 'removeItem');
describe("snooze bulk unverified device nag", () => {
const localStorageSetSpy = jest.spyOn(localStorage.__proto__, "setItem");
const localStorageGetSpy = jest.spyOn(localStorage.__proto__, "getItem");
const localStorageRemoveSpy = jest.spyOn(localStorage.__proto__, "removeItem");
// 14.03.2022 16:15
const now = 1647270879403;
@ -36,61 +36,65 @@ describe('snooze bulk unverified device nag', () => {
localStorageGetSpy.mockClear().mockReturnValue(null);
localStorageRemoveSpy.mockClear().mockImplementation(() => {});
jest.spyOn(Date, 'now').mockReturnValue(now);
jest.spyOn(Date, "now").mockReturnValue(now);
});
afterAll(() => {
jest.restoreAllMocks();
});
describe('snoozeBulkUnverifiedDeviceReminder()', () => {
it('sets the current time in local storage', () => {
describe("snoozeBulkUnverifiedDeviceReminder()", () => {
it("sets the current time in local storage", () => {
snoozeBulkUnverifiedDeviceReminder();
expect(localStorageSetSpy).toHaveBeenCalledWith(SNOOZE_KEY, now.toString());
});
it('catches an error from localstorage', () => {
const loggerErrorSpy = jest.spyOn(logger, 'error');
localStorageSetSpy.mockImplementation(() => { throw new Error('oups'); });
it("catches an error from localstorage", () => {
const loggerErrorSpy = jest.spyOn(logger, "error");
localStorageSetSpy.mockImplementation(() => {
throw new Error("oups");
});
snoozeBulkUnverifiedDeviceReminder();
expect(loggerErrorSpy).toHaveBeenCalled();
});
});
describe('isBulkUnverifiedDeviceReminderSnoozed()', () => {
it('returns false when there is no snooze in storage', () => {
describe("isBulkUnverifiedDeviceReminderSnoozed()", () => {
it("returns false when there is no snooze in storage", () => {
const result = isBulkUnverifiedDeviceReminderSnoozed();
expect(localStorageGetSpy).toHaveBeenCalledWith(SNOOZE_KEY);
expect(result).toBe(false);
});
it('catches an error from localstorage and returns false', () => {
const loggerErrorSpy = jest.spyOn(logger, 'error');
localStorageGetSpy.mockImplementation(() => { throw new Error('oups'); });
it("catches an error from localstorage and returns false", () => {
const loggerErrorSpy = jest.spyOn(logger, "error");
localStorageGetSpy.mockImplementation(() => {
throw new Error("oups");
});
const result = isBulkUnverifiedDeviceReminderSnoozed();
expect(result).toBe(false);
expect(loggerErrorSpy).toHaveBeenCalled();
});
it('returns false when snooze timestamp in storage is not a number', () => {
localStorageGetSpy.mockReturnValue('test');
it("returns false when snooze timestamp in storage is not a number", () => {
localStorageGetSpy.mockReturnValue("test");
const result = isBulkUnverifiedDeviceReminderSnoozed();
expect(result).toBe(false);
});
it('returns false when snooze timestamp in storage is over a week ago', () => {
it("returns false when snooze timestamp in storage is over a week ago", () => {
const msDay = 1000 * 60 * 60 * 24;
// snoozed 8 days ago
localStorageGetSpy.mockReturnValue(now - (msDay * 8));
localStorageGetSpy.mockReturnValue(now - msDay * 8);
const result = isBulkUnverifiedDeviceReminderSnoozed();
expect(result).toBe(false);
});
it('returns true when snooze timestamp in storage is less than a week ago', () => {
it("returns true when snooze timestamp in storage is less than a week ago", () => {
const msDay = 1000 * 60 * 60 * 24;
// snoozed 8 days ago
localStorageGetSpy.mockReturnValue(now - (msDay * 6));
localStorageGetSpy.mockReturnValue(now - msDay * 6);
const result = isBulkUnverifiedDeviceReminderSnoozed();
expect(result).toBe(true);
});