2020-05-19 18:17:55 +00:00
|
|
|
import { mount, createLocalVue } from "@vue/test-utils";
|
|
|
|
import Vuex from "vuex";
|
|
|
|
import RelationsView from "@/components/automation/modals/RelationsView";
|
2020-06-05 18:30:14 +00:00
|
|
|
import "../../utils/quasar.js";
|
2020-05-19 18:17:55 +00:00
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
describe("Relations.vue", () => {
|
|
|
|
|
|
|
|
const policy = {
|
|
|
|
id: 1,
|
|
|
|
name: "Test Policy",
|
|
|
|
active: true,
|
2020-08-25 23:28:06 +00:00
|
|
|
clients: [{ id: 1, client: "Test Name" }],
|
|
|
|
sites: [{ id: 1, site: "Test Name" }],
|
2020-05-19 18:17:55 +00:00
|
|
|
agents: []
|
|
|
|
};
|
|
|
|
|
|
|
|
const related = {
|
|
|
|
agents: [
|
|
|
|
{
|
2020-08-25 23:28:06 +00:00
|
|
|
pk: 1,
|
|
|
|
hostname: "Test Name",
|
|
|
|
site: "Test Site",
|
|
|
|
client: "Test Client"
|
|
|
|
},
|
2020-05-19 18:17:55 +00:00
|
|
|
{
|
2020-08-25 23:28:06 +00:00
|
|
|
pk: 2,
|
|
|
|
site: "Test Site",
|
|
|
|
hostname: "Test Name2",
|
|
|
|
site: "Test Site",
|
2020-05-19 18:17:55 +00:00
|
|
|
client: "Test Client"
|
|
|
|
}
|
|
|
|
],
|
2020-08-25 23:28:06 +00:00
|
|
|
server_sites: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
client_name: "Test Name",
|
|
|
|
site: "Test Name"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
workstation_sites: [
|
2020-05-19 18:17:55 +00:00
|
|
|
{
|
2020-08-25 23:28:06 +00:00
|
|
|
id: 2,
|
|
|
|
client_name: "Test Name",
|
2020-05-19 18:17:55 +00:00
|
|
|
site: "Test Name"
|
|
|
|
}
|
|
|
|
],
|
2020-08-25 23:28:06 +00:00
|
|
|
server_clients: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
client: "Test Name"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
client: "Test Name2"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 3,
|
|
|
|
client: "Test Name3"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
workstation_clients: [
|
2020-05-19 18:17:55 +00:00
|
|
|
{
|
2020-08-25 23:28:06 +00:00
|
|
|
id: 4,
|
2020-05-19 18:17:55 +00:00
|
|
|
client: "Test Name"
|
2020-08-25 23:28:06 +00:00
|
|
|
},
|
2020-05-19 18:17:55 +00:00
|
|
|
{
|
2020-08-25 23:28:06 +00:00
|
|
|
id: 5,
|
2020-05-19 18:17:55 +00:00
|
|
|
client: "Test Name2"
|
2020-08-25 23:28:06 +00:00
|
|
|
},
|
2020-05-19 18:17:55 +00:00
|
|
|
{
|
2020-08-25 23:28:06 +00:00
|
|
|
id: 6,
|
2020-05-19 18:17:55 +00:00
|
|
|
client: "Test Name3"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
let wrapper, actions, store;
|
|
|
|
|
|
|
|
// Runs before every test
|
|
|
|
beforeEach(() => {
|
|
|
|
|
|
|
|
actions = {
|
|
|
|
getRelated: jest.fn(() => new Promise(res => res({ data: related }))),
|
|
|
|
};
|
|
|
|
|
|
|
|
store = new Vuex.Store({
|
|
|
|
modules: {
|
|
|
|
automation: {
|
|
|
|
namespaced: true,
|
|
|
|
actions,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper = mount(RelationsView, {
|
2020-08-25 23:28:06 +00:00
|
|
|
localVue,
|
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
policy: policy
|
|
|
|
}
|
2020-05-19 18:17:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// The Tests
|
|
|
|
it("calls vuex actions on mount", () => {
|
|
|
|
|
|
|
|
expect(actions.getRelated).toHaveBeenCalledWith(expect.anything(), policy.id);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Checks the correct number of list items are rendered in clients tab", async () => {
|
|
|
|
|
2020-08-25 23:28:06 +00:00
|
|
|
await wrapper.findComponent({ ref: "clients" }).trigger("click");
|
2020-05-19 18:17:55 +00:00
|
|
|
|
|
|
|
const list = wrapper.findAll(".q-item");
|
2020-08-25 23:28:06 +00:00
|
|
|
expect(list.length).toBeGreaterThanOrEqual(related.server_clients.length + related.workstation_clients.length);
|
2020-05-19 18:17:55 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Checks the correct number of list items are rendered in sites tab", async () => {
|
|
|
|
|
2020-08-25 23:28:06 +00:00
|
|
|
await wrapper.findComponent({ ref: "sites" }).trigger("click");
|
2020-05-19 18:17:55 +00:00
|
|
|
|
|
|
|
const list = wrapper.findAll(".q-item");
|
2020-08-25 23:28:06 +00:00
|
|
|
expect(list.length).toBeGreaterThanOrEqual(related.server_sites.length + related.workstation_sites.length);
|
2020-05-19 18:17:55 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Checks the correct number of list items are rendered in agents tab", async () => {
|
|
|
|
|
2020-08-25 23:28:06 +00:00
|
|
|
await wrapper.findComponent({ ref: "agents" }).trigger("click");
|
2020-05-19 18:17:55 +00:00
|
|
|
|
|
|
|
const list = wrapper.findAll(".q-item");
|
|
|
|
expect(list.length).toBeGreaterThanOrEqual(related.agents.length);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2020-08-25 23:28:06 +00:00
|
|
|
|