Fix some JS tests

- Description tests were not updated after description moved from shadowDOM to lightDOM
- Missing egw caused errors
This commit is contained in:
nathan 2022-06-07 16:39:04 -06:00
parent ae167995eb
commit ec608e905a
6 changed files with 21 additions and 14 deletions

View File

@ -18,6 +18,7 @@ import {LitFlatpickr} from "lit-flatpickr";
import "flatpickr/dist/plugins/scrollPlugin.js";
import {holidays} from "./Holidays";
import flatpickr from "flatpickr";
import {egw} from "../../jsapi/egw_global";
// Request this year's holidays now
holidays(new Date().getFullYear());
@ -29,7 +30,7 @@ const l10n = [
'mn', 'ms', 'my', 'nl', 'no', 'pa', 'pl', 'pt', 'ro', 'ru', 'si', 'sk', 'sl', 'sq', 'sr-cyr', 'sr', 'sv', 'th', 'tr',
'uk', 'uz', 'uz_latn', 'vn', 'zh-tw', 'zh',
];
const lang = <string>egw.preference('lang');
const lang = egw ? <string>egw.preference('lang') || "" : "";
// only load localization, if we have one
if (l10n.indexOf(lang) >= 0)
{
@ -424,7 +425,7 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(ValidateMixin(LitFl
*/
protected _localize(options)
{
let first_dow = this.egw().preference('weekdaystarts', 'calendar') || 'Monday';
let first_dow = <string>this.egw()?.preference('weekdaystarts', 'calendar') || 'Monday';
const DOW_MAP = {Monday: 1, Sunday: 0, Saturday: 6};
options.locale = {
firstDayOfWeek: DOW_MAP[first_dow]

View File

@ -2,6 +2,8 @@
* Static holiday cache
* access through holidays(year)
*/
import {egw} from "../../jsapi/egw_global";
let _holiday_cache = {};
/**
@ -19,7 +21,7 @@ let _holiday_cache = {};
export function holidays(year) : Promise<{ [key : string] : Array<object> }> | { [key : string] : Array<object> }
{
// No country selected causes error, so skip if it's missing
if(!egw.preference('country', 'common'))
if(!egw || !egw.preference('country', 'common'))
{
return {};
}

View File

@ -137,7 +137,7 @@ export class Et2Description extends Et2Widget(LitElement) implements et2_IDetach
super.requestUpdate(...arguments);
// Due to how we do the rendering into the light DOM (not sure it's right) we need this after
// value change or it won't actually show up
if(attribute == "value" && this.parentNode)
if(["value", "href", "activate_links"].indexOf(attribute) != -1 && this.parentNode)
{
this.updateComplete.then(() => render(this._renderContent(), <HTMLElement><unknown>this));
}

View File

@ -56,7 +56,7 @@ describe("Textbox widget", () =>
await elementUpdated(element);
// Firefox puts the style tag in, so it's not an exact match
assert.match(element.shadowRoot.textContent, new RegExp(value));
assert.match(element.textContent, new RegExp(value));
});
it("translates its value", async() =>
@ -78,7 +78,7 @@ describe("Textbox widget", () =>
await elementUpdated(element);
// Firefox puts the style tag in, so it's not an exact match
assert.match(element.shadowRoot.textContent, new RegExp("Translated!"));
assert.match(element.textContent, new RegExp("Translated!"));
});
it("links when given href", async() =>
@ -92,7 +92,7 @@ describe("Textbox widget", () =>
// @ts-ignore TypeScript doesn't recognize widgets as Elements
await elementUpdated(element);
let a = element.shadowRoot.querySelector("a");
let a = element.querySelector("a");
assert.isNotNull(a, "Did not find A tag");
assert.match(a.href, new RegExp(href), "A tag had wrong href");
});
@ -107,7 +107,7 @@ describe("Textbox widget", () =>
await elementUpdated(element);
// Not turned on, make sure there is no links
assert.isNull(element.shadowRoot.querySelector("a"), "Links got activated when activate_links property is false");
assert.isNull(element.querySelector("a"), "Links got activated when activate_links property is false");
// Turn it on
element.activate_links = true;
@ -116,8 +116,8 @@ describe("Textbox widget", () =>
// @ts-ignore TypeScript doesn't recognize widgets as Elements
await elementUpdated(element);
assert.isNotNull(element.shadowRoot.querySelector("a"), "Links did not get activated when activate_links property is true");
assert.equal(element.shadowRoot.querySelector("a").href, "http://www.egroupware.org/", "Incorrect href in activated link");
assert.isNotNull(element.querySelector("a"), "Links did not get activated when activate_links property is true");
assert.equal(element.querySelector("a").href, "http://www.egroupware.org/", "Incorrect href in activated link");
});
});

View File

@ -6,6 +6,7 @@ import {et2_compileLegacyJS} from "../et2_core_legacyJSFunctions";
import {et2_cloneObject, et2_csvSplit} from "../et2_core_common";
// @ts-ignore
import type {IegwAppLocal} from "../../jsapi/egw_global";
import {egw} from "../../jsapi/egw_global";
import {ClassWithAttributes, ClassWithInterfaces} from "../et2_core_inheritance";
import {css, dedupeMixin, PropertyValues, unsafeCSS} from "@lion/core";
import type {et2_container} from "../et2_core_baseWidget";
@ -87,7 +88,7 @@ const Et2WidgetMixin = (superClass) =>
static get styles()
{
return [
...(super.styles ? (Symbol.iterator in Object(super.styles) ? super.styles : [super.styles]) : []),
...(super.styles ? (Array.isArray(super.styles) ? super.styles : [super.styles]) : []),
css`
:host([disabled]) {
display: none;
@ -789,7 +790,7 @@ const Et2WidgetMixin = (superClass) =>
transformAttributes(this, this.getArrayMgr("content"), attrs);
// Add in additional modifications
if(this.id && this.getArrayMgr("modifications").getEntry(this.id))
if(this.id && this.getArrayMgr("modifications")?.getEntry(this.id))
{
transformAttributes(this, this.getArrayMgr("content"), this.getArrayMgr("modifications").getEntry(this.id));
}

View File

@ -8,7 +8,10 @@ import {egw} from "../../jsapi/egw_global";
* This makes sure the built-in icons can be found
*/
registerIconLibrary('default', {
resolver: name => `${egw.webserverUrl}/node_modules/@shoelace-style/shoelace/dist/assets/icons/${name}.svg`,
resolver: name =>
{
return typeof egw !== "undefined" ? `${egw.webserverUrl}/node_modules/@shoelace-style/shoelace/dist/assets/icons/${name}.svg` : ''
},
});
/**
@ -22,7 +25,7 @@ const egw_icons = {'chevron-down': 'arrow_down', 'x': 'close', 'x-circle-fill':
registerIconLibrary("system", {
resolver: (name) =>
{
if(egw_icons[name])
if(egw_icons[name] && egw)
{
return `${egw.webserverUrl}/pixelegg/images/${egw_icons[name]}.svg`;
}