UNPKG

@rr0/cms

Version:

RR0 Content Management System (CMS)

89 lines (88 loc) 3.73 kB
import { PlaceReplacer } from "./PlaceReplacer.js"; import { OrganizationService } from "../org/OrganizationService.js"; import { cmsTestUtil } from "../test/index.js"; import { describe, expect, test } from "@javarome/testscript"; import { OrganizationMessages } from "../org/index.js"; import { Place, PlaceLocation, PlaceService } from "@rr0/place"; import { OrganizationKind } from "@rr0/data"; class MockPlaceService extends PlaceService { constructor(location, elevation, dirName) { super("place"); this.location = location; this.elevation = elevation; this.dirName = dirName; } async read(fileName) { return new Place([this.location], this.elevation, this.dirName); } async geocode(address) { return { location: this.location, data: {} }; } async getElevation(location) { return this.elevation; } } class MockOrganizationService extends OrganizationService { constructor(dirName) { super(null, cmsTestUtil.orgFactory, { rootDir: "", files: [] }, null, []); this.dirName = dirName; } async read(_fileName) { let title = "Los Alamos National Laboratories"; return { type: "org", kind: OrganizationKind.company, id: "laln", dirName: this.dirName, getTitle(_context) { return title; }, parent: undefined, title, places: [new Place([new PlaceLocation(35.87555555555556, -106.32416666666666)])], getMessages: (_context) => new OrganizationMessages([title]), events: [] }; } } describe("PlaceReplacer", () => { function createPlaceTag(doc, text) { const placeTag = doc.createElement("span"); placeTag.className = "place"; placeTag.innerHTML = text; return placeTag; } test("link to existing organization", { skip: true }, async () => { const location = new PlaceLocation(35.8440582, -106.287162); const elevation = 2161.025390625; const dirName = "org/us/state/nm/lanl/"; const placeService = new MockPlaceService(location, { elevation }, dirName); const orgService = new MockOrganizationService(dirName); const replacer = new PlaceReplacer(); const context = cmsTestUtil.newHtmlContext("people/a/AlexanderJohnB/index.html", ""); const doc = context.file.document; const text = "LANL"; const placeTag = createPlaceTag(doc, text); const replacement = await replacer.replacement(context, placeTag); expect(replacement.tagName).toBe("A"); expect(replacement.className).toBe("plac"); expect(replacement.href).toBe(`/${dirName}`); expect(replacement.textContent).toBe(text); expect(replacement.getAttribute("onclick")).toBe(`showMap(event,${location.lat},${location.lng},true)`); }); test("link to non-existing organization", async () => { const location = new PlaceLocation(34.0, -105.0); const elevation = 100.0; const dirName = ""; const replacer = new PlaceReplacer(); const context = cmsTestUtil.newHtmlContext("people/a/AlexanderJohnB/index.html", ""); const doc = context.file.document; const text = "Non existing"; const placeTag = createPlaceTag(doc, text); const replacement = await replacer.replacement(context, placeTag); expect(replacement.tagName).toBe("SPAN"); expect(replacement.className).toBe("plac"); expect(replacement.textContent).toBe(text); //expect(replacement.getAttribute("onclick")).toBe(`showMap(event,'${text}',true)`) }); });