Skip to content

Commit

Permalink
add built-in control flow tests with signals
Browse files Browse the repository at this point in the history
  • Loading branch information
AtofStryker committed Jun 20, 2024
1 parent b6d6f7e commit 3f93d59
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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')
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

<div>
<div data-cy="control-flow-superheroes-display">
<h1> SuperHeroes</h1>
<ul data-cy="control-flow-superheroes-list" >
@for (superHero of superHeroes(); track superHero.name; let idx = $index) {
<li [attr.data-index]="idx">
<p data-cy="name"> Name: {{ superHero.name }} </p>
<p data-cy="nickname">Nickname: {{ superHero.nickname }} </p>
<p data-cy="age">
@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
}
</p>
<p data-cy="mortality">
@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
}
}
</p>
</li>
}
</ul>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:host {
height: 100%;
display: block;
}
Original file line number Diff line number Diff line change
@@ -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<SuperHero[]>()
}

3 comments on commit 3f93d59

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3f93d59 Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.13.0/linux-x64/angular-signals-ct-harness-3f93d5918df1ad117dde1e535ce743d6b10d6d77/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3f93d59 Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.13.0/linux-arm64/angular-signals-ct-harness-3f93d5918df1ad117dde1e535ce743d6b10d6d77/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3f93d59 Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.13.0/darwin-arm64/angular-signals-ct-harness-3f93d5918df1ad117dde1e535ce743d6b10d6d77/cypress.tgz

Please sign in to comment.