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:
SergeyVS 2024-03-07 16:45:20 +03:00
parent a63d44e856
commit 25e3775117

View File

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