forked from microsoft/playwright
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ct): add mount support for template strings
- Loading branch information
chronospatian
committed
May 15, 2024
1 parent
7f4626a
commit 9eb93a1
Showing
11 changed files
with
215 additions
and
21 deletions.
There are no files selected for viewing
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
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
26 changes: 26 additions & 0 deletions
26
tests/components/ct-angular/src/components/providers.component.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,26 @@ | ||
import { Component, inject, Injectable, NgModule } from '@angular/core'; | ||
|
||
@Injectable() | ||
export class Store { | ||
state = { | ||
text: `Store` | ||
} | ||
} | ||
|
||
@NgModule({ | ||
providers: [Store] | ||
}) | ||
export class StoreModule {} | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'app-imports', | ||
template: ` | ||
{{ provider?.state.text }}: from provider | ||
{{ environmentProvider?.state.text }}: from environmentProvider | ||
` | ||
}) | ||
export class ProvidersComponent { | ||
provider = inject(Store, { self: true, optional: true }) | ||
environmentProvider = inject(Store, { skipSelf: true, optional: true }) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { expect, test } from '@playwright/experimental-ct-angular'; | ||
import type { HooksConfig } from '../playwright'; | ||
import { ProvidersComponent, Store, StoreModule } from '@/components/providers.component'; | ||
|
||
test('should add imports', async ({ mount }) => { | ||
const component = await mount<HooksConfig>(ProvidersComponent, { | ||
imports: [StoreModule], | ||
}); | ||
await expect(component).toContainText('Store: from environmentProvider') | ||
await expect(component).not.toContainText('Store: from provider') | ||
}) | ||
|
||
test('should add environment providers', async ({ mount }) => { | ||
const component = await mount<HooksConfig>(ProvidersComponent, { | ||
environmentProviders: [Store], | ||
}); | ||
|
||
await expect(component).toContainText('Store: from environmentProvider') | ||
await expect(component).not.toContainText('Store: from provider') | ||
}) | ||
|
||
test('should add component providers', async ({ mount }) => { | ||
const component = await mount<HooksConfig>(ProvidersComponent, { | ||
providers: [Store], | ||
}); | ||
|
||
await expect(component).not.toContainText('Store: from environmentProvider') | ||
await expect(component).toContainText('Store: from provider') | ||
}) | ||
|
||
test('should add component view providers', async ({ mount }) => { | ||
const component = await mount<HooksConfig>(ProvidersComponent, { | ||
viewProviders: [Store], | ||
}); | ||
|
||
await expect(component).not.toContainText('Store: from environmentProvider') | ||
await expect(component).toContainText('Store: from provider') | ||
}) |
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,23 @@ | ||
import { expect, test } from '@playwright/experimental-ct-angular'; | ||
import { NamedSlotsComponent } from '@/components/named-slots.component'; | ||
|
||
test('should render a string', async ({ mount }) => { | ||
const component = await mount(` | ||
<app-named-slots> | ||
<div ngProjectAs="[header]">{{header}}</div> | ||
<div ngProjectAs="[main]">{{main}}</div> | ||
<div ngProjectAs="[footer]">{{footer}}</div> | ||
</app-named-slots> | ||
`, { | ||
imports: [NamedSlotsComponent], | ||
props: { | ||
header: "Header", | ||
main: "Main", | ||
footer: "Footer" | ||
} | ||
}); | ||
|
||
await expect(component.getByRole('banner')).toHaveText('Header') | ||
await expect(component.getByRole('main')).toHaveText('Main') | ||
await expect(component.getByRole('contentinfo')).toHaveText('Footer') | ||
}) |
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,30 @@ | ||
import { expect, test } from '@playwright/experimental-ct-angular'; | ||
import type { HooksConfig } from '../playwright'; | ||
import { ButtonComponent } from '@/components/button.component'; | ||
|
||
test('should render a string', async ({ mount }) => { | ||
const messages = [] as any[] | ||
const component = await mount<HooksConfig>(`<app-button data-testid="test" [title]="title" (click)="message.emit('Clicked!')" />`, { | ||
imports: [ButtonComponent], | ||
props: { | ||
title: "Hello!" | ||
}, | ||
on: { | ||
message: (value: any) => messages.push(value) | ||
} | ||
}); | ||
|
||
await expect(component).toHaveText('Hello!') | ||
|
||
await component.update({ | ||
props: { | ||
title: 'Goodbye!' | ||
} | ||
}) | ||
|
||
await expect(component).toHaveText('Goodbye!') | ||
|
||
await component.getByTestId('test').click() | ||
|
||
expect(messages).toEqual(['Clicked!']) | ||
}) |
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