-
Notifications
You must be signed in to change notification settings - Fork 0
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 #24 from FelipeDuarteLuna/19-02-2024 - Directives
Add log Directive
- Loading branch information
Showing
6 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
modules/data-access/auth/src/lib/guards/auth/auth.guard.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
33 changes: 33 additions & 0 deletions
33
modules/feature/home/src/lib/directives/log/log.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,33 @@ | ||
import { Component } from '@angular/core'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { mockProducts } from 'product-data-access'; | ||
import { ProductCardComponent } from 'modules/ui/product/src/components/product-card.component'; | ||
import { LogDirective } from './log.directive'; | ||
|
||
@Component({ | ||
selector: 'lib-host-component', | ||
template: ` | ||
<lib-product-card libLog [product]="product"></lib-product-card> | ||
`, | ||
}) | ||
class HostComponent { | ||
product = mockProducts[0]; | ||
} | ||
|
||
describe('LogDirective', () => { | ||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [HostComponent], | ||
imports: [LogDirective, ProductCardComponent, RouterTestingModule], | ||
}).compileComponents(); | ||
}); | ||
|
||
it('should have cursor pointer', () => { | ||
const fixture = TestBed.createComponent(HostComponent); | ||
fixture.detectChanges(); | ||
const card: HTMLElement = | ||
fixture.nativeElement.querySelector('lib-product-card'); | ||
expect(card.style.cursor).toBe('pointer'); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
modules/feature/home/src/lib/directives/log/log.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,46 @@ | ||
import { | ||
Directive, | ||
ElementRef, | ||
EventEmitter, | ||
HostListener, | ||
Input, | ||
OnInit, | ||
Output, | ||
Renderer2, | ||
inject, | ||
} from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
import { ProductCardComponent } from 'modules/ui/product/src/components/product-card.component'; | ||
|
||
@Directive({ | ||
selector: '[libLog]', | ||
standalone: true, | ||
}) | ||
export class LogDirective implements OnInit { | ||
@Input() id = ''; | ||
@Output() doubleClick = new EventEmitter<void>(); | ||
|
||
router = inject(Router); | ||
productCardComponent = inject(ProductCardComponent); | ||
elementRef = inject(ElementRef); | ||
renderer = inject(Renderer2); | ||
|
||
ngOnInit(): void { | ||
this.renderer.setStyle(this.elementRef.nativeElement, 'cursor', 'pointer'); | ||
} | ||
|
||
@HostListener('click', ['$event']) | ||
onClick(): void { | ||
// eslint-disable-next-line no-console | ||
console.log('Cliclou no CARD: ', this.id); | ||
//this.router.navigate(['product',this.id]); | ||
// eslint-disable-next-line no-console | ||
console.log(this.elementRef.nativeElement); | ||
this.router.navigate(['product', this.productCardComponent.product.id]); | ||
} | ||
|
||
@HostListener('dblclick', ['$event']) | ||
onDoubleClick(): void { | ||
this.doubleClick.emit(); | ||
} | ||
} |
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