PluginProbe ʕ •ᴥ•ʔ
Presto Player / trunk
Presto Player vtrunk
4.3.1 4.3.0 4.2.4 4.2.3 4.2.2 4.2.0 4.2.1 trunk 1.10.0 1.10.1 1.10.2 1.11.0 1.12.0 1.13.0 1.14.0 1.14.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.13 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3-beta1 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.0-beta1 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1.0 3.1.1 3.1.2 3.1.3 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4
presto-player / src / admin / dashboard / utils / test / transformers.spec.js
presto-player / src / admin / dashboard / utils / test Last commit date
classnames.spec.js 1 month ago dateUtils.spec.js 1 month ago formatters.spec.js 1 month ago pluginUtils.spec.js 1 month ago transformers.spec.js 1 month ago
transformers.spec.js
104 lines
1 import {
2 transformMediaItem,
3 transformUserItem,
4 } from "../transformers";
5
6 describe("transformers", () => {
7 describe("transformMediaItem", () => {
8 it("flattens the API shape into the component shape", () => {
9 const item = {
10 video: { id: 1, post_id: 100, title: "Hello" },
11 stats: [{ data: "42 views" }, { data: "1m 30s" }],
12 poster_image: "https://cdn/p.jpg",
13 };
14 expect(transformMediaItem(item)).toEqual({
15 id: 1,
16 postId: 100,
17 title: "Hello",
18 totalViews: "42",
19 avgViewTime: "1m 30s",
20 poster_image: "https://cdn/p.jpg",
21 });
22 });
23
24 it("strips commas from view counts in stats[0].data", () => {
25 const item = {
26 video: { id: 2, post_id: 2, title: "A" },
27 stats: [{ data: "1,234,567 views" }, { data: "0s" }],
28 };
29 expect(transformMediaItem(item).totalViews).toBe("1234567");
30 });
31
32 it("falls back to '0' views and '0s' avg when stats are missing", () => {
33 const item = { video: { id: 3, post_id: 3, title: "A" } };
34 const out = transformMediaItem(item);
35 expect(out.totalViews).toBe("0");
36 expect(out.avgViewTime).toBe("0s");
37 });
38
39 it("falls back to localized 'Untitled' when title is empty", () => {
40 const out = transformMediaItem({
41 video: { id: 4, post_id: 4, title: "" },
42 stats: [],
43 });
44 expect(out.title).toBe("Untitled");
45 });
46
47 it("decodes HTML entities in the title", () => {
48 const out = transformMediaItem({
49 video: { id: 5, post_id: 5, title: "John's & Co" },
50 stats: [],
51 });
52 expect(out.title).toBe("John's & Co");
53 });
54
55 it("defaults postId to null when video.post_id is absent", () => {
56 const out = transformMediaItem({
57 video: { id: 6, title: "x" },
58 stats: [],
59 });
60 expect(out.postId).toBeNull();
61 });
62
63 it("defaults poster_image to null when not provided", () => {
64 const out = transformMediaItem({
65 video: { id: 7, post_id: 7, title: "x" },
66 stats: [],
67 });
68 expect(out.poster_image).toBeNull();
69 });
70
71 it("returns '0' totalViews when stats[0].data has no digits", () => {
72 const item = {
73 video: { id: 8, post_id: 8, title: "x" },
74 stats: [{ data: "no number here" }, { data: "1s" }],
75 };
76 expect(transformMediaItem(item).totalViews).toBe("0");
77 });
78 });
79
80 describe("transformUserItem", () => {
81 it("flattens the API shape into the component shape", () => {
82 const item = {
83 user: { id: 11, name: "Ada Lovelace" },
84 stats: [{ data: "9 views" }, { data: "30s" }],
85 };
86 expect(transformUserItem(item)).toEqual({
87 id: 11,
88 name: "Ada Lovelace",
89 totalViews: "9",
90 avgViewTime: "30s",
91 });
92 });
93
94 it("falls back to localized 'Unknown User' when name is empty", () => {
95 const out = transformUserItem({
96 user: { id: 13, name: "" },
97 stats: [],
98 });
99 expect(out.name).toBe("Unknown User");
100 });
101
102 });
103 });
104