Added more unit tests to increase code coverage

This commit is contained in:
Alex Janousek
2025-10-27 15:00:52 -04:00
parent 6c3a516aa6
commit c273d5dd6f
9 changed files with 446 additions and 1 deletions

View File

@@ -1,6 +1,11 @@
beforeAll(() => {
// ErrorBanner module sets window.NotifyModules.ErrorBanner for backward compatibility
const originalNotifyModules = window.NotifyModules;
delete window.NotifyModules;
require('../../app/assets/javascripts/errorBanner.js');
expect(window.NotifyModules).toBeDefined();
expect(window.NotifyModules.ErrorBanner).toBeDefined();
});
afterAll(() => {
@@ -20,6 +25,13 @@ describe("Error Banner", () => {
window.NotifyModules.ErrorBanner.hideBanner();
expect(document.querySelector('.banner-dangerous').classList).toContain('display-none')
});
test("Will not error when no banner elements exist", () => {
document.body.innerHTML = `<div>No banners here</div>`;
expect(() => {
window.NotifyModules.ErrorBanner.hideBanner();
}).not.toThrow();
});
});
describe("The `showBanner` method", () => {
@@ -34,6 +46,13 @@ describe("Error Banner", () => {
test("Will show the element", () => {
expect(document.querySelector('.banner-dangerous').classList).not.toContain('display-none')
});
test("Will not error when no banner elements exist", () => {
document.body.innerHTML = `<div>No banners here</div>`;
expect(() => {
window.NotifyModules.ErrorBanner.showBanner();
}).not.toThrow();
});
});
test("Module exports ErrorBanner to window.NotifyModules", () => {