@@ -19,7 +19,7 @@ import { mocked, MockedObject } from "jest-mock";
19
19
import { ClientEvent , MatrixClient } from "matrix-js-sdk/src/client" ;
20
20
import { Room , RoomEvent } from "matrix-js-sdk/src/models/room" ;
21
21
import { MatrixEvent } from "matrix-js-sdk/src/models/event" ;
22
- import { EventType , RoomStateEvent } from "matrix-js-sdk/src/matrix" ;
22
+ import { EventType , MatrixError , RoomStateEvent } from "matrix-js-sdk/src/matrix" ;
23
23
import { MEGOLM_ALGORITHM } from "matrix-js-sdk/src/crypto/olmlib" ;
24
24
import { fireEvent , render , screen , RenderResult } from "@testing-library/react" ;
25
25
@@ -34,6 +34,7 @@ import {
34
34
filterConsole ,
35
35
mkRoomMemberJoinEvent ,
36
36
mkThirdPartyInviteEvent ,
37
+ emitPromise ,
37
38
} from "../../test-utils" ;
38
39
import { MatrixClientPeg } from "../../../src/MatrixClientPeg" ;
39
40
import { Action } from "../../../src/dispatcher/actions" ;
@@ -55,6 +56,7 @@ import VoipUserMapper from "../../../src/VoipUserMapper";
55
56
import WidgetUtils from "../../../src/utils/WidgetUtils" ;
56
57
import { WidgetType } from "../../../src/widgets/WidgetType" ;
57
58
import WidgetStore from "../../../src/stores/WidgetStore" ;
59
+ import { ViewRoomErrorPayload } from "../../../src/dispatcher/payloads/ViewRoomErrorPayload" ;
58
60
59
61
// Fake random strings to give a predictable snapshot for IDs
60
62
jest . mock ( "matrix-js-sdk/src/randomstring" , ( ) => ( {
@@ -138,8 +140,8 @@ describe("RoomView", () => {
138
140
return roomView ;
139
141
} ;
140
142
141
- const renderRoomView = async ( ) : Promise < ReturnType < typeof render > > => {
142
- if ( stores . roomViewStore . getRoomId ( ) !== room . roomId ) {
143
+ const renderRoomView = async ( switchRoom = true ) : Promise < ReturnType < typeof render > > => {
144
+ if ( switchRoom && stores . roomViewStore . getRoomId ( ) !== room . roomId ) {
143
145
const switchedRoom = new Promise < void > ( ( resolve ) => {
144
146
const subFn = ( ) => {
145
147
if ( stores . roomViewStore . getRoomId ( ) ) {
@@ -498,4 +500,19 @@ describe("RoomView", () => {
498
500
} ) ;
499
501
} ) ;
500
502
} ) ;
503
+
504
+ it ( "should show error view if failed to look up room alias" , async ( ) => {
505
+ const { asFragment, findByText } = await renderRoomView ( false ) ;
506
+
507
+ defaultDispatcher . dispatch < ViewRoomErrorPayload > ( {
508
+ action : Action . ViewRoomError ,
509
+ room_alias : "#addy:server" ,
510
+ room_id : null ,
511
+ err : new MatrixError ( { errcode : "M_NOT_FOUND" } ) ,
512
+ } ) ;
513
+ await emitPromise ( stores . roomViewStore , UPDATE_EVENT ) ;
514
+
515
+ await findByText ( "Are you sure you're at the right place?" ) ;
516
+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
517
+ } ) ;
501
518
} ) ;
0 commit comments