Skip to content

Commit 78a2df9

Browse files
author
Etienne Laurent
committed
tests
1 parent 0ac6515 commit 78a2df9

2 files changed

Lines changed: 155 additions & 5 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% extends data.outerLayout %}
2+
3+
{% block main %}
4+
<title>{{ data.page.title }}</title>
5+
6+
<h3>rich-text-image-page</h3>
7+
{% area data.page, 'main' %}
8+
{% endblock %}

test/rich-text-widget.js

Lines changed: 147 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,52 @@ describe('Rich Text Widget', function () {
55
let apos;
66
this.timeout(t.timeout);
77

8+
before(async function () {
9+
apos = await t.create({
10+
root: module,
11+
modules: {
12+
'@apostrophecms/page': {
13+
options: {
14+
park: [
15+
{
16+
title: 'Test Page',
17+
type: 'rich-text-image-page',
18+
slug: '/rich-text-image-page',
19+
parkedId: 'rich-text-image-page'
20+
}
21+
],
22+
types: [
23+
{
24+
name: 'rich-text-image-page',
25+
label: 'Rich Text Image Page'
26+
}
27+
]
28+
}
29+
},
30+
'rich-text-image-page': {
31+
extend: '@apostrophecms/page-type',
32+
fields: {
33+
add: {
34+
main: {
35+
type: 'area',
36+
options: {
37+
widgets: {
38+
'@apostrophecms/rich-text': {}
39+
}
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}
46+
});
47+
});
48+
849
after(function() {
950
return t.destroy(apos);
1051
});
1152

1253
it('should have rich text link types by default', async function () {
13-
apos = await t.create({
14-
root: module,
15-
modules: {}
16-
});
17-
1854
const richText = apos.modules['@apostrophecms/rich-text-widget'];
1955

2056
assert(richText.linkFields);
@@ -161,4 +197,110 @@ describe('Rich Text Widget', function () {
161197
assert.equal(attributes.a.includes('data-bool'), true);
162198
assert.equal(attributes.a.includes('data-single-choice'), true);
163199
});
200+
201+
it.only('should add images for testing', async function() {
202+
const req = apos.task.getReq();
203+
const base = apos.http.getBase();
204+
205+
// add image with alt attribute:
206+
const image1 = await apos.image.insert(req, {
207+
_id: 'image-1:en:published',
208+
type: '@apostrophecms/image',
209+
slug: 'image-1',
210+
visibility: 'public',
211+
attachment: {
212+
_id: 'attachment-1',
213+
crop: null,
214+
group: 'images',
215+
name: 'attachment-1',
216+
title: 'Attachment 1',
217+
extension: 'jpg',
218+
type: 'attachment',
219+
archivedDocIds: [],
220+
length: 184317,
221+
md5: '816e2fe1190b7aa81ed26d8479e26181',
222+
width: 500,
223+
height: 400,
224+
landscape: true,
225+
used: true,
226+
utilized: true,
227+
archived: false
228+
},
229+
alt: 'Test Image 1'
230+
});
231+
232+
// add image without alt attribute:
233+
const image2 = await apos.image.insert(req, {
234+
_id: 'image-2:en:published',
235+
type: '@apostrophecms/image',
236+
slug: 'image-2',
237+
visibility: 'public',
238+
attachment: {
239+
_id: 'attachment-2',
240+
crop: null,
241+
group: 'images',
242+
name: 'attachment-2',
243+
title: 'Attachment 2',
244+
extension: 'jpg',
245+
type: 'attachment',
246+
archivedDocIds: [],
247+
length: 184317,
248+
md5: '816e2fe1190b7aa81ed26d8479e26182',
249+
width: 500,
250+
height: 400,
251+
landscape: true,
252+
used: true,
253+
utilized: true,
254+
archived: false
255+
}
256+
});
257+
258+
// update page with rich text widget containing images:
259+
260+
const page = await apos.page.find(req, { slug: '/rich-text-image-page' }).toObject();
261+
262+
page.main = {
263+
_id: 'area',
264+
metaType: 'area',
265+
items: [
266+
{
267+
_id: 'widget',
268+
metaType: 'widget',
269+
type: '@apostrophecms/rich-text',
270+
content: '<figure class="image-float-left"><img src="/api/v1/@apostrophecms/image/image-1/src" alt="Test Image 1"><figcaption></figcaption></figure><figure class="image-float-left"><img src="/api/v1/@apostrophecms/image/image-2/src" alt=""><figcaption></figcaption></figure>',
271+
imageIds: [ image1.aposDocId, image2.aposDocId ]
272+
}
273+
]
274+
};
275+
276+
await apos.page.update(req, page);
277+
278+
// assert that alt attributes are present in the rendered HTML:
279+
280+
const response1 = await fetch(`${base}/rich-text-image-page`, {
281+
method: 'GET'
282+
});
283+
const text1 = await response1.text();
284+
285+
assert(text1.includes('alt="Test Image 1"'));
286+
assert(text1.includes('alt=""'));
287+
288+
// update alt attributes:
289+
290+
image1.alt = 'Updated Test Image 1';
291+
image2.alt = 'Updated Test Image 2';
292+
293+
await apos.image.update(req, image1);
294+
await apos.image.update(req, image2);
295+
296+
// re-fetch the page to check if the updated alt attributes are present:
297+
298+
const response2 = await fetch(`${base}/rich-text-image-page`, {
299+
method: 'GET'
300+
});
301+
const text2 = await response2.text();
302+
303+
assert(text2.includes('alt="Updated Test Image 1"'));
304+
assert(text2.includes('alt="Updated Test Image 2"'));
305+
});
164306
});

0 commit comments

Comments
 (0)