Merge pull request #13739 from guerler/add_history_tests

Add history component tests
This commit is contained in:
Marius van den Beek
2022-04-19 14:50:18 +02:00
committed by GitHub
15 changed files with 141 additions and 132 deletions
@@ -0,0 +1,33 @@
import { mount } from "@vue/test-utils";
import { getLocalVue } from "jest/helpers";
import CollectionDescription from "./CollectionDescription";
const localVue = getLocalVue();
describe("CollectionDescription", () => {
let wrapper;
beforeEach(() => {
wrapper = mount(CollectionDescription, {
propsData: {
collectionType: "list",
elementCount: 10,
},
localVue,
});
});
it("check basics", async () => {
const details = wrapper.findAll("span");
expect(details.at(0).text()).toBe("a list");
expect(details.at(1).text()).toBe("with 10 items");
await wrapper.setProps({ elementCount: 1 });
expect(details.at(1).text()).toBe("with 1 item");
await wrapper.setProps({ collectionType: "paired" });
expect(details.at(0).text()).toBe("a dataset pair");
await wrapper.setProps({ collectionType: "list:paired" });
expect(details.at(0).text()).toBe("a list of pairs");
await wrapper.setProps({ collectionType: "other" });
expect(details.at(0).text()).toBe("a nested list");
});
});
@@ -9,7 +9,8 @@
<script>
export default {
props: {
item: { type: Object, required: true },
collectionType: { type: String, required: true },
elementCount: { type: Number, required: true },
},
data() {
return {
@@ -24,12 +25,6 @@ export default {
collectionLabel() {
return this.labels[this.collectionType] || "nested list";
},
collectionType() {
return this.item.collection_type;
},
elementCount() {
return this.item.element_count;
},
},
};
</script>
@@ -0,0 +1,60 @@
import { mount } from "@vue/test-utils";
import { getLocalVue } from "jest/helpers";
import ContentItem from "./ContentItem";
const localVue = getLocalVue();
describe("ContentItem", () => {
let wrapper;
beforeEach(() => {
wrapper = mount(ContentItem, {
propsData: {
expandDataset: false,
item: {
id: "item_id",
some_data: "some_data",
tags: ["tag1", "tag2", "tag3"],
},
id: 1,
isDataset: true,
isHistoryItem: false,
name: "name",
selected: false,
selectable: false,
},
localVue,
});
});
it("check basics", async () => {
expect(wrapper.attributes("data-hid")).toBe("1");
expect(wrapper.find(".content-title").text()).toBe("name");
const tags = wrapper.find(".nametags").findAll(".badge");
// verify tags
expect(tags.length).toBe(3);
for (let i = 0; i < 3; i++) {
expect(tags.at(i).text()).toBe(`tag${i + 1}`);
}
// expansion button
const $el = wrapper.find(".cursor-pointer");
$el.trigger("click");
expect(wrapper.emitted()["update:expand-dataset"]).toBeDefined();
// select and unselect
const noSelector = wrapper.find(".selector > svg");
expect(noSelector.exists()).toBe(false);
await wrapper.setProps({ selectable: true });
expect(wrapper.classes()).toEqual(expect.arrayContaining(["alert-success"]));
const selector = wrapper.find(".selector > svg");
expect(selector.attributes("data-icon")).toBe("square");
selector.trigger("click");
await localVue.nextTick();
expect(wrapper.emitted()["update:selected"][0][0]).toBe(true);
await wrapper.setProps({ selected: true });
selector.trigger("click");
await localVue.nextTick();
expect(wrapper.emitted()["update:selected"][1][0]).toBe(false);
expect(wrapper.classes()).toEqual(expect.arrayContaining(["alert-info"]));
expect(selector.attributes("data-icon")).toBe("check-square");
});
});
@@ -29,7 +29,10 @@
<span class="id hid">{{ id }}</span>
<span>:</span>
<span class="content-title name">{{ name }}</span>
<CollectionDescription v-if="!isDataset" :item="item" />
<CollectionDescription
v-if="!isDataset"
:collection-type="item.collection_type"
:element-count="item.element_count" />
<div v-if="item.tags && item.tags.length > 0" class="nametags">
<Nametag v-for="tag in item.tags" :key="tag" :tag="tag" />
</div>
@@ -17,7 +17,7 @@
</b-button>
<b-button
v-b-modal.history-selector-modal
v-b-modal.selector-history-modal
data-description="switch to another history"
size="sm"
variant="link"
@@ -128,13 +128,13 @@
</b-button-group>
</nav>
<HistorySelectorModal
id="history-selector-modal"
<SelectorModal
id="selector-history-modal"
:histories="histories"
:current-history="history"
@selectHistory="$emit('setCurrentHistory', $event)" />
<CopyHistoryModal id="copy-history-modal" :history="history" />
<CopyModal id="copy-history-modal" :history="history" />
<b-modal
id="history-privacy-modal"
@@ -165,14 +165,14 @@
<script>
import { legacyNavigationMixin } from "components/plugins/legacyNavigation";
import { switchToLegacyHistoryPanel } from "components/History/adapters/betaToggle";
import CopyHistoryModal from "components/History/Modals/CopyModal";
import HistorySelectorModal from "components/History/Modals/HistorySelectorModal";
import CopyModal from "components/History/Modals/CopyModal";
import SelectorModal from "components/History/Modals/SelectorModal";
export default {
mixins: [legacyNavigationMixin],
components: {
CopyHistoryModal,
HistorySelectorModal,
CopyModal,
SelectorModal,
},
props: {
histories: { type: Array, required: true },
@@ -95,7 +95,6 @@
</Listing>
</div>
</section>
<ToolHelpModal />
</section>
</SelectedItems>
</ExpandedItems>
@@ -111,7 +110,6 @@ import { deleteContent, updateContentFields } from "components/History/model/que
import ExpandedItems from "components/History/Content/ExpandedItems";
import SelectedItems from "components/History/Content/SelectedItems";
import Listing from "components/History/Layout/Listing";
import ToolHelpModal from "components/History/Modals/ToolHelpModal";
import HistoryOperations from "./HistoryOperations/Index";
import HistoryDetails from "./HistoryDetails";
import HistoryEmpty from "./HistoryEmpty";
@@ -135,7 +133,6 @@ export default {
LoadingSpan,
Listing,
SelectedItems,
ToolHelpModal,
},
props: {
history: { type: Object, required: true },
@@ -1,49 +0,0 @@
<template>
<b-modal v-model="hasTool" :title="modalTitle">
<div v-if="tool && tool.help.length" v-html="tool.help"></div>
<p v-else>{{ "Tool help is unavailable for this dataset." | localize }}</p>
</b-modal>
</template>
<script>
import { loadToolFromJob } from "components/History/model/queries";
export default {
data() {
return {
tool: null,
};
},
computed: {
modalTitle() {
return this.tool ? `Tool Help: ${this.tool.name}` : "Tool Help";
},
helpHtml() {
return this.tool ? this.tool.help : "";
},
hasTool: {
get() {
return Boolean(this.tool);
},
set(newVal) {
this.tool = null;
},
},
},
methods: {
async toggleToolHelp(jobId) {
if (this.tool && this.tool.job_id == jobId) {
this.closePanel();
} else {
this.tool = await loadToolFromJob(jobId);
}
},
closePanel() {
this.tool = null;
},
},
created() {
this.eventHub.$on("toggleToolHelp", this.toggleToolHelp);
},
};
</script>
@@ -23,8 +23,8 @@ export class HistoryPanelProxy {
this.models = models;
this.unwatch = null;
},
each(callback) {
const historyItems = store.getters.getHistoryItems({ historyId: model.id, filterText: "" });
each(callback, filterText = "") {
const historyItems = store.getters.getHistoryItems({ historyId: model.id, filterText: filterText });
historyItems.forEach((model) => {
callback(new Backbone.Model(model));
});
@@ -48,7 +48,7 @@ const getQueryString = (filterText) => {
};
const actions = {
fetchHistoryItems: async ({ commit, dispatch }, { historyId, filterText, offset }) => {
fetchHistoryItems: async ({ commit }, { historyId, filterText, offset }) => {
const queryString = getQueryString(filterText);
const params = `v=dev&order=hid&offset=${offset}&limit=${limit}`;
const url = `api/histories/${historyId}/contents?${params}&${queryString}`;
File diff suppressed because one or more lines are too long
@@ -6,59 +6,23 @@ import * as _ from "underscore";
window.TourGenerator = Backbone.View.extend({
initialize: function (options) {
var me = this;
me.toolId = options.toolId;
me.toolVersion = options.toolVersion;
const Galaxy = window.bundleEntries.getGalaxyInstance();
const toolId = options.toolId;
const toolVersion = options.toolVersion;
// Add attribute 'tour_id' to the execution button
$("#execute").attr("tour_id", "execute");
Toastr.info("Tour generation might take some time.");
$.getJSON(
`${Galaxy.root}api/webhooks/tour_generator/data/`,
{
tool_id: me.toolId,
tool_version: me.toolVersion,
`${Galaxy.root}api/webhooks/tour_generator/data/`, {
tool_id: toolId,
tool_version: toolVersion,
},
function (obj) {
(obj) => {
if (obj.success) {
if (obj.data.useDatasets) {
Galaxy.currHistoryPanel.refreshContents(); // Refresh history panel
// Add a delay because of the history panel refreshing
setTimeout(function () {
var datasets = [],
numUploadedDatasets = 0;
_.each(obj.data.hids, function (hid) {
var dataset = Galaxy.currHistoryPanel.collection.where({
hid: hid,
})[0];
if (dataset) datasets.push(dataset);
});
if (datasets.length === obj.data.hids.length) {
_.each(datasets, function (dataset) {
if (dataset.get("state") === "ok") {
numUploadedDatasets++;
} else {
dataset.on("change:state", function (model) {
if (model.get("state") === "ok") numUploadedDatasets++;
// Make sure that all test datasets have been successfully uploaded
if (numUploadedDatasets === datasets.length)
me._generateTour(obj.data.tour);
});
}
});
} else {
Toastr.warning("Cannot generate a tour.");
console.error("Some of the test datasets cannot be found in the history.");
}
}, 1500);
this._getData(obj);
} else {
me._generateTour(obj.data.tour);
this._generateTour(obj.data.tour);
}
} else {
Toastr.warning("Cannot generate a tour.");
@@ -67,12 +31,29 @@ window.TourGenerator = Backbone.View.extend({
}
);
},
_getData: function(obj, attempts = 20, delay = 1000) {
let datasets = [];
_.each(obj.data.hids, (hid) => {
Galaxy.currHistoryPanel.collection.each((dataset) => {
datasets.push(dataset);
}, `hid=${hid} state=ok`);
});
if (datasets.length === obj.data.hids.length) {
this._generateTour(obj.data.tour);
} else if (attempts > 0) {
setTimeout(() => {
this._getData(obj, attempts - 1);
}, delay);
} else {
Toastr.warning("Cannot generate a tour.");
console.error("Some of the test datasets cannot be found in the history.");
}
},
_generateTour: function (data) {
var Galaxy = window.bundleEntries.getGalaxyInstance();
var tour = Galaxy.giveTourWithData(data);
const Galaxy = window.bundleEntries.getGalaxyInstance();
const tour = Galaxy.giveTourWithData(data);
// Force ending the tour when pressing the Execute button
$("#execute").on("mousedown", function () {
$("#execute").on("mousedown", () => {
if (tour) {
tour.end();
}
@@ -10,7 +10,6 @@ VALID_LOGIN_RETRIES = 3
class HistorySharingTestCase(SeleniumTestCase):
@selenium_test
def test_sharing_valid(self):
self.use_legacy_history()
user1_email, user2_email, history_id = self.setup_two_users_with_one_shared_history()
self.submit_login(user2_email, retries=VALID_LOGIN_RETRIES)
response = self.api_get(f"histories/{history_id}", raw=True)
@@ -18,7 +17,6 @@ class HistorySharingTestCase(SeleniumTestCase):
@selenium_test
def test_sharing_valid_by_id(self):
self.use_legacy_history()
user1_email, user2_email, history_id = self.setup_two_users_with_one_shared_history(share_by_id=True)
self.submit_login(user2_email, retries=VALID_LOGIN_RETRIES)
response = self.api_get(f"histories/{history_id}", raw=True)
@@ -26,7 +24,6 @@ class HistorySharingTestCase(SeleniumTestCase):
@selenium_test
def test_unsharing(self):
self.use_legacy_history()
user1_email, user2_email, history_id = self.setup_two_users_with_one_shared_history()
self.submit_login(user1_email, retries=VALID_LOGIN_RETRIES)
self.home()
@@ -62,7 +59,6 @@ class HistorySharingTestCase(SeleniumTestCase):
@selenium_test
def test_sharing_with_invalid_user(self):
self.use_legacy_history()
user1_email = self._get_random_email()
self.register(user1_email)
self.share_history_with_user(user_email="invalid_user@test.com")
@@ -70,7 +66,6 @@ class HistorySharingTestCase(SeleniumTestCase):
@selenium_test
def test_sharing_with_self(self):
self.use_legacy_history()
user1_email = self._get_random_email()
self.register(user1_email)
self.share_history_with_user(user_email=user1_email)
@@ -34,11 +34,8 @@ class ToolDescribingToursTestCase(SeleniumTestCase):
def test_generate_tour_with_data(self):
"""Ensure a tour with data populates history."""
self._ensure_tdt_available()
self.use_legacy_history()
self.tool_open("md5sum")
self.tool_form_generate_tour()
self.history_panel_wait_for_hid_ok(1)
popover_component = self.components.tour.popover._
@@ -49,7 +46,6 @@ class ToolDescribingToursTestCase(SeleniumTestCase):
self.screenshot("tool_describing_tour_0_start")
popover_component.next.wait_for_and_click()
self.sleep_for(self.wait_types.UX_RENDER)
text = popover_component.content.wait_for_visible().text
@@ -57,7 +53,6 @@ class ToolDescribingToursTestCase(SeleniumTestCase):
self.screenshot("tool_describing_tour_1_select")
popover_component.next.wait_for_and_click()
self.sleep_for(self.wait_types.UX_RENDER)
title = popover_component.title.wait_for_visible().text
-1
View File
@@ -104,7 +104,6 @@ class UploadsTestCase(SeleniumTestCase, UsesHistoryItemAssertions):
@selenium_test
def test_upload_paired_list(self):
self.use_legacy_history()
self.upload_paired_list(
[self.get_filename("1.tabular"), self.get_filename("2.tabular")], name="Test Paired List"
)