Fix Et2Select was losing options set in template

All JS tests now pass.  yay.
This commit is contained in:
nathan 2022-06-08 14:57:26 -06:00
parent b7258692a4
commit 45ccceb1c7
2 changed files with 17 additions and 9 deletions

View File

@ -8,7 +8,6 @@
*/
import {Et2InputWidget} from "../Et2InputWidget/Et2InputWidget";
import {StaticOptions} from "./StaticOptions";
import {dedupeMixin, html, PropertyValues, render, repeat, TemplateResult} from "@lion/core";
import {et2_readAttrWithDefault} from "../et2_core_xml";
import {cleanSelectOptions, find_select_options, SelectOption} from "./FindSelectOptions";
@ -79,11 +78,18 @@ export const Et2widgetWithSelectMixin = dedupeMixin((superclass) =>
}
}
/**
* Options found in the XML when reading the template
* @type {SelectOption[]}
* @private
*/
private _xmlOptions : SelectOption[] = [];
constructor()
{
super();
this.__select_options = <StaticOptions[]>[];
this.__select_options = <SelectOption[]>[];
}
/** @param {import('@lion/core').PropertyValues } changedProperties */
@ -94,7 +100,7 @@ export const Et2widgetWithSelectMixin = dedupeMixin((superclass) =>
// If the ID changed (or was just set) find the select options
if(changedProperties.has("id"))
{
const options = find_select_options(this);
const options = find_select_options(this, {}, this._xmlOptions);
if (options.length) this.select_options = options;
}
@ -239,6 +245,7 @@ export const Et2widgetWithSelectMixin = dedupeMixin((superclass) =>
title: et2_readAttrWithDefault(options[i], "title", "")
});
}
this._xmlOptions = new_options;
if(options.length == 0 && this.__select_options.length)
{
// Start with any existing options, (static options from type)

View File

@ -17,7 +17,8 @@ let element : Et2Select;
window.egw = {
tooltipUnbind: () => {},
lang: i => i + "*",
image: () => "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNS4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURC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guNDUzeiIvPg0KPC9zdmc+DQo=",
webserverUrl: ""
};
let options = [
@ -64,7 +65,7 @@ describe("Select widget", () =>
element = <Et2Select>container.getWidgetById('select');
/** TESTING **/
assert.equal(element.querySelector("select").children.length, 1, "Missing static option");
assert.isNotNull(element.querySelector("[value='option']"), "Missing static option");
});
it("directly in sel_options", async() =>
@ -83,7 +84,7 @@ describe("Select widget", () =>
element = <Et2Select>container.getWidgetById('select');
/** TESTING **/
assert.equal(element.querySelector("select").children.length, 2);
assert.equal(element.querySelectorAll("sl-menu-item").length, 2);
});
it("merges static options with sel_options", async() =>
@ -105,7 +106,7 @@ describe("Select widget", () =>
/** TESTING **/
// @ts-ignore o.value isn't known by TypeScript, but it's there
let option_keys = Object.values(element.querySelector("select").children).map(o => o.value);
let option_keys = Object.values(element.querySelectorAll("sl-menu-item")).map(o => o.value);
assert.include(option_keys, "option", "Static option missing");
assert.includeMembers(option_keys, ["1", "2", "option"], "Option mis-match");
assert.equal(option_keys.length, 3);
@ -136,9 +137,9 @@ describe("Select widget", () =>
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
await elementUpdated(element);
// Now check
// Now check - value is preferred over get_value()
assert.equal(element.get_value(), test_value, "Wrong value from widget");
assert.equal(element.querySelector("select").value, test_value, "Wrong value in DOM")
assert.equal(element.value, test_value, "Wrong value from widget");
});
});
});