Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linter #293

Merged
merged 7 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
"module_system/**/*.{ts,tsx}",
// :TCHAP: Lint our cypress files, copied from react-sdk. React-sdk lints them too, so we keep up !
"cypress/**/*.ts",
"test/**/*.{ts,tsx,js}",
],
extends: [
"plugin:matrix-org/typescript",
Expand Down
7 changes: 6 additions & 1 deletion res/themes/tchap-light/css/_tchap_custom_vars.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ body {
--username-colors_5: #000091;
--username-colors_6: #000091;
--username-colors_7: #000091;
--avatar-background-colors_0:#8F96A4; /* if using getComputedStyle(document.body).getPropertyValue it's better to leave no space */

/* if using getComputedStyle(document.body).getPropertyValue it's better to leave no space */
/* stylelint-disable-next-line declaration-colon-space-after */
--avatar-background-colors_0:#8F96A4;
/* stylelint-disable-next-line declaration-colon-space-after */
--avatar-background-colors_1:#8F96A4;
/* stylelint-disable-next-line declaration-colon-space-after */
--avatar-background-colors_2:#8F96A4;
}
2 changes: 1 addition & 1 deletion src/util/TchapRoomUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class TchapRoomUtils {
return this.getTchapRoomTypeInternal(isEncrypted, tchapRoomAccessRule);
}

private static getTchapRoomTypeInternal(
static getTchapRoomTypeInternal(
isEncrypted: boolean, tchapRoomAccessRule: TchapRoomAccessRule): TchapRoomType {
if (!isEncrypted) {
return TchapRoomType.Forum;
Expand Down
2 changes: 1 addition & 1 deletion test/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module.exports = {
env: {
mocha: true,
},
}
};
3 changes: 2 additions & 1 deletion test/setupTests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

//is duplicated from matrix-react-sdk/test/setupTests.js in order to work
import Adapter from "@wojtekmaj/enzyme-adapter-react-17";
// eslint-disable-next-line deprecate/import
import { configure } from "enzyme";
configure({ adapter: new Adapter() });
configure({ adapter: new Adapter() });
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@

import React from 'react';
import { mount, ReactWrapper,shallow } from 'enzyme';
// eslint-disable-next-line @typescript-eslint/no-unused-vars deprecate/import
import { mount, ReactWrapper } from 'enzyme';
import { act } from 'react-dom/test-utils';
import toJson from 'enzyme-to-json'

//jest.mock('matrix-react-sdk/src/languageHandler')

import { TchapRoomType } from '../../../../../src/@types/tchap';
import toJson from 'enzyme-to-json';
import { MatrixClientPeg } from 'matrix-react-sdk/src/MatrixClientPeg';
import { EventEmitter } from "events";
import { _t } from 'matrix-react-sdk/src/languageHandler';

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

//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 All @@ -25,8 +23,6 @@ import TchapUtils from '../../../../../src/util/TchapUtils';
});
*/

import TchapCreateRoomDialog from "../../../../../src/components/views/dialogs/TchapCreateRoomDialog";

/*
* This unit test targets the TchapCreateRoomDialog react component. It is mounted virtually to be tested thanks to enzyme framework.
* With the act function, a state is set inside the component, meanwhile the submitForm function submits the form in order to make action on the internal state of the component.
Expand All @@ -42,20 +38,20 @@ describe("TchapCreateRoomDialog", () => {
defaultName: undefined, // unused for Tchap version
parentSpace: undefined, // unused for Tchap version
defaultEncrypted: undefined, // unused for Tchap version
onFinished: jest.fn()
onFinished: jest.fn(),
};

//simulate the submit of the form
const submitForm = async (wrapper: ReactWrapper) =>{
const submitForm = async (wrapper: ReactWrapper) => {
act(() => {
wrapper.find('form').simulate('submit', { preventDefault: () => { } });
})
});
await new Promise(process.nextTick);
}
};

// build a new component using enzyme
const getComponent = (props = {}): ReactWrapper =>
mount(<TchapCreateRoomDialog {...defaultProps} {...props} />);
mount(<TchapCreateRoomDialog {...defaultProps} {...props} />);

/*
// Note : you can also build a shallow component https://fr.reactjs.org/docs/shallow-renderer.html
Expand All @@ -75,7 +71,8 @@ describe("TchapCreateRoomDialog", () => {

//mock tchap utils
jest.spyOn(TchapUtils, 'getShortDomain').mockReturnValue("AGENT");
jest.spyOn(TchapUtils, 'getRoomFederationOptions').mockReturnValue({ showRoomFederationOption: true, roomFederationDefault: false });
jest.spyOn(TchapUtils, 'getRoomFederationOptions').mockReturnValue(
{ showRoomFederationOption: true, roomFederationDefault: false });
});

it('should render the whole component', () => {
Expand All @@ -85,50 +82,53 @@ describe("TchapCreateRoomDialog", () => {
});

it('should render the whole component with with the allow access switch', () => {
jest.spyOn(TchapUtils, 'getRoomFederationOptions').mockReturnValue({ showRoomFederationOption: true, roomFederationDefault: false });
jest.spyOn(TchapUtils, 'getRoomFederationOptions').mockReturnValue(
{ showRoomFederationOption: true, roomFederationDefault: false });
const component = getComponent();
const allowAccessSwitch = component.find(".mx_SettingsFlag");
expect(toJson(allowAccessSwitch)).toMatchSnapshot("allow access switch is present, allows other domain than AGENT");
expect(toJson(allowAccessSwitch)).toMatchSnapshot(
"allow access switch is present, allows other domain than AGENT");
});

it('should render the room dialog without the allow access switch', () => {
jest.spyOn(TchapUtils, 'getRoomFederationOptions').mockReturnValue({ showRoomFederationOption: false, roomFederationDefault: false });
jest.spyOn(TchapUtils, 'getRoomFederationOptions').mockReturnValue(
{ showRoomFederationOption: false, roomFederationDefault: false });
const component = getComponent();
const allowAccessSwitch = component.find(".mx_SettingsFlag");
expect(allowAccessSwitch).toEqual({});
});

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

await submitForm(wrapper);

expect(onFinished).toBeCalledTimes(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
const wrapper = getComponent({ onFinished, defaultName });
// set state in component
act(() => {
wrapper.setState({
tchapRoomType: TchapRoomType.Private
tchapRoomType: TchapRoomType.Private,
});
});

await submitForm(wrapper);

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

it("Should create a private room", async () => {
const onFinished = jest.fn();
Expand All @@ -139,10 +139,10 @@ describe("TchapCreateRoomDialog", () => {
creation_content: {
"m.federate": true,
},
"initial_state": [
initial_state: [
{
"content": {
"rule": "restricted",
"rule": "restricted",
},
"state_key": "",
"type": "im.vector.room.access_rules",
Expand All @@ -157,22 +157,21 @@ describe("TchapCreateRoomDialog", () => {
historyVisibility: "invited",
};

const wrapper = getComponent({ onFinished});
const wrapper = getComponent({ onFinished });

// set state in component
act(() => {
wrapper.setState({
name: roomName,
tchapRoomType: TchapRoomType.Private,
isFederated:true
isFederated: true,
});
});

await submitForm(wrapper);

expect(onFinished).toHaveBeenCalledWith(true, privateRoomExpectedOpts);
})

});

it("Should create a public room without federation", async () => {
const onFinished = jest.fn();
Expand All @@ -183,10 +182,10 @@ describe("TchapCreateRoomDialog", () => {
creation_content: {
"m.federate": false,
},
"initial_state": [
initial_state: [
{
"content": {
"rule": "restricted",
"rule": "restricted",
},
"state_key": "",
"type": "im.vector.room.access_rules",
Expand All @@ -200,21 +199,21 @@ describe("TchapCreateRoomDialog", () => {
encryption: false,
historyVisibility: "shared",
};
const wrapper = getComponent({ onFinished});
const wrapper = getComponent({ onFinished });

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

await submitForm(wrapper);

expect(onFinished).toHaveBeenCalledWith(true, publicRoomWithoutFederationExpectedOpts);
})
});

it("Should create a public room with federation", async () => {
const onFinished = jest.fn();
Expand All @@ -225,10 +224,10 @@ describe("TchapCreateRoomDialog", () => {
creation_content: {
"m.federate": true,
},
"initial_state": [
initial_state: [
{
"content": {
"rule": "restricted",
"rule": "restricted",
},
"state_key": "",
"type": "im.vector.room.access_rules",
Expand All @@ -242,21 +241,21 @@ describe("TchapCreateRoomDialog", () => {
encryption: false,
historyVisibility: "shared",
};
const wrapper = getComponent({ onFinished});
const wrapper = getComponent({ onFinished });

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

await submitForm(wrapper);

expect(onFinished).toHaveBeenCalledWith(true, publicRoomWithFederationExpectedOpts);
})
});

it("Should create an external room", async () => {
const onFinished = jest.fn();
Expand All @@ -267,10 +266,10 @@ describe("TchapCreateRoomDialog", () => {
creation_content: {
"m.federate": true,
},
"initial_state": [
initial_state: [
{
"content": {
"rule": "unrestricted",
"rule": "unrestricted",
},
"state_key": "",
"type": "im.vector.room.access_rules",
Expand All @@ -284,23 +283,22 @@ describe("TchapCreateRoomDialog", () => {
encryption: true,
historyVisibility: "invited",
};
const wrapper = getComponent({ onFinished});
const wrapper = getComponent({ onFinished });

// set state in component
act(() => {
wrapper.setState({
name: roomName,
tchapRoomType: TchapRoomType.External,
isFederated:true
isFederated: true,
});
});

await submitForm(wrapper);

expect(onFinished).toHaveBeenCalledWith(true, externalRoomExpectedOpts);
})
})

});
});

class MockClient extends EventEmitter {
// getUserId = jest.fn();
Expand All @@ -321,5 +319,3 @@ class MockClient extends EventEmitter {
// getClientWellKnown = jest.fn();
getDomain = jest.fn();
}


Loading