forked from extern/egroupware
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:
parent
ae167995eb
commit
ec608e905a
@ -18,6 +18,7 @@ import {LitFlatpickr} from "lit-flatpickr";
|
|||||||
import "flatpickr/dist/plugins/scrollPlugin.js";
|
import "flatpickr/dist/plugins/scrollPlugin.js";
|
||||||
import {holidays} from "./Holidays";
|
import {holidays} from "./Holidays";
|
||||||
import flatpickr from "flatpickr";
|
import flatpickr from "flatpickr";
|
||||||
|
import {egw} from "../../jsapi/egw_global";
|
||||||
|
|
||||||
// Request this year's holidays now
|
// Request this year's holidays now
|
||||||
holidays(new Date().getFullYear());
|
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',
|
'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',
|
'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
|
// only load localization, if we have one
|
||||||
if (l10n.indexOf(lang) >= 0)
|
if (l10n.indexOf(lang) >= 0)
|
||||||
{
|
{
|
||||||
@ -424,7 +425,7 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(ValidateMixin(LitFl
|
|||||||
*/
|
*/
|
||||||
protected _localize(options)
|
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};
|
const DOW_MAP = {Monday: 1, Sunday: 0, Saturday: 6};
|
||||||
options.locale = {
|
options.locale = {
|
||||||
firstDayOfWeek: DOW_MAP[first_dow]
|
firstDayOfWeek: DOW_MAP[first_dow]
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
* Static holiday cache
|
* Static holiday cache
|
||||||
* access through holidays(year)
|
* access through holidays(year)
|
||||||
*/
|
*/
|
||||||
|
import {egw} from "../../jsapi/egw_global";
|
||||||
|
|
||||||
let _holiday_cache = {};
|
let _holiday_cache = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,7 +21,7 @@ let _holiday_cache = {};
|
|||||||
export function holidays(year) : Promise<{ [key : string] : Array<object> }> | { [key : string] : Array<object> }
|
export function holidays(year) : Promise<{ [key : string] : Array<object> }> | { [key : string] : Array<object> }
|
||||||
{
|
{
|
||||||
// No country selected causes error, so skip if it's missing
|
// No country selected causes error, so skip if it's missing
|
||||||
if(!egw.preference('country', 'common'))
|
if(!egw || !egw.preference('country', 'common'))
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ export class Et2Description extends Et2Widget(LitElement) implements et2_IDetach
|
|||||||
super.requestUpdate(...arguments);
|
super.requestUpdate(...arguments);
|
||||||
// Due to how we do the rendering into the light DOM (not sure it's right) we need this after
|
// 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
|
// 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));
|
this.updateComplete.then(() => render(this._renderContent(), <HTMLElement><unknown>this));
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ describe("Textbox widget", () =>
|
|||||||
await elementUpdated(element);
|
await elementUpdated(element);
|
||||||
|
|
||||||
// Firefox puts the style tag in, so it's not an exact match
|
// 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() =>
|
it("translates its value", async() =>
|
||||||
@ -78,7 +78,7 @@ describe("Textbox widget", () =>
|
|||||||
await elementUpdated(element);
|
await elementUpdated(element);
|
||||||
|
|
||||||
// Firefox puts the style tag in, so it's not an exact match
|
// 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() =>
|
it("links when given href", async() =>
|
||||||
@ -92,7 +92,7 @@ describe("Textbox widget", () =>
|
|||||||
// @ts-ignore TypeScript doesn't recognize widgets as Elements
|
// @ts-ignore TypeScript doesn't recognize widgets as Elements
|
||||||
await elementUpdated(element);
|
await elementUpdated(element);
|
||||||
|
|
||||||
let a = element.shadowRoot.querySelector("a");
|
let a = element.querySelector("a");
|
||||||
assert.isNotNull(a, "Did not find A tag");
|
assert.isNotNull(a, "Did not find A tag");
|
||||||
assert.match(a.href, new RegExp(href), "A tag had wrong href");
|
assert.match(a.href, new RegExp(href), "A tag had wrong href");
|
||||||
});
|
});
|
||||||
@ -107,7 +107,7 @@ describe("Textbox widget", () =>
|
|||||||
await elementUpdated(element);
|
await elementUpdated(element);
|
||||||
|
|
||||||
// Not turned on, make sure there is no links
|
// 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
|
// Turn it on
|
||||||
element.activate_links = true;
|
element.activate_links = true;
|
||||||
@ -116,8 +116,8 @@ describe("Textbox widget", () =>
|
|||||||
// @ts-ignore TypeScript doesn't recognize widgets as Elements
|
// @ts-ignore TypeScript doesn't recognize widgets as Elements
|
||||||
await elementUpdated(element);
|
await elementUpdated(element);
|
||||||
|
|
||||||
assert.isNotNull(element.shadowRoot.querySelector("a"), "Links did not get activated when activate_links property is true");
|
assert.isNotNull(element.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.equal(element.querySelector("a").href, "http://www.egroupware.org/", "Incorrect href in activated link");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import {et2_compileLegacyJS} from "../et2_core_legacyJSFunctions";
|
|||||||
import {et2_cloneObject, et2_csvSplit} from "../et2_core_common";
|
import {et2_cloneObject, et2_csvSplit} from "../et2_core_common";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import type {IegwAppLocal} from "../../jsapi/egw_global";
|
import type {IegwAppLocal} from "../../jsapi/egw_global";
|
||||||
|
import {egw} from "../../jsapi/egw_global";
|
||||||
import {ClassWithAttributes, ClassWithInterfaces} from "../et2_core_inheritance";
|
import {ClassWithAttributes, ClassWithInterfaces} from "../et2_core_inheritance";
|
||||||
import {css, dedupeMixin, PropertyValues, unsafeCSS} from "@lion/core";
|
import {css, dedupeMixin, PropertyValues, unsafeCSS} from "@lion/core";
|
||||||
import type {et2_container} from "../et2_core_baseWidget";
|
import type {et2_container} from "../et2_core_baseWidget";
|
||||||
@ -87,7 +88,7 @@ const Et2WidgetMixin = (superClass) =>
|
|||||||
static get styles()
|
static get styles()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
...(super.styles ? (Symbol.iterator in Object(super.styles) ? super.styles : [super.styles]) : []),
|
...(super.styles ? (Array.isArray(super.styles) ? super.styles : [super.styles]) : []),
|
||||||
css`
|
css`
|
||||||
:host([disabled]) {
|
:host([disabled]) {
|
||||||
display: none;
|
display: none;
|
||||||
@ -789,7 +790,7 @@ const Et2WidgetMixin = (superClass) =>
|
|||||||
transformAttributes(this, this.getArrayMgr("content"), attrs);
|
transformAttributes(this, this.getArrayMgr("content"), attrs);
|
||||||
|
|
||||||
// Add in additional modifications
|
// 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));
|
transformAttributes(this, this.getArrayMgr("content"), this.getArrayMgr("modifications").getEntry(this.id));
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,10 @@ import {egw} from "../../jsapi/egw_global";
|
|||||||
* This makes sure the built-in icons can be found
|
* This makes sure the built-in icons can be found
|
||||||
*/
|
*/
|
||||||
registerIconLibrary('default', {
|
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", {
|
registerIconLibrary("system", {
|
||||||
resolver: (name) =>
|
resolver: (name) =>
|
||||||
{
|
{
|
||||||
if(egw_icons[name])
|
if(egw_icons[name] && egw)
|
||||||
{
|
{
|
||||||
return `${egw.webserverUrl}/pixelegg/images/${egw_icons[name]}.svg`;
|
return `${egw.webserverUrl}/pixelegg/images/${egw_icons[name]}.svg`;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user