mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-03 15:41:06 -04:00
Add tests for 'data-show-now-as-default' on/off
This commit is contained in:
committed by
Chris Hill-Scott
parent
b5360c14cc
commit
741ab9288f
@@ -123,30 +123,60 @@ describe('RadioSelect', () => {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
describe("when the page has loaded it should have a button for each category", () => {
|
||||
describe("when the page has loaded", () => {
|
||||
|
||||
let categoryButtons;
|
||||
describe("if the 'data-show-now-as-default' attribute", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
test("is set to true the module should have a 'Now' option", () => {
|
||||
|
||||
// start module
|
||||
window.GOVUK.modules.start();
|
||||
// default is for it to be set to true
|
||||
|
||||
categoryButtons = document.querySelectorAll('.radio-select__column:nth-child(2) .radio-select__button--category');
|
||||
// start module
|
||||
window.GOVUK.modules.start();
|
||||
|
||||
expect(document.querySelectorAll('.radio-select__column').length).toEqual(2);
|
||||
|
||||
});
|
||||
|
||||
test("is set to false the module should not have a 'Now' option", () => {
|
||||
|
||||
document.querySelector('.radio-select').setAttribute('data-show-now-as-default', 'false');
|
||||
|
||||
// start module
|
||||
window.GOVUK.modules.start();
|
||||
|
||||
expect(document.querySelectorAll('.radio-select__column').length).toEqual(1);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test("the number of buttons should match the categories", () => {
|
||||
describe("it should have a button for each category", () => {
|
||||
|
||||
expect(categoryButtons.length).toBe(CATEGORIES.length);
|
||||
let categoryButtons;
|
||||
|
||||
});
|
||||
beforeEach(() => {
|
||||
|
||||
test("each button's text should match their category", () => {
|
||||
// start module
|
||||
window.GOVUK.modules.start();
|
||||
|
||||
categoryButtons = document.querySelectorAll('.radio-select__column:nth-child(2) .radio-select__button--category');
|
||||
|
||||
});
|
||||
|
||||
test("the number of buttons should match the categories", () => {
|
||||
|
||||
expect(categoryButtons.length).toBe(CATEGORIES.length);
|
||||
|
||||
});
|
||||
|
||||
test("each button's text should match their category", () => {
|
||||
|
||||
// check the buttons have the right text
|
||||
CATEGORIES.forEach((category, idx) => {
|
||||
expect(categoryButtons[idx].getAttribute('value')).toEqual(category);
|
||||
});
|
||||
|
||||
// check the buttons have the right text
|
||||
CATEGORIES.forEach((category, idx) => {
|
||||
expect(categoryButtons[idx].getAttribute('value')).toEqual(category);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user