Skip to content

Commit

Permalink
Merge pull request #32 from martenson/fix_multiselect_order_23.2
Browse files Browse the repository at this point in the history
fix old test add new test
  • Loading branch information
guerler authored Jan 26, 2024
2 parents 9784f5f + e5739e5 commit a0bbd50
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions client/src/components/Form/Elements/FormData/FormData.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const defaultOptions = {
{ id: "hda1", hid: 1, name: "hdaName1", src: "hda", tags: ["tag1"] },
{ id: "hda2", hid: 2, name: "hdaName2", src: "hda", tags: ["tag1", "tag2"] },
{ id: "hda3", hid: 3, name: "hdaName3", src: "hda", tags: ["tag2", "tag3"] },
{ id: "hda3", hid: 4, name: "hdaName4", src: "hda" },
{ id: "hda4", hid: 4, name: "hdaName4", src: "hda" },
],
hdca: [
{ id: "hdca5", hid: 5, name: "hdcaName5", src: "hdca" },
Expand All @@ -61,7 +61,7 @@ describe("FormData", () => {
const value_1 = {
batch: false,
product: false,
values: [{ id: "hda3", src: "hda", map_over_type: null }],
values: [{ id: "hda4", src: "hda", map_over_type: null }],
};
const options = wrapper.find(".btn-group").findAll("button");
expect(options.length).toBe(4);
Expand Down Expand Up @@ -122,7 +122,7 @@ describe("FormData", () => {
expect(wrapper.emitted().input.length).toEqual(1);
const selectedValues = wrapper.findAll(SELECTED_VALUE);
expect(selectedValues.length).toBe(2);
expect(selectedValues.at(0).text()).toBe("4: hdaName4");
expect(selectedValues.at(0).text()).toBe("3: hdaName3");
expect(selectedValues.at(1).text()).toBe("2: hdaName2");
const value_0 = {
batch: false,
Expand Down Expand Up @@ -153,6 +153,39 @@ describe("FormData", () => {
expect(wrapper.emitted().input[2][0]).toEqual(null);
});

it("properly sorts multiple datasets", async () => {
const wrapper = createTarget({
value: {
// the order of values does not matter here
values: [
{ id: "hda2", src: "hda" },
{ id: "hda3", src: "hda" },
{ id: "hda1", src: "hda" },
],
},
multiple: true,
optional: true,
options: defaultOptions,
});
const selectedValues = wrapper.findAll(SELECTED_VALUE);
expect(selectedValues.length).toBe(3);
// the values in the multiselect are sorted by hid DESC
expect(selectedValues.at(0).text()).toBe("3: hdaName3");
expect(selectedValues.at(1).text()).toBe("2: hdaName2");
expect(selectedValues.at(2).text()).toBe("1: hdaName1");
await selectedValues.at(0).trigger("click");
const value_sorted = {
batch: false,
product: false,
values: [
// the values in the emitted input are sorted by hid ASC
{ id: "hda1", map_over_type: null, src: "hda" },
{ id: "hda2", map_over_type: null, src: "hda" },
],
};
expect(wrapper.emitted().input[1][0]).toEqual(value_sorted);
});

it("dataset collection as hda", async () => {
const wrapper = createTarget({
value: { values: [{ id: "dce1", src: "dce" }] },
Expand Down

0 comments on commit a0bbd50

Please sign in to comment.