forked from Ivasoft/geovisio-website
Feat/add token page
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { it, describe, expect, vi } from 'vitest'
|
||||
import { it, describe, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { shallowMount, mount } from '@vue/test-utils'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import Terminal from '../../../components/Terminal.vue'
|
||||
import Button from '../../../components/Button.vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import fr from '../../../locales/fr.json'
|
||||
import { updateClipboard } from '../../../utils/copyToClipboard'
|
||||
|
||||
const i18n = createI18n({
|
||||
locale: 'fr',
|
||||
@@ -14,100 +15,101 @@ const i18n = createI18n({
|
||||
fr
|
||||
}
|
||||
})
|
||||
describe('Terminal', () => {
|
||||
describe('Template', () => {
|
||||
it('should render the component with good wording keys', () => {
|
||||
const wrapper = shallowMount(Terminal, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('pages.upload.button_copy')
|
||||
})
|
||||
it('should render the view with the button', () => {
|
||||
const wrapper = shallowMount(Terminal, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('<button')
|
||||
expect(wrapper.html()).contains('icon="bi bi-clipboard-plus"')
|
||||
expect(wrapper.html()).contains('look="button--white"')
|
||||
})
|
||||
})
|
||||
describe('Props', () => {
|
||||
it('should have default props', () => {
|
||||
const wrapper = shallowMount(Terminal, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.vm.textUpload).toBe('')
|
||||
expect(wrapper.vm.textInstall).toBe('')
|
||||
})
|
||||
it('should have props filled', () => {
|
||||
const wrapper = shallowMount(Terminal, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
},
|
||||
props: {
|
||||
textUpload: 'upload',
|
||||
textInstall: 'install'
|
||||
}
|
||||
})
|
||||
expect(wrapper.vm.textUpload).toBe('upload')
|
||||
expect(wrapper.vm.textInstall).toBe('install')
|
||||
})
|
||||
})
|
||||
describe('Methods', () => {
|
||||
it('should have default clipboard img', () => {
|
||||
const wrapper = shallowMount(Terminal, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('bi bi-clipboard-plus')
|
||||
})
|
||||
it('calls copyText function on button click and updates clipboard icon', async () => {
|
||||
Object.defineProperty(navigator, 'clipboard', {
|
||||
value: {
|
||||
writeText: (msg) => msg
|
||||
}
|
||||
})
|
||||
vi.useFakeTimers()
|
||||
const wrapper = mount(Terminal, {
|
||||
global: {
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
},
|
||||
components: {
|
||||
Button
|
||||
}
|
||||
}
|
||||
})
|
||||
const spy = vi.spyOn(wrapper.vm, 'copyText')
|
||||
const buttonWrapper = wrapper.findComponent(Button)
|
||||
await buttonWrapper.vm.$emit('trigger')
|
||||
|
||||
expect(spy).toHaveBeenCalled()
|
||||
expect(wrapper.vm.uploadIsCopied).toBe(true)
|
||||
vi.runAllTimers()
|
||||
expect(wrapper.vm.uploadIsCopied).toBe(false)
|
||||
describe('Template', () => {
|
||||
it('should render the component with good wording keys', () => {
|
||||
const wrapper = shallowMount(Terminal, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('pages.upload.button_copy')
|
||||
})
|
||||
it('should render the view with the button', () => {
|
||||
const wrapper = shallowMount(Terminal, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('<button')
|
||||
expect(wrapper.html()).contains('icon="bi bi-clipboard-plus"')
|
||||
expect(wrapper.html()).contains('look="button--white"')
|
||||
})
|
||||
})
|
||||
describe('Props', () => {
|
||||
it('should have default props', () => {
|
||||
const wrapper = shallowMount(Terminal, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.vm.textUpload).toBe('')
|
||||
expect(wrapper.vm.textInstall).toBe('')
|
||||
})
|
||||
it('should have props filled', () => {
|
||||
const wrapper = shallowMount(Terminal, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
},
|
||||
props: {
|
||||
textUpload: 'upload',
|
||||
textInstall: 'install'
|
||||
}
|
||||
})
|
||||
expect(wrapper.vm.textUpload).toBe('upload')
|
||||
expect(wrapper.vm.textInstall).toBe('install')
|
||||
})
|
||||
})
|
||||
describe('Methods', () => {
|
||||
it('should have default clipboard img', () => {
|
||||
const wrapper = shallowMount(Terminal, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('bi bi-clipboard-plus')
|
||||
})
|
||||
it('calls copyText function on button click', async () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
})
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
const wrapper = mount(Terminal, {
|
||||
global: {
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
},
|
||||
components: {
|
||||
Button
|
||||
}
|
||||
}
|
||||
})
|
||||
vi.mock('../../../utils/copyToClipboard')
|
||||
updateClipboard.mockReturnValue(true)
|
||||
const spy = vi.spyOn(wrapper.vm, 'copyText')
|
||||
|
||||
const buttonWrapper = wrapper.findComponent(Button)
|
||||
await buttonWrapper.vm.$emit('trigger')
|
||||
|
||||
expect(spy).toHaveBeenCalled()
|
||||
expect(updateClipboard).toHaveBeenCalled()
|
||||
expect(wrapper.vm.uploadIsCopied).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user