git.psu.edu will be upgraded to critical security release 13.7.4 Monday, 11/18 between 9 and 10pm. Please email support@git.psu.edu if you have trouble with anything Gitlab-related. Please see the git.psu.edu Yammer group for more information.

Commit 4ce1ec06 authored by Ryan Diehl's avatar Ryan Diehl

feat: add external-link directive

parent b2f2ce96
Pipeline #104826 passed with stages
in 5 minutes and 7 seconds
......@@ -30,3 +30,7 @@ let obj = {
```
## yes-no pipe
## external-link directive
Usage `<a utExternalLink href="">`. Will expand to `<a utExternalLink target="_blank" rel="noopener noreferrer" href="">`
......@@ -3,6 +3,8 @@ export * from './lib/before-unload/before-unload.module';
export * from './lib/caps-lock/caps-lock.directive';
export * from './lib/caps-lock/caps-lock.module';
export * from './lib/coalescing-component-factory-resolver/coalescing-component-factory.resolver';
export * from './lib/external-link/external-link.directive';
export * from './lib/external-link/external-link.module';
export * from './lib/ng-let/ng-let.directive';
export * from './lib/ng-let/ng-let.module';
export * from './lib/safe-pipe/safe-pipe.module';
......
import { Component } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ExternalLinkDirective } from './external-link.directive';
@Component({
template: '<a utExternalLink href="https://google.com">Google</a>'
})
class TestComponent {}
describe('ExternalLinkDirective', () => {
describe('driver component', () => {
let fixture: ComponentFixture<TestComponent>;
let component: TestComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [TestComponent, ExternalLinkDirective]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create driver component', () => {
expect(component).toBeDefined();
});
it('should add target and rel attributes', () => {
const el = fixture.debugElement.query(By.directive(ExternalLinkDirective));
expect(el.componentInstance).toBeDefined();
expect(el.attributes['target']).toEqual('_blank');
expect(el.attributes['rel']).toEqual('noopener noreferrer');
});
});
});
import { Directive, ElementRef, OnInit, Renderer2 } from '@angular/core';
@Directive({
selector: '[utExternalLink]'
})
export class ExternalLinkDirective implements OnInit {
constructor(private el: ElementRef, private renderer: Renderer2) {}
public ngOnInit(): void {
this.renderer.setAttribute(this.el.nativeElement, 'target', '_blank');
this.renderer.setAttribute(this.el.nativeElement, 'rel', 'noopener noreferrer');
}
}
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ExternalLinkDirective } from './external-link.directive';
@NgModule({
declarations: [ExternalLinkDirective],
imports: [CommonModule],
exports: [ExternalLinkDirective]
})
export class ExternalLinkModule {}
  • SonarQube analysis indicates that quality gate is failed.

    • Bugs is failed: Actual value 1 > 0
    • high_severity_vulns is passed: Actual value 0
    • medium_severity_vulns is passed: Actual value 0

    SonarQube analysis reported 13 issues

    • 1 major
    • 🔽 7 minor
    • 5 info

    Top 10 extra issues

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. Unexpected empty source 📘
    2. 🔽 Add an "alt" attribute to this image. 📘
    3. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    4. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    5. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    6. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    7. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    8. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    9. Make sure that cookie is written safely here. 📘
    10. Make sure that using a regular expression is safe here. 📘
    • ... 3 more
  • SonarQube analysis indicates that quality gate is failed.

    • Bugs is failed: Actual value 1 > 0
    • high_severity_vulns is passed: Actual value 0
    • medium_severity_vulns is passed: Actual value 0

    SonarQube analysis reported 13 issues

    • 1 major
    • 🔽 7 minor
    • 5 info

    Top 10 extra issues

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. Unexpected empty source 📘
    2. 🔽 Add an "alt" attribute to this image. 📘
    3. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    4. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    5. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    6. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    7. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    8. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    9. Make sure that cookie is written safely here. 📘
    10. Make sure that using a regular expression is safe here. 📘
    • ... 3 more
  • SonarQube analysis indicates that quality gate is failed.

    • Bugs is failed: Actual value 1 > 0
    • high_severity_vulns is passed: Actual value 0
    • medium_severity_vulns is passed: Actual value 0

    SonarQube analysis reported 13 issues

    • 1 major
    • 🔽 7 minor
    • 5 info

    Top 10 extra issues

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. Unexpected empty source 📘
    2. 🔽 Add an "alt" attribute to this image. 📘
    3. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    4. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    5. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    6. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    7. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    8. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    9. Make sure that cookie is written safely here. 📘
    10. Make sure that using a regular expression is safe here. 📘
    • ... 3 more
  • SonarQube analysis indicates that quality gate is failed.

    • Bugs is failed: Actual value 1 > 0
    • high_severity_vulns is passed: Actual value 0
    • medium_severity_vulns is passed: Actual value 0

    SonarQube analysis reported 13 issues

    • 1 major
    • 🔽 7 minor
    • 5 info

    Top 10 extra issues

    Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:

    1. Unexpected empty source 📘
    2. 🔽 Add an "alt" attribute to this image. 📘
    3. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    4. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    5. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    6. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    7. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    8. 🔽 This assertion is unnecessary since it does not change the type of the expression. 📘
    9. Make sure that cookie is written safely here. 📘
    10. Make sure that using a regular expression is safe here. 📘
    • ... 3 more
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment