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

@ -44,13 +44,13 @@ describe("SettingsStore", () => {
}),
} as unknown as BasePlatform);
TEST_DATA.forEach(d => {
TEST_DATA.forEach((d) => {
SettingsStore.setValue(d.name, null, d.level, d.value);
});
});
describe("getValueAt", () => {
TEST_DATA.forEach(d => {
TEST_DATA.forEach((d) => {
it(`should return the value "${d.level}"."${d.name}"`, () => {
expect(SettingsStore.getValueAt(d.level, d.name)).toBe(d.value);
// regression test #22545

View file

@ -19,13 +19,13 @@ import dis from "../../../src/dispatcher/dispatcher";
import FontSizeController from "../../../src/settings/controllers/FontSizeController";
import { SettingLevel } from "../../../src/settings/SettingLevel";
const dispatchSpy = jest.spyOn(dis, 'dispatch');
const dispatchSpy = jest.spyOn(dis, "dispatch");
describe('FontSizeController', () => {
it('dispatches a font size action on change', () => {
describe("FontSizeController", () => {
it("dispatches a font size action on change", () => {
const controller = new FontSizeController();
controller.onChange(SettingLevel.ACCOUNT, '$room:server', 12);
controller.onChange(SettingLevel.ACCOUNT, "$room:server", 12);
expect(dispatchSpy).toHaveBeenCalledWith({
action: Action.UpdateFontSize,

View file

@ -18,15 +18,15 @@ import IncompatibleController from "../../../src/settings/controllers/Incompatib
import { SettingLevel } from "../../../src/settings/SettingLevel";
import SettingsStore from "../../../src/settings/SettingsStore";
describe('IncompatibleController', () => {
const settingsGetValueSpy = jest.spyOn(SettingsStore, 'getValue');
describe("IncompatibleController", () => {
const settingsGetValueSpy = jest.spyOn(SettingsStore, "getValue");
beforeEach(() => {
settingsGetValueSpy.mockClear();
});
describe('incompatibleSetting', () => {
describe('when incompatibleValue is not set', () => {
it('returns true when setting value is true', () => {
describe("incompatibleSetting", () => {
describe("when incompatibleValue is not set", () => {
it("returns true when setting value is true", () => {
// no incompatible value set, defaulted to true
const controller = new IncompatibleController("feature_spotlight", { key: null });
settingsGetValueSpy.mockReturnValue(true);
@ -36,56 +36,56 @@ describe('IncompatibleController', () => {
expect(settingsGetValueSpy).toHaveBeenCalledWith("feature_spotlight");
});
it('returns false when setting value is not true', () => {
it("returns false when setting value is not true", () => {
// no incompatible value set, defaulted to true
const controller = new IncompatibleController("feature_spotlight", { key: null });
settingsGetValueSpy.mockReturnValue('test');
settingsGetValueSpy.mockReturnValue("test");
expect(controller.incompatibleSetting).toBe(false);
});
});
describe('when incompatibleValue is set to a value', () => {
it('returns true when setting value matches incompatible value', () => {
const controller = new IncompatibleController("feature_spotlight", { key: null }, 'test');
settingsGetValueSpy.mockReturnValue('test');
describe("when incompatibleValue is set to a value", () => {
it("returns true when setting value matches incompatible value", () => {
const controller = new IncompatibleController("feature_spotlight", { key: null }, "test");
settingsGetValueSpy.mockReturnValue("test");
expect(controller.incompatibleSetting).toBe(true);
});
it('returns false when setting value is not true', () => {
const controller = new IncompatibleController("feature_spotlight", { key: null }, 'test');
settingsGetValueSpy.mockReturnValue('not test');
it("returns false when setting value is not true", () => {
const controller = new IncompatibleController("feature_spotlight", { key: null }, "test");
settingsGetValueSpy.mockReturnValue("not test");
expect(controller.incompatibleSetting).toBe(false);
});
});
describe('when incompatibleValue is set to a function', () => {
it('returns result from incompatibleValue function', () => {
describe("when incompatibleValue is set to a function", () => {
it("returns result from incompatibleValue function", () => {
const incompatibleValueFn = jest.fn().mockReturnValue(false);
const controller = new IncompatibleController("feature_spotlight", { key: null }, incompatibleValueFn);
settingsGetValueSpy.mockReturnValue('test');
settingsGetValueSpy.mockReturnValue("test");
expect(controller.incompatibleSetting).toBe(false);
expect(incompatibleValueFn).toHaveBeenCalledWith('test');
expect(incompatibleValueFn).toHaveBeenCalledWith("test");
});
});
});
describe('getValueOverride()', () => {
it('returns forced value when setting is incompatible', () => {
describe("getValueOverride()", () => {
it("returns forced value when setting is incompatible", () => {
settingsGetValueSpy.mockReturnValue(true);
const forcedValue = { key: null };
const controller = new IncompatibleController("feature_spotlight", forcedValue);
expect(controller.getValueOverride(
SettingLevel.ACCOUNT, '$room:server', true, SettingLevel.ACCOUNT,
)).toEqual(forcedValue);
expect(
controller.getValueOverride(SettingLevel.ACCOUNT, "$room:server", true, SettingLevel.ACCOUNT),
).toEqual(forcedValue);
});
it('returns null when setting is not incompatible', () => {
it("returns null when setting is not incompatible", () => {
settingsGetValueSpy.mockReturnValue(false);
const forcedValue = { key: null };
const controller = new IncompatibleController("feature_spotlight", forcedValue);
expect(controller.getValueOverride(
SettingLevel.ACCOUNT, '$room:server', true, SettingLevel.ACCOUNT,
)).toEqual(null);
expect(
controller.getValueOverride(SettingLevel.ACCOUNT, "$room:server", true, SettingLevel.ACCOUNT),
).toEqual(null);
});
});
});

View file

@ -20,14 +20,14 @@ import SystemFontController from "../../../src/settings/controllers/SystemFontCo
import { SettingLevel } from "../../../src/settings/SettingLevel";
import SettingsStore from "../../../src/settings/SettingsStore";
const dispatchSpy = jest.spyOn(dis, 'dispatch');
const dispatchSpy = jest.spyOn(dis, "dispatch");
describe('SystemFontController', () => {
it('dispatches a font size action on change', () => {
const getValueSpy = jest.spyOn(SettingsStore, 'getValue').mockReturnValue(true);
describe("SystemFontController", () => {
it("dispatches a font size action on change", () => {
const getValueSpy = jest.spyOn(SettingsStore, "getValue").mockReturnValue(true);
const controller = new SystemFontController();
controller.onChange(SettingLevel.ACCOUNT, '$room:server', 12);
controller.onChange(SettingLevel.ACCOUNT, "$room:server", 12);
expect(dispatchSpy).toHaveBeenCalledWith({
action: Action.UpdateSystemFont,

View file

@ -19,57 +19,50 @@ import { SettingLevel } from "../../../src/settings/SettingLevel";
import SettingsStore from "../../../src/settings/SettingsStore";
import { DEFAULT_THEME } from "../../../src/theme";
describe('ThemeController', () => {
jest.spyOn(SettingsStore, 'getValue').mockReturnValue([]);
describe("ThemeController", () => {
jest.spyOn(SettingsStore, "getValue").mockReturnValue([]);
afterEach(() => {
// reset
ThemeController.isLogin = false;
});
it('returns null when calculatedValue is falsy', () => {
it("returns null when calculatedValue is falsy", () => {
const controller = new ThemeController();
expect(controller.getValueOverride(
SettingLevel.ACCOUNT,
'$room:server',
undefined, /* calculatedValue */
SettingLevel.ACCOUNT,
)).toEqual(null);
expect(
controller.getValueOverride(
SettingLevel.ACCOUNT,
"$room:server",
undefined /* calculatedValue */,
SettingLevel.ACCOUNT,
),
).toEqual(null);
});
it('returns light when login flag is set', () => {
it("returns light when login flag is set", () => {
const controller = new ThemeController();
ThemeController.isLogin = true;
expect(controller.getValueOverride(
SettingLevel.ACCOUNT,
'$room:server',
'dark',
SettingLevel.ACCOUNT,
)).toEqual('light');
expect(controller.getValueOverride(SettingLevel.ACCOUNT, "$room:server", "dark", SettingLevel.ACCOUNT)).toEqual(
"light",
);
});
it('returns default theme when value is not a valid theme', () => {
it("returns default theme when value is not a valid theme", () => {
const controller = new ThemeController();
expect(controller.getValueOverride(
SettingLevel.ACCOUNT,
'$room:server',
'my-test-theme',
SettingLevel.ACCOUNT,
)).toEqual(DEFAULT_THEME);
expect(
controller.getValueOverride(SettingLevel.ACCOUNT, "$room:server", "my-test-theme", SettingLevel.ACCOUNT),
).toEqual(DEFAULT_THEME);
});
it('returns null when value is a valid theme', () => {
it("returns null when value is a valid theme", () => {
const controller = new ThemeController();
expect(controller.getValueOverride(
SettingLevel.ACCOUNT,
'$room:server',
'dark',
SettingLevel.ACCOUNT,
)).toEqual(null);
expect(controller.getValueOverride(SettingLevel.ACCOUNT, "$room:server", "dark", SettingLevel.ACCOUNT)).toEqual(
null,
);
});
});

View file

@ -20,14 +20,14 @@ import UseSystemFontController from "../../../src/settings/controllers/UseSystem
import { SettingLevel } from "../../../src/settings/SettingLevel";
import SettingsStore from "../../../src/settings/SettingsStore";
const dispatchSpy = jest.spyOn(dis, 'dispatch');
const dispatchSpy = jest.spyOn(dis, "dispatch");
describe('UseSystemFontController', () => {
it('dispatches a font size action on change', () => {
const getValueSpy = jest.spyOn(SettingsStore, 'getValue').mockReturnValue(12);
describe("UseSystemFontController", () => {
it("dispatches a font size action on change", () => {
const getValueSpy = jest.spyOn(SettingsStore, "getValue").mockReturnValue(12);
const controller = new UseSystemFontController();
controller.onChange(SettingLevel.ACCOUNT, '$room:server', true);
controller.onChange(SettingLevel.ACCOUNT, "$room:server", true);
expect(dispatchSpy).toHaveBeenCalledWith({
action: Action.UpdateSystemFont,

View file

@ -15,10 +15,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { sleep } from 'matrix-js-sdk/src/utils';
import { sleep } from "matrix-js-sdk/src/utils";
import SettingsStore from '../../../src/settings/SettingsStore';
import { SettingLevel } from '../../../src/settings/SettingLevel';
import SettingsStore from "../../../src/settings/SettingsStore";
import { SettingLevel } from "../../../src/settings/SettingLevel";
import { FontWatcher } from "../../../src/settings/watchers/FontWatcher";
import { Action } from "../../../src/dispatcher/actions";
import { untilDispatch } from "../../test-utils";
@ -31,7 +31,7 @@ async function setSystemFont(font: string): Promise<void> {
await sleep(1); // await the FontWatcher doing its action
}
describe('FontWatcher', function() {
describe("FontWatcher", function () {
it("should load font on start()", async () => {
const watcher = new FontWatcher();
await setSystemFont("Font Name");
@ -67,15 +67,15 @@ describe('FontWatcher', function() {
fontWatcher.stop();
});
it('encloses the fonts by double quotes and sets them as the system font', async () => {
it("encloses the fonts by double quotes and sets them as the system font", async () => {
await setSystemFont("Fira Sans Thin, Commodore 64");
expect(document.body.style.fontFamily).toBe(`"Fira Sans Thin","Commodore 64"`);
});
it('does not add double quotes if already present and sets the font as the system font', async () => {
it("does not add double quotes if already present and sets the font as the system font", async () => {
await setSystemFont(`"Commodore 64"`);
expect(document.body.style.fontFamily).toBe(`"Commodore 64"`);
});
it('trims whitespace, encloses the fonts by double quotes, and sets them as the system font', async () => {
it("trims whitespace, encloses the fonts by double quotes, and sets them as the system font", async () => {
await setSystemFont(` Fira Code , "Commodore 64" `);
expect(document.body.style.fontFamily).toBe(`"Fira Code","Commodore 64"`);
});

View file

@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import SettingsStore from '../../../src/settings/SettingsStore';
import ThemeWatcher from '../../../src/settings/watchers/ThemeWatcher';
import { SettingLevel } from '../../../src/settings/SettingLevel';
import SettingsStore from "../../../src/settings/SettingsStore";
import ThemeWatcher from "../../../src/settings/watchers/ThemeWatcher";
import { SettingLevel } from "../../../src/settings/SettingLevel";
function makeMatchMedia(values: any) {
class FakeMediaQueryList {
@ -27,7 +27,9 @@ function makeMatchMedia(values: any) {
removeListener() {}
addEventListener() {}
removeEventListener() {}
dispatchEvent() { return true; }
dispatchEvent() {
return true;
}
constructor(query: string) {
this.matches = values[query];
@ -40,11 +42,7 @@ function makeMatchMedia(values: any) {
}
function makeGetValue(values: any) {
return function getValue<T = any>(
settingName: string,
_roomId: string = null,
_excludeDefault = false,
): T {
return function getValue<T = any>(settingName: string, _roomId: string = null, _excludeDefault = false): T {
return values[settingName];
};
}
@ -61,8 +59,8 @@ function makeGetValueAt(values: any) {
};
}
describe('ThemeWatcher', function() {
it('should choose a light theme by default', () => {
describe("ThemeWatcher", function () {
it("should choose a light theme by default", () => {
// Given no system settings
global.matchMedia = makeMatchMedia({});
@ -71,12 +69,12 @@ describe('ThemeWatcher', function() {
expect(themeWatcher.getEffectiveTheme()).toBe("light");
});
it('should choose default theme if system settings are inconclusive', () => {
it("should choose default theme if system settings are inconclusive", () => {
// Given no system settings but we asked to use them
global.matchMedia = makeMatchMedia({});
SettingsStore.getValue = makeGetValue({
"use_system_theme": true,
"theme": "light",
use_system_theme: true,
theme: "light",
});
// Then getEffectiveTheme returns light
@ -84,115 +82,114 @@ describe('ThemeWatcher', function() {
expect(themeWatcher.getEffectiveTheme()).toBe("light");
});
it('should choose a dark theme if that is selected', () => {
it("should choose a dark theme if that is selected", () => {
// Given system says light high contrast but theme is set to dark
global.matchMedia = makeMatchMedia({
"(prefers-contrast: more)": true,
"(prefers-color-scheme: light)": true,
});
SettingsStore.getValueAt = makeGetValueAt({ "theme": "dark" });
SettingsStore.getValueAt = makeGetValueAt({ theme: "dark" });
// Then getEffectiveTheme returns dark
const themeWatcher = new ThemeWatcher();
expect(themeWatcher.getEffectiveTheme()).toBe("dark");
});
it('should choose a light theme if that is selected', () => {
it("should choose a light theme if that is selected", () => {
// Given system settings say dark high contrast but theme set to light
global.matchMedia = makeMatchMedia({
"(prefers-contrast: more)": true,
"(prefers-color-scheme: dark)": true,
});
SettingsStore.getValueAt = makeGetValueAt({ "theme": "light" });
SettingsStore.getValueAt = makeGetValueAt({ theme: "light" });
// Then getEffectiveTheme returns light
const themeWatcher = new ThemeWatcher();
expect(themeWatcher.getEffectiveTheme()).toBe("light");
});
it('should choose a light-high-contrast theme if that is selected', () => {
it("should choose a light-high-contrast theme if that is selected", () => {
// Given system settings say dark and theme set to light-high-contrast
global.matchMedia = makeMatchMedia({ "(prefers-color-scheme: dark)": true });
SettingsStore.getValueAt = makeGetValueAt({ "theme": "light-high-contrast" });
SettingsStore.getValueAt = makeGetValueAt({ theme: "light-high-contrast" });
// Then getEffectiveTheme returns light-high-contrast
const themeWatcher = new ThemeWatcher();
expect(themeWatcher.getEffectiveTheme()).toBe("light-high-contrast");
});
it('should choose a light theme if system prefers it (via default)', () => {
it("should choose a light theme if system prefers it (via default)", () => {
// Given system prefers lightness, even though we did not
// click "Use system theme" or choose a theme explicitly
global.matchMedia = makeMatchMedia({ "(prefers-color-scheme: light)": true });
SettingsStore.getValueAt = makeGetValueAt({});
SettingsStore.getValue = makeGetValue({ "use_system_theme": true });
SettingsStore.getValue = makeGetValue({ use_system_theme: true });
// Then getEffectiveTheme returns light
const themeWatcher = new ThemeWatcher();
expect(themeWatcher.getEffectiveTheme()).toBe("light");
});
it('should choose a dark theme if system prefers it (via default)', () => {
it("should choose a dark theme if system prefers it (via default)", () => {
// Given system prefers darkness, even though we did not
// click "Use system theme" or choose a theme explicitly
global.matchMedia = makeMatchMedia({ "(prefers-color-scheme: dark)": true });
SettingsStore.getValueAt = makeGetValueAt({});
SettingsStore.getValue = makeGetValue({ "use_system_theme": true });
SettingsStore.getValue = makeGetValue({ use_system_theme: true });
// Then getEffectiveTheme returns dark
const themeWatcher = new ThemeWatcher();
expect(themeWatcher.getEffectiveTheme()).toBe("dark");
});
it('should choose a light theme if system prefers it (explicit)', () => {
it("should choose a light theme if system prefers it (explicit)", () => {
// Given system prefers lightness
global.matchMedia = makeMatchMedia({ "(prefers-color-scheme: light)": true });
SettingsStore.getValueAt = makeGetValueAt({ "use_system_theme": true });
SettingsStore.getValue = makeGetValue({ "use_system_theme": true });
SettingsStore.getValueAt = makeGetValueAt({ use_system_theme: true });
SettingsStore.getValue = makeGetValue({ use_system_theme: true });
// Then getEffectiveTheme returns light
const themeWatcher = new ThemeWatcher();
expect(themeWatcher.getEffectiveTheme()).toBe("light");
});
it('should choose a dark theme if system prefers it (explicit)', () => {
it("should choose a dark theme if system prefers it (explicit)", () => {
// Given system prefers darkness
global.matchMedia = makeMatchMedia({ "(prefers-color-scheme: dark)": true });
SettingsStore.getValueAt = makeGetValueAt({ "use_system_theme": true });
SettingsStore.getValue = makeGetValue({ "use_system_theme": true });
SettingsStore.getValueAt = makeGetValueAt({ use_system_theme: true });
SettingsStore.getValue = makeGetValue({ use_system_theme: true });
// Then getEffectiveTheme returns dark
const themeWatcher = new ThemeWatcher();
expect(themeWatcher.getEffectiveTheme()).toBe("dark");
});
it('should choose a high-contrast theme if system prefers it', () => {
it("should choose a high-contrast theme if system prefers it", () => {
// Given system prefers high contrast and light
global.matchMedia = makeMatchMedia({
"(prefers-contrast: more)": true,
"(prefers-color-scheme: light)": true,
});
SettingsStore.getValueAt = makeGetValueAt({ "use_system_theme": true });
SettingsStore.getValue = makeGetValue({ "use_system_theme": true });
SettingsStore.getValueAt = makeGetValueAt({ use_system_theme: true });
SettingsStore.getValue = makeGetValue({ use_system_theme: true });
// Then getEffectiveTheme returns light-high-contrast
const themeWatcher = new ThemeWatcher();
expect(themeWatcher.getEffectiveTheme()).toBe("light-high-contrast");
});
it('should not choose a high-contrast theme if not available', () => {
it("should not choose a high-contrast theme if not available", () => {
// Given system prefers high contrast and dark, but we don't (yet)
// have a high-contrast dark theme
global.matchMedia = makeMatchMedia({
"(prefers-contrast: more)": true,
"(prefers-color-scheme: dark)": true,
});
SettingsStore.getValueAt = makeGetValueAt({ "use_system_theme": true });
SettingsStore.getValue = makeGetValue({ "use_system_theme": true });
SettingsStore.getValueAt = makeGetValueAt({ use_system_theme: true });
SettingsStore.getValue = makeGetValue({ use_system_theme: true });
// Then getEffectiveTheme returns dark
const themeWatcher = new ThemeWatcher();
expect(themeWatcher.getEffectiveTheme()).toBe("dark");
});
});