Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Add snapshot test
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Feb 23, 2023
1 parent 6c72541 commit 19ad1a2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
15 changes: 14 additions & 1 deletion test/stores/RoomViewStore-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { Room } from "matrix-js-sdk/src/matrix";
import { MatrixError, Room } from "matrix-js-sdk/src/matrix";
import { sleep } from "matrix-js-sdk/src/utils";

import { RoomViewStore } from "../../src/stores/RoomViewStore";
Expand Down Expand Up @@ -284,6 +284,19 @@ describe("RoomViewStore", function () {
await viewCall();
});

it("should display an error message when the room is unreachable via the roomId", async () => {
// When
// View and wait for the room
dis.dispatch({ action: Action.ViewRoom, room_id: roomId });
await untilDispatch(Action.ActiveRoomChanged, dis);
// Generate error to display the expected error message
const error = new MatrixError(undefined, 404);
roomViewStore.showJoinRoomError(error, roomId);

// Then
expect(Modal.createDialog).toMatchSnapshot();

This comment has been minimized.

Copy link
@t3chguy

t3chguy Feb 23, 2023

Member

this is a weird thing to snapshot as it'll vary when its return type is added to

This comment has been minimized.

Copy link
@florianduros

florianduros Feb 23, 2023

Author Contributor

The generated HTML is always the same in the case of an 404 error and the room is unreachable with the roomId, so I though it was a good idea to test the html structure and its content with a snapshot. There is something underneath that I'm missing ?

This comment has been minimized.

Copy link
@t3chguy

t3chguy Feb 23, 2023

Member

Then the snapshot should be scoped to just the modal props or the DOM rather than

[MockFunction] {
  "calls": [
    [
      [Function],
      {
        "description": <div>
          You attempted to join using a room ID without providing a list of servers to join through. Room IDs are internal identifiers and cannot be used to join a room without additional information.
          <br />
          <br />
          If you know a room address, try joining through that instead.
        </div>,
        "title": "Failed to join",
      },
    ],
  ],
  "results": [
    {
      "type": "return",
      "value": undefined,
    },
  ],
}

This comment has been minimized.

Copy link
@florianduros

florianduros Feb 23, 2023

Author Contributor

Okay, I understand. I used the same behaviour than the other test in this test suite but testing only the description field make more sense

});

describe("when listening to a voice broadcast", () => {
let voiceBroadcastPlayback: VoiceBroadcastPlayback;

Expand Down
25 changes: 25 additions & 0 deletions test/stores/__snapshots__/RoomViewStore-test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`RoomViewStore should display an error message when the room is unreachable via the roomId 1`] = `
[MockFunction] {
"calls": [
[
[Function],
{
"description": <div>
You attempted to join using a room ID without providing a list of servers to join through. Room IDs are internal identifiers and cannot be used to join a room without additional information.
<br />
<br />
If you know a room address, try joining through that instead.
</div>,
"title": "Failed to join",
},
],
],
"results": [
{
"type": "return",
"value": undefined,
},
],
}
`;

exports[`RoomViewStore when recording a voice broadcast and trying to view a call, it should not actually view it and show the info dialog 1`] = `
[MockFunction] {
"calls": [
Expand Down

0 comments on commit 19ad1a2

Please sign in to comment.