Commit 5b0360e6 authored by guerler's avatar guerler
Browse files

Add test case for dataset download component

parent 88f6fba6
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
                <b-button v-if="showError" class="px-1" title="Error" size="sm" variant="link" @click.stop="onError">
                    <span class="fa fa-bug" />
                </b-button>
                <dataset-download v-if="showDownloads" :item="item" />
                <dataset-download v-if="showDownloads" :item="item" @on-download="onDownload" />
                <b-button
                    v-if="showDownloads"
                    class="px-1"
@@ -61,7 +61,6 @@

<script>
import { legacyNavigationMixin } from "components/plugins/legacyNavigation";
import { prependPath } from "utils/redirect";
import { copy as sendToClipboard } from "utils/clipboard";
import { absPath } from "utils/redirect";
import DatasetDownload from "./DatasetDownload";
@@ -103,6 +102,9 @@ export default {
            const msg = this.localize("Link is copied to your clipboard");
            sendToClipboard(absPath(this.downloadUrl), msg);
        },
        onDownload(resource) {
            window.location.href = resource;
        },
        onError() {
            this.backboneRoute("datasets/error", { dataset_id: this.item.id });
        },
+43 −0
Original line number Diff line number Diff line
import { mount } from "@vue/test-utils";
import { getLocalVue } from "jest/helpers";
import DatasetDownload from "./DatasetDownload";

const localVue = getLocalVue();

const items = [
    { id: "item_id", extension: "ext", meta_files: [{ file_type: "a" }, { file_type: "b" }] },
    { id: "item_id", extension: "ext", meta_files: [] },
];

describe("DatasetDownload", () => {
    let wrapper;

    beforeEach(() => {
        wrapper = mount(DatasetDownload, {
            propsData: {
                item: items[0],
            },
            localVue,
        });
    });

    it("checks basics", async () => {
        const dropdownItems = wrapper.findAll(".dropdown-item");
        expect(dropdownItems.length).toBe(3);
        expect(dropdownItems.at(0).text()).toBe("Download Dataset");
        expect(dropdownItems.at(1).text()).toBe("Download a");
        expect(dropdownItems.at(2).text()).toBe("Download b");
        for (let i = 0; i < dropdownItems.length; i++) {
            await dropdownItems.at(i).trigger("click");
        }
        await wrapper.setProps({ item: items[1] });
        const foundItems = wrapper.find(".dropdown-item").exists();
        expect(foundItems).toBe(false);
        await wrapper.trigger("click");
        const emitted = wrapper.emitted()["on-download"];
        expect(emitted[0][0]).toBe(`/api/datasets/item_id/display?to_ext=ext`);
        expect(emitted[1][0]).toBe(`/dataset/get_metadata_file?hda_id=item_id&metadata_name=a`);
        expect(emitted[2][0]).toBe(`/dataset/get_metadata_file?hda_id=item_id&metadata_name=b`);
        expect(emitted[3][0]).toBe(`/api/datasets/item_id/display?to_ext=ext`);
    });
});
+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ export default {
    },
    methods: {
        onDownload(resource, extension = "") {
            window.location.href = `${resource}${extension}`;
            this.$emit("on-download", `${resource}${extension}`);
        },
    },
};