Add tests for various different counter states

This commit is contained in:
Tom Byers
2020-09-18 11:51:16 +01:00
parent 2f18e4b2f0
commit 704de9ebf3

View File

@@ -610,7 +610,7 @@ describe('TemplateFolderForm', () => {
test("the content of the counter should reflect the selection", () => {
expect(visibleCounterText).toEqual('2 selected');
expect(visibleCounterText).toEqual('1 template, 1 folder selected');
});
@@ -781,4 +781,70 @@ describe('TemplateFolderForm', () => {
});
describe("Additional selection counter scenarios", () => {
let templateFolderCheckboxes;
beforeEach(() => {
// start module
window.GOVUK.modules.start();
templateFolderCheckboxes = getTemplateFolderCheckboxes();
visibleCounterText = getVisibleCounter().textContent.trim();
hiddenCounterText = getHiddenCounter().textContent.trim();
formControls = templateFolderForm.querySelector('#sticky_template_forms');
// reset sticky JS mocks called when the module starts
resetStickyMocks();
});
afterEach(() => resetStickyMocks());
describe("When just templates are selected", () => {
test("the content of both visible and hidden counters should match", () => {
helpers.triggerEvent(templateFolderCheckboxes[1], 'click');
helpers.triggerEvent(templateFolderCheckboxes[2], 'click');
expect(visibleCounterText).toEqual(hiddenCounterText);
});
test("the content of the counter should reflect the selection", () => {
helpers.triggerEvent(templateFolderCheckboxes[1], 'click');
helpers.triggerEvent(templateFolderCheckboxes[2], 'click');
expect(visibleCounterText).toEqual('2 templates selected');
});
});
describe("When just folders are selected", () => {
test("the content of both visible and hidden counters should match", () => {
helpers.triggerEvent(templateFolderCheckboxes[0], 'click');
expect(visibleCounterText).toEqual(hiddenCounterText);
});
test("the content of the counter should reflect the selection", () => {
helpers.triggerEvent(templateFolderCheckboxes[0], 'click');
expect(visibleCounterText).toEqual('1 folder selected');
});
});
});
});