Fix clicking MXID in timeline going to matrix.to (#11263)
* Fix clicking MXID in timeline going to matrix.to * Add tests * Increase coverage
This commit is contained in:
parent
3a784c71e8
commit
cb592dc709
2 changed files with 50 additions and 7 deletions
|
@ -13,7 +13,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
import { linkify, Type } from "../src/linkify-matrix";
|
||||
|
||||
import { EventListeners } from "linkifyjs";
|
||||
|
||||
import { linkify, Type, options } from "../src/linkify-matrix";
|
||||
import dispatcher from "../src/dispatcher/dispatcher";
|
||||
import { Action } from "../src/dispatcher/actions";
|
||||
|
||||
describe("linkify-matrix", () => {
|
||||
const linkTypesByInitialCharacter: Record<string, string> = {
|
||||
|
@ -324,6 +329,26 @@ describe("linkify-matrix", () => {
|
|||
|
||||
describe("roomalias plugin", () => {
|
||||
genTests("#");
|
||||
|
||||
it("should intercept clicks with a ViewRoom dispatch", () => {
|
||||
const dispatchSpy = jest.spyOn(dispatcher, "dispatch");
|
||||
|
||||
const handlers = (options.events as (href: string, type: string) => EventListeners)(
|
||||
"#room:server.com",
|
||||
"roomalias",
|
||||
);
|
||||
|
||||
const event = new MouseEvent("mousedown");
|
||||
event.preventDefault = jest.fn();
|
||||
handlers.click(event);
|
||||
expect(event.preventDefault).toHaveBeenCalled();
|
||||
expect(dispatchSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
action: Action.ViewRoom,
|
||||
room_alias: "#room:server.com",
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("userid plugin", () => {
|
||||
|
@ -344,6 +369,28 @@ describe("linkify-matrix", () => {
|
|||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("should intercept clicks with a ViewUser dispatch", () => {
|
||||
const dispatchSpy = jest.spyOn(dispatcher, "dispatch");
|
||||
|
||||
const handlers = (options.events as (href: string, type: string) => EventListeners)(
|
||||
"@localpart:server.com",
|
||||
"userid",
|
||||
);
|
||||
|
||||
const event = new MouseEvent("mousedown");
|
||||
event.preventDefault = jest.fn();
|
||||
handlers.click(event);
|
||||
expect(event.preventDefault).toHaveBeenCalled();
|
||||
expect(dispatchSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
action: Action.ViewUser,
|
||||
member: expect.objectContaining({
|
||||
userId: "@localpart:server.com",
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("matrix uri", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue