-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch component-tests of https://github.com/cassus/playwright-bdd
- Loading branch information
Showing
15 changed files
with
2,353 additions
and
134 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { defineBddConfig, BDDInputConfig } from './config'; | ||
export { createBdd } from './stepDefinitions/createBdd'; | ||
export { test } from './run/bddFixtures'; | ||
export { test, BddFixtures, bddFixtures } from './run/bddFixtures'; | ||
export { BddWorld, BddWorldOptions } from './run/bddWorld'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Feature: component-tests | ||
|
||
Scenario: Mount component and interact with it | ||
Given Mounted input component | ||
When I type "ABC" | ||
Then input field has "ABC" | ||
|
||
Scenario: Using event handler in a component | ||
Given Mounted button with an event handler that record how many times it was pressed | ||
When I press the button | ||
Then the recorded number of times the button was pressed is 1 | ||
When I press the button | ||
Then the recorded number of times the button was pressed is 2 |
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,13 @@ | ||
import { defineConfig } from '@playwright/experimental-ct-react'; | ||
import { defineBddConfig } from '../../dist'; | ||
|
||
const testDir = defineBddConfig({ | ||
importTestFrom: 'steps/fixtures.ts', | ||
paths: ['features'], | ||
require: ['steps/steps.tsx'], | ||
}); | ||
|
||
export default defineConfig({ | ||
testDir, | ||
forbidOnly: Boolean(process.env.FORBID_ONLY), | ||
}); |
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,6 @@ | ||
<html lang="en"> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="./index.ts"></script> | ||
</body> | ||
</html> |
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 @@ | ||
// Apply theme here, add anything your component needs at runtime here. |
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,13 @@ | ||
import { test as ctBase } from '@playwright/experimental-ct-react'; | ||
import { BddFixtures, bddFixtures } from '../../../dist'; | ||
|
||
type Fixtures = { | ||
world: { | ||
clickedTimes: number; | ||
}; | ||
}; | ||
|
||
const bddCtBase = ctBase.extend<BddFixtures>(bddFixtures); | ||
export const test = bddCtBase.extend<Fixtures>({ | ||
world: ({}, use) => use({ clickedTimes: 0 }), | ||
}); |
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,35 @@ | ||
import React from 'react-dom'; | ||
import { expect } from '@playwright/test'; | ||
import { createBdd } from '../../../dist'; | ||
import { test } from './fixtures'; | ||
|
||
const { Given, When, Then } = createBdd(test); | ||
|
||
Given('Mounted input component', async ({ mount }) => { | ||
await mount(<input type="text" data-testid="textField" />); | ||
}); | ||
|
||
When('I type {string}', async ({ page }, arg: string) => { | ||
await page.getByTestId('textField').fill(arg); | ||
}); | ||
|
||
Then('input field has {string}', async ({ page }, arg: string) => { | ||
await expect(page.getByTestId('textField')).toHaveValue(arg); | ||
}); | ||
|
||
Given( | ||
'Mounted button with an event handler that record how many times it was pressed', | ||
async ({ mount, world }) => { | ||
await mount( | ||
<button type="button" data-testid="button" onClick={() => (world.clickedTimes += 1)} />, | ||
); | ||
}, | ||
); | ||
|
||
When('I press the button', async ({ page }) => { | ||
await page.getByTestId('button').click(); | ||
}); | ||
|
||
Then('the recorded number of times the button was pressed is {int}', async ({ world }, arg) => { | ||
expect(world.clickedTimes).toBe(arg); | ||
}); |
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,3 @@ | ||
import { test, getTestName, execPlaywrightTest } from '../helpers.mjs'; | ||
|
||
test(getTestName(import.meta), (t) => execPlaywrightTest(t.name)); |
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