-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/app/shared/cms/components/cms-navigation-link/cms-navigation-link.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!-- eslint-disable @angular-eslint/template/interactive-supports-focus --> | ||
<!-- eslint-disable @angular-eslint/template/click-events-have-key-events --> | ||
<ng-container *ngIf="pagelet?.hasParam('Link')"> | ||
<li | ||
#subMenu | ||
[class]="'dropdown ' + pagelet.stringParam('CSSClass', '')" | ||
[ngClass]="{ open: opened }" | ||
(mouseenter)="subMenuShow(subMenu)" | ||
(mouseleave)="subMenuHide(subMenu)" | ||
(click)="subMenuHide(subMenu)" | ||
> | ||
<ng-container *ngIf="isRouterLink(pagelet, 'Link'); else externalLink"> | ||
<a | ||
[routerLink]="routerLink(pagelet, 'Link')" | ||
[ngStyle]="{ width: !pagelet.hasParam('SubNavigationHTML') ? '100%' : '' }" | ||
> | ||
{{ pagelet.stringParam('LinkText') }} | ||
</a> | ||
</ng-container> | ||
<ng-template #externalLink> | ||
<a | ||
[href]="pagelet.stringParam('Link')" | ||
[ngStyle]="{ width: !pagelet.hasParam('SubNavigationHTML') ? '100%' : '' }" | ||
> | ||
{{ pagelet.stringParam('LinkText') }} | ||
</a> | ||
</ng-template> | ||
|
||
<ng-container *ngIf="pagelet.hasParam('SubNavigationHTML')"> | ||
<a class="dropdown-toggle" (click)="toggleOpen()"> | ||
<fa-icon *ngIf="opened; else closed" [icon]="['fas', 'minus']" /> | ||
<ng-template #closed><fa-icon [icon]="['fas', 'plus']" /></ng-template> | ||
</a> | ||
<ul class="category-level1 dropdown-menu"> | ||
<li class="sub-navigation-content"> | ||
<div [ishServerHtml]="pagelet.stringParam('SubNavigationHTML')"></div> | ||
</li> | ||
</ul> | ||
</ng-container> | ||
</li> | ||
</ng-container> |
82 changes: 82 additions & 0 deletions
82
src/app/shared/cms/components/cms-navigation-link/cms-navigation-link.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { FaIconComponent } from '@fortawesome/angular-fontawesome'; | ||
import { MockComponent, MockDirective } from 'ng-mocks'; | ||
|
||
import { ServerHtmlDirective } from 'ish-core/directives/server-html.directive'; | ||
import { createContentPageletView } from 'ish-core/models/content-view/content-view.model'; | ||
|
||
import { CMSNavigationLinkComponent } from './cms-navigation-link.component'; | ||
|
||
describe('Cms Navigation Link Component', () => { | ||
let component: CMSNavigationLinkComponent; | ||
let fixture: ComponentFixture<CMSNavigationLinkComponent>; | ||
let element: HTMLElement; | ||
|
||
const pagelet = { | ||
definitionQualifiedName: 'dqn', | ||
id: 'id', | ||
displayName: 'name', | ||
domain: 'domain', | ||
configurationParameters: { | ||
Link: 'route://home', | ||
LinkText: 'Home', | ||
CSSClass: 'nav-link', | ||
}, | ||
}; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [RouterTestingModule], | ||
declarations: [CMSNavigationLinkComponent, MockComponent(FaIconComponent), MockDirective(ServerHtmlDirective)], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(CMSNavigationLinkComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
}); | ||
|
||
it('should be created', () => { | ||
component.pagelet = createContentPageletView(pagelet); | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
expect(element).toMatchInlineSnapshot(` | ||
<li class="dropdown nav-link"> | ||
<a ng-reflect-router-link="/home" style="width: 100%" href="/home"> Home </a> | ||
</li> | ||
`); | ||
}); | ||
|
||
it('should render external link if set', () => { | ||
component.pagelet = createContentPageletView({ | ||
...pagelet, | ||
configurationParameters: { ...pagelet.configurationParameters, Link: 'https://test.com', LinkText: 'External' }, | ||
}); | ||
fixture.detectChanges(); | ||
expect(element).toMatchInlineSnapshot( | ||
`<li class="dropdown nav-link"><a href="https://test.com" style="width: 100%"> External </a></li>` | ||
); | ||
}); | ||
|
||
it('should render Sub Navigation HTML if set', () => { | ||
component.pagelet = createContentPageletView({ | ||
...pagelet, | ||
configurationParameters: { ...pagelet.configurationParameters, SubNavigationHTML: '<span>Hello World</span>' }, | ||
}); | ||
fixture.detectChanges(); | ||
expect(element).toMatchInlineSnapshot(` | ||
<li class="dropdown nav-link"> | ||
<a ng-reflect-router-link="/home" href="/home"> Home </a | ||
><a class="dropdown-toggle"><fa-icon ng-reflect-icon="fas,plus"></fa-icon></a> | ||
<ul class="category-level1 dropdown-menu"> | ||
<li class="sub-navigation-content"> | ||
<div ng-reflect-ish-server-html="<span>Hello World</span>"></div> | ||
</li> | ||
</ul> | ||
</li> | ||
`); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
src/app/shared/cms/components/cms-navigation-link/cms-navigation-link.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; | ||
|
||
import { ContentViewHelper } from 'ish-core/models/content-view/content-view.helper'; | ||
import { ContentPageletView } from 'ish-core/models/content-view/content-view.model'; | ||
import { CMSComponent } from 'ish-shared/cms/models/cms-component/cms-component.model'; | ||
|
||
@Component({ | ||
selector: 'ish-cms-navigation-link', | ||
templateUrl: './cms-navigation-link.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class CMSNavigationLinkComponent implements CMSComponent { | ||
@Input({ required: true }) pagelet: ContentPageletView; | ||
|
||
opened = false; | ||
|
||
isRouterLink = ContentViewHelper.isRouterLink; | ||
routerLink = ContentViewHelper.getRouterLink; | ||
|
||
subMenuShow(subMenu: HTMLElement) { | ||
subMenu.classList.add('hover'); | ||
} | ||
|
||
subMenuHide(subMenu: HTMLElement) { | ||
subMenu.classList.remove('hover'); | ||
} | ||
|
||
toggleOpen() { | ||
this.opened = !this.opened; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters