From 2d4d9d80bd933b264544d930ce28b772a368532f Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn <100320+knorrium@users.noreply.github.com> Date: Sat, 19 Mar 2022 22:14:37 -0700 Subject: [PATCH] Add new directive for UI tests --- frontend/src/app/app.module.ts | 2 ++ frontend/src/app/data-cy.directive.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 frontend/src/app/data-cy.directive.ts diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 99917815c..cb59c19dc 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -78,6 +78,7 @@ import { ShortenStringPipe } from './shared/pipes/shorten-string-pipe/shorten-st import { GraphsComponent } from './components/graphs/graphs.component'; import { DifficultyAdjustmentsTable } from './components/difficulty-adjustments-table/difficulty-adjustments-table.components'; import { BlocksList } from './components/blocks-list/blocks-list.component'; +import { DataCyDirective } from './data-cy.directive'; @NgModule({ declarations: [ @@ -137,6 +138,7 @@ import { BlocksList } from './components/blocks-list/blocks-list.component'; GraphsComponent, DifficultyAdjustmentsTable, BlocksList, + DataCyDirective, ], imports: [ BrowserModule.withServerTransition({ appId: 'serverApp' }), diff --git a/frontend/src/app/data-cy.directive.ts b/frontend/src/app/data-cy.directive.ts new file mode 100644 index 000000000..1e8e9aec7 --- /dev/null +++ b/frontend/src/app/data-cy.directive.ts @@ -0,0 +1,13 @@ +import { Directive, ElementRef, Renderer2 } from '@angular/core'; +import { environment } from '../environments/environment'; + +@Directive({ + selector: '[data-cy]' +}) +export class DataCyDirective { + constructor(private el: ElementRef, private renderer: Renderer2) { + if (environment.production) { + renderer.removeAttribute(el.nativeElement, 'data-cy'); + } + } +}