Skip to content

Commit

Permalink
test: adds initial tests with playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
zecarrera committed Sep 19, 2024
1 parent abfb40c commit bb5d65c
Show file tree
Hide file tree
Showing 15 changed files with 1,421 additions and 5 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
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@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# misc
.DS_Store
*.pem
*.vscode

# debug
npm-debug.log*
Expand All @@ -37,3 +38,8 @@ next-env.d.ts


*.env
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
779 changes: 779 additions & 0 deletions mockoon/RealWorldApi.json

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@playwright/test": "^1.47.1",
"@types/node": "^20.14.9",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
Expand All @@ -40,4 +41,4 @@
"tailwindcss": "^3.4.4",
"typescript": "^5.5.2"
}
}
}
79 changes: 79 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './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:3000',
// reuseExistingServer: !process.env.CI,
// },
});
2 changes: 1 addition & 1 deletion src/app/article/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const SingleArticle: React.FC<TSingleArticleProps> = async ({ params }) => {
session.username === article.author.username
}
/>
<p className="py-5 px-4 md:px-10 lg:px-14 text-lg text-justify">
<p className="py-5 px-4 md:px-10 lg:px-14 text-lg text-justify" data-testid="article-description-view">
{article.body}
</p>
<TagList
Expand Down
3 changes: 2 additions & 1 deletion src/components/article/Article.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ export const Article: React.FC<TArticleProps> = ({
/>
</div>
<Link href={`/article/${slug}`}>
<h1 className="text-2xl font-bold">{title}</h1>
<h1 className="text-2xl font-bold" data-testid="article-title">{title}</h1>
<h2
className={`text-zinc-400 ${sourceSansProExtraLight} font-extralight`}
data-testid="article-description"
>
{description}
</h2>
Expand Down
1 change: 1 addition & 0 deletions src/components/article/comments/CommentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const CommentForm: React.FC<TCommentProps> = ({
<form
onSubmit={form.handleSubmit(onSubmit)}
className="border rounded-md border-gray-200"
data-testid="comment-form"
>
<FormField
control={form.control}
Expand Down
2 changes: 1 addition & 1 deletion src/components/article/comments/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const Comments: React.FC<TCommentsProps> = async ({ slug, token }) => {
key={comment.id}
className="my-5 mx-2 md:w-3/6 md:mx-auto border rounded-md"
>
<p className="p-5 border-b">{comment.body}</p>
<p className="p-5 border-b" data-testid="comment-body">{comment.body}</p>
<div className="flex justify-between items-center p-3 text-sm bg-gray-100">
<UserAvatar
username={comment.author.username}
Expand Down
1 change: 1 addition & 0 deletions src/components/article/comments/DeleteCommentButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const DeleteCommentButton: React.FC<TDeleteButtonProps> = ({
width={15}
onClick={() => deleteComment(slug, id)}
className="cursor-pointer text-gray-400"
data-testid="delete-comment"
/>
);
};
1 change: 1 addition & 0 deletions src/components/article/singleArticle/EditButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const EditButton: React.FC<{ slug: string; className?: string }> = ({
"border border-red-50 text-red-50 text-xs opacity-80 flex items-center gap-[3px] rounded h-fit p-1 hover:opacity-45",
className
)}
data-testid="edit-article-link"
>
<Pencil width={13} height={13} />
<span>Edit Article</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const SingleArticleHeader: React.FC<TSingleArticleActivity> = async ({
}) => {
return (
<div className="min-w-full py-2 px-4 md:px-10 lg:px-14 flex flex-col gap-5 bg-black-custom shadow-custom text-white">
<h1 className="md:text-5xl mx-auto w-fit h-fit">{slug}</h1>
<h1 className="md:text-5xl mx-auto w-fit h-fit" data-testid="article-view-slug">{slug}</h1>
<SingleArticleActivity
slug={slug}
username={username}
Expand Down
Loading

0 comments on commit bb5d65c

Please sign in to comment.