movied users from old project to new project anover repository, updated tests, cleared warns and errors in tests

This commit is contained in:
2024-04-01 15:26:46 +03:00
parent 10114ff67e
commit 28c13c00ec
50 changed files with 3798 additions and 776 deletions

View File

@@ -1,15 +1,17 @@
import { mount} from '@vue/test-utils'
import { expect, test, describe, vi } from 'vitest'
import Sites from '@pages/SitesManagerPage/SitesManagerPage.vue';
import Services from '@pages/ServicesManagerPage/ServicesManagerPage.vue';
import { createStore } from 'vuex'
import {store as services} from '@/store/modules/services';
import {store as users} from '@/store/modules/users';
import axios from "axios";
import {store as services} from "@/store/modules/services"
import {store as users} from "@/store/modules/users"
import AdapterOfServices from '@adapters/adapterOfServices/Services'
import ServiceOfServices from '@services/serviceOfServices/Services.js'
vi.mock('axios')
describe("tests App mounted with vuex", () => {
describe("tests Services Manager Page component", () => {
const store = createStore({
plugins: [],
modules: {
@@ -18,48 +20,64 @@ describe("tests App mounted with vuex", () => {
},
})
const mockData = [
const defaultServices = [
{
"id": 1,
"first_name": "Leanne",
"last_name": "Graham",
"email": "test@mail.ru",
"role": "admin",
"is_active": true
}
"created_at": "2024-03-06T17:31:31.948355541+03:00",
"updated_at": "2024-03-06T17:31:31.948355541+03:00",
"deleted_at": null,
"name": "jsonplaceholder.typicode.com",
"port": 9965,
"proxy_ip": "172.25.78.153",
"site_ip": "https://jsonplaceholder.typicode.com/",
"internet_uri": "localhost",
"description": "localhost",
"is_online": true
},
]
const resServices = [
{
"id": 1,
"created_at": "2024-03-06T17:31:31.948355541+03:00",
"updated_at": "2024-03-06T17:31:31.948355541+03:00",
"deleted_at": null,
"name": "jsonplaceholder.typicode.com",
"port": 9965,
"proxy_ip": "172.25.78.153",
"device_ip": "https://jsonplaceholder.typicode.com/",
"internet_uri": "localhost",
"description": "localhost",
"is_online": true
},
]
axios.get.mockResolvedValue({
data: mockData,
data: defaultServices,
})
test('tests App mounted with vuex', async () => {
const wrapper = mount(Sites, {
shallow: true,
const adapterOfServices = new AdapterOfServices(import.meta.env.VITE_API_ADDR)
const serviceOfServices = new ServiceOfServices(adapterOfServices, store)
test('Services Manager Page mounted with vuex', async () => {
const wrapper = mount(Services, {
// shallow: true,
global: {
plugins: [store]
}
})
const siteId = 1
const answer = await wrapper.vm.selectSite(siteId, "production")
// console.log('wrapper.vm', wrapper.vm)
const usersList = store.getters['users/usersList']
const componentState = store.getters['users/componentState']
const selectedService = store.getters['services/selectedService']
await serviceOfServices.fetchServices()
expect(usersList).toEqual([{
"id": 1,
"first_name": "Leanne",
"last_name": "Graham",
"email": "test@mail.ru",
"role": "admin",
"is_active": true
}])
expect(componentState).toEqual('active')
expect(selectedService).toBe(null)
expect(answer).toBe("ok")
const uploadServices = store.getters['services/services']
expect(uploadServices).toEqual(resServices) // full services array of store
expect(wrapper.html()).toContain('me-2 mb-6')
expect(wrapper.text()).toContain('На главную')
})
})