Add UserProfilesStore, LruCache and cache for user permalink profiles (#10425)

This commit is contained in:
Michael Weimann 2023-03-27 10:07:43 +02:00 committed by GitHub
parent 1c039fcd38
commit aec454dd6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 925 additions and 55 deletions

View file

@ -14,16 +14,30 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { MatrixClient } from "matrix-js-sdk/src/matrix";
import { SdkContextClass } from "../../src/contexts/SDKContext";
import { UserProfilesStore } from "../../src/stores/UserProfilesStore";
import { VoiceBroadcastPreRecordingStore } from "../../src/voice-broadcast";
import { createTestClient } from "../test-utils";
jest.mock("../../src/voice-broadcast/stores/VoiceBroadcastPreRecordingStore");
describe("SdkContextClass", () => {
const sdkContext = SdkContextClass.instance;
let sdkContext = SdkContextClass.instance;
let client: MatrixClient;
beforeAll(() => {
client = createTestClient();
});
beforeEach(() => {
sdkContext = new SdkContextClass();
});
it("instance should always return the same instance", () => {
expect(SdkContextClass.instance).toBe(sdkContext);
const globalInstance = SdkContextClass.instance;
expect(SdkContextClass.instance).toBe(globalInstance);
});
it("voiceBroadcastPreRecordingStore should always return the same VoiceBroadcastPreRecordingStore", () => {
@ -31,4 +45,29 @@ describe("SdkContextClass", () => {
expect(first).toBeInstanceOf(VoiceBroadcastPreRecordingStore);
expect(sdkContext.voiceBroadcastPreRecordingStore).toBe(first);
});
it("userProfilesStore should raise an error without a client", () => {
expect(() => {
sdkContext.userProfilesStore;
}).toThrow("Unable to create UserProfilesStore without a client");
});
describe("when SDKContext has a client", () => {
beforeEach(() => {
sdkContext.client = client;
});
it("userProfilesStore should return a UserProfilesStore", () => {
const store = sdkContext.userProfilesStore;
expect(store).toBeInstanceOf(UserProfilesStore);
// it should return the same instance
expect(sdkContext.userProfilesStore).toBe(store);
});
it("onLoggedOut should clear the UserProfilesStore", () => {
const store = sdkContext.userProfilesStore;
sdkContext.onLoggedOut();
expect(sdkContext.userProfilesStore).not.toBe(store);
});
});
});