Skip to content

Commit e2c9bcd

Browse files
test: SNI-6834 add video component specs
1 parent 32fbf35 commit e2c9bcd

File tree

1 file changed

+192
-0
lines changed

1 file changed

+192
-0
lines changed
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
import { mount } from "@vue/test-utils";
2+
import { AdvancedVideo } from "../../src";
3+
import { CloudinaryVideo } from "@cloudinary/url-gen";
4+
import { auto, vp9 } from "@cloudinary/url-gen/qualifiers/videoCodec";
5+
import { videoCodec } from "@cloudinary/url-gen/actions/transcode";
6+
import { waitTicks } from "./utils";
7+
8+
const cloudinaryVideo = new CloudinaryVideo(
9+
"sample",
10+
{ cloudName: "demo" },
11+
{ analytics: false }
12+
);
13+
14+
const cloudinaryVideoWithAnalytics = new CloudinaryVideo(
15+
"sample",
16+
{ cloudName: "demo" },
17+
{ analytics: true }
18+
);
19+
20+
describe("AdvancedVideo", () => {
21+
it("AdvancedVideo should be truthy", () => {
22+
expect(AdvancedVideo).toBeTruthy();
23+
});
24+
25+
it("should render video with default sources", async function () {
26+
const component = mount(AdvancedVideo, {
27+
props: { cldVid: cloudinaryVideo },
28+
});
29+
// wait because @cloudinary/html takes time to update the img element
30+
await waitTicks(1);
31+
32+
expect(component.html()).toContain(
33+
"<video>\n" +
34+
' <source src="https://res.cloudinary.com/demo/video/upload/sample.webm" type="video/webm">\n' +
35+
' <source src="https://res.cloudinary.com/demo/video/upload/sample.mp4" type="video/mp4">\n' +
36+
' <source src="https://res.cloudinary.com/demo/video/upload/sample.ogv" type="video/ogg">\n</video>'
37+
);
38+
});
39+
40+
it("should generate url sources with correct placement of extension and url analytics", async function () {
41+
const component = mount(AdvancedVideo, {
42+
props: { cldVid: cloudinaryVideoWithAnalytics },
43+
});
44+
await waitTicks(1);
45+
46+
expect(component.html()).toContain(
47+
"https://res.cloudinary.com/demo/video/upload/sample.webm?_a="
48+
);
49+
expect(component.html()).toContain(
50+
"https://res.cloudinary.com/demo/video/upload/sample.ogv?_a="
51+
);
52+
expect(component.html()).toContain(
53+
"https://res.cloudinary.com/demo/video/upload/sample.mp4?_a="
54+
);
55+
});
56+
57+
it("should render video with input sources", async function () {
58+
const sources = [
59+
{
60+
type: "mp4",
61+
codecs: ["vp8", "vorbis"],
62+
transcode: videoCodec(auto()),
63+
},
64+
{
65+
type: "webm",
66+
codecs: ["avc1.4D401E", "mp4a.40.2"],
67+
transcode: videoCodec(vp9()),
68+
},
69+
];
70+
71+
const component = mount(AdvancedVideo, {
72+
props: { cldVid: cloudinaryVideo, sources },
73+
});
74+
await waitTicks(1);
75+
76+
expect(component.html()).toContain(
77+
"<video>\n" +
78+
' <source src="https://res.cloudinary.com/demo/video/upload/vc_auto/sample.mp4" type="video/mp4; codecs=vp8, vorbis">\n' +
79+
' <source src="https://res.cloudinary.com/demo/video/upload/vc_vp9/sample.webm" type="video/webm; codecs=avc1.4D401E, mp4a.40.2">\n</video>'
80+
);
81+
});
82+
83+
it("should pass video attributes", async function () {
84+
const component = mount(AdvancedVideo, {
85+
props: {
86+
cldVid: cloudinaryVideo,
87+
controls: true,
88+
autoplay: true,
89+
playsInline: false,
90+
loop: true,
91+
// muted: true,
92+
},
93+
});
94+
await waitTicks(1);
95+
96+
expect(component.html()).toContain('loop=""');
97+
expect(component.html()).not.toContain("playsinline");
98+
expect(component.html()).toContain('autoplay=""');
99+
expect(component.html()).toContain('controls=""');
100+
// TODO: There are some issues with muted attribute in Vue
101+
// expect(component.html()).toContain('muted=""');
102+
});
103+
104+
it("should contain poster", async function () {
105+
const component = mount(AdvancedVideo, {
106+
props: { cldVid: cloudinaryVideo, poster: "www.example.com" },
107+
});
108+
await waitTicks(1);
109+
110+
expect(component.html()).toContain('poster="www.example.com"');
111+
});
112+
113+
it("should emit play event", async function () {
114+
const mockCallback = jest.fn();
115+
116+
const component = mount(AdvancedVideo, {
117+
props: { cldVid: cloudinaryVideo, play: mockCallback },
118+
});
119+
await waitTicks(1);
120+
121+
component.trigger("play");
122+
await waitTicks(1);
123+
124+
expect(component.emitted().play).toBeTruthy();
125+
// TODO: This assertion should be enabled
126+
// expect(mockCallback).toHaveBeenCalledTimes(1);
127+
});
128+
129+
it("should emit loadStart event", async function () {
130+
const mockCallback = jest.fn();
131+
132+
const component = mount(AdvancedVideo, {
133+
props: { cldVid: cloudinaryVideo, loadStart: mockCallback },
134+
});
135+
await waitTicks(1);
136+
137+
component.trigger("loadstart");
138+
await waitTicks(1);
139+
140+
expect(component.emitted().loadstart).toBeTruthy();
141+
// TODO: This assertion should be enabled
142+
// expect(mockCallback).toHaveBeenCalledTimes(1);
143+
});
144+
145+
it("should emit ended event", async function () {
146+
const mockCallback = jest.fn();
147+
148+
const component = mount(AdvancedVideo, {
149+
props: { cldVid: cloudinaryVideo, ended: mockCallback },
150+
});
151+
await waitTicks(1);
152+
153+
component.trigger("ended");
154+
await waitTicks(1);
155+
156+
expect(component.emitted().ended).toBeTruthy();
157+
// TODO: This assertion should be enabled
158+
// expect(mockCallback).toHaveBeenCalledTimes(1);
159+
});
160+
161+
it("should emit error event", async function () {
162+
const mockCallback = jest.fn();
163+
164+
const component = mount(AdvancedVideo, {
165+
props: { cldVid: cloudinaryVideo, error: mockCallback },
166+
});
167+
await waitTicks(1);
168+
169+
component.trigger("error");
170+
await waitTicks(1);
171+
172+
expect(component.emitted().error).toBeTruthy();
173+
// TODO: This assertion should be enabled
174+
// expect(mockCallback).toHaveBeenCalledTimes(1);
175+
});
176+
177+
it("should emit playing event", async function () {
178+
const mockCallback = jest.fn();
179+
180+
const component = mount(AdvancedVideo, {
181+
props: { cldVid: cloudinaryVideo, playing: mockCallback },
182+
});
183+
await waitTicks(1);
184+
185+
component.trigger("playing");
186+
await waitTicks(1);
187+
188+
expect(component.emitted().playing).toBeTruthy();
189+
// TODO: This assertion should be enabled
190+
// expect(mockCallback).toHaveBeenCalledTimes(1);
191+
});
192+
});

0 commit comments

Comments
 (0)