Initial commit

This commit is contained in:
2024-03-05 11:36:21 +03:00
commit bf2f060b94
212 changed files with 100448 additions and 0 deletions

View File

@@ -0,0 +1,177 @@
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 routeOptions from '@store/modules/proxy/routeOptions.json'
import {createStore} from 'vuex'
const defaultRoutes = [{
"id": 7,
"created_at": "2024-02-27T12:02:34.666042252+03:00",
"updated_at": "2024-02-27T12:02:34.666042252+03:00",
"deleted_at": null,
"server_id": -1,
"path": "/route",
"role": 0,
"description": "with route",
"order": 0,
"deepness": 0,
"is_cb_on": true,
"cb_request_limit": 0,
"cb_min_requests": 7,
"cb_error_threshold_percentage": 0,
"cb_interval_duration": 0,
"cb_open_state_timeout": 0,
"is_online": false
},
{
"id": 8,
"created_at": "2024-02-27T12:05:45.268921795+03:00",
"updated_at": "2024-02-27T12:05:45.268921795+03:00",
"deleted_at": null,
"server_id": 7,
"path": "new/3",
"role": 0,
"description": "",
"order": 0,
"deepness": 0,
"is_cb_on": false,
"cb_request_limit": 3,
"cb_min_requests": 5,
"cb_error_threshold_percentage": 0,
"cb_interval_duration": 0,
"cb_open_state_timeout": 0,
"is_online": true
},
{
"id": 9,
"created_at": "2024-02-27T12:11:09.940033992+03:00",
"updated_at": "2024-02-27T12:11:09.940033992+03:00",
"deleted_at": null,
"server_id": -1,
"path": "new/1",
"role": 0,
"description": "",
"order": 0,
"deepness": 9,
"is_cb_on": true,
"cb_request_limit": 0,
"cb_min_requests": 0,
"cb_error_threshold_percentage": 0,
"cb_interval_duration": 0,
"cb_open_state_timeout": 5,
"is_online": false
}]
const store = createStore({
plugins: [],
modules: {
proxy: {
state: {
routes: [],
routesState: "await",
routesLib: {},
routeOptions: routeOptions
},
getters: {
routes: (state) => state.routes,
routesState: (state) => state.routesState,
routesLib: (state) => state.routesLib,
routeOptions: (state) => state.routeOptions,
},
mutations: {
setRoutes: (state, updval) => state.routes = updval,
setRoutesState: (state, updval) => state.routesState = updval,
setRoutesLib: (state, updval) => state.routesLib = updval,
},
actions: {
uploadSiteRoutes: async ({commit}, siteProps) => {
commit('setSelectedSite', siteProps)
commit('setRoutes', defaultRoutes)
},
updateRouteRow: () => ({}),
removeRoute: () => ({}),
breateAddingRoute: () => ({}),
},
namespaced: true,
}
}
})
describe("Routes", () => {
it("Not renders routes and buttons in RoutesList, if routesState value not 'active'", async () => {
const wrapper = mount(RoutesList, {
global: {
plugins: [store],
},
shallow: true,
})
expect(wrapper.html()).not.toContain('Добавить роут')
expect(wrapper.html()).not.toContain('Закрыть')
})
it("Not renders routes - empty array in RoutesList, if routesState value 'active', renders buttons", async () => {
store.commit('proxy/setRoutesState', 'active')
const getters = {...store.getters }
const routesState = getters['proxy/routesState']
const wrapper = mount(RoutesList, {
global: {
plugins: [store],
},
data() {
return {
open: false,
}
},
})
if (routesState === 'active') {
await wrapper.setData({ open: true })
}
expect(wrapper.html()).toContain('Добавить роут')
expect(wrapper.html()).toContain('Закрыть')
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 () => {
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, {
global: {
plugins: [store],
},
data() {
return {
open: false,
}
},
})
console.log('routes 3 test', routes)
if (routesState === 'active') {
await wrapper.setData({ open: true })
}
console.log('wrapper 3 test', wrapper.html())
expect(wrapper.html()).toContain('Добавить роут')
expect(wrapper.html()).toContain('Закрыть')
// expect(wrapper.html()).toContain('ri-delete-bin-line')
})
})