Unverified Commit f7ffd305 authored by Björn Grüning's avatar Björn Grüning Committed by GitHub
Browse files

Merge pull request #13987 from jmchilton/workflow_delete_unit_tests

Localize workflow deletion confirmation message...
parents 3aa7c974 c92d610f
Loading
Loading
Loading
Loading
+51 −0
Original line number Diff line number Diff line
import WorkflowDropdown from "./WorkflowDropdown";
import { shallowMount } from "@vue/test-utils";
import { getLocalVue } from "jest/helpers";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import flushPromises from "flush-promises";

const localVue = getLocalVue(true);

@@ -86,4 +89,52 @@ describe("WorkflowDropdown.vue", () => {
            expect(workflowOptions().at(2).text()).toBeLocalizationOf("View");
        });
    });

    describe("workflow clicking workflow deletion", () => {
        let axiosMock;
        let confirmRequest;

        async function mountAndDelete() {
            const workflow = {
                name: TEST_WORKFLOW_NAME,
                id: "workflowid123",
                description: TEST_WORKFLOW_DESCRIPTION,
                owner: "test",
            };
            initWrapperForWorkflow(workflow);
            await wrapper.vm.onDelete();
            await flushPromises();
        }

        beforeEach(async () => {
            axiosMock = new MockAdapter(axios);
            confirmRequest = true;
            global.confirm = jest.fn(() => confirmRequest);
            axiosMock.onDelete("/api/workflows/workflowid123").reply(202, "deleted...");
        });

        afterEach(() => {
            axiosMock.restore();
        });

        it("should confirm with localized deletion message", async () => {
            await mountAndDelete();
            expect(global.confirm).toHaveBeenCalledWith(expect.toBeLocalized());
        });

        it("should fire deletion API request upon confirmation", async () => {
            await mountAndDelete();
            const emitted = wrapper.emitted();
            expect(emitted["onRemove"][0][0]).toEqual("workflowid123");
            expect(emitted["onSuccess"][0][0]).toEqual("deleted...");
        });

        it("should not fire deletion API request if not confirmed", async () => {
            confirmRequest = false;
            await mountAndDelete();
            const emitted = wrapper.emitted();
            expect(emitted["onRemove"]).toBeFalsy();
            expect(emitted["onSuccess"]).toBeFalsy();
        });
    });
});
+2 −1
Original line number Diff line number Diff line
@@ -164,7 +164,8 @@ export default {
        onDelete: function () {
            const id = this.workflow.id;
            const name = this.workflow.name;
            if (window.confirm(`Are you sure you want to delete workflow '${name}'?`)) {
            const confirmationMessage = this.l(`Are you sure you want to delete workflow '${name}'?`);
            if (window.confirm(confirmationMessage)) {
                this.services
                    .deleteWorkflow(id)
                    .then((message) => {
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ function isTestLocalized(text) {
}

expect.extend({
    toBeLocalizationOf(received) {
    toBeLocalized(received) {
        const pass = isTestLocalized(received);
        if (pass) {
            return {