-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathimages.spec.ts
More file actions
163 lines (161 loc) · 3.93 KB
/
images.spec.ts
File metadata and controls
163 lines (161 loc) · 3.93 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { describe, expect, test } from 'vitest';
import { VFile } from 'vfile';
import { imageNoAltTextTransform } from './images.js';
describe('Test imageNoAltTextTransform', () => {
test('image without alt text generates warning', () => {
const mdast = {
type: 'root',
children: [
{
type: 'image',
url: 'https://images.com/cats',
align: 'center',
},
],
};
const file = new VFile();
imageNoAltTextTransform(mdast, file);
expect(mdast).toEqual({
type: 'root',
children: [
{
type: 'image',
url: 'https://images.com/cats',
align: 'center',
},
],
});
// A warning was created
expect(file.messages.length).toBe(1);
expect(file.messages[0].message.includes('missing alt text')).toBe(true);
});
test('image without alt text does not generate a warning', () => {
const mdast = {
type: 'root',
children: [
{
type: 'image',
url: 'https://images.com/cats',
alt: 'I have alt text',
align: 'center',
},
],
};
const file = new VFile();
imageNoAltTextTransform(mdast, file);
expect(mdast).toEqual({
type: 'root',
children: [
{
type: 'image',
url: 'https://images.com/cats',
alt: 'I have alt text',
align: 'center',
},
],
});
// A warning was created
expect(file.messages.length).toBe(0);
});
test('image inside captioned figure warns about generated alt text', () => {
const mdast = {
type: 'container',
kind: 'figure',
children: [
{
type: 'image',
url: 'https://images.com/cats',
alt: 'I don’t have alt text, but I do have a caption',
data: {
altTextIsAutoGenerated: true,
},
},
{
type: 'caption',
children: [
{
type: 'paragraph',
children: [
{
type: 'text',
value: 'I don’t have alt text, but I do have a caption',
},
],
},
],
},
],
enumerator: '1',
};
const file = new VFile();
imageNoAltTextTransform(mdast, file);
expect(mdast).toEqual({
type: 'container',
kind: 'figure',
children: [
{
type: 'image',
url: 'https://images.com/cats',
alt: 'I don’t have alt text, but I do have a caption',
data: {
altTextIsAutoGenerated: true,
},
},
{
type: 'caption',
children: [
{
type: 'paragraph',
children: [
{
type: 'text',
value: 'I don’t have alt text, but I do have a caption',
},
],
},
],
},
],
enumerator: '1',
});
// A warning was created
expect(file.messages.length).toBe(1);
expect(file.messages[0].message.includes('was auto-generated')).toBe(true);
});
test('image inside output does not generate warning', () => {
const mdast = {
type: 'root',
children: [
{
type: 'output',
children: [
{
type: 'image',
url: 'https://images.com/cats',
align: 'center',
},
],
},
],
};
const file = new VFile();
imageNoAltTextTransform(mdast, file);
expect(mdast).toEqual({
type: 'root',
children: [
{
type: 'output',
children: [
{
type: 'image',
url: 'https://images.com/cats',
align: 'center',
},
],
},
],
});
// A warning was created
expect(file.messages.length).toBe(0);
});
});