From 7a5d2a3bd959910dce56975a1683d31b07551e62 Mon Sep 17 00:00:00 2001 From: Matthieu Hostache Date: Wed, 26 Feb 2020 11:12:06 +0100 Subject: [PATCH] WebUI: add udp pages --- pkg/api/handler_overview.go | 43 ++++ pkg/api/testdata/overview-dynamic.json | 12 ++ pkg/api/testdata/overview-empty.json | 12 ++ pkg/api/testdata/overview-features.json | 12 ++ pkg/api/testdata/overview-providers.json | 12 ++ webui/src/_mixins/GetTableProps.js | 7 + webui/src/_services/TcpService.js | 8 +- webui/src/_services/UdpService.js | 47 +++++ webui/src/components/_commons/NavBar.vue | 1 + .../src/components/_commons/PanelServers.vue | 9 +- webui/src/pages/_commons/RouterDetail.vue | 5 +- webui/src/pages/_commons/ServiceDetail.vue | 6 +- webui/src/pages/dashboard/Index.vue | 26 +++ webui/src/pages/udp/Routers.vue | 94 +++++++++ webui/src/pages/udp/Services.vue | 95 +++++++++ webui/src/router/routes.js | 59 ++++++ webui/src/store/index.js | 4 +- webui/src/store/udp/actions.js | 53 +++++ webui/src/store/udp/getters.js | 27 +++ webui/src/store/udp/index.js | 12 ++ webui/src/store/udp/mutations.js | 105 ++++++++++ webui/src/store/udp/mutations.spec.js | 197 ++++++++++++++++++ webui/src/store/udp/state.js | 6 + 23 files changed, 842 insertions(+), 10 deletions(-) create mode 100644 webui/src/_services/UdpService.js create mode 100644 webui/src/pages/udp/Routers.vue create mode 100644 webui/src/pages/udp/Services.vue create mode 100644 webui/src/store/udp/actions.js create mode 100644 webui/src/store/udp/getters.js create mode 100644 webui/src/store/udp/index.js create mode 100644 webui/src/store/udp/mutations.js create mode 100644 webui/src/store/udp/mutations.spec.js create mode 100644 webui/src/store/udp/state.js diff --git a/pkg/api/handler_overview.go b/pkg/api/handler_overview.go index 21f1921e1..9bbb47796 100644 --- a/pkg/api/handler_overview.go +++ b/pkg/api/handler_overview.go @@ -32,6 +32,7 @@ type features struct { type overview struct { HTTP schemeOverview `json:"http"` TCP schemeOverview `json:"tcp"` + UDP schemeOverview `json:"udp"` Features features `json:"features,omitempty"` Providers []string `json:"providers,omitempty"` } @@ -47,6 +48,10 @@ func (h Handler) getOverview(rw http.ResponseWriter, request *http.Request) { Routers: getTCPRouterSection(h.runtimeConfiguration.TCPRouters), Services: getTCPServiceSection(h.runtimeConfiguration.TCPServices), }, + UDP: schemeOverview{ + Routers: getUDPRouterSection(h.runtimeConfiguration.UDPRouters), + Services: getUDPServiceSection(h.runtimeConfiguration.UDPServices), + }, Features: getFeatures(h.staticConfig), Providers: getProviders(h.staticConfig), } @@ -155,6 +160,44 @@ func getTCPServiceSection(services map[string]*runtime.TCPServiceInfo) *section } } +func getUDPRouterSection(routers map[string]*runtime.UDPRouterInfo) *section { + var countErrors int + var countWarnings int + for _, rt := range routers { + switch rt.Status { + case runtime.StatusDisabled: + countErrors++ + case runtime.StatusWarning: + countWarnings++ + } + } + + return §ion{ + Total: len(routers), + Warnings: countWarnings, + Errors: countErrors, + } +} + +func getUDPServiceSection(services map[string]*runtime.UDPServiceInfo) *section { + var countErrors int + var countWarnings int + for _, svc := range services { + switch svc.Status { + case runtime.StatusDisabled: + countErrors++ + case runtime.StatusWarning: + countWarnings++ + } + } + + return §ion{ + Total: len(services), + Warnings: countWarnings, + Errors: countErrors, + } +} + func getProviders(conf static.Configuration) []string { if conf.Providers == nil { return nil diff --git a/pkg/api/testdata/overview-dynamic.json b/pkg/api/testdata/overview-dynamic.json index bd553ad9c..b89a17df6 100644 --- a/pkg/api/testdata/overview-dynamic.json +++ b/pkg/api/testdata/overview-dynamic.json @@ -32,5 +32,17 @@ "total": 3, "warnings": 1 } + }, + "udp": { + "routers": { + "errors": 0, + "total": 0, + "warnings": 0 + }, + "services": { + "errors": 0, + "total": 0, + "warnings": 0 + } } } \ No newline at end of file diff --git a/pkg/api/testdata/overview-empty.json b/pkg/api/testdata/overview-empty.json index 974fa846a..78dd6c8a6 100644 --- a/pkg/api/testdata/overview-empty.json +++ b/pkg/api/testdata/overview-empty.json @@ -32,5 +32,17 @@ "total": 0, "warnings": 0 } + }, + "udp": { + "routers": { + "errors": 0, + "total": 0, + "warnings": 0 + }, + "services": { + "errors": 0, + "total": 0, + "warnings": 0 + } } } \ No newline at end of file diff --git a/pkg/api/testdata/overview-features.json b/pkg/api/testdata/overview-features.json index 91b0c1c45..d2fb0d3ff 100644 --- a/pkg/api/testdata/overview-features.json +++ b/pkg/api/testdata/overview-features.json @@ -32,5 +32,17 @@ "total": 0, "warnings": 0 } + }, + "udp": { + "routers": { + "errors": 0, + "total": 0, + "warnings": 0 + }, + "services": { + "errors": 0, + "total": 0, + "warnings": 0 + } } } \ No newline at end of file diff --git a/pkg/api/testdata/overview-providers.json b/pkg/api/testdata/overview-providers.json index 516194468..f49804ea5 100644 --- a/pkg/api/testdata/overview-providers.json +++ b/pkg/api/testdata/overview-providers.json @@ -41,5 +41,17 @@ "total": 0, "warnings": 0 } + }, + "udp": { + "routers": { + "errors": 0, + "total": 0, + "warnings": 0 + }, + "services": { + "errors": 0, + "total": 0, + "warnings": 0 + } } } \ No newline at end of file diff --git a/webui/src/_mixins/GetTableProps.js b/webui/src/_mixins/GetTableProps.js index a15ddcb28..dc9a39209 100644 --- a/webui/src/_mixins/GetTableProps.js +++ b/webui/src/_mixins/GetTableProps.js @@ -100,6 +100,7 @@ const columnsByResource = { 'tls', 'provider' ], + udpRouters: ['status', 'entryPoints', 'name', 'service', 'provider'], services: ['status', 'name', 'type', 'servers', 'provider'], middlewares: ['status', 'name', 'type', 'provider'] } @@ -111,12 +112,18 @@ const propsByType = { 'tcp-routers': { columns: columnsByResource.routers }, + 'udp-routers': { + columns: columnsByResource.udpRouters + }, 'http-services': { columns: columnsByResource.services }, 'tcp-services': { columns: columnsByResource.services }, + 'udp-services': { + columns: columnsByResource.services + }, 'http-middlewares': { columns: columnsByResource.middlewares } diff --git a/webui/src/_services/TcpService.js b/webui/src/_services/TcpService.js index 41c7d3dfa..3ca965e24 100644 --- a/webui/src/_services/TcpService.js +++ b/webui/src/_services/TcpService.js @@ -8,7 +8,7 @@ function getAllRouters (params) { .then(response => { const { data = [], headers } = response const total = getTotal(headers, params) - console.log('Success -> HttpService -> getAllRouters', response.data) + console.log('Success -> TcpService -> getAllRouters', response.data) return { data, total } }) } @@ -16,7 +16,7 @@ function getAllRouters (params) { function getRouterByName (name) { return APP.api.get(`${apiBase}/routers/${name}`) .then(body => { - console.log('Success -> HttpService -> getRouterByName', body.data) + console.log('Success -> TcpService -> getRouterByName', body.data) return body.data }) } @@ -26,7 +26,7 @@ function getAllServices (params) { .then(response => { const { data = [], headers } = response const total = getTotal(headers, params) - console.log('Success -> HttpService -> getAllServices', response.data) + console.log('Success -> TcpService -> getAllServices', response.data) return { data, total } }) } @@ -34,7 +34,7 @@ function getAllServices (params) { function getServiceByName (name) { return APP.api.get(`${apiBase}/services/${name}`) .then(body => { - console.log('Success -> HttpService -> getServiceByName', body.data) + console.log('Success -> TcpService -> getServiceByName', body.data) return body.data }) } diff --git a/webui/src/_services/UdpService.js b/webui/src/_services/UdpService.js new file mode 100644 index 000000000..fd641d357 --- /dev/null +++ b/webui/src/_services/UdpService.js @@ -0,0 +1,47 @@ +import { APP } from '../_helpers/APP' +import { getTotal } from './utils' + +const apiBase = '/udp' + +function getAllRouters (params) { + return APP.api.get(`${apiBase}/routers?search=${params.query}&status=${params.status}&per_page=${params.limit}&page=${params.page}`) + .then(response => { + const { data = [], headers } = response + const total = getTotal(headers, params) + console.log('Success -> UdpService -> getAllRouters', response.data) + return { data, total } + }) +} + +function getRouterByName (name) { + return APP.api.get(`${apiBase}/routers/${name}`) + .then(body => { + console.log('Success -> UdpService -> getRouterByName', body.data) + return body.data + }) +} + +function getAllServices (params) { + return APP.api.get(`${apiBase}/services?search=${params.query}&status=${params.status}&per_page=${params.limit}&page=${params.page}`) + .then(response => { + const { data = [], headers } = response + const total = getTotal(headers, params) + console.log('Success -> UdpService -> getAllServices', response.data) + return { data, total } + }) +} + +function getServiceByName (name) { + return APP.api.get(`${apiBase}/services/${name}`) + .then(body => { + console.log('Success -> UdpService -> getServiceByName', body.data) + return body.data + }) +} + +export default { + getAllRouters, + getRouterByName, + getAllServices, + getServiceByName +} diff --git a/webui/src/components/_commons/NavBar.vue b/webui/src/components/_commons/NavBar.vue index 0818f6135..8a474cc6d 100644 --- a/webui/src/components/_commons/NavBar.vue +++ b/webui/src/components/_commons/NavBar.vue @@ -10,6 +10,7 @@ + diff --git a/webui/src/components/_commons/PanelServers.vue b/webui/src/components/_commons/PanelServers.vue index 36968b476..dcd89b725 100644 --- a/webui/src/components/_commons/PanelServers.vue +++ b/webui/src/components/_commons/PanelServers.vue @@ -3,7 +3,7 @@
-
+
Status
@@ -15,7 +15,7 @@
-
+
@@ -41,13 +41,16 @@ import AvatarState from './AvatarState' export default { name: 'PanelServers', - props: ['data', 'dense'], + props: ['data', 'dense', 'hasStatus'], components: { AvatarState }, computed: { isDense () { return this.dense !== undefined + }, + showStatus () { + return this.hasStatus !== undefined } }, filters: { diff --git a/webui/src/pages/_commons/RouterDetail.vue b/webui/src/pages/_commons/RouterDetail.vue index 0d3097156..2aa29492c 100644 --- a/webui/src/pages/_commons/RouterDetail.vue +++ b/webui/src/pages/_commons/RouterDetail.vue @@ -109,7 +109,7 @@
-
+
TLS
@@ -192,6 +192,7 @@ export default { }, ...mapGetters('http', { http_routerByName: 'routerByName' }), ...mapGetters('tcp', { tcp_routerByName: 'routerByName' }), + ...mapGetters('udp', { udp_routerByName: 'routerByName' }), hasMiddlewares () { return this.$route.meta.protocol === 'http' && this.middlewares.length > 0 }, @@ -208,6 +209,7 @@ export default { methods: { ...mapActions('http', { http_getRouterByName: 'getRouterByName', getMiddlewareByName: 'getMiddlewareByName' }), ...mapActions('tcp', { tcp_getRouterByName: 'getRouterByName' }), + ...mapActions('udp', { udp_getRouterByName: 'getRouterByName' }), ...mapActions('entrypoints', { getEntrypointsByName: 'getByName' }), refreshAll () { if (this.routerByName.loading) { @@ -274,6 +276,7 @@ export default { clearInterval(this.timeOutGetAll) this.$store.commit('http/getRouterByNameClear') this.$store.commit('tcp/getRouterByNameClear') + this.$store.commit('udp/getRouterByNameClear') } } diff --git a/webui/src/pages/_commons/ServiceDetail.vue b/webui/src/pages/_commons/ServiceDetail.vue index 17596b296..68c158bbc 100644 --- a/webui/src/pages/_commons/ServiceDetail.vue +++ b/webui/src/pages/_commons/ServiceDetail.vue @@ -54,7 +54,7 @@
- +
@@ -173,6 +173,7 @@ export default { computed: { ...mapGetters('http', { http_serviceByName: 'serviceByName' }), ...mapGetters('tcp', { tcp_serviceByName: 'serviceByName' }), + ...mapGetters('udp', { udp_serviceByName: 'serviceByName' }), protocol () { return this.$route.meta.protocol }, @@ -189,6 +190,7 @@ export default { methods: { ...mapActions('http', { http_getServiceByName: 'getServiceByName', http_getRouterByName: 'getRouterByName' }), ...mapActions('tcp', { tcp_getServiceByName: 'getServiceByName', tcp_getRouterByName: 'getRouterByName' }), + ...mapActions('udp', { udp_getServiceByName: 'getServiceByName', udp_getRouterByName: 'getRouterByName' }), refreshAll () { if (this.serviceByName.loading) { return @@ -238,6 +240,8 @@ export default { beforeDestroy () { clearInterval(this.timeOutGetAll) this.$store.commit('http/getServiceByNameClear') + this.$store.commit('tcp/getServiceByNameClear') + this.$store.commit('udp/getServiceByNameClear') } } diff --git a/webui/src/pages/dashboard/Index.vue b/webui/src/pages/dashboard/Index.vue index 02e9a6ad2..f9a8098d5 100644 --- a/webui/src/pages/dashboard/Index.vue +++ b/webui/src/pages/dashboard/Index.vue @@ -70,6 +70,29 @@
+
+
+
+ +
UDP
+
+
+
+ +
+
+
+
+

+ +

+
+
+
+
+
@@ -157,6 +180,9 @@ export default { allTCP () { return this.overviewAll.items.tcp }, + allUDP () { + return this.overviewAll.items.udp + }, allFeatures () { return this.overviewAll.items.features }, diff --git a/webui/src/pages/udp/Routers.vue b/webui/src/pages/udp/Routers.vue new file mode 100644 index 000000000..c46900430 --- /dev/null +++ b/webui/src/pages/udp/Routers.vue @@ -0,0 +1,94 @@ + + + + + diff --git a/webui/src/pages/udp/Services.vue b/webui/src/pages/udp/Services.vue new file mode 100644 index 000000000..988ace32b --- /dev/null +++ b/webui/src/pages/udp/Services.vue @@ -0,0 +1,95 @@ + + + + + diff --git a/webui/src/router/routes.js b/webui/src/router/routes.js index 28ac34a0b..53565cf9d 100644 --- a/webui/src/router/routes.js +++ b/webui/src/router/routes.js @@ -158,6 +158,65 @@ const routes = [ } } ] + }, + { + path: '/udp', + redirect: '/udp/routers', + component: LayoutDefault, + children: [ + { + path: 'routers', + name: 'udpRouters', + components: { + default: () => import('pages/udp/Routers.vue'), + NavBar: () => import('components/_commons/ToolBar.vue') + }, + props: { default: true, NavBar: true }, + meta: { + protocol: 'udp', + title: 'TCP Routers' + } + }, + { + path: 'routers/:name', + name: 'udpRouterDetail', + components: { + default: () => import('pages/_commons/RouterDetail.vue'), + NavBar: () => import('components/_commons/ToolBar.vue') + }, + props: { default: true, NavBar: true }, + meta: { + protocol: 'udp', + title: 'TCP Router Detail' + } + }, + { + path: 'services', + name: 'udpServices', + components: { + default: () => import('pages/udp/Services.vue'), + NavBar: () => import('components/_commons/ToolBar.vue') + }, + props: { default: true, NavBar: true }, + meta: { + protocol: 'udp', + title: 'TCP Services' + } + }, + { + path: 'services/:name', + name: 'udpServiceDetail', + components: { + default: () => import('pages/_commons/ServiceDetail.vue'), + NavBar: () => import('components/_commons/ToolBar.vue') + }, + props: { default: true, NavBar: true }, + meta: { + protocol: 'udp', + title: 'TCP Service Detail' + } + } + ] } ] diff --git a/webui/src/store/index.js b/webui/src/store/index.js index 190ad6594..5011c5bd4 100644 --- a/webui/src/store/index.js +++ b/webui/src/store/index.js @@ -5,6 +5,7 @@ import core from './core' import entrypoints from './entrypoints' import http from './http' import tcp from './tcp' +import udp from './udp' Vue.use(Vuex) @@ -19,7 +20,8 @@ export default function (/* { ssrContext } */) { core, entrypoints, http, - tcp + tcp, + udp }, // enable strict mode (adds overhead!) diff --git a/webui/src/store/udp/actions.js b/webui/src/store/udp/actions.js new file mode 100644 index 000000000..15fe3a7be --- /dev/null +++ b/webui/src/store/udp/actions.js @@ -0,0 +1,53 @@ +import UdpService from '../../_services/UdpService' + +export function getAllRouters ({ commit }, params) { + commit('getAllRoutersRequest') + return UdpService.getAllRouters(params) + .then(body => { + commit('getAllRoutersSuccess', { body, ...params }) + return body + }) + .catch(error => { + commit('getAllRoutersFailure', error) + return Promise.reject(error) + }) +} + +export function getRouterByName ({ commit }, name) { + commit('getRouterByNameRequest') + return UdpService.getRouterByName(name) + .then(body => { + commit('getRouterByNameSuccess', body) + return body + }) + .catch(error => { + commit('getRouterByNameFailure', error) + return Promise.reject(error) + }) +} + +export function getAllServices ({ commit }, params) { + commit('getAllServicesRequest') + return UdpService.getAllServices(params) + .then(body => { + commit('getAllServicesSuccess', { body, ...params }) + return body + }) + .catch(error => { + commit('getAllServicesFailure', error) + return Promise.reject(error) + }) +} + +export function getServiceByName ({ commit }, name) { + commit('getServiceByNameRequest') + return UdpService.getServiceByName(name) + .then(body => { + commit('getServiceByNameSuccess', body) + return body + }) + .catch(error => { + commit('getServiceByNameFailure', error) + return Promise.reject(error) + }) +} diff --git a/webui/src/store/udp/getters.js b/webui/src/store/udp/getters.js new file mode 100644 index 000000000..2b9611e94 --- /dev/null +++ b/webui/src/store/udp/getters.js @@ -0,0 +1,27 @@ +// ---------------------------- +// all Routers +// ---------------------------- +export function allRouters (state) { + return state.allRouters +} + +// ---------------------------- +// Router by Name +// ---------------------------- +export function routerByName (state) { + return state.routerByName +} + +// ---------------------------- +// all Services +// ---------------------------- +export function allServices (state) { + return state.allServices +} + +// ---------------------------- +// Service by Name +// ---------------------------- +export function serviceByName (state) { + return state.serviceByName +} diff --git a/webui/src/store/udp/index.js b/webui/src/store/udp/index.js new file mode 100644 index 000000000..babab8ec5 --- /dev/null +++ b/webui/src/store/udp/index.js @@ -0,0 +1,12 @@ +import state from './state' +import * as getters from './getters' +import * as mutations from './mutations' +import * as actions from './actions' + +export default { + namespaced: true, + getters, + mutations, + actions, + state +} diff --git a/webui/src/store/udp/mutations.js b/webui/src/store/udp/mutations.js new file mode 100644 index 000000000..69df42013 --- /dev/null +++ b/webui/src/store/udp/mutations.js @@ -0,0 +1,105 @@ +import { withPagination } from '../../_helpers/Mutations' + +// ---------------------------- +// Get All Routers +// ---------------------------- +export function getAllRoutersRequest (state) { + withPagination('request', { statePath: 'allRouters' })(state) +} + +export function getAllRoutersSuccess (state, data) { + const { query = '', status = '' } = data + const currentState = state.allRouters + + const isSameContext = currentState.currentQuery === query && currentState.currentStatus === status + + state.allRouters = { + ...state.allRouters, + currentQuery: query, + currentStatus: status + } + + withPagination('success', { + isSameContext, + statePath: 'allRouters' + })(state, data) +} + +export function getAllRoutersFailure (state, error) { + withPagination('failure', { statePath: 'allRouters' })(state, error) +} + +export function getAllRoutersClear (state) { + state.allRouters = {} +} + +// ---------------------------- +// Get Router By Name +// ---------------------------- +export function getRouterByNameRequest (state) { + state.routerByName.loading = true +} + +export function getRouterByNameSuccess (state, body) { + state.routerByName = { item: body, loading: false } +} + +export function getRouterByNameFailure (state, error) { + state.routerByName = { error } +} + +export function getRouterByNameClear (state) { + state.routerByName = {} +} + +// ---------------------------- +// Get All Services +// ---------------------------- +export function getAllServicesRequest (state) { + withPagination('request', { statePath: 'allServices' })(state) +} + +export function getAllServicesSuccess (state, data) { + const { query = '', status = '' } = data + const currentState = state.allServices + + const isSameContext = currentState.currentQuery === query && currentState.currentStatus === status + + state.allServices = { + ...state.allServices, + currentQuery: query, + currentStatus: status + } + + withPagination('success', { + isSameContext, + statePath: 'allServices' + })(state, data) +} + +export function getAllServicesFailure (state, error) { + withPagination('failure', { statePath: 'allServices' })(state, error) +} + +export function getAllServicesClear (state) { + state.allServices = {} +} + +// ---------------------------- +// Get Service By Name +// ---------------------------- +export function getServiceByNameRequest (state) { + state.serviceByName.loading = true +} + +export function getServiceByNameSuccess (state, body) { + state.serviceByName = { item: body, loading: false } +} + +export function getServiceByNameFailure (state, error) { + state.serviceByName = { error } +} + +export function getServiceByNameClear (state) { + state.serviceByName = {} +} diff --git a/webui/src/store/udp/mutations.spec.js b/webui/src/store/udp/mutations.spec.js new file mode 100644 index 000000000..fa09e3d74 --- /dev/null +++ b/webui/src/store/udp/mutations.spec.js @@ -0,0 +1,197 @@ +import { expect } from 'chai' +import store from './index.js' + +const { + getAllRoutersRequest, + getAllRoutersSuccess, + getAllRoutersFailure, + getAllServicesRequest, + getAllServicesSuccess, + getAllServicesFailure +} = store.mutations + +describe('udp mutations', function () { + /* Routers */ + describe('udp routers mutations', function () { + it('getAllRoutersRequest', function () { + const state = { + allRouters: { + items: [{}, {}, {}] + } + } + + getAllRoutersRequest(state) + + expect(state.allRouters.loading).to.equal(true) + expect(state.allRouters.items.length).to.equal(3) + }) + + it('getAllRoutersSuccess page 1', function () { + const state = { + allRouters: { + loading: true + } + } + + const data = { + body: { + data: [{}, {}, {}], + total: 3 + }, + query: 'test query', + status: 'warning', + page: 1 + } + + getAllRoutersSuccess(state, data) + + expect(state.allRouters.loading).to.equal(false) + expect(state.allRouters.total).to.equal(3) + expect(state.allRouters.items.length).to.equal(3) + expect(state.allRouters.currentPage).to.equal(1) + expect(state.allRouters.currentQuery).to.equal('test query') + expect(state.allRouters.currentStatus).to.equal('warning') + }) + + it('getAllRoutersSuccess page 2', function () { + const state = { + allRouters: { + loading: false, + items: [{ id: 1 }, { id: 2 }, { id: 3 }], + total: 3, + currentPage: 1, + currentQuery: 'test query', + currentStatus: 'warning' + } + } + + const data = { + body: { + data: [{ id: 4 }, { id: 5 }, { id: 6 }, { id: 7 }], + total: 4 + }, + query: 'test query', + status: 'warning', + page: 2 + } + + getAllRoutersSuccess(state, data) + + expect(state.allRouters.loading).to.equal(false) + expect(state.allRouters.total).to.equal(7) + expect(state.allRouters.items.length).to.equal(7) + expect(state.allRouters.currentPage).to.equal(2) + expect(state.allRouters.currentQuery).to.equal('test query') + expect(state.allRouters.currentStatus).to.equal('warning') + }) + + it('getAllRoutersFailing', function () { + const state = { + allRouters: { + items: [{}, {}, {}], + loading: true + } + } + + const error = { message: 'invalid request: page: 3, per_page: 10' } + + getAllRoutersFailure(state, error) + + expect(state.allRouters.loading).to.equal(false) + expect(state.allRouters.endReached).to.equal(true) + expect(state.allRouters.items.length).to.equal(3) + }) + }) + + /* Services */ + describe('udp services mutations', function () { + it('getAllServicesRequest', function () { + const state = { + allServices: { + items: [{}, {}, {}] + } + } + + getAllServicesRequest(state) + + expect(state.allServices.loading).to.equal(true) + expect(state.allServices.items.length).to.equal(3) + }) + + it('getAllServicesSuccess page 1', function () { + const state = { + allServices: { + loading: true + } + } + + const data = { + body: { + data: [{}, {}, {}], + total: 3 + }, + query: 'test query', + status: 'warning', + page: 1 + } + + getAllServicesSuccess(state, data) + + expect(state.allServices.loading).to.equal(false) + expect(state.allServices.total).to.equal(3) + expect(state.allServices.items.length).to.equal(3) + expect(state.allServices.currentPage).to.equal(1) + expect(state.allServices.currentQuery).to.equal('test query') + expect(state.allServices.currentStatus).to.equal('warning') + }) + + it('getAllServicesSuccess page 2', function () { + const state = { + allServices: { + loading: false, + items: [{ id: 1 }, { id: 2 }, { id: 3 }], + total: 3, + currentPage: 1, + currentQuery: 'test query', + currentStatus: 'warning' + } + } + + const data = { + body: { + data: [{ id: 4 }, { id: 5 }, { id: 6 }, { id: 7 }], + total: 4 + }, + query: 'test query', + status: 'warning', + page: 2 + } + + getAllServicesSuccess(state, data) + + expect(state.allServices.loading).to.equal(false) + expect(state.allServices.total).to.equal(7) + expect(state.allServices.items.length).to.equal(7) + expect(state.allServices.currentPage).to.equal(2) + expect(state.allServices.currentQuery).to.equal('test query') + expect(state.allServices.currentStatus).to.equal('warning') + }) + + it('getAllServicesFailing', function () { + const state = { + allServices: { + items: [{}, {}, {}], + loading: true + } + } + + const error = { message: 'invalid request: page: 3, per_page: 10' } + + getAllServicesFailure(state, error) + + expect(state.allServices.loading).to.equal(false) + expect(state.allServices.endReached).to.equal(true) + expect(state.allServices.items.length).to.equal(3) + }) + }) +}) diff --git a/webui/src/store/udp/state.js b/webui/src/store/udp/state.js new file mode 100644 index 000000000..0eb429a34 --- /dev/null +++ b/webui/src/store/udp/state.js @@ -0,0 +1,6 @@ +export default { + allRouters: {}, + routerByName: {}, + allServices: {}, + serviceByName: {} +}