import { Application } from 'stimulus'; import SidebarController from '../../controllers/sidebar_controller'; describe('SidebarController', () => { beforeAll(() => { document.head.innerHTML = ''; }); beforeEach(() => { document.body.innerHTML = `
`; const application = Application.start(); application.register('sidebar', SidebarController); }); describe('#disableCurrentNavItem', () => { it('sets the disabled attribute on the open menu button', () => { window.dispatchEvent(new Event('load')); const button = document.getElementById('apps_button'); expect(button.getAttribute('disabled')).toEqual('true'); }); }); describe('#expandDropdown', () => { beforeEach(() => { const assignMock = jest.fn(); delete window.location; window.location = { href: assignMock }; }); afterEach(() => { window.location = location; }); it('redirects to the first child navigation item', () => { const button = document.getElementById('advanced_button'); button.click(); expect(window.location.href).toEqual('/admin/advanced/broadcasts'); }); it('closes other menu items', () => { const button = document.getElementById('advanced_button'); button.click(); expect(document.getElementById('apps').classList).toContain('hide'); }); }); });