forked from Ivasoft/geovisio-website
fix tests
This commit is contained in:
@@ -36,7 +36,6 @@ describe('Template', () => {
|
||||
expect(wrapper.html()).contains('general.header.contribute_text')
|
||||
})
|
||||
it('should render the component login link', async () => {
|
||||
import.meta.env.VITE_API_URL = 'api-url/'
|
||||
const wrapper = shallowMount(Header, {
|
||||
global: {
|
||||
plugins: [i18n, router],
|
||||
@@ -45,7 +44,7 @@ describe('Template', () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(wrapper.html()).contains('path="api-url/api/auth/login')
|
||||
expect(wrapper.html()).contains('path="api/auth/login')
|
||||
})
|
||||
})
|
||||
describe('When the user is logged', () => {
|
||||
@@ -117,5 +116,20 @@ describe('Methods', () => {
|
||||
|
||||
expect(wrapper.vm.menuIsClosed).toBe(true)
|
||||
})
|
||||
it('Should be open and close by clicking', async () => {
|
||||
wrapper = shallowMount(Header, {
|
||||
global: {
|
||||
plugins: [i18n, router],
|
||||
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,36 +0,0 @@
|
||||
import { it, describe, expect, vi, beforeEach } from 'vitest'
|
||||
import { flushPromises, shallowMount } from '@vue/test-utils'
|
||||
import MySequenceView from '../../../views/MySequenceView.vue'
|
||||
import axios from 'axios'
|
||||
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 view without sequences', async () => {
|
||||
import.meta.env.VITE_API_URL = 'api-url/'
|
||||
await axios.get.mockReturnValue({ data: { links: [] } })
|
||||
const wrapper = shallowMount(MySequenceView, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
await flushPromises()
|
||||
|
||||
expect(axios.get).toHaveBeenCalledWith(
|
||||
`${import.meta.env.VITE_API_URL}api/collections/1234567`
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -5,8 +5,8 @@ import axios from 'axios'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import fr from '../../../locales/fr.json'
|
||||
import Button from '../../../components/Button.vue'
|
||||
|
||||
vi.mock('@/utils/dates', () => ({
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
vi.mock('../../../utils/dates', () => ({
|
||||
formatDate: vi.fn()
|
||||
}))
|
||||
vi.mock('axios')
|
||||
@@ -20,6 +20,10 @@ const i18n = createI18n({
|
||||
fr
|
||||
}
|
||||
})
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: []
|
||||
})
|
||||
|
||||
const mockResponseSequences = [
|
||||
{
|
||||
@@ -43,28 +47,26 @@ const mockResponseSequences = [
|
||||
|
||||
describe('Template', () => {
|
||||
it('should render the view without sequences', async () => {
|
||||
import.meta.env.VITE_API_URL = 'api-url/'
|
||||
await axios.get.mockReturnValue({ data: { links: [] } })
|
||||
vi.spyOn(axios, 'get').mockResolvedValue({ data: { links: [] } })
|
||||
const wrapper = shallowMount(MySequencesView, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
plugins: [i18n, router],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
}
|
||||
}
|
||||
})
|
||||
await flushPromises()
|
||||
expect(axios.get).toHaveBeenCalledWith(
|
||||
`${import.meta.env.VITE_API_URL}api/users/me/catalog`
|
||||
)
|
||||
expect(axios.get).toHaveBeenCalledWith('api/users/me/catalog')
|
||||
expect(wrapper.vm.userSequences).toEqual([])
|
||||
expect(wrapper.html()).contains('general.header.contribute_text')
|
||||
expect(wrapper.html()).contains('path="/partager-des-photos"')
|
||||
})
|
||||
|
||||
it('should render the view with a sequence in the list', async () => {
|
||||
import.meta.env.VITE_API_URL = 'api-url/'
|
||||
await axios.get.mockReturnValue({ data: { links: mockResponseSequences } })
|
||||
vi.spyOn(axios, 'get').mockResolvedValue({
|
||||
data: { links: mockResponseSequences }
|
||||
})
|
||||
const wrapper = shallowMount(MySequencesView, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
@@ -74,9 +76,7 @@ describe('Template', () => {
|
||||
}
|
||||
})
|
||||
await flushPromises()
|
||||
expect(axios.get).toHaveBeenCalledWith(
|
||||
`${import.meta.env.VITE_API_URL}api/users/me/catalog`
|
||||
)
|
||||
expect(axios.get).toHaveBeenCalledWith('api/users/me/catalog')
|
||||
expect(wrapper.vm.userSequences).toEqual([mockResponseSequences[1]])
|
||||
expect(wrapper.html()).contains('src="https://my-link/thumb.jpg"')
|
||||
expect(wrapper.html()).contains('ma sequence 1')
|
||||
@@ -117,7 +117,6 @@ describe('Methods', () => {
|
||||
}
|
||||
]
|
||||
beforeEach(async () => {
|
||||
import.meta.env.VITE_API_URL = 'api-url/'
|
||||
await axios.get.mockReturnValue({
|
||||
data: { links: mockResponseSequencesToSort }
|
||||
})
|
||||
@@ -126,7 +125,7 @@ describe('Methods', () => {
|
||||
it('should should sort sequences by title', async () => {
|
||||
const wrapper = shallowMount(MySequencesView, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
plugins: [i18n, router],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
},
|
||||
@@ -150,7 +149,7 @@ describe('Methods', () => {
|
||||
it('should should sort sequences by number of pictures', async () => {
|
||||
const wrapper = shallowMount(MySequencesView, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
plugins: [i18n, router],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
},
|
||||
@@ -174,7 +173,7 @@ describe('Methods', () => {
|
||||
it('should should sort sequences by date', async () => {
|
||||
const wrapper = shallowMount(MySequencesView, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
plugins: [i18n, router],
|
||||
mocks: {
|
||||
$t: (msg) => msg
|
||||
},
|
||||
|
||||
@@ -36,7 +36,6 @@ const mockResponseTokens = [
|
||||
describe('Template', () => {
|
||||
describe('When all the tokens list are fetched', () => {
|
||||
it('should render all the tokens hidden', async () => {
|
||||
import.meta.env.VITE_API_URL = 'my-api/'
|
||||
vi.spyOn(axios, 'get').mockResolvedValue({ data: mockResponseTokens })
|
||||
const wrapper = shallowMount(MySettingsView, {
|
||||
global: {
|
||||
@@ -48,7 +47,7 @@ describe('Template', () => {
|
||||
})
|
||||
await flushPromises()
|
||||
|
||||
expect(axios.get).toHaveBeenCalledWith('my-api/api/users/me/tokens')
|
||||
expect(axios.get).toHaveBeenCalledWith('api/users/me/tokens')
|
||||
expect(wrapper.vm.userTokens).toEqual(mockResponseTokens)
|
||||
expect(wrapper.html()).contains('•••••••••••••••••••••••••••••••')
|
||||
expect(wrapper.html()).contains('icon="bi bi-eye"')
|
||||
|
||||
@@ -3,6 +3,7 @@ import { shallowMount } from '@vue/test-utils'
|
||||
import UploadView from '../../../views/UploadView.vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import fr from '../../../locales/fr.json'
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
|
||||
const i18n = createI18n({
|
||||
locale: 'fr',
|
||||
@@ -13,13 +14,15 @@ const i18n = createI18n({
|
||||
fr
|
||||
}
|
||||
})
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: []
|
||||
})
|
||||
describe('Template', () => {
|
||||
it('should render the view with the button link', async () => {
|
||||
import.meta.env.VITE_API_URL = 'api-url/'
|
||||
const wrapper = shallowMount(UploadView, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
plugins: [i18n, router],
|
||||
mocks: {
|
||||
$t: (msg) => msg,
|
||||
authConf: {
|
||||
@@ -39,7 +42,7 @@ describe('Template', () => {
|
||||
import.meta.env.VITE_API_URL = 'api-url/'
|
||||
const wrapper = shallowMount(UploadView, {
|
||||
global: {
|
||||
plugins: [i18n],
|
||||
plugins: [i18n, router],
|
||||
mocks: {
|
||||
$t: (msg) => msg,
|
||||
authConf: {
|
||||
|
||||
Reference in New Issue
Block a user