Skip to content

Commit

Permalink
feat(menu): allow to add custom menu links
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Malkevich committed Mar 12, 2019
1 parent ddc4a91 commit 5200932
Show file tree
Hide file tree
Showing 5 changed files with 338 additions and 93 deletions.
6 changes: 5 additions & 1 deletion projects/demo/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';

import { AppComponent } from './app.component';
import { By } from '@angular/platform-browser';
import { DynamicMenuService } from 'projects/dynamic-menu/src/public_api';

describe('Component: App', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [AppComponent],
providers: [{ provide: DynamicMenuService, useValue: {} }],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
});
});
Expand Down
30 changes: 28 additions & 2 deletions projects/demo/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { DynamicMenuService } from 'projects/dynamic-menu/src/public_api';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent {}
export class AppComponent implements OnInit {
constructor(private dynamicMenuService: DynamicMenuService) {}

ngOnInit(): void {
this.dynamicMenuService.addMenuAfter(['path3', ':id', 'path6'], {
path: 'custom-path',
data: { menu: { label: 'Custom Section' } },
});
this.dynamicMenuService.addMenuToStart(['path3', ':id', 'path6'], {
path: 'custom-path2',
data: { menu: { label: 'Custom Section - Start' } },
});
this.dynamicMenuService.addMenuToEnd(['path3', ':id', 'path6'], {
path: 'custom-path3',
data: { menu: { label: 'Custom Section - End' } },
});
this.dynamicMenuService.addMenuToStart([''], {
path: 'custom-path-start',
data: { menu: { label: 'Custom Section - Start' } },
});
this.dynamicMenuService.addMenuToEnd([''], {
path: 'custom-path-end',
data: { menu: { label: 'Custom Section - End' } },
});
}
}
2 changes: 1 addition & 1 deletion projects/dynamic-menu/src/lib/dynamic-menu.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ describe('Service: DynamicMenu', () => {

expect(menu[1].path).toBe('child');
expect(menu[1].data.menu.label).toBe('Child');
expect(menu[1].data.menu.children.length).toBe(0); // Not yet loaded
expect(menu[1].data.menu.children).toBeUndefined(); // Not yet loaded

callback.calls.reset();

Expand Down
Loading

0 comments on commit 5200932

Please sign in to comment.