84 lines
2.3 KiB
JavaScript
84 lines
2.3 KiB
JavaScript
import { mount} from '@vue/test-utils'
|
||
import { expect, test, describe, vi } from 'vitest'
|
||
import Services from '@pages/ServicesManagerPage/ServicesManagerPage.vue';
|
||
import { createStore } from 'vuex'
|
||
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 Services Manager Page component", () => {
|
||
const store = createStore({
|
||
plugins: [],
|
||
modules: {
|
||
services,
|
||
users
|
||
},
|
||
})
|
||
|
||
const defaultServices = [
|
||
{
|
||
"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",
|
||
"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: defaultServices,
|
||
})
|
||
|
||
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]
|
||
}
|
||
})
|
||
|
||
// console.log('wrapper.vm', wrapper.vm)
|
||
|
||
await serviceOfServices.fetchServices()
|
||
|
||
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('На главную')
|
||
})
|
||
|
||
})
|
||
|
||
|