mirror of
https://github.com/jpros/tacticalrmm-web.git
synced 2026-02-23 21:01:11 +00:00
More Vue Tests
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
icon="fas fa-plus"
|
||||
label="Add Check"
|
||||
text-color="black"
|
||||
ref="add"
|
||||
>
|
||||
<q-menu>
|
||||
<q-list dense style="min-width: 200px">
|
||||
@@ -62,6 +63,7 @@
|
||||
push
|
||||
@click="onRefresh(checks.id)"
|
||||
icon="refresh"
|
||||
ref="refresh"
|
||||
/>
|
||||
<template v-if="allChecks === undefined || allChecks.length === 0">
|
||||
<p>No Checks</p>
|
||||
@@ -105,6 +107,7 @@
|
||||
clickable
|
||||
v-close-popup
|
||||
@click="showEditDialog(props.row.check_type)"
|
||||
id="context-edit"
|
||||
>
|
||||
<q-item-section side>
|
||||
<q-icon name="edit" />
|
||||
@@ -115,6 +118,7 @@
|
||||
clickable
|
||||
v-close-popup
|
||||
@click="deleteCheck(props.row.id, props.row.check_type)"
|
||||
id="context-delete"
|
||||
>
|
||||
<q-item-section side>
|
||||
<q-icon name="delete" />
|
||||
@@ -124,7 +128,12 @@
|
||||
|
||||
<q-separator></q-separator>
|
||||
|
||||
<q-item clickable v-close-popup @click="showPolicyCheckStatusModal(props.row)">
|
||||
<q-item
|
||||
clickable
|
||||
v-close-popup
|
||||
@click="showPolicyCheckStatusModal(props.row)"
|
||||
id="context-status"
|
||||
>
|
||||
<q-item-section side>
|
||||
<q-icon name="sync" />
|
||||
</q-item-section>
|
||||
@@ -158,6 +167,7 @@
|
||||
<span
|
||||
style="cursor:pointer;color:blue;text-decoration:underline"
|
||||
@click="showPolicyCheckStatusModal(props.row)"
|
||||
class="status-cell"
|
||||
>
|
||||
See Status
|
||||
</span>
|
||||
@@ -178,8 +188,11 @@
|
||||
</q-dialog>
|
||||
|
||||
<!-- add/edit modals -->
|
||||
<q-dialog v-model="showDialog">
|
||||
<q-dialog
|
||||
v-model="showDialog"
|
||||
@hide="hideDialog">
|
||||
<component
|
||||
v-if="dialogComponent !== null"
|
||||
:is="dialogComponent"
|
||||
@close="hideDialog"
|
||||
:policypk="checks.id"
|
||||
@@ -193,11 +206,39 @@
|
||||
import { mapState, mapGetters } from "vuex";
|
||||
import mixins, { notifySuccessConfig, notifyErrorConfig } from "@/mixins/mixins";
|
||||
import PolicyStatus from "@/components/automation/modals/PolicyStatus";
|
||||
import AddDiskSpaceCheck from "@/components/modals/checks/AddDiskSpaceCheck";
|
||||
import EditDiskSpaceCheck from "@/components/modals/checks/EditDiskSpaceCheck";
|
||||
import AddPingCheck from "@/components/modals/checks/AddPingCheck";
|
||||
import EditPingCheck from "@/components/modals/checks/EditPingCheck";
|
||||
import AddCpuLoadCheck from "@/components/modals/checks/AddCpuLoadCheck";
|
||||
import EditCpuLoadCheck from "@/components/modals/checks/EditCpuLoadCheck";
|
||||
import AddMemCheck from "@/components/modals/checks/AddMemCheck";
|
||||
import EditMemCheck from "@/components/modals/checks/EditMemCheck";
|
||||
import AddWinSvcCheck from "@/components/modals/checks/AddWinSvcCheck";
|
||||
import EditWinSvcCheck from "@/components/modals/checks/EditWinSvcCheck";
|
||||
import AddScriptCheck from "@/components/modals/checks/AddScriptCheck";
|
||||
import EditScriptCheck from "@/components/modals/checks/EditScriptCheck";
|
||||
import AddEventLogCheck from "@/components/modals/checks/AddEventLogCheck";
|
||||
import EditEventLogCheck from "@/components/modals/checks/EditEventLogCheck";
|
||||
|
||||
export default {
|
||||
name: "PolicyChecksTab",
|
||||
components: {
|
||||
PolicyStatus
|
||||
PolicyStatus,
|
||||
AddDiskSpaceCheck,
|
||||
EditDiskSpaceCheck,
|
||||
AddPingCheck,
|
||||
EditPingCheck,
|
||||
AddCpuLoadCheck,
|
||||
EditCpuLoadCheck,
|
||||
AddMemCheck,
|
||||
EditMemCheck,
|
||||
AddWinSvcCheck,
|
||||
EditWinSvcCheck,
|
||||
AddScriptCheck,
|
||||
EditScriptCheck,
|
||||
AddEventLogCheck,
|
||||
EditEventLogCheck
|
||||
},
|
||||
mixins: [mixins],
|
||||
data() {
|
||||
@@ -242,40 +283,38 @@ export default {
|
||||
this.$store.dispatch("automation/loadPolicyChecks", id);
|
||||
},
|
||||
showAddDialog(component) {
|
||||
this.dialogComponent = () => import(`@/components/modals/checks/${component}`);
|
||||
this.dialogComponent = component;
|
||||
this.showDialog = true;
|
||||
},
|
||||
showEditDialog(category) {
|
||||
let component = null;
|
||||
|
||||
switch (category) {
|
||||
case "diskspace":
|
||||
component = "EditDiskSpaceCheck";
|
||||
this.dialogComponent = "EditDiskSpaceCheck";
|
||||
break;
|
||||
case "ping":
|
||||
component = "EditPingCheck";
|
||||
this.dialogComponent = "EditPingCheck";
|
||||
break;
|
||||
case "cpuload":
|
||||
tcomponent = "EditCpuLoadCheck";
|
||||
this.dialogComponent = "EditCpuLoadCheck";
|
||||
break;
|
||||
case "memory":
|
||||
component = "EditMemCheck";
|
||||
this.dialogComponent = "EditMemCheck";
|
||||
break;
|
||||
case "winsvc":
|
||||
component = "EditWinSvcCheck";
|
||||
this.dialogComponent = "EditWinSvcCheck";
|
||||
break;
|
||||
case "script":
|
||||
component = "EditScriptCheck";
|
||||
this.dialogComponent = "EditScriptCheck";
|
||||
break;
|
||||
case "eventlog":
|
||||
component = "EditEventLogCheck";
|
||||
this.dialogComponent = "EditEventLogCheck";
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
this.dialogComponent = () => import(`@/components/modals/checks/${component}`);
|
||||
this.showDialog = true;
|
||||
|
||||
},
|
||||
hideDialog(component) {
|
||||
this.showDialog = false;
|
||||
@@ -284,10 +323,9 @@ export default {
|
||||
deleteCheck(pk, check_type) {
|
||||
this.$q
|
||||
.dialog({
|
||||
title: "Are you sure?",
|
||||
message: `Delete ${check_type} check`,
|
||||
title: `Delete ${check_type} check`,
|
||||
ok: { label: "Delete", color: "negative" },
|
||||
cancel: true,
|
||||
persistent: true
|
||||
})
|
||||
.onOk(() => {
|
||||
const data = { pk: pk, checktype: check_type };
|
||||
|
||||
@@ -65,6 +65,10 @@
|
||||
|
||||
<script>
|
||||
import axios from "axios";
|
||||
<<<<<<< HEAD:web/src/components/modals/checks/ScriptCheck.vue
|
||||
=======
|
||||
import { mapState, mapGetters } from "vuex";
|
||||
>>>>>>> More Vue Tests:web/src/components/modals/checks/AddScriptCheck.vue
|
||||
import mixins from "@/mixins/mixins";
|
||||
import { mapGetters, mapState } from "vuex";
|
||||
export default {
|
||||
|
||||
@@ -153,6 +153,12 @@ export const store = new Vuex.Store({
|
||||
context.commit("setChecks", r.data);
|
||||
});
|
||||
},
|
||||
loadDefaultServices(context) {
|
||||
return axios.get("/services/getdefaultservices/");
|
||||
},
|
||||
loadAgentServices(context, agentpk) {
|
||||
return axios.get(`/services/${agentpk}/services/`);
|
||||
},
|
||||
editCheckAlertAction(context, data) {
|
||||
return axios.patch("/checks/checkalert/", data);
|
||||
},
|
||||
|
||||
@@ -6,8 +6,18 @@ import "@/quasar.js"
|
||||
const localVue = createLocalVue();
|
||||
localVue.use(Vuex);
|
||||
|
||||
describe("AutomationManager.vue", () => {
|
||||
const bodyWrapper = createWrapper(document.body);
|
||||
|
||||
// This is needed to remove q-dialogs since body doesn't rerender
|
||||
afterEach(() => {
|
||||
const dialogs = document.querySelectorAll(".q-dialog");
|
||||
const menus = document.querySelectorAll(".q-menu");
|
||||
dialogs.forEach(x => x.remove());
|
||||
menus.forEach(x => x.remove());
|
||||
});
|
||||
|
||||
describe("AutomationManager.vue", () => {
|
||||
|
||||
const policiesData = [
|
||||
{
|
||||
id: 1,
|
||||
@@ -29,7 +39,6 @@ describe("AutomationManager.vue", () => {
|
||||
}
|
||||
];
|
||||
|
||||
const bodyWrapper = createWrapper(document.body);
|
||||
let wrapper;
|
||||
let state, mutations, actions, store;
|
||||
|
||||
@@ -83,17 +92,6 @@ describe("AutomationManager.vue", () => {
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Runs after every test
|
||||
// This is needed to remove q-dialogs since body doesn't rerender
|
||||
afterEach(() => {
|
||||
const dialogs = document.querySelectorAll(".q-dialog");
|
||||
const menus = document.querySelectorAll(".q-menu");
|
||||
dialogs.forEach(x => x.remove());
|
||||
menus.forEach(x => x.remove());
|
||||
});
|
||||
|
||||
|
||||
// The Tests
|
||||
it("calls vuex loadPolicies action on mount", () => {
|
||||
|
||||
|
||||
102
tests/unit/automation/checksData.js
Normal file
102
tests/unit/automation/checksData.js
Normal file
@@ -0,0 +1,102 @@
|
||||
|
||||
const common = {
|
||||
email_alert: false,
|
||||
failure_count: 0,
|
||||
failures: 5,
|
||||
history: [],
|
||||
last_run: null,
|
||||
more_info: null,
|
||||
status: "pending",
|
||||
task_on_failure: null,
|
||||
text_alert: false,
|
||||
agent: null,
|
||||
policy: 1
|
||||
};
|
||||
|
||||
const diskcheck = {
|
||||
id: 1,
|
||||
check_type: "diskspace",
|
||||
disk: "C:",
|
||||
threshold: 25,
|
||||
readable_desc: "Disk space check: Drive C",
|
||||
...common
|
||||
};
|
||||
|
||||
const cpuloadcheck = {
|
||||
id: 2,
|
||||
check_type: "cpuload",
|
||||
cpuload: 85,
|
||||
readable_desc: "CPU Load check: > 85%",
|
||||
...common
|
||||
};
|
||||
|
||||
const memcheck = {
|
||||
id: 3,
|
||||
check_type: "memory",
|
||||
threshold: 75,
|
||||
readable_desc: "Memory checks: > 85%",
|
||||
...common
|
||||
};
|
||||
|
||||
const scriptcheck = {
|
||||
id: 4,
|
||||
check_type: "script",
|
||||
execution_time: "0.0000",
|
||||
retcode: 0,
|
||||
script: {
|
||||
description: "Test",
|
||||
filename: "local_admin_group.bat",
|
||||
filepath: "salt://scripts//userdefined//local_admin_group.bat",
|
||||
id: 1,
|
||||
name: "Test Script",
|
||||
shell: "cmd"
|
||||
},
|
||||
stderr: null,
|
||||
stdout: null,
|
||||
timeout: 120,
|
||||
readable_desc: "Script check: Test Script",
|
||||
...common
|
||||
};
|
||||
|
||||
const winservicecheck = {
|
||||
id: 5,
|
||||
check_type: "winsvc",
|
||||
pass_if_start_pending: false,
|
||||
restart_if_stopped: false,
|
||||
svc_display_name: "Agent Activation Runtime_1232as",
|
||||
svc_name: "AarSvc_1232as",
|
||||
readable_desc: "Service check: Agent Activation Runtime_1232as",
|
||||
...common
|
||||
};
|
||||
|
||||
const pingcheck = {
|
||||
id: 6,
|
||||
name: "fghfgh",
|
||||
check_type: "ping",
|
||||
ip: "10.10.10.10",
|
||||
readable_desc: "Ping Check: Test Ping Check",
|
||||
...common
|
||||
};
|
||||
|
||||
const eventlogcheck = {
|
||||
id: 7,
|
||||
desc: "asasasa",
|
||||
check_type: "eventlog",
|
||||
log_name: "Application",
|
||||
event_id: 1456,
|
||||
event_type: "ERROR",
|
||||
fail_when: "contains",
|
||||
search_last_days: 1,
|
||||
readable_desc: "Event log check: asdsasa",
|
||||
...common,
|
||||
};
|
||||
|
||||
export {
|
||||
diskcheck,
|
||||
cpuloadcheck,
|
||||
memcheck,
|
||||
scriptcheck,
|
||||
winservicecheck,
|
||||
pingcheck,
|
||||
eventlogcheck
|
||||
}
|
||||
@@ -7,80 +7,126 @@ import "@/quasar.js";
|
||||
const localVue = createLocalVue();
|
||||
localVue.use(Vuex);
|
||||
|
||||
describe("PolicyForm.vue", () => {
|
||||
/*** TEST DATA ***/
|
||||
const clients = [
|
||||
{
|
||||
id: 1,
|
||||
client: "Test Client"
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
client: "Test Client2"
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
client: "Test Client3"
|
||||
}
|
||||
];
|
||||
const sites = [
|
||||
{
|
||||
id: 1,
|
||||
site: "Site Name",
|
||||
client_name: "Test Client"
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
site: "Site Name2",
|
||||
client_name: "Test Client2"
|
||||
}
|
||||
];
|
||||
|
||||
const clients = [
|
||||
{
|
||||
id: 1,
|
||||
client: "Test Client"
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
client: "Test Client2"
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
client: "Test Client3"
|
||||
}
|
||||
];
|
||||
const sites = [
|
||||
{
|
||||
id: 1,
|
||||
site: "Site Name",
|
||||
client_name: "Test Client"
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
site: "Site Name2",
|
||||
client_name: "Test Client2"
|
||||
}
|
||||
];
|
||||
const policy = {
|
||||
id: 1,
|
||||
name: "Test Policy",
|
||||
desc: "Test Desc",
|
||||
active: true,
|
||||
clients: [],
|
||||
sites: []
|
||||
};
|
||||
|
||||
const policy = {
|
||||
id: 1,
|
||||
name: "Test Policy",
|
||||
desc: "Test Desc",
|
||||
active: true,
|
||||
clients: [],
|
||||
sites: []
|
||||
let actions, rootActions, store;
|
||||
beforeEach(() => {
|
||||
rootActions = {
|
||||
loadClients: jest.fn(() => new Promise(res => res({ data: clients }))),
|
||||
loadSites: jest.fn(() => new Promise(res => res({ data: sites }))),
|
||||
};
|
||||
|
||||
let actions, rootActions, store;
|
||||
actions = {
|
||||
loadPolicy: jest.fn(() => new Promise(res => res({ data: policy }))),
|
||||
addPolicy: jest.fn(() => new Promise(res => res())),
|
||||
editPolicy: jest.fn(() => new Promise(res => res())),
|
||||
};
|
||||
|
||||
// Runs before every test
|
||||
store = new Vuex.Store({
|
||||
actions: rootActions,
|
||||
modules: {
|
||||
automation: {
|
||||
namespaced: true,
|
||||
actions,
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
/*** TEST SUITES ***/
|
||||
describe("PolicyForm.vue when editting", () => {
|
||||
|
||||
let wrapper;
|
||||
beforeEach(() => {
|
||||
|
||||
rootActions = {
|
||||
loadClients: jest.fn(() => new Promise(res => res({ data: clients }))),
|
||||
loadSites: jest.fn(() => new Promise(res => res({ data: sites }))),
|
||||
};
|
||||
|
||||
actions = {
|
||||
loadPolicy: jest.fn(() => new Promise(res => res({ data: policy }))),
|
||||
addPolicy: jest.fn(() => new Promise(res => res())),
|
||||
editPolicy: jest.fn(() => new Promise(res => res())),
|
||||
};
|
||||
|
||||
store = new Vuex.Store({
|
||||
actions: rootActions,
|
||||
modules: {
|
||||
automation: {
|
||||
namespaced: true,
|
||||
actions,
|
||||
}
|
||||
wrapper = mount(PolicyForm, {
|
||||
localVue,
|
||||
store,
|
||||
propsData: {
|
||||
pk: 1
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// The Tests
|
||||
it("calls vuex actions on mount", () => {
|
||||
/*** TESTS ***/
|
||||
it("calls vuex actions on mount with pk prop set", () => {
|
||||
|
||||
const wrapper = mount(PolicyForm, {
|
||||
expect(rootActions.loadClients).toHaveBeenCalled();
|
||||
expect(rootActions.loadSites).toHaveBeenCalled();
|
||||
expect(actions.loadPolicy).toHaveBeenCalledWith(expect.anything(), 1);
|
||||
|
||||
});
|
||||
|
||||
it("sends the correct edit action on submit", async () => {
|
||||
|
||||
await flushPromises();
|
||||
const form = wrapper.findComponent({ ref: "form" });
|
||||
form.vm.$emit("submit");
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
expect(actions.addPolicy).not.toHaveBeenCalled();
|
||||
expect(actions.editPolicy).toHaveBeenCalledWith(expect.anything(), policy);
|
||||
|
||||
});
|
||||
|
||||
it("Renders correct title on edit", () => {
|
||||
|
||||
expect(wrapper.vm.title).toBe("Edit Policy");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("PolicyForm.vue when adding", () => {
|
||||
|
||||
let wrapper;
|
||||
beforeEach(() => {
|
||||
|
||||
wrapper = mount(PolicyForm, {
|
||||
localVue,
|
||||
store
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/*** TESTS ***/
|
||||
it("calls vuex actions on mount", () => {
|
||||
|
||||
expect(rootActions.loadClients).toHaveBeenCalled();
|
||||
expect(rootActions.loadSites).toHaveBeenCalled();
|
||||
|
||||
@@ -89,29 +135,8 @@ describe("PolicyForm.vue", () => {
|
||||
|
||||
});
|
||||
|
||||
it("calls vuex actions on mount with pk prop set", () => {
|
||||
|
||||
mount(PolicyForm, {
|
||||
localVue,
|
||||
store,
|
||||
propsData: {
|
||||
pk: 1
|
||||
}
|
||||
});
|
||||
|
||||
expect(rootActions.loadClients).toHaveBeenCalled();
|
||||
expect(rootActions.loadSites).toHaveBeenCalled();
|
||||
expect(actions.loadPolicy).toHaveBeenCalledWith(expect.anything(), 1);
|
||||
|
||||
});
|
||||
|
||||
it("Sets client and site options correctly", async () => {
|
||||
|
||||
const wrapper = mount(PolicyForm, {
|
||||
localVue,
|
||||
store
|
||||
});
|
||||
|
||||
// Make sure the promises are resolved
|
||||
await flushPromises();
|
||||
|
||||
@@ -119,13 +144,8 @@ describe("PolicyForm.vue", () => {
|
||||
expect(wrapper.vm.siteOptions).toHaveLength(2);
|
||||
|
||||
});
|
||||
|
||||
it("sends the correct add action on submit", async () => {
|
||||
|
||||
const wrapper = mount(PolicyForm, {
|
||||
localVue,
|
||||
store
|
||||
});
|
||||
it("sends the correct add action on submit", async () => {
|
||||
|
||||
wrapper.setData({name: "Test Policy"});
|
||||
const form = wrapper.findComponent({ ref: "form" });
|
||||
@@ -137,33 +157,8 @@ describe("PolicyForm.vue", () => {
|
||||
|
||||
});
|
||||
|
||||
it("sends the correct edit action on submit", async () => {
|
||||
|
||||
const wrapper = mount(PolicyForm, {
|
||||
localVue,
|
||||
store,
|
||||
propsData: {
|
||||
pk: 1
|
||||
}
|
||||
});
|
||||
|
||||
await flushPromises();
|
||||
const form = wrapper.findComponent({ ref: "form" });
|
||||
form.vm.$emit("submit");
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
expect(actions.addPolicy).not.toHaveBeenCalled();
|
||||
expect(actions.editPolicy).toHaveBeenCalledWith(expect.anything(), policy);
|
||||
|
||||
});
|
||||
|
||||
it("sends error when name isn't set on submit", async () => {
|
||||
|
||||
const wrapper = mount(PolicyForm, {
|
||||
localVue,
|
||||
store
|
||||
});
|
||||
|
||||
const form = wrapper.findComponent({ ref: "form" });
|
||||
form.vm.$emit("submit");
|
||||
await wrapper.vm.$nextTick();
|
||||
@@ -172,28 +167,9 @@ describe("PolicyForm.vue", () => {
|
||||
expect(actions.editPolicy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("Renders correct title on edit", () => {
|
||||
|
||||
const wrapper = mount(PolicyForm, {
|
||||
localVue,
|
||||
store,
|
||||
propsData: {
|
||||
pk: 1
|
||||
}
|
||||
});
|
||||
|
||||
expect(wrapper.vm.title).toBe("Edit Policy");
|
||||
});
|
||||
|
||||
it("Renders correct title on add", () => {
|
||||
|
||||
const wrapper = mount(PolicyForm, {
|
||||
localVue,
|
||||
store,
|
||||
});
|
||||
|
||||
expect(wrapper.vm.title).toBe("Add Policy");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
398
tests/unit/automation/policycheckstab.spec.js
Normal file
398
tests/unit/automation/policycheckstab.spec.js
Normal file
@@ -0,0 +1,398 @@
|
||||
import { mount, shallowMount, createLocalVue, createWrapper } from "@vue/test-utils";
|
||||
import PolicyChecksTab from "@/components/automation/PolicyChecksTab";
|
||||
import Vuex from "vuex";
|
||||
import "@/quasar.js";
|
||||
|
||||
// Import Test Data
|
||||
import {
|
||||
diskcheck,
|
||||
cpuloadcheck,
|
||||
memcheck,
|
||||
scriptcheck,
|
||||
winservicecheck,
|
||||
pingcheck,
|
||||
eventlogcheck
|
||||
} from "./checksData.js";
|
||||
|
||||
const localVue = createLocalVue();
|
||||
localVue.use(Vuex);
|
||||
|
||||
const bodyWrapper = createWrapper(document.body);
|
||||
|
||||
// This is needed to remove q-dialogs since body doesn't rerender
|
||||
afterEach(() => {
|
||||
const dialogs = document.querySelectorAll(".q-dialog");
|
||||
const menus = document.querySelectorAll(".q-menu");
|
||||
dialogs.forEach(x => x.remove());
|
||||
menus.forEach(x => x.remove());
|
||||
});
|
||||
|
||||
/*** TEST SUITES ***/
|
||||
describe("PolicyChecksTab.vue with no policy selected", () => {
|
||||
|
||||
let wrapper, state, store;
|
||||
// Runs before every test
|
||||
beforeEach(() => {
|
||||
|
||||
// Create the Test store
|
||||
state = {
|
||||
checks: {},
|
||||
};
|
||||
|
||||
store = new Vuex.Store({
|
||||
modules: {
|
||||
automation: {
|
||||
namespaced: true,
|
||||
state,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
wrapper = shallowMount(PolicyChecksTab, {
|
||||
store,
|
||||
localVue
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/*** TESTS ***/
|
||||
it("renders text when policy is selected with no checks", () => {
|
||||
|
||||
expect(wrapper.html()).toContain("No Policy Selected");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("PolicyChecksTab.vue with policy selected and no checks", () => {
|
||||
|
||||
// Used for the add check test loop
|
||||
const addChecksMenu = [
|
||||
{ name: "AddDiskSpaceCheck", index: 0 },
|
||||
{ name: "AddPingCheck", index: 1},
|
||||
{ name: "AddCpuLoadCheck", index: 2},
|
||||
{ name: "AddMemCheck", index: 3},
|
||||
{ name: "AddWinSvcCheck", index: 4},
|
||||
{ name: "AddScriptCheck", index: 5},
|
||||
{ name: "AddEventLogCheck", index: 6}
|
||||
];
|
||||
|
||||
let wrapper, store, state, actions, getters;
|
||||
// Runs before every test
|
||||
beforeEach(() => {
|
||||
|
||||
// Create the Test store
|
||||
state = {
|
||||
checks: {
|
||||
id: 1,
|
||||
name: "Test Policy",
|
||||
diskchecks: [],
|
||||
cpuloadchecks: [],
|
||||
memchecks: [],
|
||||
scriptchecks: [],
|
||||
winservicechecks: [],
|
||||
pingchecks: [],
|
||||
eventlogchecks: []
|
||||
}
|
||||
};
|
||||
|
||||
getters = {
|
||||
allChecks(state) {
|
||||
return [
|
||||
...state.checks.diskchecks,
|
||||
...state.checks.cpuloadchecks,
|
||||
...state.checks.memchecks,
|
||||
...state.checks.scriptchecks,
|
||||
...state.checks.winservicechecks,
|
||||
...state.checks.pingchecks,
|
||||
...state.checks.eventlogchecks
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
actions = {
|
||||
loadPolicyChecks: jest.fn()
|
||||
};
|
||||
|
||||
store = new Vuex.Store({
|
||||
modules: {
|
||||
automation: {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Mount all sub components except the ones specified
|
||||
wrapper = mount(PolicyChecksTab, {
|
||||
store,
|
||||
localVue,
|
||||
stubs: [
|
||||
"AddDiskSpaceCheck",
|
||||
"AddPingCheck",
|
||||
"AddCpuLoadCheck",
|
||||
"AddMemCheck",
|
||||
"AddWinSvcCheck",
|
||||
"AddScriptCheck",
|
||||
"AddEventLogCheck"
|
||||
]
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it("renders text when policy is selected with no checks", () => {
|
||||
|
||||
expect(wrapper.html()).toContain("No Checks");
|
||||
});
|
||||
|
||||
it("sends vuex actions on refresh button click", () => {
|
||||
|
||||
wrapper.findComponent({ ref: "refresh" }).trigger("click");
|
||||
expect(actions.loadPolicyChecks).toHaveBeenCalledWith(expect.anything(), 1);
|
||||
});
|
||||
|
||||
// Create a test for each Add modal
|
||||
addChecksMenu.forEach(item => {
|
||||
it(`opens ${item.name} Dialog`, async () => {
|
||||
|
||||
const addButton = wrapper.findComponent({ ref: "add" });
|
||||
|
||||
expect(bodyWrapper.find(".q-dialog").exists()).toBe(false);
|
||||
expect(bodyWrapper.find(".q-menu").exists()).toBe(false);
|
||||
|
||||
await addButton.trigger("click");
|
||||
expect(bodyWrapper.find(".q-menu").exists()).toBe(true);
|
||||
|
||||
// Selects correct menu item
|
||||
await bodyWrapper.findAll(".q-item").wrappers[item.index].trigger("click");
|
||||
expect(bodyWrapper.find(".q-dialog").exists()).toBe(true);
|
||||
expect(wrapper.vm.showDialog).toBe(true);
|
||||
expect(wrapper.vm.dialogComponent).toBe(item.name);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("PolicyChecksTab.vue with policy selected and checks", () => {
|
||||
|
||||
// Used for the edit check test loop
|
||||
const editChecksModals = [
|
||||
{name: "EditDiskSpaceCheck", index: 0, id: 1},
|
||||
{name: "EditCpuLoadCheck", index: 1, id: 2},
|
||||
{name: "EditMemCheck", index: 2, id: 3},
|
||||
{name: "EditScriptCheck", index: 3, id: 4},
|
||||
{name: "EditWinSvcCheck", index: 4, id: 5},
|
||||
{name: "EditPingCheck", index: 5, id: 6},
|
||||
{name: "EditEventLogCheck", index: 6, id: 7}
|
||||
];
|
||||
|
||||
let state, rootActions, actions, getters, store, wrapper;
|
||||
// Runs before every test
|
||||
beforeEach(() => {
|
||||
|
||||
// Create the Test store
|
||||
state = {
|
||||
checks: {
|
||||
id: 1,
|
||||
name: "Test Policy",
|
||||
diskchecks: [diskcheck],
|
||||
cpuloadchecks: [cpuloadcheck],
|
||||
memchecks: [memcheck],
|
||||
scriptchecks: [scriptcheck],
|
||||
winservicechecks: [winservicecheck],
|
||||
pingchecks: [pingcheck],
|
||||
eventlogchecks: [eventlogcheck]
|
||||
},
|
||||
};
|
||||
|
||||
getters = {
|
||||
allChecks(state) {
|
||||
return [
|
||||
...state.checks.diskchecks,
|
||||
...state.checks.cpuloadchecks,
|
||||
...state.checks.memchecks,
|
||||
...state.checks.scriptchecks,
|
||||
...state.checks.winservicechecks,
|
||||
...state.checks.pingchecks,
|
||||
...state.checks.eventlogchecks
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
actions = {
|
||||
loadPolicyChecks: jest.fn()
|
||||
};
|
||||
|
||||
rootActions = {
|
||||
editCheckAlertAction: jest.fn(),
|
||||
deleteCheck: jest.fn()
|
||||
};
|
||||
|
||||
store = new Vuex.Store({
|
||||
actions: rootActions,
|
||||
modules: {
|
||||
automation: {
|
||||
namespaced: true,
|
||||
state,
|
||||
getters,
|
||||
actions
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Mount all sub components except the ones specified
|
||||
wrapper = mount(PolicyChecksTab, {
|
||||
store,
|
||||
localVue,
|
||||
stubs: [
|
||||
"EditDiskSpaceCheck",
|
||||
"EditPingCheck",
|
||||
"EditCpuLoadCheck",
|
||||
"EditMemCheck",
|
||||
"EditWinSvcCheck",
|
||||
"EditScriptCheck",
|
||||
"EditEventLogCheck",
|
||||
"PolicyStatus"
|
||||
]
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/*** TESTS ***/
|
||||
it("renders the correct number of rows based on checks", () => {
|
||||
|
||||
const rows = wrapper.findAll(".q-table > tbody > .q-tr").wrappers;
|
||||
expect(rows).toHaveLength(7);
|
||||
});
|
||||
|
||||
// Create a test for each Edit modal
|
||||
editChecksModals.forEach(item => {
|
||||
it(`show ${item.name} Dialog`, async () => {
|
||||
|
||||
expect(bodyWrapper.find(".q-dialog").exists()).toBe(false);
|
||||
expect(bodyWrapper.find(".q-menu").exists()).toBe(false);
|
||||
|
||||
const row = wrapper.findAll(".q-table > tbody > .q-tr").wrappers[item.index];
|
||||
await row.trigger("contextmenu");
|
||||
expect(bodyWrapper.find(".q-menu").exists()).toBe(true);
|
||||
|
||||
await bodyWrapper.find("#context-edit").trigger("click");
|
||||
expect(bodyWrapper.find(".q-dialog").exists()).toBe(true);
|
||||
expect(wrapper.vm.showDialog).toBe(true);
|
||||
expect(wrapper.vm.dialogComponent).toBe(item.name);
|
||||
expect(wrapper.vm.editCheckPK).toBe(item.id);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it("shows policy status modal on cell click", async () => {
|
||||
|
||||
expect(bodyWrapper.find(".q-dialog").exists()).toBe(false);
|
||||
|
||||
const row = wrapper.findAll(".status-cell").wrappers[0];
|
||||
await row.trigger("click");
|
||||
expect(bodyWrapper.find(".q-dialog").exists()).toBe(true);
|
||||
expect(wrapper.vm.statusCheck).toEqual(diskcheck);
|
||||
});
|
||||
|
||||
it("shows policy status modal on context menu item click", async () => {
|
||||
|
||||
expect(bodyWrapper.find(".q-dialog").exists()).toBe(false);
|
||||
expect(bodyWrapper.find(".q-menu").exists()).toBe(false);
|
||||
|
||||
const row = wrapper.findAll(".q-table > tbody > .q-tr").wrappers[0];
|
||||
await row.trigger("contextmenu");
|
||||
expect(bodyWrapper.find(".q-menu").exists()).toBe(true);
|
||||
|
||||
await bodyWrapper.find("#context-status").trigger("click");
|
||||
expect(bodyWrapper.find(".q-dialog").exists()).toBe(true);
|
||||
expect(wrapper.vm.statusCheck).toEqual(diskcheck);
|
||||
});
|
||||
|
||||
it("renders correct description for checks", () => {
|
||||
|
||||
expect(wrapper.find(".q-table").html()).toContain("Disk Space Drive C: > 25%");
|
||||
expect(wrapper.find(".q-table").html()).toContain("Avg CPU Load > 85%");
|
||||
expect(wrapper.find(".q-table").html()).toContain("Avg memory usage > 75%");
|
||||
expect(wrapper.find(".q-table").html()).toContain("Script check: Test Script");
|
||||
expect(wrapper.find(".q-table").html()).toContain("Service Check - Agent Activation Runtime_1232as");
|
||||
expect(wrapper.find(".q-table").html()).toContain("Ping fghfgh (10.10.10.10)");
|
||||
expect(wrapper.find(".q-table").html()).toContain("Event Log Check - asasasa");
|
||||
});
|
||||
|
||||
it("deletes check", async () => {
|
||||
|
||||
expect(bodyWrapper.find(".q-dialog").exists()).toBe(false);
|
||||
expect(bodyWrapper.find(".q-menu").exists()).toBe(false);
|
||||
|
||||
const row = wrapper.findAll(".q-table > tbody > .q-tr").wrappers[0];
|
||||
await row.trigger("contextmenu");
|
||||
expect(bodyWrapper.find(".q-menu").exists()).toBe(true);
|
||||
|
||||
await bodyWrapper.find("#context-delete").trigger("click");
|
||||
expect(bodyWrapper.find(".q-dialog").exists()).toBe(true);
|
||||
|
||||
//Get OK button on confirmation dialog and click it
|
||||
await bodyWrapper.findAll(".q-btn").wrappers[1].trigger("click");
|
||||
|
||||
expect(rootActions.deleteCheck).toHaveBeenCalledWith(expect.anything(), {pk: 1, checktype:"diskspace"});
|
||||
expect(actions.loadPolicyChecks).toHaveBeenCalled();
|
||||
|
||||
});
|
||||
|
||||
it("enables and disables text alerts for check", async () => {
|
||||
|
||||
//Get first checkbox in first row
|
||||
const row = wrapper.findAll(".q-checkbox").wrappers[0];
|
||||
|
||||
//Enable Text Alert
|
||||
await row.trigger("click");
|
||||
|
||||
expect(rootActions.editCheckAlertAction).toHaveBeenCalledWith(expect.anything(), {
|
||||
alertType: "text",
|
||||
checkid: 1,
|
||||
category: "diskspace",
|
||||
action: "enabled"
|
||||
});
|
||||
|
||||
//Disable Text Alert
|
||||
await row.trigger("click");
|
||||
|
||||
expect(rootActions.editCheckAlertAction).toHaveBeenCalledWith(expect.anything(), {
|
||||
alertType: "text",
|
||||
checkid: 1,
|
||||
category: "diskspace",
|
||||
action: "disabled"
|
||||
});
|
||||
});
|
||||
|
||||
it("enables and disables email alerts for check", async () => {
|
||||
|
||||
//Get second checkbox in first row
|
||||
const row = wrapper.findAll(".q-checkbox").wrappers[1];
|
||||
|
||||
//Enable Text Alert
|
||||
await row.trigger("click");
|
||||
|
||||
expect(rootActions.editCheckAlertAction).toHaveBeenCalledWith(expect.anything(), {
|
||||
alertType: "email",
|
||||
checkid: 1,
|
||||
category: "diskspace",
|
||||
action: "enabled"
|
||||
});
|
||||
|
||||
//Disable Text Alert
|
||||
await row.trigger("click");
|
||||
|
||||
expect(rootActions.editCheckAlertAction).toHaveBeenCalledWith(expect.anything(), {
|
||||
alertType: "email",
|
||||
checkid: 1,
|
||||
category: "diskspace",
|
||||
action: "disabled"
|
||||
});
|
||||
});
|
||||
|
||||
/* TODO: test @close and @hide events */
|
||||
});
|
||||
1
tests/unit/automation/policytasksstab.spec.js
Normal file
1
tests/unit/automation/policytasksstab.spec.js
Normal file
@@ -0,0 +1 @@
|
||||
// TODO after checks rework
|
||||
Reference in New Issue
Block a user