127 lines
3.3 KiB
JavaScript
127 lines
3.3 KiB
JavaScript
import { expect, test, describe, vi, beforeEach} from "vitest";
|
|
|
|
import { createStore } from 'vuex'
|
|
import {store as services} from "@/store/modules/services"
|
|
import axios from "axios";
|
|
|
|
vi.mock('axios')
|
|
|
|
describe("tests services store with vuex", () => {
|
|
const store = createStore({
|
|
plugins: [],
|
|
modules: {
|
|
services
|
|
},
|
|
})
|
|
|
|
beforeEach(() => {
|
|
store.dispatch('services/resetStore')
|
|
})
|
|
|
|
test('upload sites data', async () => {
|
|
const mockData = [
|
|
{
|
|
"id": 1,
|
|
"created_at": "2024-02-22T17:08:37.715772388+03:00",
|
|
"updated_at": "2024-02-26T14:11:38.64094899+03:00",
|
|
"deleted_at": null,
|
|
"name": "jsonplaceholder.typicode.com",
|
|
"port": 9965,
|
|
"proxy_ip": "172.25.78.153",
|
|
"site_ip": "172.25.78.153",
|
|
"internet_uri": "localhost",
|
|
"description": "localhost",
|
|
"is_online": true
|
|
}
|
|
]
|
|
|
|
const expectedData = [
|
|
{
|
|
"id": 1,
|
|
"created_at": "2024-02-22T17:08:37.715772388+03:00",
|
|
"updated_at": "2024-02-26T14:11:38.64094899+03:00",
|
|
"deleted_at": null,
|
|
"name": "jsonplaceholder.typicode.com",
|
|
"port": 9965,
|
|
"proxy_ip": "172.25.78.153",
|
|
"device_ip": "172.25.78.153",
|
|
"internet_uri": "localhost",
|
|
"description": "localhost",
|
|
"is_online": true
|
|
}
|
|
]
|
|
|
|
axios.get.mockResolvedValue({
|
|
data: mockData,
|
|
})
|
|
|
|
await store.dispatch('services/uploadSites')
|
|
const sites = store.getters['services/sites']
|
|
|
|
expect(sites).toEqual(expectedData)
|
|
})
|
|
|
|
test('test addNewSiteLayout function', async () => {
|
|
const expectedSiteData = {"port": "", "name": "", id: -1}
|
|
|
|
store.dispatch('services/addNewSiteLayout')
|
|
const selectedSite = store.getters['services/selectedSite']
|
|
const sites = store.getters['services/sites']
|
|
|
|
expect(
|
|
{
|
|
selectedSite,
|
|
sites
|
|
}
|
|
).toEqual({
|
|
selectedSite: expectedSiteData,
|
|
sites: [expectedSiteData]
|
|
})
|
|
})
|
|
|
|
test("test uploadAndSelectService function", async () => {
|
|
const mockData = [
|
|
{
|
|
"id": 1,
|
|
"created_at": "2024-02-22T17:08:37.715772388+03:00",
|
|
"updated_at": "2024-02-26T14:11:38.64094899+03:00",
|
|
"deleted_at": null,
|
|
"name": "jsonplaceholder.typicode.com",
|
|
"port": 9965,
|
|
"proxy_ip": "172.25.78.153",
|
|
"site_ip": "172.25.78.153",
|
|
"internet_uri": "localhost",
|
|
"description": "localhost",
|
|
"is_online": true
|
|
}
|
|
]
|
|
|
|
axios.get.mockResolvedValue({
|
|
data: mockData,
|
|
})
|
|
|
|
await store.dispatch('services/uploadSites')
|
|
store.dispatch('services/uploadAndSelectService', 1)
|
|
|
|
const selectedSite = store.getters['services/selectedSite']
|
|
const selectedSiteState = store.getters['services/selectedSiteState']
|
|
|
|
expect(selectedSite).toEqual({
|
|
"id": 1,
|
|
"created_at": "2024-02-22T17:08:37.715772388+03:00",
|
|
"updated_at": "2024-02-26T14:11:38.64094899+03:00",
|
|
"deleted_at": null,
|
|
"name": "jsonplaceholder.typicode.com",
|
|
"port": 9965,
|
|
"proxy_ip": "172.25.78.153",
|
|
"device_ip": "172.25.78.153",
|
|
"internet_uri": "localhost",
|
|
"description": "localhost",
|
|
"is_online": true
|
|
})
|
|
expect(selectedSiteState).toEqual('active')
|
|
})
|
|
})
|
|
|
|
|