From f1de6d060acd66b5ba69f7f494fd176d161b40f5 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 6 Jan 2020 14:38:21 +0000 Subject: [PATCH] Add a regression test for editing events and url previews Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../keybackup/CreateKeyBackupDialog.js | 2 +- .../views/settings/KeyBackupPanel.js | 2 +- .../views/messages/TextualBody-test.js | 62 +++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/async-components/views/dialogs/keybackup/CreateKeyBackupDialog.js b/src/async-components/views/dialogs/keybackup/CreateKeyBackupDialog.js index 19720e077a..1095fb4aee 100644 --- a/src/async-components/views/dialogs/keybackup/CreateKeyBackupDialog.js +++ b/src/async-components/views/dialogs/keybackup/CreateKeyBackupDialog.js @@ -24,7 +24,7 @@ import MatrixClientPeg from '../../../../MatrixClientPeg'; import { scorePassword } from '../../../../utils/PasswordScorer'; import { _t } from '../../../../languageHandler'; import { accessSecretStorage } from '../../../../CrossSigningManager'; -import SettingsStore from '../../../../../lib/settings/SettingsStore'; +import SettingsStore from '../../../../settings/SettingsStore'; const PHASE_PASSPHRASE = 0; const PHASE_PASSPHRASE_CONFIRM = 1; diff --git a/src/components/views/settings/KeyBackupPanel.js b/src/components/views/settings/KeyBackupPanel.js index bfa96f277f..3781f97dbe 100644 --- a/src/components/views/settings/KeyBackupPanel.js +++ b/src/components/views/settings/KeyBackupPanel.js @@ -21,7 +21,7 @@ import sdk from '../../../index'; import MatrixClientPeg from '../../../MatrixClientPeg'; import { _t } from '../../../languageHandler'; import Modal from '../../../Modal'; -import SettingsStore from '../../../../lib/settings/SettingsStore'; +import SettingsStore from '../../../settings/SettingsStore'; export default class KeyBackupPanel extends React.PureComponent { constructor(props) { diff --git a/test/components/views/messages/TextualBody-test.js b/test/components/views/messages/TextualBody-test.js index d93bfd307b..9e721d1d09 100644 --- a/test/components/views/messages/TextualBody-test.js +++ b/test/components/views/messages/TextualBody-test.js @@ -6,6 +6,8 @@ import { configure, 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 {sleep} from "../../../../src/utils/promise"; const TextualBody = sdk.getComponent("views.messages.TextualBody"); @@ -190,6 +192,66 @@ describe("", () => { ''); }); }); + + 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(); + 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/"); + }); + }); + }); });