This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 819
Fix font not resetting when logging out #8670
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4ebc49e
Fix font not resetting when logging out
t3chguy f25c3ae
Adopt on_logged_in and on_logged_out into DispatcherAction
t3chguy ac4bb99
Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into…
t3chguy 298ad8a
Add tests
t3chguy cd874c5
Add copyright
t3chguy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* | ||
Copyright 2022 r00ster91 <[email protected]> | ||
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. | ||
|
@@ -21,34 +22,62 @@ import { SettingLevel } from '../../../src/settings/SettingLevel'; | |
import { FontWatcher } from "../../../src/settings/watchers/FontWatcher"; | ||
import { Action } from "../../../src/dispatcher/actions"; | ||
import { untilDispatch } from "../../test-utils"; | ||
import defaultDispatcher from "../../../src/dispatcher/dispatcher"; | ||
|
||
async function setSystemFont(font: string): Promise<void> { | ||
await SettingsStore.setValue("useSystemFont", null, SettingLevel.DEVICE, !!font); | ||
await SettingsStore.setValue("systemFont", null, SettingLevel.DEVICE, font); | ||
await untilDispatch(Action.UpdateSystemFont); | ||
await sleep(1); // await the FontWatcher doing its action | ||
} | ||
|
||
describe('FontWatcher', function() { | ||
let fontWatcher: FontWatcher; | ||
beforeEach(() => { | ||
fontWatcher = new FontWatcher(); | ||
fontWatcher.start(); | ||
return SettingsStore.setValue("useSystemFont", null, SettingLevel.DEVICE, true); | ||
}); | ||
afterEach(() => { | ||
fontWatcher.stop(); | ||
it("should load font on start()", async () => { | ||
const watcher = new FontWatcher(); | ||
await setSystemFont("Font Name"); | ||
expect(document.body.style.fontFamily).toBe(""); | ||
watcher.start(); | ||
expect(document.body.style.fontFamily).toBe('"Font Name"'); | ||
}); | ||
|
||
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("should load font on Action.OnLoggedIn", async () => { | ||
await setSystemFont("Font Name"); | ||
new FontWatcher().start(); | ||
document.body.style.fontFamily = ""; // clear the fontFamily which was set by start which we tested already | ||
defaultDispatcher.fire(Action.OnLoggedIn, true); | ||
expect(document.body.style.fontFamily).toBe('"Font Name"'); | ||
}); | ||
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("should reset font on Action.OnLoggedOut", async () => { | ||
await setSystemFont("Font Name"); | ||
const watcher = new FontWatcher(); | ||
watcher.start(); | ||
expect(document.body.style.fontFamily).toBe('"Font Name"'); | ||
defaultDispatcher.fire(Action.OnLoggedOut, true); | ||
expect(document.body.style.fontFamily).toBe(""); | ||
}); | ||
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"`); | ||
|
||
describe("Sets font as expected", () => { | ||
let fontWatcher: FontWatcher; | ||
beforeEach(() => { | ||
fontWatcher = new FontWatcher(); | ||
fontWatcher.start(); | ||
}); | ||
afterEach(() => { | ||
fontWatcher.stop(); | ||
}); | ||
|
||
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 () => { | ||
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 () => { | ||
await setSystemFont(` Fira Code , "Commodore 64" `); | ||
expect(document.body.style.fontFamily).toBe(`"Fira Code","Commodore 64"`); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.