feat(added new tests for testing vue components Routers, updated routes logic, added nan check for route fields):

This commit is contained in:
2024-03-06 10:04:33 +03:00
parent 81c5c1f87f
commit 8be587a436
5 changed files with 155 additions and 80 deletions

View File

@@ -1,8 +1,9 @@
import {mount} from '@vue/test-utils'
import {expect, it, describe} from 'vitest'
import RoutesList from "@organisms/RoutersEditor/index.vue"
// import RoutersEditor from "@organisms/RoutersEditor/index.vue"
import RouterRow from '@organisms/RoutersEditor/RouterRow.vue'
import routeOptions from '@store/modules/proxy/routeOptions.json'
import { deletedRoute } from '@store/modules/proxy/helpers'
import {createStore} from 'vuex'
const defaultRoutes = [{
@@ -76,7 +77,10 @@ const store = createStore({
getters: {
routes: (state) => state.routes,
routesState: (state) => state.routesState,
routesLib: (state) => state.routesLib,
routesLib: (state) => state.routes.reduce((acc, cur) => ({
...acc,
[cur.id]: cur
}), {}),
routeOptions: (state) => state.routeOptions,
},
mutations: {
@@ -90,7 +94,10 @@ const store = createStore({
commit('setRoutes', defaultRoutes)
},
updateRouteRow: () => ({}),
removeRoute: () => ({}),
removeRoute: ({commit, state}, id) => {
const updatedRoutes = deletedRoute(id, state.routes)
commit('setRoutes', updatedRoutes)
},
breateAddingRoute: () => ({}),
},
namespaced: true,
@@ -140,38 +147,79 @@ describe("Routes", () => {
expect(wrapper.html()).not.toContain('ri-delete-bin-line')
})
it("Renders routes and buttons in RoutesList, if routesState value 'active' and not empty routes array", async () => {
it("Renders route in RoutesList, if routesState value 'active' and default props", async () => {
store.commit('proxy/setRoutesState', 'active')
store.commit('proxy/setRoutes', defaultRoutes)
const getters = {...store.getters }
const routesState = getters['proxy/routesState']
const routes = getters['proxy/routes']
const wrapper = mount(RoutesList, {
const wrapper = mount(RouterRow, {
global: {
plugins: [store],
},
data() {
return {
open: false,
}
})
expect(wrapper.html()).toContain('ri-delete-bin-line')
})
it("Renders route in RoutesList, with set props", async () => {
const wrapper = mount(RouterRow, {
global: {
plugins: [store],
stubs: ['Input', 'Textarea', 'DoubleSwitch'],
},
props: {
id: 1,
path: "/route1",
description: "default",
minRequests: 3,
},
})
console.log('routes 3 test', routes)
expect(wrapper.html()).toContain('/route1') // default props
expect(wrapper.html()).toContain('/route1') // default props
expect(wrapper.html()).toContain('3') // default props
if (routesState === 'active') {
await wrapper.setData({ open: true })
}
console.log('wrapper 3 test', wrapper.html())
await wrapper.setProps({ path: '/route2', minRequests: 7, description: 'test route' })
expect(wrapper.html()).toContain('Добавить роут')
expect(wrapper.html()).toContain('Закрыть')
// expect(wrapper.html()).toContain('ri-delete-bin-line')
expect(wrapper.html()).toContain('ri-delete-bin-line')
expect(wrapper.html()).toContain('test route') // updated props
expect(wrapper.html()).toContain('/route2') // updated props
expect(wrapper.html()).toContain('7') // updated props
})
it("Renders buttons delete and cancel in route, after click button delete", async () => {
const wrapper = mount(RouterRow, {
global: {
plugins: [store],
stubs: ['Input', 'Textarea', 'DoubleSwitch'],
},
})
await wrapper.get('.ri-delete-bin-line').trigger('click')
expect(wrapper.html()).not.toContain('ri-delete-bin-line')
expect(wrapper.html()).toContain('Отменить')
expect(wrapper.html()).toContain('Удалить')
})
it("Renders default route state, after click button delete and click button cancel", async () => {
const wrapper = mount(RouterRow, {
global: {
plugins: [store],
stubs: ['Input', 'Textarea', 'DoubleSwitch'],
},
})
await wrapper.get('.ri-delete-bin-line').trigger('click')
await wrapper.get('.bg-gray-700').trigger('click')
// console.log('wrapper 6 test', wrapper.html())
expect(wrapper.html()).toContain('ri-delete-bin-line')
expect(wrapper.html()).not.toContain('Отменить')
expect(wrapper.html()).not.toContain('Удалить')
})
})