Clear settings store cache on logout (#12786)
And clear it in the widget layout store test, also fixing the tests which didn't actually individually as they actually relied on the state bleeding between tests.
This commit is contained in:
parent
cf96a6d82c
commit
c57d8463b9
5 changed files with 31 additions and 13 deletions
|
@ -1056,6 +1056,7 @@ export async function onLoggedOut(): Promise<void> {
|
||||||
await clearStorage({ deleteEverything: true });
|
await clearStorage({ deleteEverything: true });
|
||||||
LifecycleCustomisations.onLoggedOutAndStorageCleared?.();
|
LifecycleCustomisations.onLoggedOutAndStorageCleared?.();
|
||||||
await PlatformPeg.get()?.clearStorage();
|
await PlatformPeg.get()?.clearStorage();
|
||||||
|
SettingsStore.reset();
|
||||||
|
|
||||||
// Do this last, so we can make sure all storage has been cleared and all
|
// Do this last, so we can make sure all storage has been cleared and all
|
||||||
// customisations got the memo.
|
// customisations got the memo.
|
||||||
|
|
|
@ -134,6 +134,12 @@ export default class SettingsStore {
|
||||||
// Counter used for generation of watcher IDs
|
// Counter used for generation of watcher IDs
|
||||||
private static watcherCount = 1;
|
private static watcherCount = 1;
|
||||||
|
|
||||||
|
public static reset(): void {
|
||||||
|
for (const handler of Object.values(LEVEL_HANDLERS)) {
|
||||||
|
handler.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all the feature-style setting names.
|
* Gets all the feature-style setting names.
|
||||||
* @returns {string[]} The names of the feature settings.
|
* @returns {string[]} The names of the feature settings.
|
||||||
|
|
|
@ -83,4 +83,9 @@ export default class LocalEchoWrapper extends SettingsHandler {
|
||||||
public isSupported(): boolean {
|
public isSupported(): boolean {
|
||||||
return this.handler.isSupported();
|
return this.handler.isSupported();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public reset(): void {
|
||||||
|
this.cache = {};
|
||||||
|
this.handler.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,4 +61,9 @@ export default abstract class SettingsHandler {
|
||||||
* @returns {boolean} True if this level is supported on the current device.
|
* @returns {boolean} True if this level is supported on the current device.
|
||||||
*/
|
*/
|
||||||
public abstract isSupported(): boolean;
|
public abstract isSupported(): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the handler, clearing any caches or other stored data. Called on user logout.
|
||||||
|
*/
|
||||||
|
public reset(): void {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,8 @@ describe("WidgetLayoutStore", () => {
|
||||||
off: jest.fn(),
|
off: jest.fn(),
|
||||||
getApps: () => mockApps,
|
getApps: () => mockApps,
|
||||||
} as unknown as WidgetStore);
|
} as unknown as WidgetStore);
|
||||||
|
|
||||||
|
SettingsStore.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
|
@ -156,9 +158,14 @@ describe("WidgetLayoutStore", () => {
|
||||||
await store.start();
|
await store.start();
|
||||||
|
|
||||||
expect(roomUpdateListener).toHaveBeenCalled();
|
expect(roomUpdateListener).toHaveBeenCalled();
|
||||||
expect(store.getContainerWidgets(mockRoom, Container.Top)).toEqual([mockApps[0]]);
|
expect(store.getContainerWidgets(mockRoom, Container.Top)).toEqual([]);
|
||||||
expect(store.getContainerWidgets(mockRoom, Container.Center)).toEqual([]);
|
expect(store.getContainerWidgets(mockRoom, Container.Center)).toEqual([]);
|
||||||
expect(store.getContainerWidgets(mockRoom, Container.Right)).toEqual([mockApps[1], mockApps[2], mockApps[3]]);
|
expect(store.getContainerWidgets(mockRoom, Container.Right)).toEqual([
|
||||||
|
mockApps[0],
|
||||||
|
mockApps[1],
|
||||||
|
mockApps[2],
|
||||||
|
mockApps[3],
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should clear the layout and emit an update if there are no longer apps in the room", () => {
|
it("should clear the layout and emit an update if there are no longer apps in the room", () => {
|
||||||
|
@ -238,21 +245,15 @@ describe("WidgetLayoutStore", () => {
|
||||||
"widgets": {
|
"widgets": {
|
||||||
"1": {
|
"1": {
|
||||||
"container": "top",
|
"container": "top",
|
||||||
"height": 23,
|
"height": undefined,
|
||||||
"index": 2,
|
"index": 0,
|
||||||
"width": 64,
|
"width": 100,
|
||||||
},
|
},
|
||||||
"2": {
|
"2": {
|
||||||
"container": "top",
|
"container": "right",
|
||||||
"height": 23,
|
|
||||||
"index": 0,
|
|
||||||
"width": 10,
|
|
||||||
},
|
},
|
||||||
"3": {
|
"3": {
|
||||||
"container": "top",
|
"container": "right",
|
||||||
"height": 23,
|
|
||||||
"index": 1,
|
|
||||||
"width": 26,
|
|
||||||
},
|
},
|
||||||
"4": {
|
"4": {
|
||||||
"container": "right",
|
"container": "right",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue