+
When Check Fails:
{
@@ -180,48 +190,34 @@ export default {
},
computed: {
...mapGetters(["selectedAgentPk", "scripts"]),
- /* ...mapState({
- checks: state => (this.policypk ? state.automation.checks : state.agentChecks)
- }), */
- // I have no idea why this works and the above doesn't
checks() {
return this.policypk ? this.$store.state.automation.checks : this.$store.state.agentChecks;
},
- allChecks() {
- return [
- ...this.checks.diskchecks,
- ...this.checks.cpuloadchecks,
- ...this.checks.memchecks,
- ...this.checks.scriptchecks,
- ...this.checks.winservicechecks,
- ...this.checks.pingchecks,
- ...this.checks.eventlogchecks
- ];
- },
checksOptions() {
const r = [];
- this.allChecks.forEach(k => {
- // some checks may have the same primary key so add the check type to make them unique
- r.push({ label: k.readable_desc, value: `${k.id}|${k.check_type}` });
+ this.checks.forEach(i => {
+ r.push({ label: i.readable_desc, value: i.id });
});
return r;
},
scriptOptions() {
const r = [];
- this.scripts.forEach(k => {
- r.push({ label: k.name, value: k.id });
+ this.scripts.forEach(i => {
+ r.push({ label: i.name, value: i.id });
});
return r;
},
step1Done() {
- return this.step > 1 && this.scriptPk !== null && this.taskName !== null ? true : false;
+ return this.step > 1 && this.autotask.script !== null && this.autotask.name && this.autotask.timeout
+ ? true
+ : false;
},
step2Done() {
- if (this.trigger === "daily") {
- return this.days !== null && this.days.length !== 0 && this.time !== null ? true : false;
- } else if (this.trigger === "checkfailure") {
- return this.assignedCheck !== null && this.assignedCheck.length !== 0 ? true : false;
- } else if (this.trigger === "manual") {
+ if (this.autotask.task_type === "scheduled") {
+ return this.autotask.run_time_days.length !== 0 && this.autotask.run_time_minute !== null ? true : false;
+ } else if (this.autotask.task_type === "checkfailure") {
+ return this.autotask.assigned_check !== null ? true : false;
+ } else if (this.autotask.task_type === "manual") {
return true;
} else {
return false;
diff --git a/src/store/automation.js b/src/store/automation.js
index 1d776d0..0c11ae6 100644
--- a/src/store/automation.js
+++ b/src/store/automation.js
@@ -4,22 +4,14 @@ export default {
namespaced: true,
state: {
selectedPolicy: null,
- checks: {},
+ checks: [],
automatedTasks: {},
policies: [],
},
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
- ];
+ checks(state) {
+ return state.checks;
},
selectedPolicyPk(state) {
return state.selectedPolicy;
@@ -56,7 +48,7 @@ export default {
});
},
loadPolicyChecks(context, pk) {
- axios.get(`/checks/${pk}/loadpolicychecks/`).then(r => {
+ axios.get(`/automation/${pk}/policychecks/`).then(r => {
context.commit("setPolicyChecks", r.data);
});
},
diff --git a/src/store/store.js b/src/store/store.js
index 76be940..a9b3744 100644
--- a/src/store/store.js
+++ b/src/store/store.js
@@ -24,7 +24,7 @@ export const store = new Vuex.Store({
selectedRow: null,
agentSummary: {},
winUpdates: {},
- agentChecks: {},
+ agentChecks: null,
automatedTasks: {},
agentTableLoading: false,
treeLoading: false,
@@ -39,6 +39,15 @@ export const store = new Vuex.Store({
selectedAgentPk(state) {
return state.agentSummary.id;
},
+ agentDisks(state) {
+ return state.agentSummary.disks;
+ },
+ agentServices(state) {
+ return state.agentSummary.services;
+ },
+ checks(state) {
+ return state.agentChecks;
+ },
managedByWsus(state) {
return state.agentSummary.managed_by_wsus;
},
@@ -104,7 +113,7 @@ export const store = new Vuex.Store({
},
destroySubTable(state) {
(state.agentSummary = {}),
- (state.agentChecks = {}),
+ (state.agentChecks = null),
(state.winUpdates = {});
(state.installedSoftware = []);
state.selectedRow = "";
@@ -120,7 +129,7 @@ export const store = new Vuex.Store({
})
},
getScripts(context) {
- axios.get("/checks/getscripts/").then(r => {
+ axios.get("/scripts/scripts/").then(r => {
context.commit("SET_SCRIPTS", r.data);
});
},
@@ -144,11 +153,17 @@ export const store = new Vuex.Store({
context.commit("setChecks", r.data);
});
},
- editCheckAlertAction(context, data) {
- return axios.patch("/checks/checkalert/", data);
+ loadDefaultServices(context) {
+ return axios.get("/services/getdefaultservices/");
},
- deleteCheck(context, data) {
- return axios.delete("checks/deletestandardcheck/", { data: data });
+ loadAgentServices(context, agentpk) {
+ return axios.get(`/services/${agentpk}/services/`);
+ },
+ editCheckAlert(context, pk, data) {
+ return axios.patch(`/checks/${pk}/check/`, data);
+ },
+ deleteCheck(context, pk) {
+ return axios.delete(`/checks/${pk}/check/`);
},
editAutoTask(context, data) {
return axios.patch(`/tasks/${data.id}/automatedtasks/`, data);
@@ -187,7 +202,7 @@ export const store = new Vuex.Store({
child_single.push({
label: sites_arr[i].split("|")[0],
id: sites_arr[i].split("|")[1],
- raw: sites_arr[i],
+ raw: `Site|${sites_arr[i]}`,
header: "generic",
icon: "apartment",
iconColor: sites_arr[i].split("|")[2]
@@ -196,7 +211,7 @@ export const store = new Vuex.Store({
output.push({
label: prop.split("|")[0],
id: prop.split("|")[1],
- raw: prop,
+ raw: `Client|${prop}`,
header: "root",
icon: "business",
iconColor: prop.split("|")[2],
diff --git a/src/views/Dashboard.vue b/src/views/Dashboard.vue
index da4cad0..6a8f504 100644
--- a/src/views/Dashboard.vue
+++ b/src/views/Dashboard.vue
@@ -202,12 +202,12 @@ export default {
let client, site, url;
try {
- client = this.$refs.tree.meta[activenode].parent.key.split("|")[0];
- site = activenode.split("|")[0];
+ client = this.$refs.tree.meta[activenode].parent.key.split("|")[1];
+ site = activenode.split("|")[1];
url = `/agents/bysite/${client}/${site}/`;
} catch (e) {
try {
- client = activenode.split("|")[0];
+ client = activenode.split("|")[1];
} catch (e) {
return false;
}
diff --git a/tests/unit/automation/automationmanager.spec.js b/tests/unit/automation/automationmanager.spec.js
index f96f9cd..bda8223 100644
--- a/tests/unit/automation/automationmanager.spec.js
+++ b/tests/unit/automation/automationmanager.spec.js
@@ -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,23 +92,12 @@ 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", () => {
expect(actions.loadPolicies).toHaveBeenCalled();
expect(mutations.setSelectedPolicy).toHaveBeenCalledWith(expect.anything(), null);
- expect(mutations.setPolicyChecks).toHaveBeenCalledWith(expect.anything(), {});
+ expect(mutations.setPolicyChecks).toHaveBeenCalledWith(expect.anything(), []);
expect(mutations.setPolicyAutomatedTasks).toHaveBeenCalledWith(expect.anything(), {});
});
@@ -208,7 +206,7 @@ describe("AutomationManager.vue", () => {
expect(bodyWrapper.find(".q-dialog").exists()).toBe(true);
expect(mutations.setSelectedPolicy).toHaveBeenCalledWith(expect.anything(), null);
- expect(mutations.setPolicyChecks).toHaveBeenCalledWith(expect.anything(), {});
+ expect(mutations.setPolicyChecks).toHaveBeenCalledWith(expect.anything(), []);
expect(mutations.setPolicyAutomatedTasks).toHaveBeenCalledWith(expect.anything(), {});
});
@@ -220,7 +218,7 @@ describe("AutomationManager.vue", () => {
button.trigger("click");
expect(actions.loadPolicies).toHaveBeenCalled();
expect(mutations.setSelectedPolicy).toHaveBeenCalledWith(expect.anything(), null);
- expect(mutations.setPolicyChecks).toHaveBeenCalledWith(expect.anything(), {});
+ expect(mutations.setPolicyChecks).toHaveBeenCalledWith(expect.anything(), []);
expect(mutations.setPolicyAutomatedTasks).toHaveBeenCalledWith(expect.anything(), {});
});
diff --git a/tests/unit/automation/checksData.js b/tests/unit/automation/checksData.js
new file mode 100644
index 0000000..bf35f96
--- /dev/null
+++ b/tests/unit/automation/checksData.js
@@ -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
+}
\ No newline at end of file
diff --git a/tests/unit/automation/formmodal.spec.js b/tests/unit/automation/formmodal.spec.js
index 8802ac6..216a482 100644
--- a/tests/unit/automation/formmodal.spec.js
+++ b/tests/unit/automation/formmodal.spec.js
@@ -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");
});
-});
-
+});
\ No newline at end of file
diff --git a/tests/unit/automation/policycheckstab.spec.js b/tests/unit/automation/policycheckstab.spec.js
new file mode 100644
index 0000000..67e5874
--- /dev/null
+++ b/tests/unit/automation/policycheckstab.spec.js
@@ -0,0 +1,391 @@
+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, getters, store;
+ // Runs before every test
+ beforeEach(() => {
+
+ // Create the Test store
+ // Create the Test store
+ state = {
+ checks: [],
+ selectedPolicy: null
+ };
+
+ getters = {
+ checks(state) {
+ return state.checks
+ },
+ selectedPolicyPk(state) {
+ return state.selectedPolicy
+ }
+ };
+
+ store = new Vuex.Store({
+ modules: {
+ automation: {
+ namespaced: true,
+ state,
+ getters
+ }
+ }
+ });
+
+ 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: "DiskSpaceCheck", index: 0 },
+ { name: "PingCheck", index: 1},
+ { name: "CpuLoadCheck", index: 2},
+ { name: "MemCheck", index: 3},
+ { name: "WinSvcCheck", index: 4},
+ { name: "ScriptCheck", index: 5},
+ { name: "EventLogCheck", index: 6}
+ ];
+
+ let wrapper, store, state, actions, getters;
+ // Runs before every test
+ beforeEach(() => {
+
+ // Create the Test store
+ state = {
+ checks: [],
+ selectedPolicy: 1
+ };
+
+ getters = {
+ checks(state) {
+ return state.checks
+ },
+ selectedPolicyPk(state) {
+ return state.selectedPolicy
+ }
+ };
+
+ 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: [
+ "DiskSpaceCheck",
+ "PingCheck",
+ "CpuLoadCheck",
+ "MemCheck",
+ "WinSvcCheck",
+ "ScriptCheck",
+ "EventLogCheck"
+ ]
+ });
+
+ });
+
+ 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: "DiskSpaceCheck", index: 0, id: 1},
+ {name: "CpuLoadCheck", index: 1, id: 2},
+ {name: "MemCheck", index: 2, id: 3},
+ {name: "ScriptCheck", index: 3, id: 4},
+ {name: "WinSvcCheck", index: 4, id: 5},
+ {name: "PingCheck", index: 5, id: 6},
+ {name: "EventLogCheck", index: 6, id: 7}
+ ];
+
+ let state, rootActions, actions, getters, store, wrapper;
+ // Runs before every test
+ beforeEach(() => {
+
+ // Create the Test store
+ // Create the Test store
+ state = {
+ checks: [
+ diskcheck,
+ cpuloadcheck,
+ memcheck,
+ scriptcheck,
+ winservicecheck,
+ pingcheck,
+ eventlogcheck
+ ],
+ selectedPolicy: 1
+ };
+
+ getters = {
+ checks(state) {
+ return state.checks
+ },
+ selectedPolicyPk(state) {
+ return state.selectedPolicy
+ }
+ };
+
+ 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: [
+ "DiskSpaceCheck",
+ "PingCheck",
+ "CpuLoadCheck",
+ "MemCheck",
+ "WinSvcCheck",
+ "ScriptCheck",
+ "EventLogCheck",
+ "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 */
+});
diff --git a/tests/unit/automation/policytasksstab.js b/tests/unit/automation/policytasksstab.js
new file mode 100644
index 0000000..ffbe7e6
--- /dev/null
+++ b/tests/unit/automation/policytasksstab.js
@@ -0,0 +1,8 @@
+import { mount, shallowMount, createLocalVue, createWrapper } from "@vue/test-utils";
+import PolicyAutomatedTasksTab from "@/components/automation/PolicyAutomatedTasksTab";
+import Vuex from "vuex";
+import "@/quasar.js";
+
+describe.skip("PolicyAutomatedTasks.vue", () => {
+ // TODO after checks rework
+});
\ No newline at end of file