Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ Test setup & legacy migration #408

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Playwright Tests
on:
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: setup environment
run: |
echo "TEST_IDP_EMAIL=${{ secrets.TEST_IDP_EMAIL }}" >> .env
echo "TEST_IDP_PASSWORD=${{ secrets.TEST_IDP_PASSWORD }}" >> .env
echo "NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }}" >> .env.production
echo "IDP_CLIENT_SECRET=${{ secrets.IDP_CLIENT_SECRET }}" >> .env.production
- name: Install dependencies
run: npm install -g yarn && yarn
- name: Install Playwright Browsers
run: yarn playwright install --with-deps
- name: Run Dev Server
run: |
yarn dev &
echo "Waiting for server to start..."
until curl -s http://localhost:3000 > /dev/null; do
echo "Server is not ready yet. Retrying in 2 seconds..."
sleep 2
done
- name: Run Playwright tests
run: yarn playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ yarn-error.log*
next-env.d.ts
playwright
test-results
playwright-report
playwright-report
node_modules/
/playwright-report/
/blob-report/
/playwright/.cache/
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ yarn install
yarn dev
```

## Test

Playwright를 이용하여 E2E 테스트를 진행하고 있습니다.

```bash
yarn playwright test // 모든 테스트 실행
yarn playwright test --ui // 테스트 콘솔 UI 실행
```

## Misc

해당 프로젝트는 `.gitattributes` 파일에서 eol 설정을 `lf`로 하고 있습니다.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"tinymce": "^6.8.3"
},
"devDependencies": {
"@playwright/test": "^1.49.1",
"@storybook/addon-essentials": "^8.1.2",
"@storybook/addon-interactions": "^8.1.2",
"@storybook/addon-links": "^8.1.2",
Expand Down
83 changes: 83 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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: 'setups',
testMatch: /.*\.setup\.ts$/,
},
{
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,
// },
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface ContentProps {
const Content = ({ content }: ContentProps) => {
return (
<div
data-testid={'notice-content'}
className={[
'font-normal leading-[1.4]',
'[&_p]:my-4 [&_p]:text-lg',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const NoticeInfo = async ({
const session = await auth();

return (
<div className="flex flex-col gap-[18px]">
<div className="flex flex-col gap-[18px]" data-testid={'notice-info'}>
{deadline && <Deadline deadline={dayjs(deadline).tz()} t={t} />}

<Metadata
Expand Down Expand Up @@ -59,7 +59,10 @@ const Deadline = ({ deadline, t }: PropsWithT<{ deadline: dayjs.Dayjs }>) => {
};

const Title = ({ title }: { title: string }) => (
<div className="line-clamp-3 text-[25px] font-semibold leading-[30px]">
<div
className="line-clamp-3 text-[25px] font-semibold leading-[30px]"
data-testid={'notice-title'}
>
{title}
</div>
);
Expand Down
2 changes: 2 additions & 0 deletions src/app/[lng]/write/LanguageTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const LanguageTab = ({
return (
<div className={'grid grid-cols-[90px_90px_1fr] justify-items-stretch'}>
<button
data-testid="write-korean-version-toggle"
onClick={() => setWritingTab('korean')}
className={
'border-b-[3px] p-[15px] pb-3 ' +
Expand All @@ -29,6 +30,7 @@ const LanguageTab = ({
</p>
</button>
<button
data-testid="write-english-version-toggle"
onClick={() => setWritingTab('english')}
className={
'border-b-[3px] p-[15px] pb-3 ' +
Expand Down
4 changes: 3 additions & 1 deletion src/app/[lng]/write/NoticeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ const NoticeEditor = ({
const noticeToSubmit: NoticeSubmitForm & { t: T } = {
title: state.korean.title,
deadline: state.deadline
? state.deadline.toDate() ?? undefined
? (state.deadline.toDate() ?? undefined)
: undefined,
noticeLanguage: state.english ? 'both' : 'ko',
koreanBody: state.korean.content,
Expand Down Expand Up @@ -445,6 +445,7 @@ const NoticeEditor = ({
{t('write.writeEnglishNotice')}
</p>
<Toggle
data-testid="write-has-english-version-toggle"
isSwitched={!!state.english}
onSwitch={() => {
dispatch({ type: 'TOGGLE_ENGLISH_VERSION' });
Expand Down Expand Up @@ -665,6 +666,7 @@ const NoticeEditor = ({

<div className={'mt-[10rem] flex flex-col items-center'}>
<Button
data-testid="write-submit-button"
variant="contained"
className="mb-4 w-60 rounded-[10px] py-2"
onClick={isEditMode ? handleModify : handleSubmit}
Expand Down
1 change: 1 addition & 0 deletions src/app/[lng]/write/NoticeTypeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const NoticeTypeSelector = ({
<div className="mb-5 flex gap-[10px]">
{noticeTypes.map((noticeType) => (
<div
data-testid={`write-type-${noticeType}`}
className="cursor-pointer"
key={noticeType}
onClick={() => {
Expand Down
1 change: 1 addition & 0 deletions src/app/[lng]/write/TagInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const TagInput = ({ tags, setTags, t }: PropsWithT<TagInputProps>) => {
</TagChip>
))}
<input
data-testid="write-tag-input"
value={keyword}
onChange={handleKeywordChange}
placeholder={tags.length === 0 ? t('write.writeTags') : ''}
Expand Down
1 change: 1 addition & 0 deletions src/app/[lng]/write/TitleAndContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const TitleAndContent = ({
</div>

<input
data-testid="write-title-input"
disabled={disabled}
value={title}
onChange={(e) => {
Expand Down
10 changes: 8 additions & 2 deletions src/app/components/shared/Toggle/Toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ interface ToggleProps {
onSwitch: (e: ChangeEvent<HTMLInputElement>) => void;
}

const Toggle = ({ isSwitched, onSwitch }: ToggleProps) => {
const Toggle = ({
isSwitched,
onSwitch,
...props
}: React.PropsWithChildren<
React.LabelHTMLAttributes<HTMLLabelElement> & ToggleProps
>) => {
return (
<label className={styles.wrapper}>
<label className={styles.wrapper} {...props}>
<input
role="switch"
type="checkbox"
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/shared/Zabo/Zabo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Zabo = async (props: ZaboProps & PropsWithLng) => {
const hasImage = imageUrls.length > 0;

return (
<Link href={`/${lng}/notice/${id}`}>
<Link href={`/${lng}/notice/${id}`} data-testid={'zabo'}>
<div
className={
'flex flex-col rounded-[10px] py-[10px] text-text transition hover:bg-greyLight dark:hover:bg-dark_greyDark'
Expand Down
Loading
Loading