mirror of
https://github.com/element-hq/element-web
synced 2024-11-22 09:15:41 +03:00
Step 3.1: Stop using getComponent
in tests
This commit is contained in:
parent
303f06cc61
commit
1bbecdff6c
2 changed files with 20 additions and 24 deletions
|
@ -18,7 +18,6 @@ limitations under the License.
|
||||||
|
|
||||||
import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg';
|
import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg';
|
||||||
import WebPlatform from '../../src/vector/platform/WebPlatform';
|
import WebPlatform from '../../src/vector/platform/WebPlatform';
|
||||||
import * as sdk from "matrix-react-sdk/src/index";
|
|
||||||
import * as jssdk from "matrix-js-sdk/src/matrix";
|
import * as jssdk from "matrix-js-sdk/src/matrix";
|
||||||
import "../skin-sdk";
|
import "../skin-sdk";
|
||||||
import "../jest-mocks";
|
import "../jest-mocks";
|
||||||
|
@ -28,15 +27,12 @@ import ReactTestUtils from "react-dom/test-utils";
|
||||||
import {makeType} from "matrix-react-sdk/src/utils/TypeUtils";
|
import {makeType} from "matrix-react-sdk/src/utils/TypeUtils";
|
||||||
import {ValidatedServerConfig} from "matrix-react-sdk/src/utils/AutoDiscoveryUtils";
|
import {ValidatedServerConfig} from "matrix-react-sdk/src/utils/AutoDiscoveryUtils";
|
||||||
import {sleep} from "../test-utils";
|
import {sleep} from "../test-utils";
|
||||||
import * as test_utils from "../test-utils";
|
|
||||||
import MockHttpBackend from "matrix-mock-request";
|
import MockHttpBackend from "matrix-mock-request";
|
||||||
import "fake-indexeddb/auto";
|
import "fake-indexeddb/auto";
|
||||||
import { RoomView as RoomViewClass } from 'matrix-react-sdk/src/components/structures/RoomView';
|
import { RoomView as RoomViewClass } from 'matrix-react-sdk/src/components/structures/RoomView';
|
||||||
|
import MatrixChat from "matrix-react-sdk/src/components/structures/MatrixChat";
|
||||||
|
import RoomDirectory from "matrix-react-sdk/src/components/structures/RoomDirectory";
|
||||||
const MatrixChat = sdk.getComponent('structures.MatrixChat');
|
import RoomPreviewBar from "matrix-react-sdk/src/components/views/rooms/RoomPreviewBar";
|
||||||
const RoomDirectory = sdk.getComponent('structures.RoomDirectory');
|
|
||||||
const RoomPreviewBar = sdk.getComponent('rooms.RoomPreviewBar');
|
|
||||||
|
|
||||||
const HS_URL='http://localhost';
|
const HS_URL='http://localhost';
|
||||||
const IS_URL='http://localhost';
|
const IS_URL='http://localhost';
|
||||||
|
|
|
@ -26,9 +26,8 @@ import ReactDOM from 'react-dom';
|
||||||
import ReactTestUtils from 'react-dom/test-utils';
|
import ReactTestUtils from 'react-dom/test-utils';
|
||||||
import MatrixReactTestUtils from 'matrix-react-test-utils';
|
import MatrixReactTestUtils from 'matrix-react-test-utils';
|
||||||
import * as jssdk from 'matrix-js-sdk/src/matrix';
|
import * as jssdk from 'matrix-js-sdk/src/matrix';
|
||||||
import * as sdk from 'matrix-react-sdk/src/index';
|
|
||||||
import {MatrixClientPeg} from 'matrix-react-sdk/src/MatrixClientPeg';
|
import {MatrixClientPeg} from 'matrix-react-sdk/src/MatrixClientPeg';
|
||||||
import {Views} from 'matrix-react-sdk/src/components/structures/MatrixChat';
|
import MatrixChat, {Views} from 'matrix-react-sdk/src/components/structures/MatrixChat';
|
||||||
import dis from 'matrix-react-sdk/src/dispatcher/dispatcher';
|
import dis from 'matrix-react-sdk/src/dispatcher/dispatcher';
|
||||||
import * as test_utils from '../test-utils';
|
import * as test_utils from '../test-utils';
|
||||||
import MockHttpBackend from 'matrix-mock-request';
|
import MockHttpBackend from 'matrix-mock-request';
|
||||||
|
@ -41,6 +40,8 @@ import {cleanLocalstorage} from "../test-utils";
|
||||||
import {IndexedDBCryptoStore} from "matrix-js-sdk/src/crypto/store/indexeddb-crypto-store";
|
import {IndexedDBCryptoStore} from "matrix-js-sdk/src/crypto/store/indexeddb-crypto-store";
|
||||||
import { RoomView as RoomViewClass } from 'matrix-react-sdk/src/components/structures/RoomView';
|
import { RoomView as RoomViewClass } from 'matrix-react-sdk/src/components/structures/RoomView';
|
||||||
import LoginComponent from 'matrix-react-sdk/src/components/structures/auth/Login';
|
import LoginComponent from 'matrix-react-sdk/src/components/structures/auth/Login';
|
||||||
|
import WelcomeComponent from "matrix-react-sdk/src/components/views/auth/Welcome";
|
||||||
|
import EmbeddedPage from "matrix-react-sdk/src/components/structures/EmbeddedPage";
|
||||||
|
|
||||||
const DEFAULT_HS_URL='http://my_server';
|
const DEFAULT_HS_URL='http://my_server';
|
||||||
const DEFAULT_IS_URL='http://my_is';
|
const DEFAULT_IS_URL='http://my_is';
|
||||||
|
@ -124,7 +125,6 @@ describe('loading:', function() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const MatrixChat = sdk.getComponent('structures.MatrixChat');
|
|
||||||
const fragParts = parseQsFromFragment(windowLocation);
|
const fragParts = parseQsFromFragment(windowLocation);
|
||||||
|
|
||||||
const config = Object.assign({
|
const config = Object.assign({
|
||||||
|
@ -269,7 +269,7 @@ describe('loading:', function() {
|
||||||
return awaitLoginComponent(matrixChat).then(() => {
|
return awaitLoginComponent(matrixChat).then(() => {
|
||||||
// we expect a single <Login> component
|
// we expect a single <Login> component
|
||||||
ReactTestUtils.findRenderedComponentWithType(
|
ReactTestUtils.findRenderedComponentWithType(
|
||||||
matrixChat, sdk.getComponent('structures.auth.Login'));
|
matrixChat, LoginComponent);
|
||||||
|
|
||||||
// the only outstanding request should be a GET /login
|
// the only outstanding request should be a GET /login
|
||||||
// (in particular there should be no /register request for
|
// (in particular there should be no /register request for
|
||||||
|
@ -290,7 +290,7 @@ describe('loading:', function() {
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// once the sync completes, we should have a room view
|
// once the sync completes, we should have a room view
|
||||||
ReactTestUtils.findRenderedComponentWithType(
|
ReactTestUtils.findRenderedComponentWithType(
|
||||||
matrixChat, sdk.getComponent('structures.EmbeddedPage'));
|
matrixChat, EmbeddedPage);
|
||||||
expect(windowLocation.hash).toEqual("#/home");
|
expect(windowLocation.hash).toEqual("#/home");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -343,7 +343,7 @@ describe('loading:', function() {
|
||||||
// once the sync completes, we should have a home page
|
// once the sync completes, we should have a home page
|
||||||
httpBackend.verifyNoOutstandingExpectation();
|
httpBackend.verifyNoOutstandingExpectation();
|
||||||
ReactTestUtils.findRenderedComponentWithType(
|
ReactTestUtils.findRenderedComponentWithType(
|
||||||
matrixChat, sdk.getComponent('structures.EmbeddedPage'));
|
matrixChat, EmbeddedPage);
|
||||||
expect(windowLocation.hash).toEqual("#/home");
|
expect(windowLocation.hash).toEqual("#/home");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -384,7 +384,7 @@ describe('loading:', function() {
|
||||||
|
|
||||||
// we expect a single <Login> component
|
// we expect a single <Login> component
|
||||||
ReactTestUtils.findRenderedComponentWithType(
|
ReactTestUtils.findRenderedComponentWithType(
|
||||||
matrixChat, sdk.getComponent('structures.auth.Login'),
|
matrixChat, LoginComponent,
|
||||||
);
|
);
|
||||||
|
|
||||||
// the only outstanding request should be a GET /login
|
// the only outstanding request should be a GET /login
|
||||||
|
@ -413,7 +413,7 @@ describe('loading:', function() {
|
||||||
// we should see a home page, even though we previously had
|
// we should see a home page, even though we previously had
|
||||||
// a stored mx_last_room_id
|
// a stored mx_last_room_id
|
||||||
ReactTestUtils.findRenderedComponentWithType(
|
ReactTestUtils.findRenderedComponentWithType(
|
||||||
matrixChat, sdk.getComponent('structures.EmbeddedPage'));
|
matrixChat, EmbeddedPage);
|
||||||
expect(windowLocation.hash).toEqual("#/home");
|
expect(windowLocation.hash).toEqual("#/home");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -447,7 +447,7 @@ describe('loading:', function() {
|
||||||
// once the sync completes, we should have a welcome page
|
// once the sync completes, we should have a welcome page
|
||||||
httpBackend.verifyNoOutstandingExpectation();
|
httpBackend.verifyNoOutstandingExpectation();
|
||||||
ReactTestUtils.findRenderedComponentWithType(
|
ReactTestUtils.findRenderedComponentWithType(
|
||||||
matrixChat, sdk.getComponent('auth.Welcome'));
|
matrixChat, WelcomeComponent);
|
||||||
expect(windowLocation.hash).toEqual("#/welcome");
|
expect(windowLocation.hash).toEqual("#/welcome");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -480,7 +480,7 @@ describe('loading:', function() {
|
||||||
// once the sync completes, we should have a welcome page
|
// once the sync completes, we should have a welcome page
|
||||||
httpBackend.verifyNoOutstandingExpectation();
|
httpBackend.verifyNoOutstandingExpectation();
|
||||||
ReactTestUtils.findRenderedComponentWithType(
|
ReactTestUtils.findRenderedComponentWithType(
|
||||||
matrixChat, sdk.getComponent('auth.Welcome'));
|
matrixChat, WelcomeComponent);
|
||||||
expect(windowLocation.hash).toEqual("#/welcome");
|
expect(windowLocation.hash).toEqual("#/welcome");
|
||||||
expect(MatrixClientPeg.get().baseUrl).toEqual(DEFAULT_HS_URL);
|
expect(MatrixClientPeg.get().baseUrl).toEqual(DEFAULT_HS_URL);
|
||||||
expect(MatrixClientPeg.get().idBaseUrl).toEqual(DEFAULT_IS_URL);
|
expect(MatrixClientPeg.get().idBaseUrl).toEqual(DEFAULT_IS_URL);
|
||||||
|
@ -539,7 +539,7 @@ describe('loading:', function() {
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// once the sync completes, we should have a home page
|
// once the sync completes, we should have a home page
|
||||||
ReactTestUtils.findRenderedComponentWithType(
|
ReactTestUtils.findRenderedComponentWithType(
|
||||||
matrixChat, sdk.getComponent('structures.EmbeddedPage'));
|
matrixChat, EmbeddedPage);
|
||||||
|
|
||||||
// we simulate a click on the 'login' button by firing off
|
// we simulate a click on the 'login' button by firing off
|
||||||
// the relevant dispatch.
|
// the relevant dispatch.
|
||||||
|
@ -561,7 +561,7 @@ describe('loading:', function() {
|
||||||
|
|
||||||
// we expect a single <Login> component
|
// we expect a single <Login> component
|
||||||
ReactTestUtils.findRenderedComponentWithType(
|
ReactTestUtils.findRenderedComponentWithType(
|
||||||
matrixChat, sdk.getComponent('structures.auth.Login'),
|
matrixChat, LoginComponent,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -569,7 +569,7 @@ describe('loading:', function() {
|
||||||
// ILAG renders this obsolete. I think.
|
// ILAG renders this obsolete. I think.
|
||||||
it('should allow us to return to the app', function() {
|
it('should allow us to return to the app', function() {
|
||||||
const login = ReactTestUtils.findRenderedComponentWithType(
|
const login = ReactTestUtils.findRenderedComponentWithType(
|
||||||
matrixChat, sdk.getComponent('structures.auth.Login')
|
matrixChat, LoginComponent
|
||||||
);
|
);
|
||||||
|
|
||||||
const linkText = 'Return to app';
|
const linkText = 'Return to app';
|
||||||
|
@ -586,7 +586,7 @@ describe('loading:', function() {
|
||||||
return sleep(1).then(() => {
|
return sleep(1).then(() => {
|
||||||
// we should be straight back into the home page
|
// we should be straight back into the home page
|
||||||
ReactTestUtils.findRenderedComponentWithType(
|
ReactTestUtils.findRenderedComponentWithType(
|
||||||
matrixChat, sdk.getComponent('structures.EmbeddedPage'));
|
matrixChat, EmbeddedPage);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
@ -733,19 +733,19 @@ function awaitRoomView(matrixChat, retryLimit?, retryCount?) {
|
||||||
|
|
||||||
function awaitLoginComponent(matrixChat, attempts?) {
|
function awaitLoginComponent(matrixChat, attempts?) {
|
||||||
return MatrixReactTestUtils.waitForRenderedComponentWithType(
|
return MatrixReactTestUtils.waitForRenderedComponentWithType(
|
||||||
matrixChat, sdk.getComponent('structures.auth.Login'), attempts,
|
matrixChat, LoginComponent, attempts,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function awaitWelcomeComponent(matrixChat, attempts?) {
|
function awaitWelcomeComponent(matrixChat, attempts?) {
|
||||||
return MatrixReactTestUtils.waitForRenderedComponentWithType(
|
return MatrixReactTestUtils.waitForRenderedComponentWithType(
|
||||||
matrixChat, sdk.getComponent('auth.Welcome'), attempts,
|
matrixChat, WelcomeComponent, attempts,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveFromWelcomeToLogin(matrixChat) {
|
function moveFromWelcomeToLogin(matrixChat) {
|
||||||
ReactTestUtils.findRenderedComponentWithType(
|
ReactTestUtils.findRenderedComponentWithType(
|
||||||
matrixChat, sdk.getComponent('auth.Welcome'));
|
matrixChat, WelcomeComponent);
|
||||||
dis.dispatch({ action: 'start_login' });
|
dis.dispatch({ action: 'start_login' });
|
||||||
return awaitLoginComponent(matrixChat);
|
return awaitLoginComponent(matrixChat);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue