mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 03:13:42 -05:00
Increased unit test
This commit is contained in:
@@ -352,4 +352,72 @@ describe("List entry", () => {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe("getOriginalClasses functionality", () => {
|
||||
test("Should handle inputs without any classes", () => {
|
||||
// Create input without classes
|
||||
document.body.innerHTML = `
|
||||
<div class="input-list" data-module="list-entry" data-list-item-name="domain" id="list-entry-domains">
|
||||
<div class="list-entry">
|
||||
<input type="text" name="domains-1" id="domains-1">
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
inputList = document.querySelector('.input-list');
|
||||
|
||||
// start module
|
||||
window.GOVUK.modules.start();
|
||||
|
||||
// Check that it handles missing classes gracefully
|
||||
const newInput = inputList.querySelector('.list-entry input');
|
||||
expect(newInput).not.toBeNull();
|
||||
});
|
||||
|
||||
test("Should handle empty input list", () => {
|
||||
// Create div without any inputs
|
||||
document.body.innerHTML = `
|
||||
<div class="input-list" data-module="list-entry" data-list-item-name="domain" id="list-entry-domains">
|
||||
</div>`;
|
||||
|
||||
inputList = document.querySelector('.input-list');
|
||||
|
||||
// This should not throw an error
|
||||
expect(() => {
|
||||
window.GOVUK.modules.start();
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("getId functionality", () => {
|
||||
test("Should generate IDs correctly with and without number parameter", () => {
|
||||
// Set up a simpler structure to test ID generation
|
||||
document.body.innerHTML = `
|
||||
<div class="input-list" data-module="list-entry" data-list-item-name="test-item" id="list-entry-test">
|
||||
<div class="list-entry">
|
||||
<input type="text" name="test-1" id="test-1" class="usa-input">
|
||||
</div>
|
||||
<div class="list-entry">
|
||||
<input type="text" name="test-2" id="test-2" class="usa-input">
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
inputList = document.querySelector('.input-list');
|
||||
|
||||
// start module
|
||||
window.GOVUK.modules.start();
|
||||
|
||||
// After module starts, check that IDs are generated correctly
|
||||
// The module will have regenerated the DOM
|
||||
const inputs = inputList.querySelectorAll('input');
|
||||
|
||||
// Check that inputs have proper IDs with numbers
|
||||
expect(inputs[0].id).toEqual("test-1");
|
||||
expect(inputs[1].id).toEqual("test-2");
|
||||
|
||||
// The getId function is called internally during render
|
||||
// We can verify it worked by checking the generated HTML structure
|
||||
expect(inputList.innerHTML).toContain('id="test-1"');
|
||||
expect(inputList.innerHTML).toContain('id="test-2"');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user