expandable-navbar-section.component.spec.ts (dspace-angular-dspace-7.0) | : | expandable-navbar-section.component.spec.ts (dspace-angular-dspace-7.1) | ||
---|---|---|---|---|
skipping to change at line 12 | skipping to change at line 12 | |||
import { ExpandableNavbarSectionComponent } from './expandable-navbar-section.co mponent'; | import { ExpandableNavbarSectionComponent } from './expandable-navbar-section.co mponent'; | |||
import { By } from '@angular/platform-browser'; | import { By } from '@angular/platform-browser'; | |||
import { MenuServiceStub } from '../../shared/testing/menu-service.stub'; | import { MenuServiceStub } from '../../shared/testing/menu-service.stub'; | |||
import { Component } from '@angular/core'; | import { Component } from '@angular/core'; | |||
import { of as observableOf } from 'rxjs'; | import { of as observableOf } from 'rxjs'; | |||
import { HostWindowService } from '../../shared/host-window.service'; | import { HostWindowService } from '../../shared/host-window.service'; | |||
import { MenuService } from '../../shared/menu/menu.service'; | import { MenuService } from '../../shared/menu/menu.service'; | |||
import { HostWindowServiceStub } from '../../shared/testing/host-window-service. stub'; | import { HostWindowServiceStub } from '../../shared/testing/host-window-service. stub'; | |||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | |||
import { VarDirective } from '../../shared/utils/var.directive'; | ||||
describe('ExpandableNavbarSectionComponent', () => { | describe('ExpandableNavbarSectionComponent', () => { | |||
let component: ExpandableNavbarSectionComponent; | let component: ExpandableNavbarSectionComponent; | |||
let fixture: ComponentFixture<ExpandableNavbarSectionComponent>; | let fixture: ComponentFixture<ExpandableNavbarSectionComponent>; | |||
const menuService = new MenuServiceStub(); | const menuService = new MenuServiceStub(); | |||
describe('on larger screens', () => { | describe('on larger screens', () => { | |||
beforeEach(waitForAsync(() => { | beforeEach(waitForAsync(() => { | |||
TestBed.configureTestingModule({ | TestBed.configureTestingModule({ | |||
imports: [NoopAnimationsModule], | imports: [NoopAnimationsModule], | |||
declarations: [ExpandableNavbarSectionComponent, TestComponent], | declarations: [ExpandableNavbarSectionComponent, TestComponent, VarDirec tive], | |||
providers: [ | providers: [ | |||
{ provide: 'sectionDataProvider', useValue: {} }, | { provide: 'sectionDataProvider', useValue: {} }, | |||
{ provide: MenuService, useValue: menuService }, | { provide: MenuService, useValue: menuService }, | |||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(800) } | { provide: HostWindowService, useValue: new HostWindowServiceStub(800) } | |||
] | ] | |||
}).overrideComponent(ExpandableNavbarSectionComponent, { | }).overrideComponent(ExpandableNavbarSectionComponent, { | |||
set: { | set: { | |||
entryComponents: [TestComponent] | entryComponents: [TestComponent] | |||
} | } | |||
}) | }) | |||
skipping to change at line 52 | skipping to change at line 53 | |||
fixture.detectChanges(); | fixture.detectChanges(); | |||
}); | }); | |||
it('should create', () => { | it('should create', () => { | |||
expect(component).toBeTruthy(); | expect(component).toBeTruthy(); | |||
}); | }); | |||
describe('when the mouse enters the section header', () => { | describe('when the mouse enters the section header', () => { | |||
beforeEach(() => { | beforeEach(() => { | |||
spyOn(menuService, 'activateSection'); | spyOn(menuService, 'activateSection'); | |||
const sidebarToggler = fixture.debugElement.query(By.css('li.nav-item.dr opdown')); | const sidebarToggler = fixture.debugElement.query(By.css('div.nav-item.d ropdown')); | |||
sidebarToggler.triggerEventHandler('mouseenter', { | sidebarToggler.triggerEventHandler('mouseenter', { | |||
preventDefault: () => {/**/ | preventDefault: () => {/**/ | |||
} | } | |||
}); | }); | |||
}); | }); | |||
it('should call activateSection on the menuService', () => { | it('should call activateSection on the menuService', () => { | |||
expect(menuService.activateSection).toHaveBeenCalled(); | expect(menuService.activateSection).toHaveBeenCalled(); | |||
}); | }); | |||
}); | }); | |||
describe('when the mouse leaves the section header', () => { | describe('when the mouse leaves the section header', () => { | |||
beforeEach(() => { | beforeEach(() => { | |||
spyOn(menuService, 'deactivateSection'); | spyOn(menuService, 'deactivateSection'); | |||
const sidebarToggler = fixture.debugElement.query(By.css('li.nav-item.dr opdown')); | const sidebarToggler = fixture.debugElement.query(By.css('div.nav-item.d ropdown')); | |||
sidebarToggler.triggerEventHandler('mouseleave', { | sidebarToggler.triggerEventHandler('mouseleave', { | |||
preventDefault: () => {/**/ | preventDefault: () => {/**/ | |||
} | } | |||
}); | }); | |||
}); | }); | |||
it('should call deactivateSection on the menuService', () => { | it('should call deactivateSection on the menuService', () => { | |||
expect(menuService.deactivateSection).toHaveBeenCalled(); | expect(menuService.deactivateSection).toHaveBeenCalled(); | |||
}); | }); | |||
}); | }); | |||
describe('when Enter key is pressed on section header (while inactive)', () | ||||
=> { | ||||
beforeEach(() => { | ||||
spyOn(menuService, 'activateSection'); | ||||
// Make sure section is 'inactive'. Requires calling ngOnInit() to updat | ||||
e component 'active' property. | ||||
spyOn(menuService, 'isSectionActive').and.returnValue(observableOf(false | ||||
)); | ||||
component.ngOnInit(); | ||||
fixture.detectChanges(); | ||||
const sidebarToggler = fixture.debugElement.query(By.css('div.nav-item.d | ||||
ropdown')); | ||||
// 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.d | ||||
ropdown')); | ||||
// 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 spacebar is pressed on section header (while inactive)', () = | ||||
> { | ||||
beforeEach(() => { | ||||
spyOn(menuService, 'activateSection'); | ||||
// Make sure section is 'inactive'. Requires calling ngOnInit() to updat | ||||
e component 'active' property. | ||||
spyOn(menuService, 'isSectionActive').and.returnValue(observableOf(false | ||||
)); | ||||
component.ngOnInit(); | ||||
fixture.detectChanges(); | ||||
const sidebarToggler = fixture.debugElement.query(By.css('div.nav-item.d | ||||
ropdown')); | ||||
// dispatch the (keyup.space) action used in our component HTML | ||||
sidebarToggler.nativeElement.dispatchEvent(new KeyboardEvent('keyup', { | ||||
key: ' ' })); | ||||
}); | ||||
it('should call activateSection on the menuService', () => { | ||||
expect(menuService.activateSection).toHaveBeenCalled(); | ||||
}); | ||||
}); | ||||
describe('when spacebar 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.d | ||||
ropdown')); | ||||
// dispatch the (keyup.space) action used in our component HTML | ||||
sidebarToggler.nativeElement.dispatchEvent(new KeyboardEvent('keyup', { | ||||
key: ' ' })); | ||||
}); | ||||
it('should call deactivateSection on the menuService', () => { | ||||
expect(menuService.deactivateSection).toHaveBeenCalled(); | ||||
}); | ||||
}); | ||||
describe('when a click occurs on the section header', () => { | describe('when a click occurs on the section header', () => { | |||
beforeEach(() => { | beforeEach(() => { | |||
spyOn(menuService, 'toggleActiveSection'); | spyOn(menuService, 'toggleActiveSection'); | |||
const sidebarToggler = fixture.debugElement.query(By.css('li.nav-item.dr opdown')).query(By.css('a')); | const sidebarToggler = fixture.debugElement.query(By.css('div.nav-item.d ropdown > a')); | |||
sidebarToggler.triggerEventHandler('click', { | sidebarToggler.triggerEventHandler('click', { | |||
preventDefault: () => {/**/ | preventDefault: () => {/**/ | |||
} | } | |||
}); | }); | |||
}); | }); | |||
it('should not call toggleActiveSection on the menuService', () => { | it('should not call toggleActiveSection on the menuService', () => { | |||
expect(menuService.toggleActiveSection).not.toHaveBeenCalled(); | expect(menuService.toggleActiveSection).not.toHaveBeenCalled(); | |||
}); | }); | |||
}); | }); | |||
}); | }); | |||
describe('on smaller, mobile screens', () => { | describe('on smaller, mobile screens', () => { | |||
beforeEach(waitForAsync(() => { | beforeEach(waitForAsync(() => { | |||
TestBed.configureTestingModule({ | TestBed.configureTestingModule({ | |||
imports: [NoopAnimationsModule], | imports: [NoopAnimationsModule], | |||
declarations: [ExpandableNavbarSectionComponent, TestComponent], | declarations: [ExpandableNavbarSectionComponent, TestComponent, VarDirec tive], | |||
providers: [ | providers: [ | |||
{ provide: 'sectionDataProvider', useValue: {} }, | { provide: 'sectionDataProvider', useValue: {} }, | |||
{ provide: MenuService, useValue: menuService }, | { provide: MenuService, useValue: menuService }, | |||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(300) } | { provide: HostWindowService, useValue: new HostWindowServiceStub(300) } | |||
] | ] | |||
}).overrideComponent(ExpandableNavbarSectionComponent, { | }).overrideComponent(ExpandableNavbarSectionComponent, { | |||
set: { | set: { | |||
entryComponents: [TestComponent] | entryComponents: [TestComponent] | |||
} | } | |||
}) | }) | |||
skipping to change at line 125 | skipping to change at line 198 | |||
fixture = TestBed.createComponent(ExpandableNavbarSectionComponent); | fixture = TestBed.createComponent(ExpandableNavbarSectionComponent); | |||
component = fixture.componentInstance; | component = fixture.componentInstance; | |||
spyOn(component as any, 'getMenuItemComponent').and.returnValue(TestCompon ent); | spyOn(component as any, 'getMenuItemComponent').and.returnValue(TestCompon ent); | |||
fixture.detectChanges(); | fixture.detectChanges(); | |||
}); | }); | |||
describe('when the mouse enters the section header', () => { | describe('when the mouse enters the section header', () => { | |||
beforeEach(() => { | beforeEach(() => { | |||
spyOn(menuService, 'activateSection'); | spyOn(menuService, 'activateSection'); | |||
const sidebarToggler = fixture.debugElement.query(By.css('li.nav-item.dr opdown')); | const sidebarToggler = fixture.debugElement.query(By.css('div.nav-item.d ropdown > a')); | |||
sidebarToggler.triggerEventHandler('mouseenter', { | sidebarToggler.triggerEventHandler('mouseenter', { | |||
preventDefault: () => {/**/ | preventDefault: () => {/**/ | |||
} | } | |||
}); | }); | |||
}); | }); | |||
it('should not call activateSection on the menuService', () => { | it('should not call activateSection on the menuService', () => { | |||
expect(menuService.activateSection).not.toHaveBeenCalled(); | expect(menuService.activateSection).not.toHaveBeenCalled(); | |||
}); | }); | |||
}); | }); | |||
describe('when the mouse leaves the section header', () => { | describe('when the mouse leaves the section header', () => { | |||
beforeEach(() => { | beforeEach(() => { | |||
spyOn(menuService, 'deactivateSection'); | spyOn(menuService, 'deactivateSection'); | |||
const sidebarToggler = fixture.debugElement.query(By.css('li.nav-item.dr opdown')); | const sidebarToggler = fixture.debugElement.query(By.css('div.nav-item.d ropdown > a')); | |||
sidebarToggler.triggerEventHandler('mouseleave', { | sidebarToggler.triggerEventHandler('mouseleave', { | |||
preventDefault: () => {/**/ | preventDefault: () => {/**/ | |||
} | } | |||
}); | }); | |||
}); | }); | |||
it('should not call deactivateSection on the menuService', () => { | it('should not call deactivateSection on the menuService', () => { | |||
expect(menuService.deactivateSection).not.toHaveBeenCalled(); | expect(menuService.deactivateSection).not.toHaveBeenCalled(); | |||
}); | }); | |||
}); | }); | |||
describe('when a click occurs on the section header link', () => { | describe('when a click occurs on the section header link', () => { | |||
beforeEach(() => { | beforeEach(() => { | |||
spyOn(menuService, 'toggleActiveSection'); | spyOn(menuService, 'toggleActiveSection'); | |||
const sidebarToggler = fixture.debugElement.query(By.css('li.nav-item.dr opdown')).query(By.css('a')); | const sidebarToggler = fixture.debugElement.query(By.css('div.nav-item.d ropdown > a')); | |||
sidebarToggler.triggerEventHandler('click', { | sidebarToggler.triggerEventHandler('click', { | |||
preventDefault: () => {/**/ | preventDefault: () => {/**/ | |||
} | } | |||
}); | }); | |||
}); | }); | |||
it('should call toggleActiveSection on the menuService', () => { | it('should call toggleActiveSection on the menuService', () => { | |||
expect(menuService.toggleActiveSection).toHaveBeenCalled(); | expect(menuService.toggleActiveSection).toHaveBeenCalled(); | |||
}); | }); | |||
}); | }); | |||
End of changes. 10 change blocks. | ||||
8 lines changed or deleted | 101 lines changed or added |