|
| 1 | +/* |
| 2 | +Copyright 2023 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import { MockedObject } from "jest-mock"; |
| 18 | +import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix"; |
| 19 | + |
| 20 | +import { Action } from "../../../../src/dispatcher/actions"; |
| 21 | +import { onView3pidInvite } from "../../../../src/stores/right-panel/action-handlers"; |
| 22 | +import RightPanelStore from "../../../../src/stores/right-panel/RightPanelStore"; |
| 23 | +import { RightPanelPhases } from "../../../../src/stores/right-panel/RightPanelStorePhases"; |
| 24 | + |
| 25 | +describe("onView3pidInvite()", () => { |
| 26 | + let rightPanelStore!: MockedObject<RightPanelStore>; |
| 27 | + |
| 28 | + beforeEach(() => { |
| 29 | + rightPanelStore = { |
| 30 | + pushCard: jest.fn(), |
| 31 | + showOrHidePanel: jest.fn(), |
| 32 | + } as unknown as MockedObject<RightPanelStore>; |
| 33 | + }); |
| 34 | + |
| 35 | + it("should display room member list when payload has a falsy event", () => { |
| 36 | + const payload = { |
| 37 | + action: Action.View3pidInvite, |
| 38 | + }; |
| 39 | + onView3pidInvite(payload, rightPanelStore); |
| 40 | + |
| 41 | + expect(rightPanelStore.showOrHidePanel).toHaveBeenCalledWith(RightPanelPhases.RoomMemberList); |
| 42 | + expect(rightPanelStore.pushCard).not.toHaveBeenCalled(); |
| 43 | + }); |
| 44 | + |
| 45 | + it("should push a 3pid member card on the right panel stack when payload has an event", () => { |
| 46 | + const payload = { |
| 47 | + action: Action.View3pidInvite, |
| 48 | + event: new MatrixEvent({ type: EventType.RoomThirdPartyInvite }), |
| 49 | + }; |
| 50 | + onView3pidInvite(payload, rightPanelStore); |
| 51 | + |
| 52 | + expect(rightPanelStore.showOrHidePanel).not.toHaveBeenCalled(); |
| 53 | + expect(rightPanelStore.pushCard).toHaveBeenCalledWith({ |
| 54 | + phase: RightPanelPhases.Room3pidMemberInfo, |
| 55 | + state: { memberInfoEvent: payload.event }, |
| 56 | + }); |
| 57 | + }); |
| 58 | +}); |
0 commit comments