From 3f93d5918df1ad117dde1e535ce743d6b10d6d77 Mon Sep 17 00:00:00 2001 From: AtofStryker Date: Thu, 20 Jun 2024 09:28:40 -0400 Subject: [PATCH] add built-in control flow tests with signals --- .../control-flow/control-flow.component.cy.ts | 38 +++++++++++++++++++ .../control-flow/control-flow.component.html | 36 ++++++++++++++++++ .../control-flow/control-flow.component.scss | 4 ++ .../control-flow/control-flow.component.ts | 23 +++++++++++ 4 files changed, 101 insertions(+) create mode 100644 system-tests/projects/angular-signals/src/control-flow/control-flow.component.cy.ts create mode 100644 system-tests/projects/angular-signals/src/control-flow/control-flow.component.html create mode 100644 system-tests/projects/angular-signals/src/control-flow/control-flow.component.scss create mode 100644 system-tests/projects/angular-signals/src/control-flow/control-flow.component.ts diff --git a/system-tests/projects/angular-signals/src/control-flow/control-flow.component.cy.ts b/system-tests/projects/angular-signals/src/control-flow/control-flow.component.cy.ts new file mode 100644 index 000000000000..f8a663cda8f7 --- /dev/null +++ b/system-tests/projects/angular-signals/src/control-flow/control-flow.component.cy.ts @@ -0,0 +1,38 @@ +import { ControlFlowComponent, SuperHero } from './control-flow.component' + +// @see https://angular.dev/guide/templates/control-flow +it('works with basic control flow', () => { + const superHeroes: SuperHero[] = [ + { + name: 'Clark Kent', + nickname: 'Man of Steel', + age: 28, + isMortal: true, + }, + { + name: 'Wade T. Wilson', + nickname: 'Deadpool', + age: 43, + isMortal: false, + }, + ] + + cy.mount(ControlFlowComponent, { + componentProperties: { + superHeroes, + }, + }) + + cy.get('[data-index="0"]').as('superman') + cy.get('[data-index="1"]').as('deadpool') + + cy.get('@superman').find('[data-cy="name"]').should('contain.text', 'Clark Kent') + cy.get('@superman').find('[data-cy="nickname"]').should('contain.text', 'Man of Steel') + cy.get('@superman').find('[data-cy="age"]').should('contain.text', '28 is younger than 30') + cy.get('@superman').find('[data-cy="mortality"]').should('contain.text', 'I am mortal. I will eventually die') + + cy.get('@deadpool').find('[data-cy="name"]').should('contain.text', 'Wade T. Wilson') + cy.get('@deadpool').find('[data-cy="nickname"]').should('contain.text', 'Deadpool') + cy.get('@deadpool').find('[data-cy="age"]').should('contain.text', '43 is older than 30') + cy.get('@deadpool').find('[data-cy="mortality"]').should('contain.text', 'I am immortal and will live forever') +}) diff --git a/system-tests/projects/angular-signals/src/control-flow/control-flow.component.html b/system-tests/projects/angular-signals/src/control-flow/control-flow.component.html new file mode 100644 index 000000000000..628c7dd6099e --- /dev/null +++ b/system-tests/projects/angular-signals/src/control-flow/control-flow.component.html @@ -0,0 +1,36 @@ + +
+
+

SuperHeroes

+
    + @for (superHero of superHeroes(); track superHero.name; let idx = $index) { +
  • +

    Name: {{ superHero.name }}

    +

    Nickname: {{ superHero.nickname }}

    +

    + @if (superHero.age > 30) { + {{ superHero.age }} is older than 30 + } @else if (30 > superHero.age) { + {{ superHero.age }} is younger than 30 + } @else { + Age is unknown + } +

    +

    + @switch (superHero.isMortal) { + @case (true) { + I am mortal. I will eventually die + } + @case (false) { + I am immortal and will live forever + } + @default { + Mortality status unknown + } + } +

    +
  • + } +
+
+
diff --git a/system-tests/projects/angular-signals/src/control-flow/control-flow.component.scss b/system-tests/projects/angular-signals/src/control-flow/control-flow.component.scss new file mode 100644 index 000000000000..dd8f716300ba --- /dev/null +++ b/system-tests/projects/angular-signals/src/control-flow/control-flow.component.scss @@ -0,0 +1,4 @@ +:host { + height: 100%; + display: block; +} diff --git a/system-tests/projects/angular-signals/src/control-flow/control-flow.component.ts b/system-tests/projects/angular-signals/src/control-flow/control-flow.component.ts new file mode 100644 index 000000000000..fb85abc0690d --- /dev/null +++ b/system-tests/projects/angular-signals/src/control-flow/control-flow.component.ts @@ -0,0 +1,23 @@ +import { + ChangeDetectionStrategy, + Component, + model, +} from '@angular/core' + +export type SuperHero = { + name: string + nickname: string + age: number + isMortal: boolean +} + +@Component({ + selector: 'control-flow-component', + templateUrl: './control-flow.component.html', + styleUrls: ['./control-flow.component.scss'], + standalone: true, + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class ControlFlowComponent { + superHeroes = model.required() +}