feat(added Services of Services, updated store logic for services, updated layout and logic in components with services, added logic for enable/disable service in ServiceCard componemt, added tests for services store and Services of Services, with mock axios):
This commit is contained in:
parent
a63d44e856
commit
25e3775117
@ -1,6 +1,7 @@
|
||||
import {describe, expect, beforeEach} from 'vitest'
|
||||
import {describe, expect, beforeEach, it} from 'vitest'
|
||||
import {createStore} from 'vuex'
|
||||
import {store} from '@store/modules/proxy/index.js'
|
||||
// import {store as services} from '@store/modules/proxy/index.js'
|
||||
import {addedSite, updatedSite, removedNewSite, deletedSite} from '@store/modules/proxy/helpers.js'
|
||||
|
||||
const sites = store.state.sites
|
||||
@ -24,6 +25,13 @@ const breakSavingSite = store.actions.breakSavingSite
|
||||
const removeSite = store.actions.removeSite
|
||||
const resetStore = store.actions.resetStore
|
||||
|
||||
// const store = createStore({
|
||||
// plugins: [],
|
||||
// modules: {
|
||||
// services
|
||||
// },
|
||||
// })
|
||||
|
||||
const defaultSites = [ {
|
||||
"id": 1,
|
||||
"created_at": "2024-02-22T17:08:37.715772388+03:00",
|
||||
@ -33,6 +41,7 @@ const defaultSites = [ {
|
||||
"port": 9965,
|
||||
"proxy_ip": "172.25.78.153",
|
||||
"site_ip": "172.25.78.153",
|
||||
"device_ip": "172.25.78.153",
|
||||
"internet_uri": "localhost",
|
||||
"description": "localhost",
|
||||
"is_online": true
|
||||
@ -46,6 +55,7 @@ const defaultSites = [ {
|
||||
"port": 3645,
|
||||
"proxy_ip": "172.25.78.151",
|
||||
"site_ip": "172.25.78.151",
|
||||
"device_ip": "172.25.78.151",
|
||||
"internet_uri": "",
|
||||
"description": "create... upd...",
|
||||
"is_online": true
|
||||
@ -59,6 +69,7 @@ const defaultSites = [ {
|
||||
"port": 3645,
|
||||
"proxy_ip": "172.25.78.151",
|
||||
"site_ip": "172.25.78.151",
|
||||
"device_ip": "172.25.78.151",
|
||||
"internet_uri": "",
|
||||
"description": "new updated...",
|
||||
"is_online": false
|
||||
@ -96,13 +107,13 @@ const mockStore = createStore({
|
||||
})
|
||||
|
||||
describe('mutations', () => {
|
||||
//eslint-disable-next-line no-undef
|
||||
|
||||
it('Set to empty Services', () => {
|
||||
const state = { sites: sites }
|
||||
setSites(state, null)
|
||||
expect(state.sites).to.equal(null)
|
||||
})
|
||||
//eslint-disable-next-line no-undef
|
||||
|
||||
it('Add new Service', () => {
|
||||
const newSite = {
|
||||
"id": 34,
|
||||
@ -125,12 +136,12 @@ describe('mutations', () => {
|
||||
})
|
||||
|
||||
describe('actions', () => {
|
||||
//eslint-disable-next-line no-undef
|
||||
|
||||
it('action addNewSiteLayout - added fields for new Service', async () => {
|
||||
mockStore.dispatch('addNewSiteLayout')
|
||||
expect(mockStore.state.sites[0]).toMatchObject({id: -1})
|
||||
})
|
||||
//eslint-disable-next-line no-undef
|
||||
|
||||
it('action editSelectedSite - edited fields values in selected site', async () => {
|
||||
beforeEach(() => {
|
||||
mockStore.dispatch('resetStore')
|
||||
@ -141,7 +152,7 @@ describe('actions', () => {
|
||||
mockStore.dispatch('editSelectedSite', {key: 'description', value: 'updated'})
|
||||
expect(mockStore.state.selectedSite).toMatchObject({name: 'edited test name', port: 5555, description: 'updated'})
|
||||
})
|
||||
//eslint-disable-next-line no-undef
|
||||
|
||||
it('action editSelectedSite - edited fields empty values in selected site', async () => {
|
||||
beforeEach(() => {
|
||||
mockStore.dispatch('resetStore')
|
||||
@ -152,7 +163,7 @@ describe('actions', () => {
|
||||
mockStore.dispatch('editSelectedSite', {key: 'description', value: ''})
|
||||
expect(mockStore.state.selectedSite).toMatchObject({name: '', port: '', description: ''})
|
||||
})
|
||||
//eslint-disable-next-line no-undef
|
||||
|
||||
it('action breakSavingSite - cleared selected site, replaced to default status routesState', async () => {
|
||||
beforeEach(() => {
|
||||
mockStore.dispatch('resetStore')
|
||||
@ -166,7 +177,7 @@ describe('actions', () => {
|
||||
expect(mockStore.state.selectedSite).toBeNull()
|
||||
expect(mockStore.state.routesState).toBe('await')
|
||||
})
|
||||
//eslint-disable-next-line no-undef
|
||||
|
||||
it('action resetStore - cleared all values in store', async () => {
|
||||
beforeEach(() => {
|
||||
mockStore.dispatch('resetStore')
|
||||
@ -193,7 +204,7 @@ describe('actions', () => {
|
||||
})
|
||||
|
||||
describe('helpers', () => {
|
||||
//eslint-disable-next-line no-undef
|
||||
|
||||
it('added new site', async () => {
|
||||
beforeEach(() => {
|
||||
mockStore.dispatch('resetStore')
|
||||
@ -220,7 +231,7 @@ describe('helpers', () => {
|
||||
expect(addedNewSite).toMatchObject(newSite)
|
||||
|
||||
})
|
||||
//eslint-disable-next-line no-undef
|
||||
|
||||
it('updated site', async () => {
|
||||
beforeEach(() => {
|
||||
mockStore.dispatch('resetStore')
|
||||
@ -249,7 +260,7 @@ describe('helpers', () => {
|
||||
expect(updatedSiteToStore).not.toBe(undefined)
|
||||
expect(updatedSiteToStore).toMatchObject(editedSite)
|
||||
})
|
||||
//eslint-disable-next-line no-undef
|
||||
|
||||
it('updated site - empty params', async () => {
|
||||
beforeEach(() => {
|
||||
mockStore.dispatch('resetStore')
|
||||
@ -278,7 +289,7 @@ describe('helpers', () => {
|
||||
expect(updatedSiteToStore).not.toBe(undefined)
|
||||
expect(updatedSiteToStore).toMatchObject(editedSite)
|
||||
})
|
||||
//eslint-disable-next-line no-undef
|
||||
|
||||
it('removed new site before saving to server', async () => {
|
||||
beforeEach(() => {
|
||||
mockStore.dispatch('resetStore')
|
||||
@ -296,7 +307,7 @@ describe('helpers', () => {
|
||||
const removedSiteToStore = mockStore.state.sites.find(site => site.id === -1)
|
||||
expect(removedSiteToStore).toBe(undefined) // removed site to be undefined in array sites to store
|
||||
})
|
||||
//eslint-disable-next-line no-undef
|
||||
|
||||
it('deleted selected site before saving to server', async () => {
|
||||
beforeEach(() => {
|
||||
mockStore.dispatch('resetStore')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user