-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #588 from mobi/feature_ability_to_copy_doc_permalinks
Add directive for use in adding ability to copy permalinks to doc examples
- Loading branch information
Showing
5 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
projects/go-lib/src/lib/components/go-copy/go-copy-doc-link.directive.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,54 @@ | ||
import { Component, ElementRef } from '@angular/core'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { GoCopyDocLinkDirective } from './go-copy-doc-link.directive'; | ||
import { GoCopyComponent } from './go-copy.component'; | ||
import { GoCopyModule } from './go-copy.module'; | ||
import { GoIconModule } from '../go-icon/go-icon.module'; | ||
|
||
@Component({ | ||
template: `<go-copy cardId="testId" goCopyDocLink></go-copy>` | ||
}) | ||
class TestParentComponent {} | ||
|
||
describe('GoCopyDocLinkDirective', () => { | ||
let fixture: ComponentFixture<TestParentComponent>; | ||
let elementRef: ElementRef; | ||
let goCopyComponent: GoCopyComponent; | ||
let directive: GoCopyDocLinkDirective; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ | ||
TestParentComponent | ||
], | ||
imports: [ | ||
GoCopyModule, | ||
GoIconModule | ||
] | ||
}); | ||
|
||
fixture = TestBed.createComponent(TestParentComponent); | ||
elementRef = fixture.elementRef; | ||
goCopyComponent = TestBed.createComponent(GoCopyComponent).componentInstance; | ||
directive = new GoCopyDocLinkDirective(elementRef, goCopyComponent); | ||
}); | ||
|
||
it('creates an instance', () => { | ||
expect(directive).toBeTruthy(); | ||
}); | ||
|
||
describe('ngOnInit', () => { | ||
it('adds a class of go-copy--card-header and sets the title of the element', () => { | ||
directive.ngOnInit(); | ||
expect(elementRef.nativeElement.classList).toContain('go-copy--card-header'); | ||
expect(elementRef.nativeElement.title).toBe('Copy the URL to this card'); | ||
}); | ||
|
||
|
||
it('sets the text of the element with the current url and an id selector', () => { | ||
directive.cardId = 'testId'; | ||
directive.ngOnInit(); | ||
expect(goCopyComponent.text).toBe('http://localhost:9876/context.html/#testId'); | ||
}); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
projects/go-lib/src/lib/components/go-copy/go-copy-doc-link.directive.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,22 @@ | ||
import { Directive, ElementRef, Host, Input, OnInit } from '@angular/core'; | ||
import { GoCopyComponent } from './go-copy.component'; | ||
|
||
@Directive({ | ||
selector: '[goCopyDocLink]' | ||
}) | ||
export class GoCopyDocLinkDirective implements OnInit { | ||
|
||
@Input() cardId: string; | ||
|
||
constructor( | ||
private elementRef: ElementRef, | ||
@Host() private baseComponent: GoCopyComponent | ||
) { } | ||
|
||
ngOnInit(): void { | ||
this.elementRef.nativeElement.classList.add('go-copy--card-header'); | ||
this.elementRef.nativeElement.title = 'Copy the URL to this card'; | ||
this.baseComponent.text = `${window.location.href}/#${this.cardId}`; | ||
} | ||
|
||
} |
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
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