Skip to content

Commit

Permalink
chore(test): rename mockFeatureConfig and refacto
Browse files Browse the repository at this point in the history
  • Loading branch information
marc.sirisak committed Jun 5, 2024
1 parent dc2dc45 commit a1b94fc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ describe("RoomHeader", () => {
const featurethreadName: string = "feature_thread";
const homeserverName: string = "my.home.server";

const mockFeatureConfig = (homeservers: string[], feature: string) => {
const addHomeserverToMockConfig = (homeservers: string[], feature: string) => {
// mock SdkConfig.get("tchap_features")
const config: ConfigOptions = { tchap_features: {} };
config.tchap_features[feature] = homeservers;
SdkConfig.put(config);
};

const getComponent = () => render(<RoomHeader room={room} />, getWrapper());

beforeEach(async () => {
stubClient();
room = new Room(ROOM_ID, MatrixClientPeg.get()!, "@alice:example.org", {
Expand All @@ -40,8 +42,6 @@ describe("RoomHeader", () => {
} as unknown as DMRoomMap);
});

const getComponent = () => render(<RoomHeader room={room} />, getWrapper());

afterEach(() => {
SdkConfig.reset();
jest.restoreAllMocks();
Expand All @@ -53,15 +53,15 @@ describe("RoomHeader", () => {
});

it("display well the thread button when feature is activated", async () => {
mockFeatureConfig([homeserverName], featurethreadName);
addHomeserverToMockConfig([homeserverName], featurethreadName);

getComponent();

expect(screen.queryByTestId("room-header-thread-button")).toBeInTheDocument;
});

it("hides the thread button when feature is deactivated", async () => {
mockFeatureConfig(["other.homeserver"], featurethreadName);
addHomeserverToMockConfig(["other.homeserver"], featurethreadName);

getComponent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ describe("<Notifications />", () => {

const testEmail = "[email protected]";

const mockFeatureConfig = (homeservers: string[], featureList: string[] = []) => {
const addHomeserverToMockConfig = (homeservers: string[], featureList: string[] = []) => {
// mock SdkConfig.get("tchap_features")
const config: ConfigOptions = { tchap_features: {} };
featureList.forEach((feature) => (config.tchap_features[feature] = homeservers));
Expand Down Expand Up @@ -238,7 +238,7 @@ describe("<Notifications />", () => {

it("display well the caption when email notification feature is activated", async () => {
// activate email notification in the config, otherwise the section won't appear
mockFeatureConfig([homeserverName], [featureEmailName]);
addHomeserverToMockConfig([homeserverName], [featureEmailName]);

await getComponentAndWait();

Expand All @@ -254,7 +254,7 @@ describe("<Notifications />", () => {
});

it("hides well the caption when email notification feature is deactivated for this homeserver", async () => {
mockFeatureConfig([homeserverName]);
addHomeserverToMockConfig([homeserverName]);

await getComponentAndWait();

Expand All @@ -266,7 +266,7 @@ describe("<Notifications />", () => {
});

it("hides well the caption when email notification feature is not activated for this homeserver", async () => {
mockFeatureConfig(["other.server.fr"], [featureEmailName]);
addHomeserverToMockConfig(["other.server.fr"], [featureEmailName]);

await getComponentAndWait();

Expand All @@ -278,7 +278,7 @@ describe("<Notifications />", () => {
});

it("display well the tac notification switch when feature is activated", async () => {
mockFeatureConfig([homeserverName], [featurethreadName]);
addHomeserverToMockConfig([homeserverName], [featurethreadName]);

await getComponentAndWait();

Expand All @@ -288,7 +288,7 @@ describe("<Notifications />", () => {
});

it("display hides the tac notification switch when feature is deactivated", async () => {
mockFeatureConfig([homeserverName]);
addHomeserverToMockConfig([homeserverName]);

await getComponentAndWait();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("<SpacePanel />", () => {
const featureName: string = "feature_thread";
const homeserverName: string = "my.home.server";

const mockFeatureConfig = (homeservers: string[]) => {
const addHomeserverToMockConfig = (homeservers: string[]) => {
// mock SdkConfig.get("tchap_features")
const config: ConfigOptions = { tchap_features: {} };
config.tchap_features[featureName] = homeservers;
Expand All @@ -32,14 +32,14 @@ describe("<SpacePanel />", () => {
});

it("returns true when the the homeserver include thread feature", () => {
mockFeatureConfig([homeserverName]);
addHomeserverToMockConfig([homeserverName]);
const { container } = renderSpacePanel();

expect(container.getElementsByClassName("mx_ThreadsActivityCentre_container").length).toBe(1);
});

it("returns false when the the homeserver doesnt include thread feature", async () => {
mockFeatureConfig(["other.homeserver"]);
addHomeserverToMockConfig(["other.homeserver"]);
const { container } = renderSpacePanel();

expect(container.getElementsByClassName("mx_ThreadsActivityCentre_container").length).toBe(0);
Expand Down

0 comments on commit a1b94fc

Please sign in to comment.