diff --git a/web/themes/new_weather_theme/templates/layout/afd-page.html.twig b/web/themes/new_weather_theme/templates/layout/afd-page.html.twig
index d8c06ae6d..3e91308e3 100644
--- a/web/themes/new_weather_theme/templates/layout/afd-page.html.twig
+++ b/web/themes/new_weather_theme/templates/layout/afd-page.html.twig
@@ -1,3 +1,4 @@
+{{ attach_library("new_weather_theme/combo-box") }}
{% set wfo = wfo | upper %}
@@ -34,13 +35,12 @@
-
+
+
+
{% if version_list | length > 0 %}
diff --git a/web/themes/new_weather_theme/templates/layout/frontpage.html.twig b/web/themes/new_weather_theme/templates/layout/frontpage.html.twig
index 43ac8557e..fcb2c9a09 100644
--- a/web/themes/new_weather_theme/templates/layout/frontpage.html.twig
+++ b/web/themes/new_weather_theme/templates/layout/frontpage.html.twig
@@ -1,4 +1,4 @@
-{{ attach_library("new_weather_theme/location-combo-box") }}
+{{ attach_library("new_weather_theme/combo-box-location") }}
{{ attach_library("new_weather_theme/browser-location-button") }}
@@ -30,8 +30,8 @@
{{ 'Use my location' | t }}
-
-
+
+
diff --git a/web/themes/new_weather_theme/tests/components/combo-box-tests.js b/web/themes/new_weather_theme/tests/components/combo-box-location-tests.js
similarity index 84%
rename from web/themes/new_weather_theme/tests/components/combo-box-tests.js
rename to web/themes/new_weather_theme/tests/components/combo-box-location-tests.js
index 951ed0568..a007cc3e9 100644
--- a/web/themes/new_weather_theme/tests/components/combo-box-tests.js
+++ b/web/themes/new_weather_theme/tests/components/combo-box-location-tests.js
@@ -1,15 +1,22 @@
/* eslint no-unused-expressions: off */
require("jsdom-global")(undefined, { url: "http://localhost/" });
require("../../assets/js/components/combo-box.js");
+
+// The location combobox needs the base combobox to inherit from, so set it
+// globally.
+global.ComboBox = window.customElements.get("wx-combo-box");
+
+require("../../assets/js/components/combo-box-location.js");
require("whatwg-fetch");
-//const { assert, expect, should } = require("chai");
-let assert, expect, should;
-import("chai").then((module) => {
+
+let assert;
+let expect;
+
+const chaiPromise = import("chai").then((module) => {
assert = module.assert;
expect = module.expect;
- should = module.should;
});
-const { createSandbox, stub, spy, mock } = require("sinon");
+const { createSandbox, stub } = require("sinon");
global.HTMLElement = window.HTMLElement;
@@ -19,7 +26,7 @@ HTMLElement.prototype.scrollIntoView = stub();
HTMLFormElement.prototype.submit = stub();
const wait = async (milliseconds) => {
- await new Promise((resolve, reject) => {
+ await new Promise((resolve) => {
setTimeout(() => {
resolve();
}, milliseconds);
@@ -170,7 +177,7 @@ const SEARCH_RESULT_ITEMS = {
},
};
-global.fetch = mockFetch = (url) => {
+global.fetch = async (url) => {
const parsedUrl = new URL(url);
if (parsedUrl.pathname.includes("suggest")) {
return window.Promise.resolve(
@@ -179,42 +186,38 @@ global.fetch = mockFetch = (url) => {
headers: { "Content-Type": "application/json" },
}),
);
- } else {
- const key = parsedUrl.searchParams.get("magicKey");
- const data = SEARCH_RESULT_ITEMS[key];
- return Promise.resolve(
- new Response(JSON.stringify(data), {
- status: 200,
- headers: { "Content-Type": "application/json" },
- }),
- );
}
+
+ const key = parsedUrl.searchParams.get("magicKey");
+ const data = SEARCH_RESULT_ITEMS[key];
+
+ return new Response(JSON.stringify(data), {
+ status: 200,
+ headers: { "Content-Type": "application/json" },
+ });
};
describe("Combo box unit tests", () => {
before((done) => {
- import("../../assets/js/components/combo-box.js").then(() => {
- const box = window.document.createElement("wx-combo-box");
- window.document.body.append(box);
+ chaiPromise.then(() => {
done();
});
});
+
beforeEach(() => {
window.document.body.innerHTML = "";
- const box = document.querySelector("wx-combo-box");
- if (!box) {
- document.body.append(document.createElement("wx-combo-box"));
- }
+ const box = window.document.createElement("wx-combo-box-location");
+ window.document.body.append(box);
});
it("Has the element", () => {
- assert.exists(window.document.querySelector("wx-combo-box"));
- assert.exists(window.customElements.get("wx-combo-box"));
+ assert.exists(window.document.querySelector("wx-combo-box-location"));
+ assert.exists(window.customElements.get("wx-combo-box-location"));
});
it("Element has the correct auto-generated id", () => {
- const component = document.querySelector("wx-combo-box");
- const expected = "combo-box-1";
+ const component = document.querySelector("wx-combo-box-location");
+ const expected = "combo-box-2";
const actual = component.id;
expect(expected).to.equal(actual);
@@ -222,14 +225,15 @@ describe("Combo box unit tests", () => {
describe("Input initialization", () => {
it("Adds an input element automatically", () => {
- expect(document.querySelector("wx-combo-box > input")).to.exist;
+ expect(document.querySelector("wx-combo-box-location > input")).to.exist;
});
+
it("Adds the correct aria-related attributes to the input", () => {
- const input = document.querySelector("wx-combo-box > input");
+ const input = document.querySelector("wx-combo-box-location > input");
const attrs = [
["role", "combobox"],
- ["aria-owns", "combo-box-1--list"],
- ["aria-controls", "combo-box-1--list"],
+ ["aria-owns", "combo-box-4--list"],
+ ["aria-controls", "combo-box-4--list"],
["aria-autocomplete", "none"],
["aria-activedescendant", ""],
["autocomplete", "off"],
@@ -248,18 +252,18 @@ describe("Combo box unit tests", () => {
describe("listbox initialization", () => {
it("Adds a listbox list wrapper automatically", () => {
- expect(document.querySelector("wx-combo-box > div")).to.exist;
+ expect(document.querySelector("wx-combo-box-location > div")).to.exist;
});
it("Adds the expected id automatically", () => {
- const expected = "combo-box-1--list";
- const actual = document.querySelector("wx-combo-box div").id;
+ const expected = "combo-box-6--list";
+ const actual = document.querySelector("wx-combo-box-location div").id;
expect(actual).to.equal(expected);
});
it("Adds the correct aria-related attributes", () => {
- const listbox = document.querySelector("wx-combo-box > div");
+ const listbox = document.querySelector("wx-combo-box-location > div");
const attrs = [["role", "listbox"]];
attrs.forEach((pair) => {
@@ -277,9 +281,9 @@ describe("Combo box unit tests", () => {
beforeEach(() => {
sandbox = createSandbox();
window.document.body.innerHTML = "";
- const box = document.createElement("wx-combo-box");
+ const box = document.createElement("wx-combo-box-location");
document.body.append(box);
- assert.exists(window.customElements.get("wx-combo-box"));
+ assert.exists(window.customElements.get("wx-combo-box-location"));
});
afterEach(() => {
@@ -288,7 +292,7 @@ describe("Combo box unit tests", () => {
it("Expects the component's updateSearch method to have been called on input", async () => {
const event = new Event("input", { bubbles: true });
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
const input = component.querySelector("input");
input.focus();
input.value = "Arlin";
@@ -301,7 +305,7 @@ describe("Combo box unit tests", () => {
});
it("Expects showList to have been called when updateSearch completes", async () => {
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
sandbox.spy(component, "showList");
await component.updateSearch("Arlin");
@@ -309,7 +313,7 @@ describe("Combo box unit tests", () => {
});
it("Expects showList / hideList to toggle aria-expanded (input) and expanded (element)", async () => {
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
component.showList();
expect(component.getAttribute("expanded")).to.equal("true");
expect(component.input.getAttribute("aria-expanded")).to.equal("true");
@@ -324,9 +328,9 @@ describe("Combo box unit tests", () => {
beforeEach(async () => {
sandbox = createSandbox();
window.document.body.innerHTML = "";
- const box = document.createElement("wx-combo-box");
+ const box = document.createElement("wx-combo-box-location");
document.body.append(box);
- assert.exists(window.customElements.get("wx-combo-box"));
+ assert.exists(window.customElements.get("wx-combo-box-location"));
await box.updateSearch("Arlin");
});
@@ -335,7 +339,7 @@ describe("Combo box unit tests", () => {
});
it("Selects the first element in the dropdown automatically", () => {
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
const listbox = component.querySelector("ul");
const firstItem = listbox.querySelector("li:first-child");
const actual = firstItem.getAttribute("aria-selected");
@@ -348,7 +352,7 @@ describe("Combo box unit tests", () => {
key: "ArrowDown",
bubbles: true,
});
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
const listbox = component.querySelector("ul");
const input = component.querySelector("input[slot='input']");
input.focus();
@@ -368,8 +372,7 @@ describe("Combo box unit tests", () => {
key: "ArrowUp",
bubbles: true,
});
- const component = document.querySelector("wx-combo-box");
- const listbox = component.querySelector("ul");
+ const component = document.querySelector("wx-combo-box-location");
const input = component.querySelector("input[slot='input']");
input.focus();
@@ -383,7 +386,7 @@ describe("Combo box unit tests", () => {
key: "ArrowDown",
bubbles: true,
});
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
const listbox = component.querySelector("ul");
const input = component.querySelector("input[slot='input']");
listbox
@@ -399,7 +402,7 @@ describe("Combo box unit tests", () => {
});
it("Hides the result list if the input loses focus", () => {
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
expect(component.isShowingList).to.be.true;
const event = new window.FocusEvent("blur", { bubbles: true });
@@ -414,9 +417,9 @@ describe("Combo box unit tests", () => {
beforeEach(async () => {
sandbox = createSandbox();
window.document.body.innerHTML = "";
- const box = document.createElement("wx-combo-box");
+ const box = document.createElement("wx-combo-box-location");
document.body.append(box);
- assert.exists(window.customElements.get("wx-combo-box"));
+ assert.exists(window.customElements.get("wx-combo-box-location"));
await box.updateSearch("Arlin");
});
@@ -425,7 +428,7 @@ describe("Combo box unit tests", () => {
});
it("When pushing Enter when the second item is selected _and_ submitted", () => {
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
component.showList();
const secondItem = component.querySelector(
"div[role='listbox'] > ul > li[role='option']:nth-child(2)",
@@ -447,7 +450,7 @@ describe("Combo box unit tests", () => {
});
it("When clicking the second item, it is selected and submit is called", () => {
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
const secondItem = component.querySelector(
"div[role='listbox'] > ul > li:nth-child(2)",
);
@@ -463,7 +466,7 @@ describe("Combo box unit tests", () => {
});
it("Can get the geodata from a value key", async () => {
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
const secondItem = component.querySelector(
"div[role='listbox'] > ul > li:nth-child(2)",
);
@@ -479,7 +482,7 @@ describe("Combo box unit tests", () => {
});
it("Updates the parent form action with the correct value on submit", async () => {
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
const form = document.createElement("form");
form.setAttribute("data-location-search", "");
form.append(component);
@@ -528,7 +531,7 @@ describe("Combo box unit tests", () => {
global.fetch.resolves(response);
window.document.body.innerHTML = "";
- box = document.createElement("wx-combo-box");
+ box = document.createElement("wx-combo-box-location");
document.body.append(form);
form.append(box);
});
@@ -539,7 +542,7 @@ describe("Combo box unit tests", () => {
});
it("when a user chooses a location", () => {
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
component.input.value = "chosen place";
component.url = "https://place.com";
component.submit();
@@ -556,7 +559,7 @@ describe("Combo box unit tests", () => {
it("when a user loads a location page", () => {
window.document.body.innerHTML = "";
- const component = document.createElement("wx-combo-box");
+ const component = document.createElement("wx-combo-box-location");
component.setAttribute("data-place", "Placeville, ST");
document.body.append(form);
form.append(component);
@@ -575,7 +578,7 @@ describe("Combo box unit tests", () => {
.withArgs("wxgov_recent_locations")
.returns(JSON.stringify(previous));
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
component.input.value = "chosen place";
component.url = "https://place.com";
component.submit();
@@ -601,7 +604,7 @@ describe("Combo box unit tests", () => {
.withArgs("wxgov_recent_locations")
.returns(JSON.stringify(previous));
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
component.input.value = "chosen place";
component.url = "https://place.com";
component.submit();
@@ -622,7 +625,7 @@ describe("Combo box unit tests", () => {
describe("shows previously-saved results", () => {
beforeEach(async () => {
window.document.body.innerHTML = "";
- box = document.createElement("wx-combo-box");
+ box = document.createElement("wx-combo-box-location");
document.body.append(box);
response.ok = true;
@@ -634,7 +637,7 @@ describe("Combo box unit tests", () => {
JSON.stringify([{ text: "saved result", url: "https:/com.place" }]),
);
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
component.updateSearch("");
await wait(0);
const items = component.querySelectorAll(
@@ -657,7 +660,7 @@ describe("Combo box unit tests", () => {
JSON.stringify([{ text: "saved result", url: "https:/com.place" }]),
);
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
component.updateSearch("");
await wait(0);
const items = component.querySelectorAll(
@@ -684,7 +687,7 @@ describe("Combo box unit tests", () => {
]),
);
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
component.updateSearch("res");
await wait(0);
const items = component.querySelectorAll(
@@ -704,7 +707,7 @@ describe("Combo box unit tests", () => {
JSON.stringify([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]),
);
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
component.saveSearchResult({ url: "new" });
expect(
@@ -728,7 +731,7 @@ describe("Combo box unit tests", () => {
]),
);
- const component = document.querySelector("wx-combo-box");
+ const component = document.querySelector("wx-combo-box-location");
const results = component.getSavedResults("");
// deep equality, not reference equality