Skip to content

Commit 5177999

Browse files
author
Nir Maoz
authored
test: add vue3 accessibility tests (#156)
1 parent 3789da1 commit 5177999

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { AdvancedImage, accessibility } from "../../src/index";
2+
import { CloudinaryImage } from "@cloudinary/url-gen/assets/CloudinaryImage";
3+
import { mount } from "@vue/test-utils";
4+
import { waitTicks } from "./utils";
5+
6+
const cloudinaryImage = new CloudinaryImage(
7+
"sample",
8+
{ cloudName: "demo" },
9+
{ analytics: false }
10+
);
11+
12+
describe("accessibility", () => {
13+
it("should apply default", async () => {
14+
const component = mount(AdvancedImage, {
15+
props: { cldImg: cloudinaryImage, plugins: [accessibility()] },
16+
});
17+
18+
// wait because plugin action takes time
19+
await waitTicks(2);
20+
21+
expect(component.html()).toContain(
22+
'src="https://res.cloudinary.com/demo/image/upload/co_black,e_colorize:70/sample"'
23+
);
24+
});
25+
26+
it("should apply darkmode", async () => {
27+
const component = mount(AdvancedImage, {
28+
props: {
29+
cldImg: cloudinaryImage,
30+
plugins: [accessibility({ mode: "darkmode" })],
31+
},
32+
});
33+
await waitTicks(2);
34+
expect(component.html()).toContain(
35+
'src="https://res.cloudinary.com/demo/image/upload/co_black,e_colorize:70/sample"'
36+
);
37+
});
38+
39+
it("should apply brightmode", async () => {
40+
const component = mount(AdvancedImage, {
41+
props: {
42+
cldImg: cloudinaryImage,
43+
plugins: [accessibility({ mode: "brightmode" })],
44+
},
45+
});
46+
await waitTicks(2);
47+
expect(component.html()).toContain(
48+
'src="https://res.cloudinary.com/demo/image/upload/co_white,e_colorize:40/sample"'
49+
);
50+
});
51+
52+
it("should apply monochrome", async () => {
53+
const component = mount(AdvancedImage, {
54+
props: {
55+
cldImg: cloudinaryImage,
56+
plugins: [accessibility({ mode: "monochrome" })],
57+
},
58+
});
59+
await waitTicks(2);
60+
expect(component.html()).toContain(
61+
'src="https://res.cloudinary.com/demo/image/upload/e_grayscale/sample"'
62+
);
63+
});
64+
65+
it("should apply colorblind", async () => {
66+
const component = mount(AdvancedImage, {
67+
props: {
68+
cldImg: cloudinaryImage,
69+
plugins: [accessibility({ mode: "colorblind" })],
70+
},
71+
});
72+
await waitTicks(2);
73+
expect(component.html()).toContain(
74+
'src="https://res.cloudinary.com/demo/image/upload/e_assist_colorblind/sample"'
75+
);
76+
});
77+
78+
it("should default if supplied with incorrect mode", async () => {
79+
const component = mount(AdvancedImage, {
80+
props: {
81+
cldImg: cloudinaryImage,
82+
plugins: [accessibility({ mode: "ddd" })],
83+
},
84+
});
85+
await waitTicks(2);
86+
expect(component.html()).toBe(
87+
'<img src="https://res.cloudinary.com/demo/image/upload/co_black,e_colorize:70/sample">'
88+
);
89+
});
90+
});

packages/vue3/tests/unit/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { nextTick } from "vue";
2+
3+
/**
4+
* Wait number of ticks
5+
* @param ticks
6+
*/
7+
export const waitTicks = async (ticks: number) => {
8+
for (let i = 0; i < ticks; i++) {
9+
await nextTick();
10+
}
11+
};

0 commit comments

Comments
 (0)