-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
3,829 additions
and
236 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,21 @@ | ||
{ | ||
"env": { | ||
"jest/globals": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2020, | ||
"sourceType": "module", | ||
"ecmaFeatures": { | ||
"jsx": true | ||
} | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:react/recommended", | ||
"prettier" | ||
], | ||
"plugins": [ | ||
"prettier", | ||
"jest" | ||
] | ||
} |
27 changes: 27 additions & 0 deletions
27
pokedex-app/astro-pokedex/.github/workflows/playwright.yml
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,27 @@ | ||
name: Playwright Tests | ||
on: | ||
push: | ||
branches: [ main, master ] | ||
pull_request: | ||
branches: [ main, master ] | ||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
- name: Install dependencies | ||
run: yarn | ||
- name: Install Playwright Browsers | ||
run: yarn playwright install --with-deps | ||
- name: Run Playwright tests | ||
run: yarn playwright test | ||
- uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
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 |
---|---|---|
|
@@ -19,3 +19,6 @@ pnpm-debug.log* | |
|
||
# macOS-specific files | ||
.DS_Store | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ |
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,4 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
moduleNameMapper: { | ||
'^@/components/(.*)$': '<rootDir>/src/components/$1', | ||
'^@/pages/(.*)$': '<rootDir>/src/pages/$1', | ||
}, | ||
testEnvironment: 'jest-environment-jsdom', | ||
testPathIgnorePatterns: ['<rootDir>/src/tests/e2e/', '<rootDir>/node_modules/'], | ||
} |
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,77 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: './src/tests', | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: 'html', | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
// baseURL: 'http://127.0.0.1:3000', | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
|
||
{ | ||
name: 'firefox', | ||
use: { ...devices['Desktop Firefox'] }, | ||
}, | ||
|
||
{ | ||
name: 'webkit', | ||
use: { ...devices['Desktop Safari'] }, | ||
}, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
command: 'npm run start', | ||
url: 'http://127.0.0.1:4321', | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}); |
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, expect } from '@playwright/test' | ||
|
||
test('should navigate to the about page', async ({ page }) => { | ||
// Start from the index page (the baseURL is set via the webServer in the playwright.config.ts) | ||
await page.goto('/') | ||
// Find an element with the text 'About' and click on it | ||
await page.click('text=About') | ||
// The new url should be "/about" (baseURL is used there) | ||
await expect(page).toHaveURL('/about') | ||
// The new page should contain an h1 with "About" | ||
await expect(page.locator('h1')).toContainText('About') | ||
}) | ||
|
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,14 @@ | ||
import { test, expect } from '@playwright/test' | ||
|
||
test('should navigate to the detail page', async ({ page }) => { | ||
// Start from the index page (the baseURL is set via the webServer in the playwright.config.ts) | ||
await page.goto('/') | ||
// Find the first tile element on the page and click it | ||
await page.locator('div.tile').first().click(); | ||
// The new url should be "/detail" (baseURL is used there) | ||
await expect(page).toHaveURL(/.*\/detail/); | ||
// The new page should contain an image and a table | ||
await expect(page.locator('.image img')).toBeVisible(); | ||
await expect(page.locator('.content table')).toBeVisible(); | ||
}) | ||
|
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,17 @@ | ||
import { test, expect } from '@playwright/test' | ||
|
||
const SEARCH_VALUE = 'pikachu'; | ||
|
||
test('should be able to search/filter', async ({ page }) => { | ||
// Start from the index page (the baseURL is set via the webServer in the playwright.config.ts) | ||
await page.goto('/') | ||
// Put search value into input | ||
await page.locator('#search-input').fill(SEARCH_VALUE); | ||
// Find the first tile element on the page and click it | ||
await page.locator('div.tile').first().click(); | ||
// Expect page to be detail page | ||
await expect(page).toHaveURL(/.*\/detail/); | ||
// Expect page headline to contain same search value | ||
await expect(page.locator('h3')).toContainText(SEARCH_VALUE) | ||
}) | ||
|
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,28 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import ItemCard from '@/components/ItemCard' | ||
|
||
const ITEM_DATA = { | ||
postId: 1, | ||
name: 'Bulbasaur', | ||
height: 100, | ||
weight: 100, | ||
types: [{ type: { name: 'grass' } }], | ||
} | ||
|
||
describe('ItemCard', () => { | ||
it('renders a heading', () => { | ||
render(<ItemCard {...ITEM_DATA} />) | ||
|
||
const heading = screen.getByRole('heading', { | ||
name: `#${ITEM_DATA.postId}: ${ITEM_DATA.name}`, | ||
}) | ||
|
||
expect(heading).toBeInTheDocument() | ||
}) | ||
|
||
it('renders correctly', () => { | ||
const { container } = render(<ItemCard {...ITEM_DATA} />) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
}) |
62 changes: 62 additions & 0 deletions
62
pokedex-app/astro-pokedex/src/tests/jest/__snapshots__/ItemCard.test.js.snap
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,62 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ItemCard renders correctly 1`] = ` | ||
<div> | ||
<div | ||
class="tile" | ||
> | ||
<figure | ||
class="image" | ||
> | ||
<img | ||
alt="Bulbasaur" | ||
src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/1.png" | ||
/> | ||
</figure> | ||
<div | ||
class="content" | ||
> | ||
<h3> | ||
<span | ||
class="prefix" | ||
> | ||
# | ||
1 | ||
: | ||
</span> | ||
Bulbasaur | ||
</h3> | ||
<table | ||
class="mb-4 mt-4" | ||
> | ||
<tbody> | ||
<tr> | ||
<th> | ||
Height: | ||
</th> | ||
<td> | ||
100 | ||
</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
Weight: | ||
</th> | ||
<td> | ||
100 | ||
</td> | ||
</tr> | ||
<tr> | ||
<th> | ||
Types: | ||
</th> | ||
<td> | ||
grass | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.