Newer
Older
import { describe, expect, it } from 'vitest'
import { mount } from '@vue/test-utils'
import { createPinia } from 'pinia'
import { createApp } from 'vue'
import ModalEditAvatar from '@/components/ModalEditAvatar.vue'
const pinia = createPinia()
const app = createApp({
setup() {
app.use(pinia)
},
})
const wrapper = mount(ModalEditAvatar, {
global: {
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
})
describe('ModalEditAvatar', () => {
it('renders properly when modal is closed', async () => {
const wrapper = mount(ModalEditAvatar)
expect(wrapper.find('.fixed').exists()).toBe(false)
})
it('opens modal when button is clicked', async () => {
const wrapper = mount(ModalEditAvatar)
await wrapper.find('button').trigger('click')
expect(wrapper.find('.fixed').exists()).toBe(true)
})
it('closes modal when close button is clicked', async () => {
const wrapper = mount(ModalEditAvatar)
await wrapper.find('button').trigger('click')
expect(wrapper.find('.fixed').exists()).toBe(true)
await wrapper.find('.bg-white button').trigger('click')
expect(wrapper.find('.fixed').exists()).toBe(false)
})
it('cycles avatars to the next one when next button is clicked', async () => {
const wrapper = mount(ModalEditAvatar)
await wrapper.find('button').trigger('click')
const currentAvatarSrc = wrapper.find('.avatar').attributes('src')
await wrapper.find('.avatar-container button:last-child').trigger('click')
const newAvatarSrc = wrapper.find('.avatar').attributes('src')
expect(newAvatarSrc).not.toBe(currentAvatarSrc)
})
it('cycles avatars to the previous one when previous button is clicked', async () => {
const wrapper = mount(ModalEditAvatar)
await wrapper.find('button').trigger('click')
await wrapper.find('.avatar-container button:last-child').trigger('click')
const currentAvatarSrc = wrapper.find('.avatar').attributes('src')
await wrapper.find('.avatar-container button:first-child').trigger('click')
const newAvatarSrc = wrapper.find('.avatar').attributes('src')
expect(newAvatarSrc).not.toBe(currentAvatarSrc)
})
})