|
@@ -2,64 +2,95 @@ import { flushPromises } from "@vue/test-utils";
|
|
|
import LongJobs from "@/components/LongJobs.vue";
|
|
|
import FloatingBox from "@/components/FloatingBox.vue";
|
|
|
import { getWrapper } from "@/tests/utils/utils";
|
|
|
-import { useUserAuthStore } from "@/stores/userAuth";
|
|
|
import { useLongJobsStore } from "@/stores/longJobs";
|
|
|
import { useWebsocketsStore } from "@/stores/websockets";
|
|
|
|
|
|
describe("LongJobs component", async () => {
|
|
|
beforeEach(async context => {
|
|
|
- context.socketData = {
|
|
|
- dispatch: {
|
|
|
- "users.getLongJobs": {
|
|
|
- status: "success",
|
|
|
- data: {
|
|
|
- longJobs: [
|
|
|
- {
|
|
|
- id: "8704d336-660f-4d23-8c18-a7271c6656b5",
|
|
|
- name: "Bulk verifying songs",
|
|
|
- status: "success",
|
|
|
- message:
|
|
|
- "50 songs have been successfully verified"
|
|
|
- }
|
|
|
- ]
|
|
|
- }
|
|
|
- },
|
|
|
- "users.getLongJob": {
|
|
|
- status: "success",
|
|
|
- data: {
|
|
|
- longJob: {
|
|
|
- id: "bf3dc3aa-e7aa-4b69-bfd1-8e979fe7dfa5",
|
|
|
- name: "Successfully edited tags.",
|
|
|
- status: "success",
|
|
|
- message: "Bulk editing tags"
|
|
|
+ context.mockSocket = {
|
|
|
+ data: {
|
|
|
+ dispatch: {
|
|
|
+ "users.getLongJobs": () => ({
|
|
|
+ status: "success",
|
|
|
+ data: {
|
|
|
+ longJobs: [
|
|
|
+ {
|
|
|
+ id: "8704d336-660f-4d23-8c18-a7271c6656b5",
|
|
|
+ name: "Bulk verifying songs",
|
|
|
+ status: "success",
|
|
|
+ message:
|
|
|
+ "50 songs have been successfully verified"
|
|
|
+ }
|
|
|
+ ]
|
|
|
}
|
|
|
- }
|
|
|
+ }),
|
|
|
+ "users.getLongJob": id =>
|
|
|
+ id === "bf3dc3aa-e7aa-4b69-bfd1-8e979fe7dfa5"
|
|
|
+ ? {
|
|
|
+ status: "success",
|
|
|
+ data: {
|
|
|
+ longJob: {
|
|
|
+ id,
|
|
|
+ name: "Bulk editing tags",
|
|
|
+ status: "success",
|
|
|
+ message: "Successfully edited tags."
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ : {
|
|
|
+ status: "error",
|
|
|
+ message: "Long job not found."
|
|
|
+ },
|
|
|
+ "users.removeLongJob": () => ({
|
|
|
+ status: "success"
|
|
|
+ })
|
|
|
},
|
|
|
- "users.removeLongJob": {
|
|
|
- status: "success"
|
|
|
+ progress: {
|
|
|
+ "users.getLongJob": id =>
|
|
|
+ id === "bf3dc3aa-e7aa-4b69-bfd1-8e979fe7dfa5"
|
|
|
+ ? [
|
|
|
+ {
|
|
|
+ id,
|
|
|
+ name: "Bulk editing tags",
|
|
|
+ status: "started",
|
|
|
+ message: "Updating tags."
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id,
|
|
|
+ name: "Bulk editing tags",
|
|
|
+ status: "update",
|
|
|
+ message: "Updating tags in MongoDB."
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ : []
|
|
|
+ },
|
|
|
+ on: {
|
|
|
+ "keep.event:longJob.added": {
|
|
|
+ data: { jobId: "bf3dc3aa-e7aa-4b69-bfd1-8e979fe7dfa5" }
|
|
|
+ },
|
|
|
+ "keep.event:longJob.removed": {
|
|
|
+ data: { jobId: "8704d336-660f-4d23-8c18-a7271c6656b5" }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
});
|
|
|
|
|
|
test("component does not render if there are no jobs", async () => {
|
|
|
- const wrapper = await getWrapper(LongJobs, { mockSocket: {} });
|
|
|
+ const wrapper = await getWrapper(LongJobs, { mockSocket: true });
|
|
|
expect(wrapper.findComponent(FloatingBox).exists()).toBeFalsy();
|
|
|
});
|
|
|
|
|
|
- test("component and jobs render if jobs exists", async ({ socketData }) => {
|
|
|
+ test("component and jobs render if jobs exists", async ({ mockSocket }) => {
|
|
|
const wrapper = await getWrapper(LongJobs, {
|
|
|
- mockSocket: socketData,
|
|
|
+ mockSocket,
|
|
|
stubs: { FloatingBox },
|
|
|
- beforeMount: async () => {
|
|
|
- const userAuthStore = useUserAuthStore();
|
|
|
- userAuthStore.loggedIn = true;
|
|
|
- await flushPromises();
|
|
|
- }
|
|
|
+ loginRequired: true
|
|
|
});
|
|
|
expect(wrapper.findComponent(FloatingBox).exists()).toBeTruthy();
|
|
|
const activeJobs = wrapper.findAll(".active-jobs .active-job");
|
|
|
- const { longJobs } = socketData.dispatch["users.getLongJobs"].data;
|
|
|
+ const { longJobs } =
|
|
|
+ mockSocket.data.dispatch["users.getLongJobs"]().data;
|
|
|
expect(activeJobs.length).toBe(longJobs.length);
|
|
|
});
|
|
|
|
|
@@ -69,28 +100,27 @@ describe("LongJobs component", async () => {
|
|
|
const isRemoveable = status === "success" || status === "error";
|
|
|
|
|
|
beforeEach(async context => {
|
|
|
- context.socketData.dispatch[
|
|
|
- "users.getLongJobs"
|
|
|
- ].data.longJobs[0].status = status;
|
|
|
+ const getLongJobs =
|
|
|
+ context.mockSocket.data.dispatch["users.getLongJobs"]();
|
|
|
+ getLongJobs.data.longJobs[0].status = status;
|
|
|
+ context.mockSocket.data.dispatch["users.getLongJobs"] = () =>
|
|
|
+ getLongJobs;
|
|
|
|
|
|
context.wrapper = await getWrapper(LongJobs, {
|
|
|
- mockSocket: context.socketData,
|
|
|
+ mockSocket: context.mockSocket,
|
|
|
stubs: { FloatingBox },
|
|
|
- beforeMount: async () => {
|
|
|
- const userAuthStore = useUserAuthStore();
|
|
|
- userAuthStore.loggedIn = true;
|
|
|
- await flushPromises();
|
|
|
- }
|
|
|
+ loginRequired: true
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- test("status icon and name render correctly", ({
|
|
|
+ test("status icon, name and message render correctly", ({
|
|
|
wrapper,
|
|
|
- socketData
|
|
|
+ mockSocket
|
|
|
}) => {
|
|
|
const activeJob = wrapper.find(".active-jobs .active-job");
|
|
|
const job =
|
|
|
- socketData.dispatch["users.getLongJobs"].data.longJobs[0];
|
|
|
+ mockSocket.data.dispatch["users.getLongJobs"]().data
|
|
|
+ .longJobs[0];
|
|
|
let icon;
|
|
|
if (job.status === "success") icon = "Complete";
|
|
|
else if (job.status === "error") icon = "Failed";
|
|
@@ -99,8 +129,15 @@ describe("LongJobs component", async () => {
|
|
|
icon = `i[content="${icon}"]`;
|
|
|
expect(activeJob.find(icon).exists()).toBeTruthy();
|
|
|
expect(activeJob.find(".name").text()).toBe(job.name);
|
|
|
+ (<any>(
|
|
|
+ activeJob.find(".actions .message").element.parentElement
|
|
|
+ ))._tippy.show();
|
|
|
+ expect(
|
|
|
+ document.body.querySelector(
|
|
|
+ "body > [id^=tippy] .tippy-box .long-job-message"
|
|
|
+ ).textContent
|
|
|
+ ).toBe(`Latest Update:${job.message}`);
|
|
|
});
|
|
|
- test.todo("Latest update message validation");
|
|
|
|
|
|
test(`job is ${
|
|
|
isRemoveable ? "" : "not "
|
|
@@ -117,38 +154,37 @@ describe("LongJobs component", async () => {
|
|
|
isRemoveable
|
|
|
);
|
|
|
});
|
|
|
-
|
|
|
- test("keep.event:longJob.added", async ({
|
|
|
- wrapper,
|
|
|
- socketData
|
|
|
- }) => {
|
|
|
- const websocketsStore = useWebsocketsStore();
|
|
|
- websocketsStore.socket.triggerEvent(
|
|
|
- "keep.event:longJob.added",
|
|
|
- {
|
|
|
- data: { jobId: "bf3dc3aa-e7aa-4b69-bfd1-8e979fe7dfa5" }
|
|
|
- }
|
|
|
- );
|
|
|
- await flushPromises();
|
|
|
- expect(wrapper.findAll(".active-jobs .active-job").length).toBe(
|
|
|
- socketData.dispatch["users.getLongJobs"].data.longJobs
|
|
|
- .length + 1
|
|
|
- );
|
|
|
- });
|
|
|
-
|
|
|
- test("keep.event:longJob.removed", async ({ wrapper }) => {
|
|
|
- const websocketsStore = useWebsocketsStore();
|
|
|
- websocketsStore.socket.triggerEvent(
|
|
|
- "keep.event:longJob.removed",
|
|
|
- {
|
|
|
- data: { jobId: "8704d336-660f-4d23-8c18-a7271c6656b5" }
|
|
|
- }
|
|
|
- );
|
|
|
- await flushPromises();
|
|
|
- const longJobsStore = useLongJobsStore();
|
|
|
- expect(longJobsStore.removeJob).toBeCalledTimes(1);
|
|
|
- expect(wrapper.findComponent(FloatingBox).exists()).toBeFalsy();
|
|
|
- });
|
|
|
}
|
|
|
);
|
|
|
+
|
|
|
+ test("keep.event:longJob.added", async ({ mockSocket }) => {
|
|
|
+ const wrapper = await getWrapper(LongJobs, {
|
|
|
+ mockSocket,
|
|
|
+ stubs: { FloatingBox },
|
|
|
+ loginRequired: true
|
|
|
+ });
|
|
|
+ const websocketsStore = useWebsocketsStore();
|
|
|
+ websocketsStore.socket.trigger("on", "keep.event:longJob.added");
|
|
|
+ await flushPromises();
|
|
|
+ const longJobsStore = useLongJobsStore();
|
|
|
+ expect(longJobsStore.setJob).toBeCalledTimes(3);
|
|
|
+ const activeJobs = wrapper.findAll(".active-jobs .active-job");
|
|
|
+ const { longJobs } =
|
|
|
+ mockSocket.data.dispatch["users.getLongJobs"]().data;
|
|
|
+ expect(activeJobs.length).toBe(longJobs.length + 1);
|
|
|
+ });
|
|
|
+
|
|
|
+ test("keep.event:longJob.removed", async ({ mockSocket }) => {
|
|
|
+ const wrapper = await getWrapper(LongJobs, {
|
|
|
+ mockSocket,
|
|
|
+ stubs: { FloatingBox },
|
|
|
+ loginRequired: true
|
|
|
+ });
|
|
|
+ const websocketsStore = useWebsocketsStore();
|
|
|
+ websocketsStore.socket.trigger("on", "keep.event:longJob.removed");
|
|
|
+ await flushPromises();
|
|
|
+ const longJobsStore = useLongJobsStore();
|
|
|
+ expect(longJobsStore.removeJob).toBeCalledTimes(1);
|
|
|
+ expect(wrapper.findComponent(FloatingBox).exists()).toBeFalsy();
|
|
|
+ });
|
|
|
});
|