first pages test working

This commit is contained in:
Moriz Wahl 2023-02-13 20:29:16 +01:00
parent 6aead3f75e
commit b2be8a301e
4 changed files with 32 additions and 23 deletions

View File

@ -1,7 +1,9 @@
import { config, mount } from '@vue/test-utils'
import { mount } from '@vue/test-utils'
import admin from './admin.vue'
config.stubs['nuxt-child'] = '<span><slot /></span>'
const stubs = {
'nuxt-child': true,
}
const localVue = global.localVue
@ -20,6 +22,7 @@ describe('admin.vue', () => {
return mount(admin, {
mocks,
localVue,
stubs,
})
}
@ -28,7 +31,7 @@ describe('admin.vue', () => {
})
it('renders', () => {
expect(wrapper.is('div')).toBe(true)
expect(wrapper.element.tagName).toBe('DIV')
})
})
})

View File

@ -1,15 +1,18 @@
import { config, mount } from '@vue/test-utils'
import { mount } from '@vue/test-utils'
import GroupProfileSlug from './_slug.vue'
const localVue = global.localVue
localVue.filter('date', (d) => d)
config.stubs['client-only'] = '<span><slot /></span>'
config.stubs['v-popover'] = '<span><slot /></span>'
config.stubs['nuxt-link'] = '<span><slot /></span>'
config.stubs['infinite-loading'] = '<span><slot /></span>'
config.stubs['follow-list'] = '<span><slot /></span>'
const stubs = {
'client-only': true,
'v-popover': true,
'nuxt-link': true,
'router-link': true,
'infinite-loading': true,
'follow-list': true,
}
describe('GroupProfileSlug', () => {
let wrapper
@ -201,6 +204,7 @@ describe('GroupProfileSlug', () => {
mocks,
localVue,
data,
stubs,
})
}

View File

@ -1,14 +1,16 @@
import { config, shallowMount, mount } from '@vue/test-utils'
import { shallowMount, mount } from '@vue/test-utils'
import PostIndex from './index.vue'
import Vuex from 'vuex'
import HashtagsFilter from '~/components/HashtagsFilter/HashtagsFilter'
const localVue = global.localVue
config.stubs['client-only'] = '<span><slot /></span>'
config.stubs['router-link'] = '<span><slot /></span>'
config.stubs['nuxt-link'] = '<span><slot /></span>'
config.stubs['infinite-loading'] = '<span><slot /></span>'
const stubs = {
'client-only': true,
'router-link': true,
'nuxt-link': true,
'infinite-loading': true,
}
describe('PostIndex', () => {
let wrapper
@ -95,7 +97,7 @@ describe('PostIndex', () => {
it('clears the search when the filter menu emits clearSearch', () => {
mocks.$route.query.hashtag = '#samplehashtag'
wrapper = Wrapper()
wrapper.find(HashtagsFilter).vm.$emit('clearSearch')
wrapper.findComponent(HashtagsFilter).vm.$emit('clearSearch')
expect(wrapper.vm.hashtag).toBeNull()
})
@ -123,6 +125,7 @@ describe('PostIndex', () => {
store,
mocks,
localVue,
stubs,
})
}

View File

@ -1,4 +1,4 @@
import { config, mount } from '@vue/test-utils'
import { mount } from '@vue/test-utils'
import Vuex from 'vuex'
import Vue from 'vue'
import PostSlug from './index.vue'
@ -6,10 +6,6 @@ import CommentList from '~/components/CommentList/CommentList'
import HcHashtag from '~/components/Hashtag/Hashtag'
import VueMeta from 'vue-meta'
config.stubs['client-only'] = '<span><slot /></span>'
config.stubs['nuxt-link'] = '<span><slot /></span>'
config.stubs['router-link'] = '<span><slot /></span>'
const localVue = global.localVue
localVue.directive('scrollTo', jest.fn())
localVue.use(VueMeta, { keyName: 'head' })
@ -81,6 +77,9 @@ describe('PostSlug', () => {
},
}
stubs = {
'client-only': true,
'nuxt-link': true,
'router-link': true,
HcEditor: { render: () => {}, methods: { insertReply: jest.fn(() => null) } },
ContentViewer: true,
}
@ -148,7 +147,7 @@ describe('PostSlug', () => {
describe('reply method called when emitted reply received', () => {
it('CommentList', async () => {
wrapper = await Wrapper()
wrapper.find(CommentList).vm.$emit('reply', {
wrapper.findComponent(CommentList).vm.$emit('reply', {
id: 'commentAuthorId',
slug: 'ogerly',
})
@ -176,12 +175,12 @@ describe('PostSlug', () => {
it('are present', async () => {
// Get length from backendData and compare against number of tags present in component.
expect(wrapper.findAll(HcHashtag).length).toBe(backendData.post.tags.length)
expect(wrapper.findAllComponents(HcHashtag).length).toBe(backendData.post.tags.length)
})
it('are alphabetically ordered', async () => {
// Get all HcHastag components
const wrappers = wrapper.findAll(HcHashtag).wrappers
const wrappers = wrapper.findAllComponents(HcHashtag).wrappers
// Exctract ID properties (tag names) from component.
const ids = []
wrappers.forEach((x) => {