forked from Ivasoft/geovisio-website
wip
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
import { it, describe, expect } from 'vitest'
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import BetaText from '../BetaText.vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import fr from '../../locales/fr.json'
|
||||
|
||||
const i18n = createI18n({
|
||||
locale: 'fr',
|
||||
fallbackLocale: 'fr',
|
||||
globalInjection: true,
|
||||
legacy: false,
|
||||
messages: {
|
||||
fr
|
||||
}
|
||||
})
|
||||
|
||||
describe('Template', () => {
|
||||
it('should render the component with good wording keys', async () => {
|
||||
const wrapper = shallowMount(BetaText, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('general.header.title')
|
||||
})
|
||||
})
|
||||
@@ -1,133 +0,0 @@
|
||||
import { vi, it, beforeEach, describe, expect } from 'vitest'
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import fr from '../../locales/fr.json'
|
||||
import Header from '../Header.vue'
|
||||
vi.mock('vue-router')
|
||||
|
||||
const i18n = createI18n({
|
||||
locale: 'fr',
|
||||
fallbackLocale: 'fr',
|
||||
globalInjection: true,
|
||||
legacy: false,
|
||||
messages: {
|
||||
fr
|
||||
}
|
||||
})
|
||||
|
||||
describe('Template', () => {
|
||||
beforeEach(async () => {
|
||||
const VueRouter = await import('vue-router')
|
||||
VueRouter.useRoute.mockReturnValueOnce({
|
||||
path: 'my-path'
|
||||
})
|
||||
})
|
||||
describe('When the user is not logged', () => {
|
||||
it('should render the component with good wording keys', async () => {
|
||||
import.meta.env.VITE_API_URL = 'api-url/'
|
||||
const wrapper = shallowMount(Header, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('general.header.contribute_text')
|
||||
expect(wrapper.html()).contains('general.header.help_text')
|
||||
expect(wrapper.html()).contains(
|
||||
'general.header.contribute_text_responsive'
|
||||
)
|
||||
})
|
||||
it('should render the component login link', async () => {
|
||||
import.meta.env.VITE_API_URL = 'api-url/'
|
||||
const wrapper = shallowMount(Header, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('path="api-url/api/auth/login')
|
||||
})
|
||||
})
|
||||
describe('When the user is logged', () => {
|
||||
beforeEach(async () => {
|
||||
Object.defineProperty(document, 'cookie', {
|
||||
value: 'user_id=abc123'
|
||||
})
|
||||
vi.resetModules()
|
||||
import.meta.env.VITE_API_URL = 'api-url/'
|
||||
})
|
||||
it('should render the component with good wording keys', async () => {
|
||||
const wrapper = shallowMount(Header, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('general.header.contribute_text')
|
||||
expect(wrapper.html()).contains('general.header.help_text')
|
||||
expect(wrapper.html()).contains(
|
||||
'general.header.contribute_text_responsive'
|
||||
)
|
||||
expect(wrapper.html()).contains('general.header.account_text')
|
||||
expect(wrapper.html()).contains('general.header.logout_text')
|
||||
})
|
||||
it('should render the component logout link', async () => {
|
||||
const wrapper = shallowMount(Header, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('chevron bi bi-chevron-up')
|
||||
expect(wrapper.html()).contains('auth/logout')
|
||||
expect(wrapper.html()).contains('path="mon-compte"')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Methods', () => {
|
||||
describe('toggleMenu', () => {
|
||||
let wrapper
|
||||
beforeEach(async () => {
|
||||
const VueRouter = await import('vue-router')
|
||||
VueRouter.useRoute.mockReturnValueOnce({
|
||||
path: 'my-path'
|
||||
})
|
||||
})
|
||||
it('Menu should be closed by default', () => {
|
||||
wrapper = shallowMount(Header, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
expect(wrapper.vm.menuIsClosed).toBe(true)
|
||||
})
|
||||
it('Should be open and close by clicking', async () => {
|
||||
wrapper = shallowMount(Header, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
await wrapper.find('.menu-burger').trigger('click')
|
||||
expect(wrapper.vm.menuIsClosed).toBe(false)
|
||||
|
||||
await wrapper.find('.menu-burger').trigger('click')
|
||||
expect(wrapper.vm.menuIsClosed).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,154 +0,0 @@
|
||||
import { test, describe, vi, expect } from 'vitest'
|
||||
import { mount, shallowMount } from '@vue/test-utils'
|
||||
import Link from '../Link.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
vi.mock('vue-i18n')
|
||||
|
||||
useI18n.mockReturnValue({
|
||||
t: (tKey) => tKey
|
||||
})
|
||||
const stubs = {
|
||||
'router-link': {
|
||||
template: '<router-link></router-link>'
|
||||
}
|
||||
}
|
||||
describe('Template', () => {
|
||||
describe('Snapshot', () => {
|
||||
test('Should match snapshot with external link', () => {
|
||||
const wrapper = mount(Link, {
|
||||
global: {
|
||||
stubs
|
||||
},
|
||||
props: {
|
||||
type: 'external',
|
||||
text: 'My-text',
|
||||
path: 'my-path',
|
||||
target: '_blank'
|
||||
}
|
||||
})
|
||||
expect(wrapper.element).toMatchSnapshot()
|
||||
})
|
||||
test('Should match snapshot with internal link', () => {
|
||||
const wrapper = shallowMount(Link, {
|
||||
props: {
|
||||
text: 'My-text',
|
||||
path: 'my-path'
|
||||
}
|
||||
})
|
||||
expect(wrapper.element).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
describe('Props', () => {
|
||||
test('should have default props', () => {
|
||||
const wrapper = shallowMount(Link)
|
||||
|
||||
expect(wrapper.vm.text).toBe(null)
|
||||
expect(wrapper.vm.path).toBe('')
|
||||
expect(wrapper.vm.look).toBe('')
|
||||
expect(wrapper.vm.type).toBe(null)
|
||||
expect(wrapper.vm.alt).toBe('')
|
||||
expect(wrapper.vm.icon).toBe(null)
|
||||
expect(wrapper.vm.target).toBe(null)
|
||||
expect(wrapper.vm.image).toBe(null)
|
||||
expect(wrapper.vm.disabled).toBe(false)
|
||||
})
|
||||
})
|
||||
describe('When the component is an external link', () => {
|
||||
test('should render the component as a <a>', () => {
|
||||
const wrapper = shallowMount(Link, {
|
||||
global: {
|
||||
stubs
|
||||
},
|
||||
props: {
|
||||
type: 'external'
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('<a')
|
||||
})
|
||||
test('should render an icon inside the link', () => {
|
||||
const wrapper = shallowMount(Link, {
|
||||
global: {
|
||||
stubs
|
||||
},
|
||||
props: {
|
||||
type: 'external',
|
||||
icon: 'my-icon'
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('my-icon')
|
||||
})
|
||||
test('should render the text inside the link', () => {
|
||||
const wrapper = shallowMount(Link, {
|
||||
global: {
|
||||
stubs
|
||||
},
|
||||
props: {
|
||||
type: 'external',
|
||||
text: 'my-text'
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('my-text')
|
||||
})
|
||||
test('should render an image inside the link', () => {
|
||||
const wrapper = shallowMount(Link, {
|
||||
global: {
|
||||
stubs
|
||||
},
|
||||
props: {
|
||||
type: 'external',
|
||||
image: {
|
||||
url: 'my-url.png',
|
||||
alt: 'my-alt'
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('<img')
|
||||
expect(wrapper.html()).contains('my-url.png')
|
||||
expect(wrapper.html()).contains('my-alt')
|
||||
})
|
||||
test('should render the text inside the link', () => {
|
||||
const wrapper = shallowMount(Link, {
|
||||
global: {
|
||||
stubs
|
||||
},
|
||||
props: {
|
||||
type: 'external',
|
||||
disabled: true
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('disabled')
|
||||
})
|
||||
})
|
||||
|
||||
describe('When the component is an internal link', () => {
|
||||
test('should render the component as an internal link', () => {
|
||||
const wrapper = shallowMount(Link)
|
||||
expect(wrapper.html()).contains('<router-link')
|
||||
})
|
||||
test('should render an icon inside the link', () => {
|
||||
const wrapper = shallowMount(Link, {
|
||||
props: {
|
||||
type: 'internal',
|
||||
icon: 'my-icon'
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('my-icon')
|
||||
})
|
||||
test('should render the text inside the link', () => {
|
||||
const wrapper = shallowMount(Link, {
|
||||
props: {
|
||||
text: 'my-text'
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('my-text')
|
||||
})
|
||||
test('should render the text inside the link', () => {
|
||||
const wrapper = shallowMount(Link, {
|
||||
props: {
|
||||
disabled: true
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('disabled')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,113 +0,0 @@
|
||||
import { it, describe, expect, vi } from 'vitest'
|
||||
import { shallowMount, mount } from '@vue/test-utils'
|
||||
import Terminal from '../Terminal.vue'
|
||||
import Button from '../Button.vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import fr from '../../locales/fr.json'
|
||||
|
||||
const i18n = createI18n({
|
||||
locale: 'fr',
|
||||
fallbackLocale: 'fr',
|
||||
globalInjection: true,
|
||||
legacy: false,
|
||||
messages: {
|
||||
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)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,38 +0,0 @@
|
||||
// Vitest Snapshot v1
|
||||
|
||||
exports[`Template > Snapshot > Should match snapshot with external link 1`] = `
|
||||
<a
|
||||
class="default"
|
||||
data-v-409c8661=""
|
||||
href="my-path"
|
||||
target="_blank"
|
||||
title=""
|
||||
>
|
||||
<!--v-if-->
|
||||
<!--v-if-->
|
||||
<span
|
||||
class="text"
|
||||
data-v-409c8661=""
|
||||
>
|
||||
My-text
|
||||
</span>
|
||||
</a>
|
||||
`;
|
||||
|
||||
exports[`Template > Snapshot > Should match snapshot with internal link 1`] = `
|
||||
<router-link
|
||||
class="default"
|
||||
data-v-409c8661=""
|
||||
title=""
|
||||
to="my-path"
|
||||
>
|
||||
<!--v-if-->
|
||||
<!--v-if-->
|
||||
<span
|
||||
class="text"
|
||||
data-v-409c8661=""
|
||||
>
|
||||
My-text
|
||||
</span>
|
||||
</router-link>
|
||||
`;
|
||||
Reference in New Issue
Block a user