mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Fix existing tests. Add new specs for enter key presses
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<ng-container *ngVar="(active | async) as isActive">
|
||||
<div class="nav-item dropdown expandable-navbar-section"
|
||||
<div class="nav-item dropdown expandable-navbar-section"
|
||||
*ngVar="(active | async) as isActive"
|
||||
(keyup.enter)="isActive ? deactivateSection($event) : activateSection($event)"
|
||||
(mouseenter)="activateSection($event)"
|
||||
(mouseleave)="deactivateSection($event)">
|
||||
@@ -16,5 +16,4 @@
|
||||
*ngComponentOutlet="(sectionMap$ | async).get(subSection.id).component; injector: (sectionMap$ | async).get(subSection.id).injector;"></ng-container>
|
||||
</ng-container>
|
||||
</ul>
|
||||
</div>
|
||||
</ng-container>
|
||||
</div>
|
||||
|
@@ -9,6 +9,7 @@ import { HostWindowService } from '../../shared/host-window.service';
|
||||
import { MenuService } from '../../shared/menu/menu.service';
|
||||
import { HostWindowServiceStub } from '../../shared/testing/host-window-service.stub';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { VarDirective } from '../../shared/utils/var.directive';
|
||||
|
||||
describe('ExpandableNavbarSectionComponent', () => {
|
||||
let component: ExpandableNavbarSectionComponent;
|
||||
@@ -19,7 +20,7 @@ describe('ExpandableNavbarSectionComponent', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [NoopAnimationsModule],
|
||||
declarations: [ExpandableNavbarSectionComponent, TestComponent],
|
||||
declarations: [ExpandableNavbarSectionComponent, TestComponent, VarDirective],
|
||||
providers: [
|
||||
{ provide: 'sectionDataProvider', useValue: {} },
|
||||
{ provide: MenuService, useValue: menuService },
|
||||
@@ -76,6 +77,42 @@ describe('ExpandableNavbarSectionComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when Enter key is pressed on section header (while inactive)', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(menuService, 'activateSection');
|
||||
// Make sure section is 'inactive'. Requires calling ngOnInit() to update component 'active' property.
|
||||
spyOn(menuService, 'isSectionActive').and.returnValue(observableOf(false));
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
|
||||
const sidebarToggler = fixture.debugElement.query(By.css('div.nav-item.dropdown'));
|
||||
// dispatch the (keyup.enter) action used in our component HTML
|
||||
sidebarToggler.nativeElement.dispatchEvent(new KeyboardEvent('keyup', { key: 'Enter' }));
|
||||
});
|
||||
|
||||
it('should call activateSection on the menuService', () => {
|
||||
expect(menuService.activateSection).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when Enter key is pressed on section header (while active)', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(menuService, 'deactivateSection');
|
||||
// Make sure section is 'active'. Requires calling ngOnInit() to update component 'active' property.
|
||||
spyOn(menuService, 'isSectionActive').and.returnValue(observableOf(true));
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
|
||||
const sidebarToggler = fixture.debugElement.query(By.css('div.nav-item.dropdown'));
|
||||
// dispatch the (keyup.enter) action used in our component HTML
|
||||
sidebarToggler.nativeElement.dispatchEvent(new KeyboardEvent('keyup', { key: 'Enter' }));
|
||||
});
|
||||
|
||||
it('should call deactivateSection on the menuService', () => {
|
||||
expect(menuService.deactivateSection).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when a click occurs on the section header', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(menuService, 'toggleActiveSection');
|
||||
@@ -96,7 +133,7 @@ describe('ExpandableNavbarSectionComponent', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [NoopAnimationsModule],
|
||||
declarations: [ExpandableNavbarSectionComponent, TestComponent],
|
||||
declarations: [ExpandableNavbarSectionComponent, TestComponent, VarDirective],
|
||||
providers: [
|
||||
{ provide: 'sectionDataProvider', useValue: {} },
|
||||
{ provide: MenuService, useValue: menuService },
|
||||
|
Reference in New Issue
Block a user