Add fakedom to test UI code, replace all 'innerText' with 'textContent' as it is not compatible with fakedom

This commit is contained in:
Pieter Vander Vennet 2022-06-28 03:21:18 +02:00
parent b0b674b2fb
commit 0f66d7f8cc
17 changed files with 281 additions and 20 deletions

View file

@ -174,7 +174,7 @@ class AutomationPanel extends Combine {
const feature = ffs.feature
const renderingTr = targetAction.GetRenderValue(feature.properties)
const rendering = renderingTr.txt
log.push("<a href='https://openstreetmap.org/" + feature.properties.id + "' target='_blank'>" + feature.properties.id + "</a>: " + new SubstitutedTranslation(renderingTr, new UIEventSource<any>(feature.properties), undefined).ConstructElement().innerText)
log.push("<a href='https://openstreetmap.org/" + feature.properties.id + "' target='_blank'>" + feature.properties.id + "</a>: " + new SubstitutedTranslation(renderingTr, new UIEventSource<any>(feature.properties), undefined).ConstructElement().textContent)
const actions = Utils.NoNull(SubstitutedTranslation.ExtractSpecialComponents(rendering)
.map(obj => obj.special))
for (const action of actions) {

View file

@ -107,8 +107,8 @@ export default class Table extends BaseUIElement {
let rows: HTMLTableRowElement[] = Array.from(table.rows)
rows.splice(0,1) // remove header row
rows = rows.sort((a, b) => {
const ac = a.cells[col]?.innerText?.toLowerCase()
const bc = b.cells[col]?.innerText?.toLowerCase()
const ac = a.cells[col]?.textContent?.toLowerCase()
const bc = b.cells[col]?.textContent?.toLowerCase()
if(ac === bc){
return 0
}

View file

@ -33,7 +33,7 @@ export default class TableOfContents extends Combine {
} else if (Utils.runningFromConsole) {
content = new FixedUiElement(title.AsMarkdown())
} else if (title["title"] !== undefined) {
content = new FixedUiElement(title.title.ConstructElement().innerText)
content = new FixedUiElement(title.title.ConstructElement().textContent)
} else {
console.log("Not generating a title for ", title)
continue

View file

@ -20,18 +20,18 @@ export default class Title extends BaseUIElement {
}
this.level = level;
let innerText: string = undefined;
let text: string = undefined;
if (typeof embedded === "string") {
innerText = embedded
text = embedded
} else if (embedded instanceof FixedUiElement) {
innerText = embedded.content
text = embedded.content
} else {
if (!Utils.runningFromConsole) {
innerText = embedded.ConstructElement()?.innerText
text = embedded.ConstructElement()?.textContent
}
}
this.id = innerText?.replace(/ /g, '-')
this.id = text?.replace(/ /g, '-')
?.replace(/[?#.;:/]/, "")
?.toLowerCase() ?? ""
this.SetClass(Title.defaultClassesPerLevel[level] ?? "")

View file

@ -156,8 +156,8 @@ export default class ShareScreen extends Combine {
).onClick(async () => {
const shareData = {
title: Translations.W(layout.title)?.ConstructElement().innerText ?? "",
text: Translations.W(layout.description)?.ConstructElement().innerText ?? "",
title: Translations.W(layout.title)?.ConstructElement().textContent ?? "",
text: Translations.W(layout.description)?.ConstructElement().textContent ?? "",
url: url.data,
}

View file

@ -139,7 +139,7 @@ export default class ExportPDF {
maxWidth: 125
})
const backgroundLayer: BaseLayer = State.state.backgroundLayer.data
const attribution = new FixedUiElement(backgroundLayer.layer().getAttribution() ?? backgroundLayer.name).ConstructElement().innerText
const attribution = new FixedUiElement(backgroundLayer.layer().getAttribution() ?? backgroundLayer.name).ConstructElement().textContent
doc.textWithLink(t.attr.txt, 40, 26.5, {
maxWidth: 125,
url: "https://www.openstreetmap.org/copyright"

View file

@ -112,7 +112,7 @@ export class ImageUploadFlow extends Toggle {
}
const title = matchingLayer?.title?.GetRenderValue(tags)?.Subs(tags)?.ConstructElement()?.innerText ?? tags.name ?? "https//osm.org/"+tags.id;
const title = matchingLayer?.title?.GetRenderValue(tags)?.Subs(tags)?.ConstructElement()?.textContent ?? tags.name ?? "https//osm.org/"+tags.id;
const description = [
"author:" + state.osmConnection.userDetails.data.name,
"license:" + license,

View file

@ -29,7 +29,7 @@ export class TextField extends InputElement<string> {
this._rawValue = new UIEventSource<string>("")
this._isValid = options.isValid ?? (_ => true);
const placeholder = Translations.W(options.placeholder ?? "").ConstructElement().innerText.replace("'", "&#39");
const placeholder = Translations.W(options.placeholder ?? "").ConstructElement().textContent.replace("'", "&#39");
this.SetClass("form-text-field")
let inputEl: HTMLElement

View file

@ -112,6 +112,15 @@ export class Translation extends BaseUIElement {
return "";
}
/**
*
* const tr = new Translation({"en":"English", nl: "Nederlands"})
* Locale.language.setData("en")
* const html = tr.InnerConstructElement()
* html.innerHTML // => "English"
* Locale.language.setData("nl")
* html.innerHTML // => "Nederlands"
*/
InnerConstructElement(): HTMLElement {
const el = document.createElement("span")
const self = this
@ -121,7 +130,7 @@ export class Translation extends BaseUIElement {
if (self.isDestroyed) {
return true
}
el.innerHTML = this.txt
el.innerHTML = self.txt
})
if (self.translations["*"] !== undefined || self.context === undefined || self.context?.indexOf(":") < 0) {

View file

@ -12,7 +12,7 @@ export default class Translations {
throw "Translations is static. If you want to intitialize a new translation, use the singular form"
}
public static W(s: string | BaseUIElement): BaseUIElement {
public static W(s: string | number | BaseUIElement): BaseUIElement {
if (typeof (s) === "string") {
return new FixedUiElement(s);
}