Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit 4727f3a

Browse files
authored
fix(image-list): linting files (#464)
* fix(image-list): linting files docs(image-list): update test(image-list): add snapshots * test(image-list): add snapshots
1 parent 512827d commit 4727f3a

File tree

5 files changed

+130
-18
lines changed

5 files changed

+130
-18
lines changed

components/image-list/ImageList.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ export default {
2626
},
2727
computed: {
2828
classes () {
29-
let standard = {}
29+
const standard = {}
3030
if (this.column > 0 && !this.masonry) {
3131
standard['image-list-standard-' + this.column] = true
3232
}
3333
34-
let masonry = {}
34+
const masonry = {}
3535
if (this.column > 0 && this.masonry) {
3636
masonry['image-list-masonry-' + this.column] = true
3737
masonry['mdc-image-list--masonry'] = true
3838
}
3939
40-
let others = {}
40+
const others = {}
4141
others['mdc-image-list--with-text-protection'] = this.textProtection
4242
4343
return { ...standard, ...masonry, ...others }

components/image-list/ImageListItem.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
name="image"
1212
/>
1313
<div
14-
v-if="$slots['default']"
14+
v-if="$slots.default"
1515
class="mdc-image-list__supporting"
1616
>
1717
<span class="mdc-image-list__label">
@@ -48,8 +48,8 @@ export default {
4848
methods: {
4949
updateSlot () {
5050
if (this.$slots.image) {
51-
this.$slots.image.map(n => {
52-
n.elm.classList.add('mdc-image-list__image')
51+
this.$slots.image.forEach(n => {
52+
if (n.elm instanceof Element) n.elm.classList.add('mdc-image-list__image')
5353
})
5454
}
5555
}

components/image-list/README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
## ImageList
1+
## Image List
22

33
### Markup
44

55
```html
66
<m-image-list
7-
:standardColumn="2"
8-
textProtection>
7+
:column="2"
8+
text-protection>
99
<m-image-list-item>
10-
<img slot="image" src="../assets/images/cat.jpg">
10+
<img slot="image" src="../assets/images/cat.jpg" alt="Cat">
1111
Cat
1212
</m-image-list-item>
1313
<m-image-list-item>
14-
<img slot="image" src="../assets/images/cat.jpg">
14+
<img slot="image" src="../assets/images/cat.jpg" alt="Cat">
1515
Cat
1616
</m-image-list-item>
1717
<m-image-list-item>
18-
<img slot="image" src="../assets/images/cat.jpg">
18+
<img slot="image" src="../assets/images/cat.jpg" alt="Cat">
1919
Cat
2020
</m-image-list-item>
2121
<m-image-list-item>
22-
<img slot="image" src="../assets/images/cat.jpg">
22+
<img slot="image" src="../assets/images/cat.jpg" alt="Cat">
2323
Cat
2424
</m-image-list-item>
2525
</m-image-list>
@@ -30,17 +30,17 @@
3030

3131
| Prop | Type | Default | Description |
3232
|------|------|---------|-------------|
33-
| standardColumn | Number | - | standard columns per line |
34-
| masonryColumn | Number | - | masonry columns per line |
33+
| column | Number | 0 | columns per line, `0` means not to shrink or grow |
34+
| masonry | Boolean | false | masonry if `true`, standard if `false` |
3535
| textProtection | Boolean | false | label will be positioned in a scrim overlaying each image |
3636

3737
### Slots
3838

3939
| Slot | Description |
4040
|------|-------------|
41-
| default | should be ImageListItem(s) |
41+
| default | should be `<m-image-list-item>` |
4242

43-
## ImageListItem
43+
## Image List Item
4444

4545
### Props
4646

@@ -50,7 +50,7 @@
5050

5151
### Slots
5252

53-
| Slot |Description |
53+
| Slot | Description |
5454
|------|-------------|
5555
| default | image label |
5656
| image | img element |
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import 'mutationobserver-shim'
2+
import { mount } from '@vue/test-utils'
3+
import ImageList from '../ImageList.vue'
4+
import ImageListItem from '../ImageListItem'
5+
6+
describe('ImageList', () => {
7+
it('should mount', () => {
8+
const wrapper = mount(ImageList)
9+
expect(wrapper.isVueInstance()).toBeTruthy()
10+
})
11+
12+
it('should render with no prop', () => {
13+
const wrapper = mount(ImageList)
14+
expect(wrapper).toMatchSnapshot()
15+
expect(wrapper.classes()).toContain('mdc-image-list')
16+
})
17+
18+
it('should render as standard', () => {
19+
const wrapper = mount(ImageList, {
20+
propsData: {
21+
column: 1
22+
}
23+
})
24+
expect(wrapper).toMatchSnapshot()
25+
expect(wrapper.classes()).toContain('image-list-standard-1')
26+
})
27+
28+
it('should render as masonry', () => {
29+
const wrapper = mount(ImageList, {
30+
propsData: {
31+
masonry: true,
32+
column: 1
33+
}
34+
})
35+
expect(wrapper).toMatchSnapshot()
36+
expect(wrapper.classes()).toContain('mdc-image-list--masonry')
37+
expect(wrapper.classes()).toContain('image-list-masonry-1')
38+
})
39+
40+
it('should render with text-protection', () => {
41+
const wrapper = mount(ImageList, {
42+
propsData: {
43+
textProtection: true
44+
}
45+
})
46+
expect(wrapper).toMatchSnapshot()
47+
expect(wrapper.classes()).toContain('mdc-image-list--with-text-protection')
48+
})
49+
})
50+
51+
describe('ImageListItem', () => {
52+
it('should mount', () => {
53+
const wrapper = mount(ImageListItem)
54+
expect(wrapper.isVueInstance()).toBeTruthy()
55+
})
56+
57+
it('should render with no prop', () => {
58+
const wrapper = mount(ImageListItem)
59+
expect(wrapper).toMatchSnapshot()
60+
expect(wrapper.classes()).toContain('mdc-image-list__item')
61+
expect(wrapper.vm.$data.slotObserver).toBeDefined()
62+
})
63+
64+
it('should render without adjust aspect ratio', () => {
65+
const wrapper = mount(ImageListItem, {
66+
propsData: {
67+
adjustAspectRatio: false
68+
}
69+
})
70+
expect(wrapper).toMatchSnapshot()
71+
expect(wrapper.find('.mdc-image-list__image-aspect-container').exists()).toBe(false)
72+
})
73+
74+
it('should render with img', () => {
75+
const wrapper = mount(ImageListItem, {
76+
slots: {
77+
image: '<img src="cat.jpg" alt="Cat">'
78+
}
79+
})
80+
expect(wrapper).toMatchSnapshot()
81+
expect(wrapper.find('.mdc-image-list__image').is('img')).toBe(true)
82+
})
83+
})
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ImageList should render as masonry 1`] = `<ul class="mdc-image-list image-list-masonry-1 mdc-image-list--masonry"></ul>`;
4+
5+
exports[`ImageList should render as standard 1`] = `<ul class="mdc-image-list image-list-standard-1"></ul>`;
6+
7+
exports[`ImageList should render with no prop 1`] = `<ul class="mdc-image-list"></ul>`;
8+
9+
exports[`ImageList should render with text-protection 1`] = `<ul class="mdc-image-list mdc-image-list--with-text-protection"></ul>`;
10+
11+
exports[`ImageListItem should render with img 1`] = `
12+
<li class="mdc-image-list__item">
13+
<div class="mdc-image-list__image-aspect-container"><img src="cat.jpg" alt="Cat" class="mdc-image-list__image"></div>
14+
<!---->
15+
</li>
16+
`;
17+
18+
exports[`ImageListItem should render with no prop 1`] = `
19+
<li class="mdc-image-list__item">
20+
<div class="mdc-image-list__image-aspect-container"></div>
21+
<!---->
22+
</li>
23+
`;
24+
25+
exports[`ImageListItem should render without adjust aspect ratio 1`] = `
26+
<li class="mdc-image-list__item">
27+
<!---->
28+
</li>
29+
`;

0 commit comments

Comments
 (0)