Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
MatMoore committed Feb 26, 2024
1 parent 730c59e commit 4eb5ead
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions tests/javascript/test_enhanced_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const widget_html = `
<option value="*">All domains</option>
<option value="a">Domain A</option>
<option value="b">Domain B</option>
<option value="c">Domain C</option>
</select>
</div>
<div class="govuk-form-group js-required">
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -162,5 +204,3 @@ describe("after selecting a domain", () => {
});
});
});

// TODO: clear selected subdomain when choosing parent domain

0 comments on commit 4eb5ead

Please sign in to comment.