Add a regression test for editing events and url previews
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
c551f2983a
commit
f1de6d060a
3 changed files with 64 additions and 2 deletions
|
@ -24,7 +24,7 @@ import MatrixClientPeg from '../../../../MatrixClientPeg';
|
||||||
import { scorePassword } from '../../../../utils/PasswordScorer';
|
import { scorePassword } from '../../../../utils/PasswordScorer';
|
||||||
import { _t } from '../../../../languageHandler';
|
import { _t } from '../../../../languageHandler';
|
||||||
import { accessSecretStorage } from '../../../../CrossSigningManager';
|
import { accessSecretStorage } from '../../../../CrossSigningManager';
|
||||||
import SettingsStore from '../../../../../lib/settings/SettingsStore';
|
import SettingsStore from '../../../../settings/SettingsStore';
|
||||||
|
|
||||||
const PHASE_PASSPHRASE = 0;
|
const PHASE_PASSPHRASE = 0;
|
||||||
const PHASE_PASSPHRASE_CONFIRM = 1;
|
const PHASE_PASSPHRASE_CONFIRM = 1;
|
||||||
|
|
|
@ -21,7 +21,7 @@ import sdk from '../../../index';
|
||||||
import MatrixClientPeg from '../../../MatrixClientPeg';
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
import Modal from '../../../Modal';
|
import Modal from '../../../Modal';
|
||||||
import SettingsStore from '../../../../lib/settings/SettingsStore';
|
import SettingsStore from '../../../settings/SettingsStore';
|
||||||
|
|
||||||
export default class KeyBackupPanel extends React.PureComponent {
|
export default class KeyBackupPanel extends React.PureComponent {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
|
|
@ -6,6 +6,8 @@ import { configure, mount } from "enzyme";
|
||||||
import sdk from "../../../skinned-sdk";
|
import sdk from "../../../skinned-sdk";
|
||||||
import {mkEvent, mkStubRoom} from "../../../test-utils";
|
import {mkEvent, mkStubRoom} from "../../../test-utils";
|
||||||
import MatrixClientPeg from "../../../../src/MatrixClientPeg";
|
import MatrixClientPeg from "../../../../src/MatrixClientPeg";
|
||||||
|
import * as languageHandler from "../../../../src/languageHandler";
|
||||||
|
import {sleep} from "../../../../src/utils/promise";
|
||||||
|
|
||||||
const TextualBody = sdk.getComponent("views.messages.TextualBody");
|
const TextualBody = sdk.getComponent("views.messages.TextualBody");
|
||||||
|
|
||||||
|
@ -190,6 +192,66 @@ describe("<TextualBody />", () => {
|
||||||
'</span></span>');
|
'</span></span>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("renders url previews correctly", () => {
|
||||||
|
languageHandler.setMissingEntryGenerator(key => key.split('|', 2)[1]);
|
||||||
|
|
||||||
|
MatrixClientPeg.matrixClient = {
|
||||||
|
getRoom: () => mkStubRoom("room_id"),
|
||||||
|
getAccountData: () => undefined,
|
||||||
|
getUrlPreview: (url) => new Promise(() => {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
const ev = mkEvent({
|
||||||
|
type: "m.room.message",
|
||||||
|
room: "room_id",
|
||||||
|
user: "sender",
|
||||||
|
content: {
|
||||||
|
body: "Visit https://matrix.org/",
|
||||||
|
msgtype: "m.text",
|
||||||
|
},
|
||||||
|
event: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const wrapper = mount(<TextualBody mxEvent={ev} showUrlPreview={true} />);
|
||||||
|
expect(wrapper.text()).toBe(ev.getContent().body);
|
||||||
|
|
||||||
|
let widgets = wrapper.find("LinkPreviewWidget");
|
||||||
|
// at this point we should have exactly one widget
|
||||||
|
expect(widgets.length).toBe(1);
|
||||||
|
expect(widgets.at(0).prop("link")).toBe("https://matrix.org/");
|
||||||
|
|
||||||
|
// simulate an event edit and check the transition from the old URL preview to the new one
|
||||||
|
const ev2 = mkEvent({
|
||||||
|
type: "m.room.message",
|
||||||
|
room: "room_id",
|
||||||
|
user: "sender",
|
||||||
|
content: {
|
||||||
|
"m.new_content": {
|
||||||
|
body: "Visit https://vector.im/ and https://riot.im/",
|
||||||
|
msgtype: "m.text",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
event: true,
|
||||||
|
});
|
||||||
|
ev.makeReplaced(ev2);
|
||||||
|
|
||||||
|
wrapper.setProps({
|
||||||
|
mxEvent: ev,
|
||||||
|
replacingEventId: ev.getId(),
|
||||||
|
}, () => {
|
||||||
|
expect(wrapper.text()).toBe(ev2.getContent()["m.new_content"].body + "(edited)");
|
||||||
|
|
||||||
|
// XXX: this is to give TextualBody enough time for state to settle
|
||||||
|
wrapper.setState({}, () => {
|
||||||
|
widgets = wrapper.find("LinkPreviewWidget");
|
||||||
|
// at this point we should have exactly two widgets (not the matrix.org one anymore)
|
||||||
|
expect(widgets.length).toBe(2);
|
||||||
|
expect(widgets.at(0).prop("link")).toBe("https://vector.im/");
|
||||||
|
expect(widgets.at(1).prop("link")).toBe("https://riot.im/");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue