Skip to content

Commit

Permalink
Merge pull request #1100 from tchapgouv/bump-4.7.0
Browse files Browse the repository at this point in the history
bump 4.7.0
  • Loading branch information
MarcWadai authored Sep 5, 2024
2 parents 374d6be + 935a6fe commit db5fe7e
Show file tree
Hide file tree
Showing 8 changed files with 900 additions and 1,194 deletions.
2 changes: 1 addition & 1 deletion config.preprod.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"feature_video_rooms": false,
"feature_notification_settings2": false,
"feature_new_room_decoration_ui": true,
"feature_rust_crypto": false
"feature_rust_crypto": true
},
"feedback": {
"existing_issues_url": "https://github.com/tchapgouv/tchap-web-v4/issues?q=is%3Aopen+is%3Aissue+sort%3Areactions-%2B1-desc",
Expand Down
2 changes: 1 addition & 1 deletion config.prod.lab.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"feature_video_rooms": false,
"feature_notification_settings2": false,
"feature_new_room_decoration_ui": true,
"feature_rust_crypto": false
"feature_rust_crypto": true
},
"feedback": {
"existing_issues_url": "https://github.com/tchapgouv/tchap-web-v4/issues?q=is%3Aopen+is%3Aissue+sort%3Areactions-%2B1-desc",
Expand Down
1 change: 0 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import type { Config } from "jest";
}
*/
const config: Config = {
snapshotSerializers: ["enzyme-to-json/serializer"],
testEnvironment: "jsdom",
testEnvironmentOptions: {
url: "http://localhost/",
Expand Down
4 changes: 4 additions & 0 deletions modules/tchap-translations/tchap_translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -793,5 +793,9 @@
"onboarding|check_user_guide_action": {
"en": "Read the article",
"fr": "Lire l'article"
},
"migrating_crypto": {
"en": "Hang tight. We are updating %(brand)s to make encryption faster and more reliable. Don't worry, it can take some time",
"fr": "Accrochez-vous. Nous mettons à jour %(brand)s pour que le chiffrement soit plus rapide et plus fiable. N'ayez crainte, cela peut prendre jusqu'à 10 minutes"
}
}
10 changes: 2 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "element-web",
"productName": "Tchap",
"version": "4.6.1",
"version": "4.7.0",
"version-element-web": "1.11.72",
"description": "A feature-rich client for Matrix.org",
"author": "DINUM",
Expand Down Expand Up @@ -85,9 +85,9 @@
"@types/react": "17.0.80"
},
"dependencies": {
"@formatjs/intl-segmenter": "^11.5.7",
"@gouvfr-lasuite/integration": "^1.0.1",
"@matrix-org/olm": "3.2.15",
"@formatjs/intl-segmenter": "^11.5.7",
"@matrix-org/react-sdk-module-api": "^2.3.0",
"jsrsasign": "^11.0.0",
"katex": "^0.16.0",
Expand All @@ -101,9 +101,6 @@
},
"devDependencies-comments": {
"tchap-added": {
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.7",
"enzyme": "^3.11.0",
"enzyme-to-json": "^3.6.2",
"cypress packages": "since we run cypress from tchap-web repo, not from react-sdk. We cypress-related deps from matric-react-sdk.",
"@testing-library/jest-dom": "^6.4.2",
"@types/testing-library__jest-dom": "^6.0.0"
Expand Down Expand Up @@ -170,7 +167,6 @@
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.7",
"allchange": "^1.0.6",
"autoprefixer": "^10.4.8",
"axe-core": "^4.4.3",
Expand All @@ -188,8 +184,6 @@
"cypress-axe": "^1.0.0",
"cypress-real-events": "^1.7.1",
"dotenv": "^16.0.2",
"enzyme": "^3.11.0",
"enzyme-to-json": "^3.6.2",
"eslint": "8.57.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^9.0.0",
Expand Down
5 changes: 0 additions & 5 deletions test/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
//is duplicated from matrix-react-sdk/test/setupTests.js in order to work
import Adapter from "@wojtekmaj/enzyme-adapter-react-17";
import "@testing-library/jest-dom";
// eslint-disable-next-line deprecate/import
import { configure } from "enzyme";
configure({ adapter: new Adapter() });
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from "react";
// eslint-disable-next-line deprecate/import
import { mount, ReactWrapper } from "enzyme";
// eslint-disable-next-line deprecate/import
import { act } from "react-dom/test-utils";
import { RenderResult, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { MatrixClientPeg } from "matrix-react-sdk/src/MatrixClientPeg";
import { EventEmitter } from "events";

import { TchapRoomType } from "../../../../../../src/tchap/@types/tchap";
import TchapUtils from "../../../../../../src/tchap/util/TchapUtils";
import TchapCreateRoomDialog from "../../../../../../src/tchap/components/views/dialogs/TchapCreateRoomDialog";

import { flushPromises } from "~matrix-react-sdk/test/test-utils";

//mocking module with jest.mock should be done outside the test. Before any import of the mocked module.
//I could not make a mock of TchapCreateRoomDialog, the real implementation was taken each time. Then I used jest spyOn

Expand Down Expand Up @@ -41,24 +41,39 @@ describe("TchapCreateRoomDialog", () => {
};

//simulate the submit of the form
const submitForm = async (wrapper: ReactWrapper) => {
act(() => {
wrapper.find("form").simulate("submit", { preventDefault: () => {} });
});
await new Promise(process.nextTick);
const submitForm = async (component: RenderResult) => {
// Note : component.getByX is preferable, and fails nicely if not found.
// But querySelector is good enough and doesn't need to change the prod code.
const createButton = component.getByTestId("dialog-primary-button");

await userEvent.click(createButton);

await flushPromises(); // needed to run through all the chained promises in BugReportDialog.onSubmit
};

// build a new component using enzyme
const getComponent = (props = {}): ReactWrapper => mount(<TchapCreateRoomDialog {...defaultProps} {...props} />);
// simulate click on room type radio button
const selectRoomType = async (roomType: TchapRoomType) => {
const privateCheckbox = screen.getByDisplayValue(roomType);

/*
// Note : you can also build a shallow component https://fr.reactjs.org/docs/shallow-renderer.html
// can be used for simple component
// not used in this test
const getShallowComponent = (props={}) => {
shallow(<TchapCreateRoomDialog {...defaultProps} {...props} />);
}
*/
await userEvent.click(privateCheckbox);
};

// simuate switch federation click
const switchFederacationClick = async () => {
const switchFederation = screen.getByRole("switch");

await userEvent.click(switchFederation);
};

// simulate field typing
const typeRoomName = async (text: string) => {
const nameField = screen.getByRole("textbox");

await userEvent.type(nameField, text);
};

// build a new component
const getComponent = (props: Record<string, any>) => render(<TchapCreateRoomDialog {...defaultProps} {...props} />);

beforeEach(() => {
jest.resetAllMocks();
Expand All @@ -81,77 +96,78 @@ describe("TchapCreateRoomDialog", () => {
showForumFederationSwitch: true,
forumFederationSwitchDefaultValue: false,
});
const component = getComponent();
const forumFederationSwitch = component.find(".tc_TchapRoomTypeSelector_forum div.mx_ToggleSwitch");
expect(forumFederationSwitch.exists()).toEqual(true);

getComponent({});

const federatedSwitch = screen.getByRole("switch");
expect(federatedSwitch).toBeTruthy();
});

it("should be absent", () => {
jest.spyOn(TchapUtils, "getRoomFederationOptions").mockReturnValue({
showForumFederationSwitch: false,
forumFederationSwitchDefaultValue: false,
});
const component = getComponent();
const forumFederationSwitch = component.find(".tc_TchapRoomTypeSelector_forum div.mx_ToggleSwitch");
expect(forumFederationSwitch.exists()).toEqual(false);
getComponent({});

const federatedSwitch = screen.queryByRole("switch");

expect(federatedSwitch).toBeNull();
});

it("should be true by default", () => {
it("should be true by default", async () => {
jest.spyOn(TchapUtils, "getRoomFederationOptions").mockReturnValue({
showForumFederationSwitch: true,
forumFederationSwitchDefaultValue: true,
});
const component = getComponent();
const forumFederationSwitch = component.find(".tc_TchapRoomTypeSelector_forum div.mx_ToggleSwitch");
expect(forumFederationSwitch.prop("aria-checked")).toBeTruthy();

await getComponent({});

const federatedSwitch = screen.getByRole("switch");
expect(federatedSwitch?.getAttribute("aria-checked")).toEqual("true");
});

it("should be false by default", () => {
jest.spyOn(TchapUtils, "getRoomFederationOptions").mockReturnValue({
showForumFederationSwitch: true,
forumFederationSwitchDefaultValue: false,
});
const component = getComponent();
const forumFederationSwitch = component.find(".tc_TchapRoomTypeSelector_forum div.mx_ToggleSwitch");
expect(forumFederationSwitch.prop("aria-checked")).toBeFalsy();
getComponent({});
const federatedSwitch = screen.getByRole("switch");
expect(federatedSwitch?.getAttribute("aria-checked")).toEqual("false");
});
});

it("Should not create any room wihout a name", async () => {
const onFinished = jest.fn();
const wrapper = getComponent({ onFinished });
// set state in component
act(() => {
wrapper.setState({
name: "",
tchapRoomType: TchapRoomType.Private,
});
});

await selectRoomType(TchapRoomType.Private);

await submitForm(wrapper);

expect(onFinished).toBeCalledTimes(0);
expect(onFinished).toHaveBeenCalledTimes(0);
});

it("Should create a room with default value", async () => {
const onFinished = jest.fn();
const defaultName = "defaultName";
const wrapper = getComponent({ onFinished, defaultName });
// set state in component
act(() => {
wrapper.setState({
tchapRoomType: TchapRoomType.Private,
});
});
const wrapper = getComponent({ onFinished });

await typeRoomName(defaultName);

await selectRoomType(TchapRoomType.Private);

await submitForm(wrapper);

expect(onFinished).toBeCalledTimes(1);
expect(onFinished).toHaveBeenCalledTimes(1);
});

it("Should create a private room", async () => {
const onFinished = jest.fn();

const wrapper = getComponent({ onFinished });

const privateRoomExpectedOpts = {
createOpts: {
name: roomName,
Expand All @@ -176,16 +192,9 @@ describe("TchapCreateRoomDialog", () => {
historyVisibility: "invited",
};

const wrapper = getComponent({ onFinished });
await typeRoomName(roomName);

// set state in component
act(() => {
wrapper.setState({
name: roomName,
tchapRoomType: TchapRoomType.Private,
showFederateSwitch: false,
});
});
await selectRoomType(TchapRoomType.Private);

await submitForm(wrapper);

Expand Down Expand Up @@ -220,15 +229,9 @@ describe("TchapCreateRoomDialog", () => {
};
const wrapper = getComponent({ onFinished });

// set state in component
act(() => {
wrapper.setState({
name: roomName,
tchapRoomType: TchapRoomType.Forum,
forumFederationSwitchValue: false,
showFederateSwitch: true,
});
});
await typeRoomName(roomName);

await selectRoomType(TchapRoomType.Forum);

await submitForm(wrapper);

Expand All @@ -238,6 +241,11 @@ describe("TchapCreateRoomDialog", () => {
it("Should create a public room with federation and switch", async () => {
const onFinished = jest.fn();

jest.spyOn(TchapUtils, "getRoomFederationOptions").mockReturnValue({
showForumFederationSwitch: true,
forumFederationSwitchDefaultValue: false,
});

const publicRoomWithFederationExpectedOpts = {
createOpts: {
name: roomName,
Expand All @@ -263,15 +271,11 @@ describe("TchapCreateRoomDialog", () => {
};
const wrapper = getComponent({ onFinished });

// set state in component
act(() => {
wrapper.setState({
name: roomName,
tchapRoomType: TchapRoomType.Forum,
forumFederationSwitchValue: true,
showFederateSwitch: true,
});
});
await typeRoomName(roomName);

await selectRoomType(TchapRoomType.Forum);

await switchFederacationClick();

await submitForm(wrapper);

Expand All @@ -281,6 +285,11 @@ describe("TchapCreateRoomDialog", () => {
it("Should create a public room with federation but no switch", async () => {
const onFinished = jest.fn();

jest.spyOn(TchapUtils, "getRoomFederationOptions").mockReturnValue({
showForumFederationSwitch: false,
forumFederationSwitchDefaultValue: false,
});

const publicRoomWithFederationExpectedOpts = {
createOpts: {
name: roomName,
Expand All @@ -306,14 +315,9 @@ describe("TchapCreateRoomDialog", () => {
};
const wrapper = getComponent({ onFinished });

// set state in component
act(() => {
wrapper.setState({
name: roomName,
tchapRoomType: TchapRoomType.Forum,
showFederateSwitch: false,
});
});
await typeRoomName(roomName);

await selectRoomType(TchapRoomType.Forum);

await submitForm(wrapper);

Expand Down Expand Up @@ -348,14 +352,9 @@ describe("TchapCreateRoomDialog", () => {
};
const wrapper = getComponent({ onFinished });

// set state in component
act(() => {
wrapper.setState({
name: roomName,
tchapRoomType: TchapRoomType.External,
showFederateSwitch: false,
});
});
await typeRoomName(roomName);

await selectRoomType(TchapRoomType.External);

await submitForm(wrapper);

Expand Down
Loading

0 comments on commit db5fe7e

Please sign in to comment.