Skip to content

Commit e2eb95c

Browse files
Merge pull request #133 from cah-danmonroe/esulisttests
Added tests for es-ulist - issue #109
2 parents 9a8f537 + d7650f2 commit e2eb95c

File tree

2 files changed

+126
-17
lines changed

2 files changed

+126
-17
lines changed

addon/templates/components/es-ulist.hbs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
<div class="list-title {{if isTitleVisible sr-only}}" id={{listId}}>{{listTitle}}</div>
22

33
{{#if isUnorderedList}}
4-
<ul aria-labelledby={{listId}} class="list list-default">
4+
<ul
5+
aria-labelledby={{listId}}
6+
class="list list-default"
7+
>
58
{{#each listItems as |item|}}
69
<li class="list-item">
7-
{{#if hasLink}}
10+
{{#if item.link}}
811
<a href={{item.link}} class="list-item-link">
9-
{{#if hasImage}}
12+
{{#if item.image}}
1013
<img src={{item.image}} class="list-item-image" alt={{item.alt}}>
1114
{{/if}}
1215
{{item.text}}
1316
</a>
1417
{{else}}
15-
{{#if hasImage}}
18+
{{#if item.image}}
1619
<img src={{item.image}} class="list-item-image" alt={{item.alt}}>
1720
{{/if}}
1821
{{item.text}}
Lines changed: 119 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,140 @@
11
import { render } from '@ember/test-helpers';
2-
import { module, skip, test } from 'qunit';
2+
import { module, test } from 'qunit';
33
import { setupRenderingTest } from 'ember-qunit';
44
import hbs from 'htmlbars-inline-precompile';
55

66
module('Integration | Component | es ulist', function(hooks){
77
setupRenderingTest(hooks);
88

9-
test('it renders', async function(assert) {
9+
test('it renders with border', async function(assert) {
1010

11-
// Set any properties with this.set('myProperty', 'value');
12-
// Handle any actions with this.on('myAction', function(val) { ... });
11+
await render(hbs`{{es-ulist hasBorder=true}}`);
1312

14-
await render(hbs`{{es-ulist}}`);
13+
assert.dom('.es-ulist').hasClass('bordered');
1514

16-
assert.dom('*').hasText('');
1715
});
1816

19-
skip('the list is populated', function(){
17+
module('Title', function () {
18+
test('it renders the title with correct id', async function(assert) {
19+
assert.expect(2);
2020

21-
});
21+
await render(hbs`{{es-ulist elementId="mylist" listTitle="My List Title"}}`);
2222

23-
skip('a list with images renders the images correctly', function(){
23+
assert.dom('#mylist').hasText('My List Title');
24+
assert.dom('.es-ulist').doesNotHaveClass('bordered');
25+
});
2426

25-
});
27+
test('it renders the title with sr-only class when isTitleVisible is true', async function(assert) {
28+
assert.expect(2);
2629

27-
skip('the id value of the list title matches the value in the aria-describedby property on the list element', function(){
30+
await render(hbs`{{es-ulist isTitleVisible=true sr-only="srClass" elementId="mylist" listTitle="My List Title"}}`);
2831

29-
});
32+
assert.dom('#list-mylist').hasClass('list-title');
33+
assert.dom('#list-mylist').hasClass('srClass');
34+
});
35+
36+
test('it renders the title without sr-only class when isTitleVisible is false', async function(assert) {
37+
assert.expect(2);
3038

31-
skip('when hasLink is set to true, a link element renders', function(){
39+
await render(hbs`{{es-ulist isTitleVisible=false sr-only="srClass" elementId="mylist" listTitle="My List Title"}}`);
40+
41+
assert.dom('#list-mylist').hasClass('list-title');
42+
assert.dom('#list-mylist').doesNotHaveClass('srClass');
43+
});
3244

3345
});
46+
47+
module('List', function () {
48+
module('Ordered List', function () {
49+
50+
test('the list does not have unorderded items', async function(assert){
51+
assert.expect(1);
52+
53+
await render(hbs`{{es-ulist isUnorderedList=false}}`);
54+
55+
assert.dom('.es-ulist ul').doesNotExist();
56+
});
57+
58+
});
59+
module('Unordered List', function () {
60+
61+
test('the id value of the list title matches the value in the aria-labelledby property on the list element', async function(assert){
62+
assert.expect(2);
63+
64+
await render(hbs`{{es-ulist elementId='mylist' isUnorderedList=true}}`);
65+
66+
assert.dom('.es-ulist ul').hasAttribute('aria-labelledby', 'list-mylist');
67+
assert.dom('.list-title').hasAttribute('id', 'list-mylist');
68+
69+
});
70+
71+
test('the list does not have ordered items', async function(assert){
72+
assert.expect(1);
73+
74+
await render(hbs`{{es-ulist isUnorderedList=false}}`);
75+
76+
assert.dom('.es-ulist ol').doesNotExist();
77+
});
78+
79+
module('With items', function (hooks) {
80+
let listItems;
81+
hooks.beforeEach(function () {
82+
listItems = [
83+
{
84+
text: 'item 1',
85+
image: '/images/tomsters/columbus.png',
86+
alt: 'Columbus'
87+
},
88+
{
89+
text: 'item 2',
90+
link: 'http://emberjs.com'
91+
},
92+
{
93+
text: 'item 3',
94+
link: 'http://guides.emberjs.com',
95+
image: '/images/tomsters/chicago.png',
96+
alt: 'Chicago'
97+
},
98+
]
99+
this.set('listItems', listItems);
100+
});
101+
102+
test('the list has correct aria label and classes', async function(assert){
103+
assert.expect(3);
104+
105+
await render(hbs`{{es-ulist elementId='mylist' isUnorderedList=true}}`);
106+
107+
assert.dom('.es-ulist ul').hasAttribute('aria-labelledby', 'list-mylist');
108+
assert.dom('.es-ulist ul').hasClass('list');
109+
assert.dom('.es-ulist ul').hasClass('list-default');
110+
111+
});
112+
113+
test('the list is populated', async function(assert){
114+
assert.expect(14);
115+
116+
await render(hbs`{{es-ulist isUnorderedList=true listItems=listItems}}`);
117+
118+
assert.dom('.es-ulist ul li').exists({count: 3});
119+
assert.dom('.es-ulist ul li:nth-child(1) img').hasAttribute('src', '/images/tomsters/columbus.png');
120+
assert.dom('.es-ulist ul li:nth-child(1) img').hasAttribute('alt', 'Columbus');
121+
assert.dom('.es-ulist ul li:nth-child(1) img').hasClass('list-item-image');
122+
assert.dom('.es-ulist ul li:nth-child(1)').hasText('item 1');
123+
124+
assert.dom('.es-ulist ul li:nth-child(2) a').hasAttribute('href', 'http://emberjs.com');
125+
assert.dom('.es-ulist ul li:nth-child(2) a').hasClass('list-item-link');
126+
assert.dom('.es-ulist ul li:nth-child(2)').hasText('item 2');
127+
128+
assert.dom('.es-ulist ul li:nth-child(3) a').hasAttribute('href', 'http://guides.emberjs.com');
129+
assert.dom('.es-ulist ul li:nth-child(3) img').hasAttribute('src', '/images/tomsters/chicago.png');
130+
assert.dom('.es-ulist ul li:nth-child(3) img').hasAttribute('alt', 'Chicago');
131+
assert.dom('.es-ulist ul li:nth-child(3) img').hasClass('list-item-image');
132+
assert.dom('.es-ulist ul li:nth-child(3) a').hasClass('list-item-link');
133+
assert.dom('.es-ulist ul li:nth-child(3)').hasText('item 3');
134+
135+
});
136+
});
137+
138+
});
139+
})
34140
});

0 commit comments

Comments
 (0)