Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/primefaces/primeng
Browse files Browse the repository at this point in the history
  • Loading branch information
cetincakiroglu committed May 2, 2024
2 parents 721f58a + 383ce26 commit 25488aa
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 330 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/app/components/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ describe('Checkbox', () => {
const input = fixture.nativeElement.querySelector('input');
const boxEl = fixture.nativeElement.querySelector('.p-checkbox-box');
const labelEl = fixture.nativeElement.querySelector('.p-checkbox-label');
const onBlurSpy = spyOn(checkbox, 'onBlur').and.callThrough();
const onFocusSpy = spyOn(checkbox, 'onFocus').and.callThrough();
const onBlurSpy = spyOn(checkbox, 'onInputBlur').and.callThrough();
const onFocusSpy = spyOn(checkbox, 'onInputFocus').and.callThrough();
input.dispatchEvent(new Event('focus'));
fixture.detectChanges();

Expand Down
4 changes: 4 additions & 0 deletions src/app/components/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,10 @@ export class Menu implements OnDestroy {
this.onEnterKey(event);
break;

case 'NumpadEnter':
this.onEnterKey(event);
break;

case 'Space':
this.onSpaceKey(event);
break;
Expand Down
13 changes: 8 additions & 5 deletions src/app/components/menubar/menubar.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import { MenuItem } from 'primeng/api';
* @group Templates
*/
export interface MenubarTemplates {
/**
/**
* Custom item template.
*/
item(context: {
item(context: {
/**
* Item instance.
*/
$implicit: MenuItem

}): TemplateRef<{ $implicit: MenuItem }>;
$implicit: MenuItem;
/**
* Whether root or not
*/
root: boolean;
}): TemplateRef<{ $implicit: MenuItem; root: boolean }>;
/**
* Custom template of start.
*/
Expand Down
70 changes: 14 additions & 56 deletions src/app/components/menubar/menubar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { ComponentFixture, fakeAsync, flush, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { Menubar, MenubarModule, MenubarService, MenubarSub } from './menubar';
import { RouterModule } from '@angular/router';

describe('Menubar', () => {
let menubar: Menubar;
let fixture: ComponentFixture<Menubar>;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [NoopAnimationsModule, RouterTestingModule.withRoutes([{ path: 'test', component: Menubar }]), MenubarModule],
imports: [NoopAnimationsModule, RouterModule.forRoot([{ path: 'test', component: Menubar }]), MenubarModule],
providers: [MenubarService]
});

Expand Down Expand Up @@ -45,7 +45,7 @@ describe('Menubar', () => {
const subMenu = fixture.debugElement.query(By.css('.p-menubar-root-list')).componentInstance as MenubarSub;
expect(subMenu.baseZIndex).toEqual(20);
expect(subMenu.autoZIndex).toEqual(false);
expect(subMenu.autoDisplay).toBeUndefined();
expect(subMenu.autoDisplay).toBeDefined();
expect(subMenu.autoDisplay).toEqual(menubar.autoDisplay);
expect(subMenu.autoZIndex).toEqual(menubar.autoZIndex);
expect(subMenu.baseZIndex).toEqual(menubar.baseZIndex);
Expand Down Expand Up @@ -121,53 +121,11 @@ describe('Menubar', () => {
const parentEl = fixture.debugElement.query(By.css('.p-menubar-root-list'));
const firstParentEl = parentEl.query(By.css('.p-menuitem-link'));
const secondParentEl = parentEl.queryAll(By.css('.p-menuitem-link'))[1];
firstParentEl.nativeElement.dispatchEvent(new Event('click'));
fixture.detectChanges();

expect(firstParentEl.parent.nativeElement.classList.contains('p-menuitem-active')).toBe(true);
expect(secondParentEl.parent.nativeElement.classList.contains('p-menuitem-active')).toBe(false);
});

it('should call itemClick', () => {
menubar.model = [
{
label: 'File',
icon: 'pi pi-fw pi-file',
items: [
{
label: 'New',
icon: 'pi pi-fw pi-plus'
},
{ label: 'Open' },
{ separator: true },
{ label: 'Quit' }
]
},
{
label: 'Edit',
icon: 'pi pi-fw pi-pencil',
items: [
{ label: 'Delete', icon: 'pi pi-fw pi-trash' },
{ label: 'Refresh', icon: 'pi pi-fw pi-refresh' }
]
}
];
fixture.detectChanges();

const parentEl = fixture.debugElement.query(By.css('.p-menubar-root-list'));
const firstParentEl = parentEl.query(By.css('.p-menuitem-link'));
const secondParentEl = parentEl.queryAll(By.css('.p-menuitem-link'))[1];
firstParentEl.nativeElement.dispatchEvent(new Event('click'));
fixture.detectChanges();

const firstSubmenuList = fixture.debugElement.query(By.css('.p-submenu-list'));
const firstSubItem = firstSubmenuList.query(By.css('.p-menuitem-link'));
firstSubItem.nativeElement.click();
firstParentEl.nativeElement.click();
fixture.detectChanges();

expect(firstParentEl.componentInstance.activeItem).toEqual(null);
expect(secondParentEl.componentInstance.activeItem).toEqual(null);
expect(firstParentEl.parent.nativeElement.className).not.toContain('p-menuitem-active');
expect(firstParentEl?.parent?.parent?.nativeElement.classList.contains('p-menuitem-active')).toBe(true);
expect(secondParentEl?.parent?.parent?.nativeElement.classList.contains('p-menuitem-active')).toBe(false);
});

it('should call onItemMouseEnter and not show firstParentMenu', () => {
Expand Down Expand Up @@ -241,11 +199,11 @@ describe('Menubar', () => {
firstParentEl.nativeElement.dispatchEvent(new Event('mouseleave'));
tick(300);
fixture.detectChanges();
expect(firstParentEl.parent.nativeElement.classList.contains('p-menuitem-active')).toBe(true);
expect(firstParentEl?.parent?.parent?.nativeElement.classList.contains('p-menuitem-active')).toBe(true);
flush();
}));

it('should call itemClick and bindEventListener', () => {
it('should call itemClick', () => {
menubar.model = [
{
label: 'File',
Expand Down Expand Up @@ -273,7 +231,7 @@ describe('Menubar', () => {

const parentEl = fixture.debugElement.query(By.css('.p-menubar-root-list'));
const firstParentEl = parentEl.query(By.css('.p-menuitem-link'));
const bindEventListenerSpy = spyOn(firstParentEl.componentInstance, 'bindDocumentClickListener').and.callThrough();
const secondParentEl = parentEl.queryAll(By.css('.p-menuitem-link'))[1];
firstParentEl.nativeElement.click();
fixture.detectChanges();

Expand All @@ -282,8 +240,9 @@ describe('Menubar', () => {
firstSubItem.nativeElement.dispatchEvent(new Event('mouseenter'));
fixture.detectChanges();

expect(bindEventListenerSpy).toHaveBeenCalled();
expect(firstParentEl.parent.nativeElement.className).toContain('p-menuitem-active');
expect(firstParentEl?.parent?.parent?.nativeElement.className).toContain('p-menuitem-active');
expect(secondParentEl?.parent?.parent?.nativeElement.className).not.toContain('p-menuitem-active');

});

it('should show router items', () => {
Expand Down Expand Up @@ -315,10 +274,9 @@ describe('Menubar', () => {

const parentEl = fixture.debugElement.query(By.css('.p-menubar-root-list'));
const firstParentEl = parentEl.query(By.css('.p-menuitem-link'));
firstParentEl.nativeElement.dispatchEvent(new Event('click'));
firstParentEl.nativeElement.click();
fixture.detectChanges();

expect(firstParentEl.componentInstance.activeItem.label).toEqual(firstParentEl.nativeElement.textContent);
expect(firstParentEl?.componentInstance.activeItemPath[0].item.label).toEqual(firstParentEl.nativeElement.textContent);
});

it('should call itemClick', () => {
Expand Down
Loading

0 comments on commit 25488aa

Please sign in to comment.