Step 3.1: Stop using getComponent in tests

This commit is contained in:
Travis Ralston 2022-03-02 14:09:24 -07:00
parent 15b84bd9a6
commit 26dc2ba45e
23 changed files with 27 additions and 63 deletions

View file

@ -24,7 +24,6 @@ import { mount } from "enzyme";
import * as TestUtils from "react-dom/test-utils";
import { MatrixClientPeg } from '../../../src/MatrixClientPeg';
import sdk from '../../skinned-sdk';
import MessagePanel, { shouldFormContinuation } from "../../../src/components/structures/MessagePanel";
import SettingsStore from "../../../src/settings/SettingsStore";
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
@ -32,6 +31,9 @@ import RoomContext from "../../../src/contexts/RoomContext";
import DMRoomMap from "../../../src/utils/DMRoomMap";
import { UnwrappedEventTile } from "../../../src/components/views/rooms/EventTile";
import * as TestUtilsMatrix from "../../test-utils";
import EventListSummary from "../../../src/components/views/elements/EventListSummary";
import GenericEventListSummary from "../../../src/components/views/elements/GenericEventListSummary";
import DateSeparator from "../../../src/components/views/messages/DateSeparator";
let client;
const room = new Matrix.Room("!roomId:server_name");
@ -298,7 +300,7 @@ describe('MessagePanel', function() {
expect(tiles.length).toEqual(2);
const summaryTiles = TestUtils.scryRenderedComponentsWithType(
res, sdk.getComponent('elements.EventListSummary'),
res, EventListSummary,
);
expect(summaryTiles.length).toEqual(1);
});
@ -443,7 +445,7 @@ describe('MessagePanel', function() {
expect(tiles.at(0).props().mxEvent.getType()).toEqual("m.room.create");
expect(tiles.at(1).props().mxEvent.getType()).toEqual("m.room.encryption");
const summaryTiles = res.find(sdk.getComponent('views.elements.GenericEventListSummary'));
const summaryTiles = res.find(GenericEventListSummary);
const summaryTile = summaryTiles.at(0);
const summaryEventTiles = summaryTile.find(UnwrappedEventTile);
@ -483,7 +485,7 @@ describe('MessagePanel', function() {
events={events}
/>,
);
const Dates = res.find(sdk.getComponent('messages.DateSeparator'));
const Dates = res.find(DateSeparator);
expect(Dates.length).toEqual(1);
});

View file

@ -20,9 +20,10 @@ import ReactTestUtils from 'react-dom/test-utils';
import { mocked } from 'jest-mock';
import { createClient, MatrixClient } from "matrix-js-sdk/src/matrix";
import sdk from '../../../skinned-sdk';
import SdkConfig from '../../../../src/SdkConfig';
import { mkServerConfig } from "../../../test-utils";
import Login from "../../../../src/components/structures/auth/Login";
import PasswordLogin from "../../../../src/components/views/auth/PasswordLogin";
jest.mock("matrix-js-sdk/src/matrix");
@ -30,10 +31,6 @@ const flushPromises = async () => await new Promise(process.nextTick);
jest.useRealTimers();
const Login = sdk.getComponent(
'structures.auth.Login',
);
describe('Login', function() {
let parentDiv;
const mockClient = mocked({
@ -80,7 +77,7 @@ describe('Login', function() {
const form = ReactTestUtils.findRenderedComponentWithType(
root,
sdk.getComponent('auth.PasswordLogin'),
PasswordLogin,
);
expect(form).toBeTruthy();
@ -94,7 +91,7 @@ describe('Login', function() {
const form = ReactTestUtils.findRenderedComponentWithType(
root,
sdk.getComponent('auth.PasswordLogin'),
PasswordLogin,
);
expect(form).toBeTruthy();
@ -118,7 +115,7 @@ describe('Login', function() {
const root = render();
await flushPromises();
const form = ReactTestUtils.findRenderedComponentWithType(root, sdk.getComponent('auth.PasswordLogin'));
const form = ReactTestUtils.findRenderedComponentWithType(root, PasswordLogin);
expect(form).toBeTruthy();
const ssoButton = ReactTestUtils.findRenderedDOMComponentWithClass(root, "mx_SSOButton");

View file

@ -19,17 +19,14 @@ import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import { createClient } from 'matrix-js-sdk/src/matrix';
import sdk from '../../../skinned-sdk';
import SdkConfig, { DEFAULTS } from '../../../../src/SdkConfig';
import { createTestClient, mkServerConfig } from "../../../test-utils";
import Registration from "../../../../src/components/structures/auth/Registration";
import RegistrationForm from "../../../../src/components/views/auth/RegistrationForm";
jest.mock('matrix-js-sdk/src/matrix');
jest.useFakeTimers();
const Registration = sdk.getComponent(
'structures.auth.Registration',
);
describe('Registration', function() {
let parentDiv;
@ -79,7 +76,7 @@ describe('Registration', function() {
const form = ReactTestUtils.findRenderedComponentWithType(
root,
sdk.getComponent('auth.RegistrationForm'),
RegistrationForm,
);
expect(form).toBeTruthy();
});

View file

@ -18,7 +18,6 @@ import React from 'react';
import { mocked } from 'jest-mock';
import { mount } from 'enzyme';
import '../../../skinned-sdk';
import LeftPanelLiveShareWarning from '../../../../src/components/views/beacon/LeftPanelLiveShareWarning';
import { OwnBeaconStore, OwnBeaconStoreEvent } from '../../../../src/stores/OwnBeaconStore';
import { flushPromises } from '../../../test-utils';

View file

@ -20,7 +20,6 @@ import { mount } from 'enzyme';
import { Room, Beacon, BeaconEvent } from 'matrix-js-sdk/src/matrix';
import { logger } from 'matrix-js-sdk/src/logger';
import '../../../skinned-sdk';
import RoomLiveShareWarning from '../../../../src/components/views/beacon/RoomLiveShareWarning';
import { OwnBeaconStore, OwnBeaconStoreEvent } from '../../../../src/stores/OwnBeaconStore';
import {

View file

@ -17,7 +17,6 @@ limitations under the License.
import React from 'react';
import { mount } from 'enzyme';
import '../../../skinned-sdk';
import StyledLiveBeaconIcon from '../../../../src/components/views/beacon/StyledLiveBeaconIcon';
describe('<StyledLiveBeaconIcon />', () => {

View file

@ -18,12 +18,10 @@ import React from 'react';
import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
import sdk from '../../../skinned-sdk';
import { MatrixClientPeg } from '../../../../src/MatrixClientPeg';
import { stubClient } from '../../../test-utils';
import { findById, flushPromises } from '../../../test-utils';
const AccessSecretStorageDialog = sdk.getComponent("dialogs.security.AccessSecretStorageDialog");
import AccessSecretStorageDialog from "../../../../src/components/views/dialogs/security/AccessSecretStorageDialog";
describe("AccessSecretStorageDialog", function() {
it("Closes the dialog if _onRecoveryKeyNext is called with a valid key", async () => {

View file

@ -20,13 +20,9 @@ import ReactTestUtils from 'react-dom/test-utils';
import MatrixReactTestUtils from 'matrix-react-test-utils';
import { sleep } from "matrix-js-sdk/src/utils";
import sdk from '../../../skinned-sdk';
import { MatrixClientPeg } from '../../../../src/MatrixClientPeg';
import * as TestUtilsMatrix from '../../../test-utils';
const InteractiveAuthDialog = sdk.getComponent(
'views.dialogs.InteractiveAuthDialog',
);
import InteractiveAuthDialog from "../../../../src/components/views/dialogs/InteractiveAuthDialog";
describe('InteractiveAuthDialog', function() {
let parentDiv;

View file

@ -2,11 +2,11 @@ import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
import ShallowRenderer from "react-test-renderer/shallow";
import sdk from '../../../skinned-sdk';
import * as testUtils from '../../../test-utils';
import _EventListSummary from "../../../../src/components/views/elements/EventListSummary";
// Give ELS a matrixClient in its child context
const EventListSummary = testUtils.wrapInMatrixClientContext(sdk.getComponent('views.elements.EventListSummary'));
const EventListSummary = testUtils.wrapInMatrixClientContext(_EventListSummary);
describe('EventListSummary', function() {
// Generate dummy event tiles for use in simulating an expanded MELS

View file

@ -18,7 +18,6 @@ import React from 'react';
import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
import '../../../skinned-sdk';
import LiveDurationDropdown, { DEFAULT_DURATION_MS }
from '../../../../src/components/views/location/LiveDurationDropdown';
import { findById, mockPlatformPeg } from '../../../test-utils';

View file

@ -14,11 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import sdk from "../../../skinned-sdk";
import { textForLocation } from "../../../../src/components/views/location/shareLocation";
sdk.getComponent("LocationPicker");
describe("LocationButton", () => {
describe("textForLocation", () => {
it("with no description, simply dumps URI and date", () => {

View file

@ -17,7 +17,6 @@ limitations under the License.
import React from 'react';
import { mount } from 'enzyme';
import '../../../skinned-sdk';
import { MapError } from '../../../../src/components/views/location/MapError';
import { LocationShareError } from '../../../../src/utils/location';

View file

@ -18,17 +18,15 @@ import React from "react";
import { mount } from "enzyme";
import { mocked } from "jest-mock";
import sdk from "../../../skinned-sdk";
import { formatFullDateNoTime } from "../../../../src/DateUtils";
import SettingsStore from "../../../../src/settings/SettingsStore";
import { UIFeature } from "../../../../src/settings/UIFeature";
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
import { getMockClientWithEventEmitter } from "../../../test-utils";
import DateSeparator from "../../../../src/components/views/messages/DateSeparator";
jest.mock("../../../../src/settings/SettingsStore");
const DateSeparator = sdk.getComponent("views.messages.DateSeparator");
describe("DateSeparator", () => {
const HOUR_MS = 3600000;
const DAY_MS = HOUR_MS * 24;

View file

@ -29,7 +29,6 @@ import { TEXT_NODE_TYPE } from "matrix-js-sdk/src/@types/extensible_events";
import maplibregl from 'maplibre-gl';
import { logger } from 'matrix-js-sdk/src/logger';
import sdk from "../../../skinned-sdk";
import MLocationBody, {
isSelfLocation,
} from "../../../../src/components/views/messages/MLocationBody";
@ -44,8 +43,6 @@ jest.mock("../../../../src/utils/WellKnownUtils", () => ({
getTileServerWellKnown: jest.fn(),
}));
sdk.getComponent("views.messages.MLocationBody");
describe("MLocationBody", () => {
describe("isSelfLocation", () => {
it("Returns true for a full m.asset event", () => {

View file

@ -31,7 +31,6 @@ import {
} from "matrix-events-sdk";
import { MockedObject } from "jest-mock";
import sdk from "../../../skinned-sdk";
import {
UserVote,
allVotes,
@ -43,11 +42,10 @@ import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
import { IBodyProps } from "../../../../src/components/views/messages/IBodyProps";
import { getMockClientWithEventEmitter } from "../../../test-utils";
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
import MPollBody from "../../../../src/components/views/messages/MPollBody";
const CHECKED = "mx_MPollBody_option_checked";
const MPollBody = sdk.getComponent("views.messages.MPollBody");
const mockClient = getMockClientWithEventEmitter({
getUserId: jest.fn().mockReturnValue("@me:example.com"),
sendEvent: jest.fn().mockReturnValue(Promise.resolve({ "event_id": "fake_send_id" })),

View file

@ -17,14 +17,13 @@ limitations under the License.
import React from "react";
import { mount } from "enzyme";
import sdk from "../../../skinned-sdk";
import { mkEvent, mkStubRoom } from "../../../test-utils";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
import * as languageHandler from "../../../../src/languageHandler";
import * as TestUtils from "../../../test-utils";
import DMRoomMap from "../../../../src/utils/DMRoomMap";
import _TextualBody from "../../../../src/components/views/messages/TextualBody";
const _TextualBody = sdk.getComponent("views.messages.TextualBody");
const TextualBody = TestUtils.wrapInMatrixClientContext(_TextualBody);
describe("<TextualBody />", () => {

View file

@ -31,7 +31,6 @@ import {
PollEndEvent,
} from "matrix-events-sdk";
import "../../../skinned-sdk";
import {
stubClient,
mkStubRoom,

View file

@ -19,7 +19,6 @@ import { mount, ReactWrapper } from "enzyme";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import '../../../skinned-sdk'; // Must be first for skinning to work
import { createTestClient, mkEvent, mkStubRoom, stubClient } from "../../../test-utils";
import MessageComposer from "../../../../src/components/views/rooms/MessageComposer";
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";

View file

@ -19,15 +19,13 @@ import { mount, ReactWrapper } from "enzyme";
import { Room } from "matrix-js-sdk/src/models/room";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import sdk from "../../../skinned-sdk";
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
import { Layout } from "../../../../src/settings/enums/Layout";
import RoomContext, { TimelineRenderingType } from "../../../../src/contexts/RoomContext";
import { createTestClient } from "../../../test-utils";
import { IRoomState } from "../../../../src/components/structures/RoomView";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
const MessageComposerButtons = sdk.getComponent("views.rooms.MessageComposerButtons");
import MessageComposerButtons from "../../../../src/components/views/rooms/MessageComposerButtons";
describe("MessageComposerButtons", () => {
it("Renders emoji and upload buttons in wide mode", () => {

View file

@ -5,12 +5,14 @@ import { MatrixClient, Room, RoomMember } from 'matrix-js-sdk/src/matrix';
import * as TestUtils from '../../../test-utils';
import { MatrixClientPeg } from '../../../../src/MatrixClientPeg';
import sdk from '../../../skinned-sdk';
import dis from '../../../../src/dispatcher/dispatcher';
import DMRoomMap from '../../../../src/utils/DMRoomMap';
import { DefaultTagID } from "../../../../src/stores/room-list/models";
import RoomListStore, { RoomListStoreClass } from "../../../../src/stores/room-list/RoomListStore";
import RoomListLayoutStore from "../../../../src/stores/room-list/RoomListLayoutStore";
import RoomList from "../../../../src/components/views/rooms/RoomList";
import RoomSublist from "../../../../src/components/views/rooms/RoomSublist";
import RoomTile from "../../../../src/components/views/rooms/RoomTile";
function generateRoomId() {
return '!' + Math.random().toString().slice(2, 10) + ':domain';
@ -54,7 +56,6 @@ describe('RoomList', () => {
parentDiv = document.createElement('div');
document.body.appendChild(parentDiv);
const RoomList = sdk.getComponent('views.rooms.RoomList');
const WrappedRoomList = TestUtils.wrapInMatrixClientContext(RoomList);
root = ReactDOM.render(
<WrappedRoomList searchFilter="" onResize={() => {}} />,
@ -119,10 +120,7 @@ describe('RoomList', () => {
});
function expectRoomInSubList(room, subListTest) {
const RoomSubList = sdk.getComponent('views.rooms.RoomSublist');
const RoomTile = sdk.getComponent('views.rooms.RoomTile');
const subLists = ReactTestUtils.scryRenderedComponentsWithType(root, RoomSubList);
const subLists = ReactTestUtils.scryRenderedComponentsWithType(root, RoomSublist);
const containingSubList = subLists.find(subListTest);
let expectedRoomTile;

View file

@ -21,7 +21,6 @@ import { mocked } from "jest-mock";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import "../../../skinned-sdk";
import {
stubClient,
mockStateEventImplementation,

View file

@ -20,12 +20,10 @@ import { SearchResult } from "matrix-js-sdk/src/models/search-result";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { EventType } from "matrix-js-sdk/src/@types/event";
import sdk from "../../../skinned-sdk";
import { createTestClient } from "../../../test-utils";
import EventTile from "../../../../src/components/views/rooms/EventTile";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
const SearchResultTile = sdk.getComponent("views.rooms.SearchResultTile");
import SearchResultTile from "../../../../src/components/views/rooms/SearchResultTile";
describe("SearchResultTile", () => {
beforeAll(() => {

View file

@ -19,7 +19,6 @@ import { mount } from "enzyme";
import { act } from "react-dom/test-utils";
import { mocked } from "jest-mock";
import "../../../skinned-sdk";
import { stubClient, mkStubRoom, wrapInMatrixClientContext } from "../../../test-utils";
import { stubVoiceChannelStore } from "../../../test-utils/voice";
import _VoiceChannelRadio from "../../../../src/components/views/voip/VoiceChannelRadio";