Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { render } from "@testing-library/react";
import fetchMock from "jest-fetch-mock";
import * as VirtualVideo from "../VirtualVideo";
 
describe("VirtualVideo", () => {
  it("should call canPlayUrl and return false if no url specified", async () => {
    const canPlayType = jest.fn();
 
    render(<VirtualVideo.VirtualVideo canPlayType={canPlayType} />);
 
    await new Promise((resolve) => setTimeout(resolve, 10));
 
    expect(canPlayType).toHaveBeenCalledWith(false);
  });
 
  it("should call canPlayUrl and return true if valid url specified", async () => {
    const canPlayType = jest.fn();
 
    render(
      <VirtualVideo.VirtualVideo
        src="https://app.heartex.ai/static/samples/opossum_snow.mp4"
        canPlayType={canPlayType}
      />,
    );
 
    await new Promise((resolve) => setTimeout(resolve, 10));
 
    expect(canPlayType).toHaveBeenCalledWith(true);
  });
 
  it("should call canPlayUrl and return true if valid relative url specified", async () => {
    const canPlayType = jest.fn();
 
    render(<VirtualVideo.VirtualVideo src="/files/opossum_intro.webm" canPlayType={canPlayType} />);
 
    await new Promise((resolve) => setTimeout(resolve, 10));
 
    expect(canPlayType).toHaveBeenCalledWith(true);
  });
 
  it("should call canPlayUrl and return true if valid url specified, even if content-type is binary/octet-stream", async () => {
    const canPlayType = jest.fn();
 
    // return binary/octet-stream for all requests, mimicking the situation where
    // the server doesn't set the content-type header and defaults to binary/octet-stream
    fetchMock.mockResponseOnce("", {
      headers: {
        "content-type": "binary/octet-stream",
      },
    });
 
    render(
      <VirtualVideo.VirtualVideo
        src="https://app.heartex.ai/static/samples/opossum_snow.mp4"
        canPlayType={canPlayType}
      />,
    );
 
    await new Promise((resolve) => setTimeout(resolve, 10));
 
    expect(canPlayType).toHaveBeenCalledWith(true);
  });
 
  it("should call canPlayUrl and return true if valid file is specified, and content-type is binary/octet-stream but no file extension", async () => {
    const canPlayType = jest.fn();
 
    // return binary/octet-stream for all requests, mimicking the situation where
    // the server doesn't set the content-type header and defaults to binary/octet-stream
    fetchMock.mockResponseOnce("", {
      headers: {
        "content-type": "binary/octet-stream",
      },
    });
 
    render(
      <VirtualVideo.VirtualVideo src="https://app.heartex.ai/static/samples/opossum_snow" canPlayType={canPlayType} />,
    );
 
    await new Promise((resolve) => setTimeout(resolve, 10));
 
    expect(canPlayType).toHaveBeenCalledWith(true);
  });
 
  it("should call canPlayUrl and return false if invalid url specified", async () => {
    const canPlayType = jest.fn();
 
    render(
      <VirtualVideo.VirtualVideo
        src="https://app.heartex.ai/static/samples/opossum_snow.avi"
        canPlayType={canPlayType}
      />,
    );
 
    await new Promise((resolve) => setTimeout(resolve, 10));
 
    expect(canPlayType).toHaveBeenCalledWith(false);
  });
 
  it("should call canPlayUrl and return false if invalid url specified, even if content-type is binary/octet-stream", async () => {
    const canPlayType = jest.fn();
 
    // return binary/octet-stream for all requests, mimicking the situation where
    // the server doesn't set the content-type header and defaults to binary/octet-stream
    fetchMock.mockResponseOnce("", {
      headers: {
        "content-type": "binary/octet-stream",
      },
    });
 
    render(
      <VirtualVideo.VirtualVideo
        src="https://app.heartex.ai/static/samples/opossum_snow.avi"
        canPlayType={canPlayType}
      />,
    );
 
    await new Promise((resolve) => setTimeout(resolve, 10));
 
    expect(canPlayType).toHaveBeenCalledWith(false);
  });
});