pages tests nearly working

This commit is contained in:
Moriz Wahl 2023-02-13 23:08:41 +01:00
parent b2eda033ee
commit 4850e456fe
27 changed files with 1248 additions and 819 deletions

View File

@ -20,6 +20,7 @@ module.exports = {
transform: { transform: {
'.*\\.(vue)$': 'vue-jest', '.*\\.(vue)$': 'vue-jest',
'^.+\\.js$': 'babel-jest', '^.+\\.js$': 'babel-jest',
'<rootDir>/node_modules/@mapbox/mapbox-gl-geocoder/dist/*': 'babel-jest',
}, },
testMatch: ['**/?(*.)+(spec|test).js?(x)'], testMatch: ['**/?(*.)+(spec|test).js?(x)'],
modulePathIgnorePatterns: ['<rootDir>/build/'], modulePathIgnorePatterns: ['<rootDir>/build/'],

View File

@ -67,7 +67,8 @@
"devDependencies": { "devDependencies": {
"@babel/core": "~7.12.3", "@babel/core": "~7.12.3",
"@babel/plugin-syntax-dynamic-import": "^7.8.3", "@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/preset-env": "~7.9.0", "@babel/plugin-transform-modules-commonjs": "^7.20.11",
"@babel/preset-env": "^7.20.2",
"@faker-js/faker": "5.1.0", "@faker-js/faker": "5.1.0",
"@nuxtjs/composition-api": "0.32.0", "@nuxtjs/composition-api": "0.32.0",
"@storybook/addon-a11y": "^6.3.6", "@storybook/addon-a11y": "^6.3.6",
@ -81,7 +82,7 @@
"async-validator": "^3.2.4", "async-validator": "^3.2.4",
"babel-core": "~7.0.0-bridge.0", "babel-core": "~7.0.0-bridge.0",
"babel-eslint": "~10.1.0", "babel-eslint": "~10.1.0",
"babel-jest": "~25.3.0", "babel-jest": "29.4",
"babel-loader": "~8.1.0", "babel-loader": "~8.1.0",
"babel-plugin-require-context-hook": "^1.0.0", "babel-plugin-require-context-hook": "^1.0.0",
"babel-preset-vue": "~2.0.2", "babel-preset-vue": "~2.0.2",

View File

@ -33,7 +33,7 @@ describe('code-of-conduct.vue', () => {
}) })
it('renders', () => { it('renders', () => {
expect(wrapper.is('div')).toBeTruthy() expect(wrapper.element.tagName).toBe('DIV')
}) })
it('has correct <head> content', () => { it('has correct <head> content', () => {

View File

@ -33,7 +33,7 @@ describe('data-privacy.vue', () => {
}) })
it('renders', () => { it('renders', () => {
expect(wrapper.is('div')).toBeTruthy() expect(wrapper.element.tagName).toBe('DIV')
}) })
it('has correct <head> content', () => { it('has correct <head> content', () => {

View File

@ -37,7 +37,7 @@ describe('donate.vue', () => {
}) })
it('renders', () => { it('renders', () => {
expect(wrapper.is('div')).toBeTruthy() expect(wrapper.element.tagName).toBe('DIV')
}) })
it('has correct <head> content', () => { it('has correct <head> content', () => {

View File

@ -33,7 +33,7 @@ describe('faq.vue', () => {
}) })
it('renders', () => { it('renders', () => {
expect(wrapper.is('div')).toBeTruthy() expect(wrapper.element.tagName).toBe('DIV')
}) })
it('has correct <head> content', () => { it('has correct <head> content', () => {

View File

@ -1,9 +1,11 @@
import { config, mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import _id from './_id.vue' import _id from './_id.vue'
const localVue = global.localVue const localVue = global.localVue
config.stubs['nuxt-child'] = '<span class="nuxt-child"><slot /></span>' const stubs = {
'nuxt-child': true,
}
describe('Group profile _id.vue', () => { describe('Group profile _id.vue', () => {
let wrapper let wrapper
@ -19,6 +21,7 @@ describe('Group profile _id.vue', () => {
return mount(_id, { return mount(_id, {
mocks, mocks,
localVue, localVue,
stubs,
}) })
} }
@ -27,7 +30,7 @@ describe('Group profile _id.vue', () => {
}) })
it('renders', () => { it('renders', () => {
expect(wrapper.findAll('.nuxt-child')).toHaveLength(1) expect(wrapper.findComponent({ name: 'nuxt-child' }).exists()).toBe(true)
}) })
}) })
}) })

View File

@ -1,10 +1,12 @@
import { config, mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import groups from './groups.vue' import groups from './groups.vue'
const localVue = global.localVue const localVue = global.localVue
config.stubs['nuxt-link'] = '<span class="nuxt-link"><slot /></span>' const stubs = {
config.stubs['client-only'] = '<span class="client-only"><slot /></span>' 'nuxt-link': true,
'client-only': true,
}
describe('groups', () => { describe('groups', () => {
let wrapper let wrapper
@ -21,6 +23,7 @@ describe('groups', () => {
return mount(groups, { return mount(groups, {
mocks, mocks,
localVue, localVue,
stubs,
}) })
} }
@ -29,7 +32,7 @@ describe('groups', () => {
}) })
it('renders', () => { it('renders', () => {
expect(wrapper.is('div')).toBe(true) expect(wrapper.element.tagName).toBe('DIV')
}) })
}) })
}) })

View File

@ -37,7 +37,7 @@ describe('imprint.vue', () => {
}) })
it('renders', () => { it('renders', () => {
expect(wrapper.is('div')).toBeTruthy() expect(wrapper.element.tagName).toBe('DIV')
}) })
it('has correct <head> content', () => { it('has correct <head> content', () => {

View File

@ -1,11 +1,13 @@
import Vuex from 'vuex' import Vuex from 'vuex'
import { config, mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import login from './login.vue' import login from './login.vue'
const localVue = global.localVue const localVue = global.localVue
config.stubs['client-only'] = '<span class="client-only"><slot /></span>' const stubs = {
config.stubs['nuxt-link'] = '<span class="nuxt-link"><slot /></span>' 'client-only': true,
'nuxt-link': true,
}
describe('Login.vue', () => { describe('Login.vue', () => {
let store let store
@ -50,6 +52,7 @@ describe('Login.vue', () => {
store, store,
mocks, mocks,
localVue, localVue,
stubs,
}) })
} }

View File

@ -32,7 +32,7 @@ describe('logout.vue', () => {
}) })
it('renders', () => { it('renders', () => {
expect(wrapper.is('div')).toBe(true) expect(wrapper.element.tagName).toBe('DIV')
}) })
it('logs out and redirects to login', () => { it('logs out and redirects to login', () => {

View File

@ -5,6 +5,8 @@ import VueMeta from 'vue-meta'
import Vuex from 'vuex' import Vuex from 'vuex'
import Map from './map' import Map from './map'
jest.mock('@mapbox/mapbox-gl-geocoder')
jest.mock('mapbox-gl', () => { jest.mock('mapbox-gl', () => {
return { return {
GeolocateControl: jest.fn(), GeolocateControl: jest.fn(),

View File

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

View File

@ -1,8 +1,11 @@
import { config, mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import Moderation from './index.vue' import Moderation from './index.vue'
const localVue = global.localVue const localVue = global.localVue
config.stubs['client-only'] = '<span><slot /></span>'
const stubs = {
'client-only': true,
}
describe('moderation/index.vue', () => { describe('moderation/index.vue', () => {
let wrapper let wrapper
@ -16,7 +19,7 @@ describe('moderation/index.vue', () => {
describe('mount', () => { describe('mount', () => {
const Wrapper = () => { const Wrapper = () => {
return mount(Moderation, { mocks, localVue }) return mount(Moderation, { mocks, localVue, stubs })
} }
beforeEach(() => { beforeEach(() => {
@ -24,7 +27,7 @@ describe('moderation/index.vue', () => {
}) })
it('renders', () => { it('renders', () => {
expect(wrapper.is('.base-card')).toBe(true) expect(wrapper.classes('base-card')).toBe(true)
}) })
}) })
}) })

View File

@ -1,4 +1,4 @@
import { config, shallowMount, mount } from '@vue/test-utils' import { shallowMount, mount } from '@vue/test-utils'
import NotificationsPage from './index.vue' import NotificationsPage from './index.vue'
import DropdownFilter from '~/components/DropdownFilter/DropdownFilter' import DropdownFilter from '~/components/DropdownFilter/DropdownFilter'
@ -7,7 +7,9 @@ import PaginationButtons from '~/components/_new/generic/PaginationButtons/Pagin
const localVue = global.localVue const localVue = global.localVue
config.stubs['client-only'] = '<span><slot /></span>' const stubs = {
'client-only': true,
}
describe('PostIndex', () => { describe('PostIndex', () => {
let wrapper, Wrapper, mocks, propsData let wrapper, Wrapper, mocks, propsData
@ -42,6 +44,7 @@ describe('PostIndex', () => {
mocks, mocks,
localVue, localVue,
propsData, propsData,
stubs,
}) })
} }
wrapper = Wrapper() wrapper = Wrapper()
@ -67,6 +70,7 @@ describe('PostIndex', () => {
mocks, mocks,
localVue, localVue,
propsData, propsData,
stubs,
}) })
} }
}) })
@ -79,7 +83,7 @@ describe('PostIndex', () => {
{ label: 'Unread', value: false }, { label: 'Unread', value: false },
] ]
wrapper = Wrapper() wrapper = Wrapper()
wrapper.find(DropdownFilter).vm.$emit('filter', propsData.filterOptions[1]) wrapper.findComponent(DropdownFilter).vm.$emit('filter', propsData.filterOptions[1])
}) })
it('sets `notificationRead` to value of received option', () => { it('sets `notificationRead` to value of received option', () => {
@ -98,7 +102,9 @@ describe('PostIndex', () => {
describe('markNotificationAsRead', () => { describe('markNotificationAsRead', () => {
beforeEach(() => { beforeEach(() => {
wrapper = Wrapper() wrapper = Wrapper()
wrapper.find(NotificationsTable).vm.$emit('markNotificationAsRead', 'notificationSourceId') wrapper
.findComponent(NotificationsTable)
.vm.$emit('markNotificationAsRead', 'notificationSourceId')
}) })
it('calls markNotificationAsRead mutation', () => { it('calls markNotificationAsRead mutation', () => {
@ -112,7 +118,7 @@ describe('PostIndex', () => {
mocks.$apollo.mutate = jest.fn().mockRejectedValueOnce({ message: 'Some error message' }) mocks.$apollo.mutate = jest.fn().mockRejectedValueOnce({ message: 'Some error message' })
wrapper = Wrapper() wrapper = Wrapper()
wrapper wrapper
.find(NotificationsTable) .findComponent(NotificationsTable)
.vm.$emit('markNotificationAsRead', 'notificationSourceId') .vm.$emit('markNotificationAsRead', 'notificationSourceId')
}) })
@ -129,7 +135,7 @@ describe('PostIndex', () => {
describe('next: given a user is on the first page', () => { describe('next: given a user is on the first page', () => {
it('adds offset to pageSize to skip first x notifications and display next page', () => { it('adds offset to pageSize to skip first x notifications and display next page', () => {
wrapper.find(PaginationButtons).vm.$emit('next') wrapper.findComponent(PaginationButtons).vm.$emit('next')
expect(wrapper.vm.offset).toEqual(12) expect(wrapper.vm.offset).toEqual(12)
}) })
}) })
@ -137,7 +143,7 @@ describe('PostIndex', () => {
describe('back: given a user is on the third page', () => { describe('back: given a user is on the third page', () => {
it('sets offset when back is emitted', () => { it('sets offset when back is emitted', () => {
wrapper.setData({ offset: 24 }) wrapper.setData({ offset: 24 })
wrapper.find(PaginationButtons).vm.$emit('back') wrapper.findComponent(PaginationButtons).vm.$emit('back')
expect(wrapper.vm.offset).toEqual(12) expect(wrapper.vm.offset).toEqual(12)
}) })
}) })

View File

@ -37,7 +37,7 @@ describe('organization.vue', () => {
}) })
it('renders', () => { it('renders', () => {
expect(wrapper.is('div')).toBeTruthy() expect(wrapper.element.tagName).toBe('DIV')
}) })
it('has correct <head> content', () => { it('has correct <head> content', () => {

View File

@ -1,11 +1,13 @@
import Vuex from 'vuex' import Vuex from 'vuex'
import { config, mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import PasswordReset from './password-reset.vue' import PasswordReset from './password-reset.vue'
const localVue = global.localVue const localVue = global.localVue
config.stubs['client-only'] = '<span class="client-only"><slot /></span>' const stubs = {
config.stubs['nuxt-child'] = '<span class="nuxt-child"><slot /></span>' 'client-only': true,
'nuxt-child': true,
}
describe('password-reset.vue', () => { describe('password-reset.vue', () => {
let wrapper let wrapper
@ -47,12 +49,13 @@ describe('password-reset.vue', () => {
return mount(PasswordReset, { return mount(PasswordReset, {
mocks, mocks,
localVue, localVue,
stubs,
}) })
} }
it('renders', async () => { it('renders', async () => {
wrapper = await Wrapper() wrapper = await Wrapper()
expect(wrapper.is('div')).toBe(true) expect(wrapper.element.tagName).toBe('DIV')
}) })
it('renders with asyncData and not loggedIn', async () => { it('renders with asyncData and not loggedIn', async () => {

View File

@ -1,9 +1,11 @@
import { config, mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import enterNonce from './enter-nonce.vue' import enterNonce from './enter-nonce.vue'
const localVue = global.localVue const localVue = global.localVue
config.stubs['nuxt-link'] = '<span class="nuxt-link"><slot /></span>' const stubs = {
'nuxt-link': true,
}
describe('enter-nonce.vue', () => { describe('enter-nonce.vue', () => {
let wrapper let wrapper
@ -20,7 +22,7 @@ describe('enter-nonce.vue', () => {
describe('mount', () => { describe('mount', () => {
const Wrapper = () => { const Wrapper = () => {
return mount(enterNonce, { mocks, localVue }) return mount(enterNonce, { mocks, localVue, stubs })
} }
beforeEach(() => { beforeEach(() => {

View File

@ -1,10 +1,11 @@
import { config, mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import request from './request.vue' import request from './request.vue'
const localVue = global.localVue const localVue = global.localVue
// config.stubs['sweetalert-icon'] = '<span><slot /></span>' const stubs = {
config.stubs['nuxt-link'] = '<span class="nuxt-link"><slot /></span>' 'nuxt-link': true,
}
describe('request.vue', () => { describe('request.vue', () => {
let wrapper let wrapper
@ -29,7 +30,7 @@ describe('request.vue', () => {
describe('mount', () => { describe('mount', () => {
const Wrapper = () => { const Wrapper = () => {
return mount(request, { mocks, localVue }) return mount(request, { mocks, localVue, stubs })
} }
beforeEach(() => { beforeEach(() => {

View File

@ -1,9 +1,11 @@
import { config, mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import _id from './_id.vue' import _id from './_id.vue'
const localVue = global.localVue const localVue = global.localVue
config.stubs['nuxt-child'] = '<span class="nuxt-child"><slot /></span>' const stubs = {
'nuxt-child': true,
}
describe('Profile _id.vue', () => { describe('Profile _id.vue', () => {
let wrapper let wrapper
@ -19,6 +21,7 @@ describe('Profile _id.vue', () => {
return mount(_id, { return mount(_id, {
mocks, mocks,
localVue, localVue,
stubs,
}) })
} }
@ -27,7 +30,7 @@ describe('Profile _id.vue', () => {
}) })
it('renders', () => { it('renders', () => {
expect(wrapper.findAll('.nuxt-child')).toHaveLength(1) expect(wrapper.findComponent({ name: 'nuxt-child' }).exists()).toBe(true)
}) })
}) })
}) })

View File

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

View File

@ -1,14 +1,16 @@
import Vuex from 'vuex' import Vuex from 'vuex'
import { config, mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import Registration from './registration.vue' import Registration from './registration.vue'
import Vue from 'vue' import Vue from 'vue'
const localVue = global.localVue const localVue = global.localVue
config.stubs['client-only'] = '<span><slot /></span>' const stubs = {
config.stubs['router-link'] = '<span><slot /></span>' 'client-only': true,
config.stubs['nuxt-link'] = '<span><slot /></span>' 'router-link': true,
config.stubs['infinite-loading'] = '<span><slot /></span>' 'nuxt-link': true,
'infinite-loading': true,
}
describe('Registration', () => { describe('Registration', () => {
let wrapper let wrapper
@ -73,6 +75,7 @@ describe('Registration', () => {
return mount(Registration, { return mount(Registration, {
mocks, mocks,
localVue, localVue,
stubs,
}) })
} }
@ -310,7 +313,7 @@ describe('Registration', () => {
it('renders', async () => { it('renders', async () => {
wrapper = await Wrapper() wrapper = await Wrapper()
expect(wrapper.is('.registration-slider')).toBe(true) expect(wrapper.classes('registration-slider')).toBe(true)
}) })
// The asyncTests must go last // The asyncTests must go last

View File

@ -1,11 +1,13 @@
import { config, mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import searchResults from './search-results.vue' import searchResults from './search-results.vue'
import VueMeta from 'vue-meta' import VueMeta from 'vue-meta'
const localVue = global.localVue const localVue = global.localVue
localVue.use(VueMeta, { keyName: 'head' }) localVue.use(VueMeta, { keyName: 'head' })
config.stubs['client-only'] = '<span class="client-only"><slot /></span>' const stubs = {
'client-only': true,
}
describe('search-results.vue', () => { describe('search-results.vue', () => {
let wrapper let wrapper
@ -32,7 +34,7 @@ describe('search-results.vue', () => {
return { ...data, ...aData } return { ...data, ...aData }
} }
} }
return mount(searchResults, { mocks, localVue }) return mount(searchResults, { mocks, localVue, stubs })
} }
it('renders', async () => { it('renders', async () => {

View File

@ -37,7 +37,7 @@ describe('support.vue', () => {
}) })
it('renders', () => { it('renders', () => {
expect(wrapper.is('div')).toBeTruthy() expect(wrapper.element.tagName).toBe('DIV')
}) })
it('has correct <head> content', () => { it('has correct <head> content', () => {

View File

@ -1,12 +1,14 @@
import Vuex from 'vuex' import Vuex from 'vuex'
import { config, mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import TermsAndConditionsConfirm from './terms-and-conditions-confirm.vue' import TermsAndConditionsConfirm from './terms-and-conditions-confirm.vue'
import VueMeta from 'vue-meta' import VueMeta from 'vue-meta'
const localVue = global.localVue const localVue = global.localVue
localVue.use(VueMeta, { keyName: 'head' }) localVue.use(VueMeta, { keyName: 'head' })
config.stubs['nuxt-link'] = '<span class="nuxt-link"><slot /></span>' const stubs = {
'nuxt-link': true,
}
describe('terms-and-conditions-confirm.vue', () => { describe('terms-and-conditions-confirm.vue', () => {
let wrapper let wrapper
@ -45,12 +47,13 @@ describe('terms-and-conditions-confirm.vue', () => {
return mount(TermsAndConditionsConfirm, { return mount(TermsAndConditionsConfirm, {
mocks, mocks,
localVue, localVue,
stubs,
}) })
} }
it('renders', async () => { it('renders', async () => {
wrapper = await Wrapper() wrapper = await Wrapper()
expect(wrapper.is('div')).toBe(true) expect(wrapper.element.tagName).toBe('DIV')
}) })
it('has correct <head> content', async () => { it('has correct <head> content', async () => {

View File

@ -33,7 +33,7 @@ describe('terms-and-conditions.vue', () => {
}) })
it('renders', () => { it('renders', () => {
expect(wrapper.is('div')).toBeTruthy() expect(wrapper.element.tagName).toBe('DIV')
}) })
it('has correct <head> content', () => { it('has correct <head> content', () => {

File diff suppressed because it is too large Load Diff