Skip to content

Commit

Permalink
refactor(playwright): �category - 테스트 중 에러 발생 시, 생성한 템플릿 제거를 finally로 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaymyong66 committed Sep 20, 2024
1 parent a14702f commit d968b6e
Showing 1 changed file with 59 additions and 43 deletions.
102 changes: 59 additions & 43 deletions frontend/playwright/tests/category.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ test('카테고리 편집 모달에서 새 카테고리를 추가 및 삭제할

const newCategoryName = `생성테스트-${browserName}`;

await createCategory({ page, categoryName: newCategoryName });
try {
await createCategory({ page, categoryName: newCategoryName });

await waitForSuccess({ page, apiUrl: '/categories' });
await waitForSuccess({ page, apiUrl: '/categories' });

const newCategoryButton = getCategoryButton({ page, categoryName: newCategoryName });
const newCategoryButton = getCategoryButton({ page, categoryName: newCategoryName });

await expect(newCategoryButton).toBeVisible();
await expect(newCategoryButton).toBeVisible();
} catch (error) {
throw Error(error);
} finally {
await deleteCategory({ page, categoryName: newCategoryName });

// 다음 테스트를 위해 테스트용 카테고리 삭제
await deleteCategory({ page, categoryName: newCategoryName });
await waitForSuccess({ page, apiUrl: '/categories' });

await waitForSuccess({ page, apiUrl: '/categories' });
const newCategoryButton = getCategoryButton({ page, categoryName: newCategoryName });

await expect(newCategoryButton).not.toBeVisible();
await expect(newCategoryButton).not.toBeVisible();
}
});

test('카테고리 편집 모달에서 카테고리명을 수정 및 삭제할 수 있다.', async ({ page, browserName }) => {
Expand All @@ -30,64 +35,75 @@ test('카테고리 편집 모달에서 카테고리명을 수정 및 삭제할
const newCategoryName = `수정테스트-${browserName}`;
const editedCategoryName = `수정완료-${browserName}`;

// 수정할 카테고리 생성
await createCategory({ page, categoryName: newCategoryName });
try {
// 수정할 카테고리 생성
await createCategory({ page, categoryName: newCategoryName });

await waitForSuccess({ page, apiUrl: '/categories' });
await waitForSuccess({ page, apiUrl: '/categories' });

const newCategoryButton = getCategoryButton({ page, categoryName: newCategoryName });
const newCategoryButton = getCategoryButton({ page, categoryName: newCategoryName });

await expect(newCategoryButton).toBeVisible();
await expect(newCategoryButton).toBeVisible();

// 카테고리 수정
await page.getByRole('button', { name: '카테고리 편집' }).click();
// 카테고리 수정
await page.getByRole('button', { name: '카테고리 편집' }).click();

const newCategoryInEditModal = page.getByText(newCategoryName).nth(1);
const newCategoryInEditModal = page.getByText(newCategoryName).nth(1);

await newCategoryInEditModal.hover();
await page.getByRole('button', { name: '카테고리 이름 변경' }).click();
await page.getByPlaceholder('카테고리 입력').click();
await page.getByPlaceholder('카테고리 입력').fill(editedCategoryName);
await page.getByRole('button', { name: '저장' }).click();
await newCategoryInEditModal.hover();
await page.getByRole('button', { name: '카테고리 이름 변경' }).click();
await page.getByPlaceholder('카테고리 입력').click();
await page.getByPlaceholder('카테고리 입력').fill(editedCategoryName);
await page.getByRole('button', { name: '저장' }).click();

const editedCategoryButton = getCategoryButton({ page, categoryName: editedCategoryName });
const editedCategoryButton = getCategoryButton({ page, categoryName: editedCategoryName });

await expect(editedCategoryButton).toBeVisible();
await expect(editedCategoryButton).toBeVisible();
} catch (error) {
throw Error(error);
} finally {
// 다음 테스트를 위해 테스트용 카테고리 삭제
await deleteCategory({ page, categoryName: editedCategoryName });

// 다음 테스트를 위해 테스트용 카테고리 삭제
await deleteCategory({ page, categoryName: editedCategoryName });
const editedCategoryButton = getCategoryButton({ page, categoryName: editedCategoryName });

await waitForSuccess({ page, apiUrl: '/categories' });
await expect(editedCategoryButton).not.toBeVisible();
await waitForSuccess({ page, apiUrl: '/categories' });
await expect(editedCategoryButton).not.toBeVisible();
}
});

test('카테고리는 최대 15글자까지만 입력할 수 있다.', async ({ page, browserName }) => {
await page.goto('/my-templates');

const rawCategoryName = `최대글자수테스트-${browserName}`;
const expectedCategoryName = rawCategoryName.slice(0, 15);

await page.getByRole('button', { name: '카테고리 편집' }).click();
await page.getByRole('button', { name: '+ 카테고리 추가' }).click();
const categoryInput = page.getByPlaceholder('카테고리 입력');
try {
await page.getByRole('button', { name: '카테고리 편집' }).click();
await page.getByRole('button', { name: '+ 카테고리 추가' }).click();
const categoryInput = page.getByPlaceholder('카테고리 입력');

await categoryInput.click();
await categoryInput.click();

for (const char of rawCategoryName) {
await page.keyboard.type(char);
}
for (const char of rawCategoryName) {
await page.keyboard.type(char);
}

await page.getByRole('button', { name: '저장' }).click();
await page.getByRole('button', { name: '저장' }).click();

await waitForSuccess({ page, apiUrl: '/categories' });
await waitForSuccess({ page, apiUrl: '/categories' });

const newCategoryButton = getCategoryButton({ page, categoryName: expectedCategoryName });
const newCategoryButton = getCategoryButton({ page, categoryName: expectedCategoryName });

await expect(newCategoryButton).toBeVisible();
await expect(newCategoryButton).toBeVisible();
} catch (error) {
throw Error(error);
} finally {
// 다음 테스트를 위해 테스트용 카테고리 삭제
await deleteCategory({ page, categoryName: expectedCategoryName });

// 다음 테스트를 위해 테스트용 카테고리 삭제
await deleteCategory({ page, categoryName: expectedCategoryName });
const newCategoryButton = getCategoryButton({ page, categoryName: expectedCategoryName });

await waitForSuccess({ page, apiUrl: '/categories' });
await expect(newCategoryButton).not.toBeVisible();
await waitForSuccess({ page, apiUrl: '/categories' });
await expect(newCategoryButton).not.toBeVisible();
}
});

0 comments on commit d968b6e

Please sign in to comment.