Skip to content

Commit cba9667

Browse files
committed
Add primitive components' basic tests
1 parent 143608c commit cba9667

File tree

38 files changed

+486
-47
lines changed

38 files changed

+486
-47
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import Avatar from './Avatar.vue'
3+
4+
let wrapper
5+
6+
describe('Avatar', () => {
7+
beforeEach(() => {
8+
wrapper = shallowMount(Avatar)
9+
})
10+
11+
it('is called', () => {
12+
expect(wrapper.exists()).toBeTruthy()
13+
})
14+
15+
it('render correctly', () => {
16+
expect(wrapper.html()).toMatchSnapshot()
17+
})
18+
})

src/components/primitives/Avatar/Avatar.vue

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,69 @@
33
import { onBeforeMount, ref } from 'vue'
44
55
export default {
6-
name: 'VAvatar',
7-
props: {
8-
alt: String ,
9-
size: {
10-
type: String,
11-
default: "is-64x64"
12-
},
13-
rounded: {
14-
type: Boolean,
15-
default: true
16-
},
17-
background: {
18-
type: String,
19-
default: 'has-background-link'
20-
},
21-
text: {
22-
type: String,
23-
default: 'has-text-white'
24-
},
25-
src: {
26-
type: String,
27-
default: null
28-
},
29-
dataSrc: {
30-
type: String,
31-
default: null
32-
},
33-
customClass: String
6+
name: 'VAvatar',
7+
props: {
8+
alt: String,
9+
size: {
10+
type: String,
11+
default: 'is-64x64',
3412
},
35-
setup(props){
36-
const source = ref(props.src || props.dataSrc)
37-
const background = ref(props.background)
38-
const text = ref(props.text)
39-
const alt = ref(props.alt)
13+
rounded: {
14+
type: Boolean,
15+
default: true,
16+
},
17+
background: {
18+
type: String,
19+
default: 'has-background-link',
20+
},
21+
text: {
22+
type: String,
23+
default: 'has-text-white',
24+
},
25+
src: {
26+
type: String,
27+
default: null,
28+
},
29+
dataSrc: {
30+
type: String,
31+
default: null,
32+
},
33+
customClass: String,
34+
},
35+
setup(props) {
36+
const source = ref(props.src || props.dataSrc)
37+
const background = ref(props.background)
38+
const text = ref(props.text)
39+
const alt = ref(props.alt)
4040
41-
onBeforeMount(async() => {
42-
if (props.dataSrc && hasBenchieSupport) {
43-
source.value = await t(props.dataSrc, $__CDN)
44-
}
45-
})
41+
onBeforeMount(async () => {
42+
if (props.dataSrc && hasBenchieSupport) {
43+
source.value = await t(props.dataSrc, $__CDN)
44+
}
45+
})
4646
47-
const backgroundColor = source.value ? '' : background.value
47+
const backgroundColor = source.value ? '' : background.value
4848
49-
const textColor = source.value ? '' : text.value
49+
const textColor = source.value ? '' : text.value
5050
51-
const caption = alt.value.split(" ")[0][0] + alt.value.split(" ")[1][0]
51+
const caption = alt.value ? alt.value.split(' ')[0][0] + alt.value.split(' ')[1][0] : ""
5252
53-
return { source, backgroundColor, textColor, caption }
54-
}
53+
return { source, backgroundColor, textColor, caption }
54+
},
5555
}
5656
</script>
5757

5858
<template>
59-
<figure class="image is-flex is-justify-content-center is-align-items-center mx-1" :class="[size, backgroundColor, textColor]">
60-
<img :src="source" :data-src="dataSrc" :alt="alt" v-if="source" :class="[customClass, {'is-rounded': rounded }]" />
61-
<span class="is-size-4" v-if="!source" :class="[{'is-rounded': rounded }]">
59+
<figure
60+
class="image is-flex is-justify-content-center is-align-items-center mx-1"
61+
:class="[size, backgroundColor, textColor]">
62+
<img
63+
:src="source"
64+
:data-src="dataSrc"
65+
:alt="alt"
66+
v-if="source"
67+
:class="[customClass, { 'is-rounded': rounded }]" />
68+
<span class="is-size-4" v-if="!source" :class="[{ 'is-rounded': rounded }]">
6269
{{ caption }}
6370
</span>
6471
</figure>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Avatar render correctly 1`] = `
4+
<figure class="image is-flex is-justify-content-center is-align-items-center mx-1 is-64x64 has-background-link has-text-white">
5+
<!--v-if--><span class="is-size-4 is-rounded"></span>
6+
</figure>
7+
`;

src/components/primitives/Button/__snapshots__/Button.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ exports[`Button render correctly 1`] = `
44
<button class="button is-primary" type="button">
55
<!--v-if-->
66
</button>
7-
`;
7+
`;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import Checkbox from './Checkbox.vue'
3+
4+
let wrapper
5+
6+
describe('Checkbox', () => {
7+
beforeEach(() => {
8+
wrapper = shallowMount(Checkbox)
9+
})
10+
11+
it('is called', () => {
12+
expect(wrapper.exists()).toBeTruthy()
13+
})
14+
15+
it('render correctly', () => {
16+
expect(wrapper.html()).toMatchSnapshot()
17+
})
18+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Checkbox render correctly 1`] = `<label class="v-checkbox checkbox"><input type="checkbox" true-value="true" false-value="false"><span class="check"></span><span class="control-label"></span></label>`;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import Field from './Field.vue'
3+
4+
let wrapper
5+
6+
describe('Field', () => {
7+
beforeEach(() => {
8+
wrapper = shallowMount(Field)
9+
})
10+
11+
it('is called', () => {
12+
expect(wrapper.exists()).toBeTruthy()
13+
})
14+
15+
it('render correctly', () => {
16+
expect(wrapper.html()).toMatchSnapshot()
17+
})
18+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Field render correctly 1`] = `
4+
<div class="field">
5+
<!--v-if-->
6+
<!--v-if-->
7+
</div>
8+
`;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import Icon from './Icon.vue'
3+
4+
let wrapper
5+
6+
describe('Icon', () => {
7+
beforeEach(() => {
8+
wrapper = shallowMount(Icon)
9+
})
10+
11+
it('is called', () => {
12+
expect(wrapper.exists()).toBeTruthy()
13+
})
14+
15+
it('render correctly', () => {
16+
expect(wrapper.html()).toMatchSnapshot()
17+
})
18+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Icon render correctly 1`] = `<span class="icon"><svg height="100%" width="100%" class=""><use href="/undefined.svg#undefined"></use></svg></span>`;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
// eslint-disable-next-line no-shadow -- ignore warning
3+
import Image from './Image.vue'
4+
5+
let wrapper
6+
7+
describe('Image', () => {
8+
beforeEach(() => {
9+
wrapper = shallowMount(Image)
10+
})
11+
12+
it('is called', () => {
13+
expect(wrapper.exists()).toBeTruthy()
14+
})
15+
16+
it('render correctly', () => {
17+
expect(wrapper.html()).toMatchSnapshot()
18+
})
19+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Image render correctly 1`] = `<figure class="image"><img class="img"></figure>`;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import Input from './Input.vue'
3+
4+
let wrapper
5+
6+
describe('Input', () => {
7+
beforeEach(() => {
8+
wrapper = shallowMount(Input)
9+
})
10+
11+
it('is called', () => {
12+
expect(wrapper.exists()).toBeTruthy()
13+
})
14+
15+
it('render correctly', () => {
16+
expect(wrapper.html()).toMatchSnapshot()
17+
})
18+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Input render correctly 1`] = `
4+
<div class="control"><input class="input">
5+
<!--v-if-->
6+
<!--v-if-->
7+
</div>
8+
`;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import Media from './Media.vue'
3+
4+
let wrapper
5+
6+
describe('Media', () => {
7+
beforeEach(() => {
8+
wrapper = shallowMount(Media)
9+
})
10+
11+
it('is called', () => {
12+
expect(wrapper.exists()).toBeTruthy()
13+
})
14+
15+
it('render correctly', () => {
16+
expect(wrapper.html()).toMatchSnapshot()
17+
})
18+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Media render correctly 1`] = `
4+
<article class="media">
5+
<div class="media-left"></div>
6+
<div class="media-content"></div>
7+
<div class="media-right"></div>
8+
</article>
9+
`;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import Modal from './Modal.vue'
3+
4+
let wrapper
5+
6+
describe('Modal', () => {
7+
beforeEach(() => {
8+
wrapper = shallowMount(Modal)
9+
})
10+
11+
it('is called', () => {
12+
expect(wrapper.exists()).toBeTruthy()
13+
})
14+
15+
it('render correctly', () => {
16+
expect(wrapper.html()).toMatchSnapshot()
17+
})
18+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Modal render correctly 1`] = `
4+
<div class="modal">
5+
<div class="modal-background"></div>
6+
<div class="modal-content"></div><button class="modal-close" aria-label="close"></button>
7+
</div>
8+
`;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import Progress from './Progress.vue'
3+
4+
let wrapper
5+
6+
describe('Progress', () => {
7+
beforeEach(() => {
8+
wrapper = shallowMount(Progress)
9+
})
10+
11+
it('is called', () => {
12+
expect(wrapper.exists()).toBeTruthy()
13+
})
14+
15+
it('render correctly', () => {
16+
expect(wrapper.html()).toMatchSnapshot()
17+
})
18+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Progress render correctly 1`] = `
4+
<div class="progress-wrapper"><progress class="progress is-darkgrey" max="100"></progress>
5+
<!--v-if-->
6+
</div>
7+
`;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import Select from './Select.vue'
3+
4+
let wrapper
5+
6+
describe('Select', () => {
7+
beforeEach(() => {
8+
wrapper = shallowMount(Select)
9+
})
10+
11+
it('is called', () => {
12+
expect(wrapper.exists()).toBeTruthy()
13+
})
14+
15+
it('render correctly', () => {
16+
expect(wrapper.html()).toMatchSnapshot()
17+
})
18+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Select render correctly 1`] = `<div class="control"><span class="select"><select><!--v-if--></select></span></div>`;

0 commit comments

Comments
 (0)