Merge remote-tracking branch 'origin/t3chguy/jest' into travis/sourcemaps

This commit is contained in:
Travis Ralston 2020-01-09 16:00:13 -07:00
commit a8c8406ac4
41 changed files with 2002 additions and 1842 deletions

View file

@ -17,14 +17,13 @@ limitations under the License.
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import expect from 'expect';
import MockHttpBackend from 'matrix-mock-request';
import {MatrixClientPeg} from '../../../src/MatrixClientPeg';
import sdk from 'matrix-react-sdk';
import sdk from '../../skinned-sdk';
import Matrix from 'matrix-js-sdk';
import * as TestUtils from 'test-utils';
import * as TestUtils from '../../test-utils';
const { waitForUpdate } = TestUtils;
const GroupView = sdk.getComponent('structures.GroupView');
@ -61,8 +60,6 @@ describe('GroupView', function() {
};
beforeEach(function() {
TestUtils.beforeEach(this);
httpBackend = new MockHttpBackend();
Matrix.request(httpBackend.requestFn);
@ -194,13 +191,13 @@ describe('GroupView', function() {
const name = ReactTestUtils.findRenderedDOMComponentWithClass(root, 'mx_GroupView_header_name');
const nameElement = ReactDOM.findDOMNode(name);
expect(nameElement).toBeTruthy();
expect(nameElement.innerText).toContain('The name of a community');
expect(nameElement.innerText).toContain(groupId);
expect(nameElement.textContent).toContain('The name of a community');
expect(nameElement.textContent).toContain(groupId);
const shortDesc = ReactTestUtils.findRenderedDOMComponentWithClass(root, 'mx_GroupView_header_shortDesc');
const shortDescElement = ReactDOM.findDOMNode(shortDesc);
expect(shortDescElement).toBeTruthy();
expect(shortDescElement.innerText).toBe('This is a community');
expect(shortDescElement.textContent).toBe('This is a community');
});
httpBackend.when('GET', '/groups/' + groupIdEncoded + '/summary').respond(200, summaryResponse);
@ -220,7 +217,7 @@ describe('GroupView', function() {
const longDesc = ReactTestUtils.findRenderedDOMComponentWithClass(root, 'mx_GroupView_groupDesc');
const longDescElement = ReactDOM.findDOMNode(longDesc);
expect(longDescElement).toBeTruthy();
expect(longDescElement.innerText).toBe('This is a LONG description.');
expect(longDescElement.textContent).toBe('This is a LONG description.');
expect(longDescElement.innerHTML).toBe('<div dir="auto">This is a <b>LONG</b> description.</div>');
});
@ -305,7 +302,7 @@ describe('GroupView', function() {
it('should show a RoomDetailList after a successful /summary & /rooms (no rooms returned)', function() {
const groupView = ReactTestUtils.findRenderedComponentWithType(root, GroupView);
const prom = waitForUpdate(groupView, 4).then(() => {
const prom = waitForUpdate(groupView, 5).then(() => {
const roomDetailList = ReactTestUtils.findRenderedDOMComponentWithClass(root, 'mx_RoomDetailList');
const roomDetailListElement = ReactDOM.findDOMNode(roomDetailList);
expect(roomDetailListElement).toBeTruthy();
@ -334,7 +331,7 @@ describe('GroupView', function() {
const roomDetailListRoomNameElement = ReactDOM.findDOMNode(roomDetailListRoomName);
expect(roomDetailListRoomNameElement).toBeTruthy();
expect(roomDetailListRoomNameElement.innerText).toEqual('Some room name');
expect(roomDetailListRoomNameElement.textContent).toEqual('Some room name');
});
httpBackend.when('GET', '/groups/' + groupIdEncoded + '/summary').respond(200, summaryResponse);
@ -365,7 +362,7 @@ describe('GroupView', function() {
const shortDesc = ReactTestUtils.findRenderedDOMComponentWithClass(root, 'mx_GroupView_header_shortDesc');
const shortDescElement = ReactDOM.findDOMNode(shortDesc);
expect(shortDescElement).toBeTruthy();
expect(shortDescElement.innerText).toBe('This is a community');
expect(shortDescElement.textContent).toBe('This is a community');
});
httpBackend.when('GET', '/groups/' + groupIdEncoded + '/summary').respond(200, summaryResponse);

View file

@ -23,17 +23,16 @@ import ReactDOM from "react-dom";
import PropTypes from "prop-types";
const TestUtils = require('react-dom/test-utils');
const expect = require('expect');
import sinon from 'sinon';
import { EventEmitter } from "events";
const sdk = require('matrix-react-sdk');
import sdk from '../../skinned-sdk';
const MessagePanel = sdk.getComponent('structures.MessagePanel');
import {MatrixClientPeg} from '../../../src/MatrixClientPeg';
import Matrix from 'matrix-js-sdk';
const test_utils = require('test-utils');
const mockclock = require('mock-clock');
const test_utils = require('../../test-utils');
const mockclock = require('../../mock-clock');
import Velocity from 'velocity-animate';
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
@ -63,17 +62,16 @@ describe('MessagePanel', function() {
const clock = mockclock.clock();
const realSetTimeout = window.setTimeout;
const events = mkEvents();
let sandbox = null;
beforeEach(function() {
test_utils.beforeEach(this);
sandbox = test_utils.stubClient();
test_utils.stubClient();
client = MatrixClientPeg.get();
client.credentials = {userId: '@me:here'};
// HACK: We assume all settings want to be disabled
SettingsStore.getValue = sinon.stub().returns(false);
SettingsStore.getValue.withArgs('showDisplaynameChanges').returns(true);
SettingsStore.getValue = jest.fn((arg) => {
return arg === "showDisplaynameChanges";
});
// This option clobbers the duration of all animations to be 1ms
// which makes unit testing a lot simpler (the animation doesn't
@ -86,7 +84,6 @@ describe('MessagePanel', function() {
delete Velocity.mock;
clock.uninstall();
sandbox.restore();
});
function mkEvents() {

View file

@ -14,14 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import sinon from 'sinon';
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import sdk from 'matrix-react-sdk';
import sdk from '../../../skinned-sdk';
import SdkConfig from '../../../../src/SdkConfig';
import * as TestUtils from '../../../test-utils';
import {mkServerConfig} from "../../../test-utils";
const Login = sdk.getComponent(
@ -32,13 +29,11 @@ describe('Login', function() {
let parentDiv;
beforeEach(function() {
TestUtils.beforeEach(this);
parentDiv = document.createElement('div');
document.body.appendChild(parentDiv);
});
afterEach(function() {
sinon.restore();
ReactDOM.unmountComponentAtNode(parentDiv);
parentDiv.remove();
});
@ -74,7 +69,7 @@ describe('Login', function() {
});
it('should show form without change server link when custom URLs disabled', function() {
sinon.stub(SdkConfig, "get").returns({
jest.spyOn(SdkConfig, "get").mockReturnValue({
disable_custom_urls: true,
});

View file

@ -14,14 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import sinon from 'sinon';
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import sdk from 'matrix-react-sdk';
import sdk from '../../../skinned-sdk';
import SdkConfig from '../../../../src/SdkConfig';
import * as TestUtils from '../../../test-utils';
import {mkServerConfig} from "../../../test-utils";
const Registration = sdk.getComponent(
@ -32,13 +29,11 @@ describe('Registration', function() {
let parentDiv;
beforeEach(function() {
TestUtils.beforeEach(this);
parentDiv = document.createElement('div');
document.body.appendChild(parentDiv);
});
afterEach(function() {
sinon.restore();
ReactDOM.unmountComponentAtNode(parentDiv);
parentDiv.remove();
});
@ -63,7 +58,7 @@ describe('Registration', function() {
});
it('should show form when custom URLs disabled', function() {
sinon.stub(SdkConfig, "get").returns({
jest.spyOn(SdkConfig, "get").mockReturnValue({
disable_custom_urls: true,
});