Skip to content

Commit

Permalink
✅ Complete writing test
Browse files Browse the repository at this point in the history
  • Loading branch information
dohyun-ko committed Jan 10, 2025
1 parent 9da80f7 commit af19437
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 28 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
Expand All @@ -13,10 +11,18 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: setup environment
run: |
echo "${{ secrets.TEST_IDP_EMAIL }}" >> .env
echo "${{ 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
- name: Run Playwright tests
run: yarn playwright test
- uses: actions/upload-artifact@v4
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
42 changes: 19 additions & 23 deletions tests/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,50 @@ test.use({
});

test.describe('User-only actions', () => {
test('write a notice', async ({ page }) => {
// await login(page);

test('write a notice', async ({ page }, testInfo) => {
await page.goto('localhost:3000/en');

await page.getByText('Write Notice').click();

await expect(page).toHaveURL(/localhost:3000\/en\/write/);

await page.getByTestId('Write English Notice too').check();
await page.getByTestId('write-has-english-version-toggle').check();

await page.getByText('General').click();
await page.getByTestId('write-type-general').click();

await page
.getByPlaceholder('Enter a title here')
.fill('Test Notice Korean Title');
.getByTestId('write-title-input')
.fill('Test Notice Korean Title: ' + testInfo.project.name);

await page.getByTitle('Rich Text Area').click();

await page.locator('#tinymce').fill('Test Notice Korean Content');
await page.keyboard.type('Test Notice Korean Content');

await page.getByText('English').click();
await page.getByTestId('write-english-version-toggle').click();

await page
.getByPlaceholder('Enter a title here')
.getByTestId('write-title-input')
.fill('Test Notice English Title');

await page.locator('#tinymce').fill('Test Notice English Content');
await page.getByPlaceholder('Enter tags').click();
await page.getByTitle('Rich Text Area').click();

await page.keyboard.type('Test Notice English Content');

await page.getByTestId('write-tag-input').click();

await page.keyboard.type('test_tag_1');
await page.keyboard.press('Space');

await page.keyboard.type('test_tag_2');
await page.keyboard.press('Enter');

await page.getByText('Submit Notice').click();
await page.getByTestId('write-submit-button').click();

await page.getByText('Confirm').click();
});

test('view user profile', async ({ page }) => {
// await login(page);

await page.goto('localhost:3000/en');

await page.locator('#my-page').click();

await expect(page).toHaveURL(/localhost:3000\/en\/mypage/);
// await 3 seconds for the notice to be written
await page.waitForTimeout(3000);

await expect(page.locator('text=Profile')).toBeVisible();
await expect(page).toHaveURL(/localhost:3000\/en\/notice/);
});
});

0 comments on commit af19437

Please sign in to comment.