From 4eb5eadcf89b1c12cd7cbb74e16f0e6ccb1e42d9 Mon Sep 17 00:00:00 2001 From: Mat Moore Date: Mon, 26 Feb 2024 09:44:40 +0000 Subject: [PATCH] Add test --- tests/javascript/test_enhanced_search.js | 44 ++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/tests/javascript/test_enhanced_search.js b/tests/javascript/test_enhanced_search.js index 4920b383..83d7ae8c 100644 --- a/tests/javascript/test_enhanced_search.js +++ b/tests/javascript/test_enhanced_search.js @@ -12,6 +12,7 @@ const widget_html = ` +
@@ -49,6 +50,47 @@ describe("initialisation", () => { }); }); +describe("after selecting a domain with no subdomains", () => { + beforeEach(() => { + document.body.innerHTML = widget_html; + + subdomainFilter = document.querySelector("#subdomains-filter"); + domainFilter = document.querySelector("#domains-filter"); + + initDomainFilter(); + + // Listen to outgoing events + domainFilter.parentElement.addEventListener( + "domain-filter-updates", + eventSpy + ); + + // Emulate selecting a domain + domainFilter.value = "c"; + domainFilter.dispatchEvent(new Event("change")); + }); + + test("selects all subdomains", () => { + expect(subdomainFilter.value).toEqual("*"); + }); + + test("only the all subdomains option is available", () => { + const options = subdomainFilter.querySelectorAll("option"); + + const values = Array.from(options).map((el) => el.value); + + expect(values).toEqual(["*"]); + }); + + test("fires an event with the selected domain/subdomain pair", () => { + expect(eventSpy.mock.calls[0][0].detail).toEqual({ + topLevelDomainValue: "c", + subdomainValue: null, + label: "Domain C", + }); + }); +}); + describe("after selecting a domain", () => { beforeEach(() => { document.body.innerHTML = widget_html; @@ -162,5 +204,3 @@ describe("after selecting a domain", () => { }); }); }); - -// TODO: clear selected subdomain when choosing parent domain