diff --git a/playwright.config.ts b/playwright.config.ts index 937ffacb..fa8072fb 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -2,8 +2,8 @@ import { defineConfig, devices } from '@playwright/test'; import path from 'path'; require('dotenv').config(); -export const STORAGE_STATE = path.join('/Users/localgaji/Documents/pyc/albbaim', './playwright/.auth/user.json'); - +export const ADMINSTATE = path.join(__dirname, './playwright/.auth/admin.json'); +export const ALBASTATE = path.join(__dirname, './playwright/.auth/alba.json'); /** * See https://playwright.dev/docs/test-configuration. */ @@ -29,33 +29,35 @@ export default defineConfig({ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', }, - + timeout: 10000, /* Configure projects for major browsers */ projects: [ - { - name: 'setup', - testMatch: /globalAdmin.setup\.ts/, - }, - { - name: 'setupAlba', - testMatch: /globalAlba.setup\.ts/, - }, + // { + // name: 'setup', + // testMatch: /globalAdmin.setup\.ts/, + // use: { storageState: ADMINSTATE }, + // }, + // { + // name: 'setupAlba', + // testMatch: /globalAlba.setup\.ts/, + // use: { storageState: ALBASTATE }, + // }, { name: 'admin', - dependencies: ['setup'], + // dependencies: ['setup'], use: { ...devices['Desktop Chrome'], - storageState: STORAGE_STATE, + storageState: ADMINSTATE, }, testMatch: '**/tests/admin/**', testIgnore: '**/tests/alba/**', }, { name: 'alba', - dependencies: ['setupAlba'], + // dependencies: ['setupAlba'], use: { ...devices['Desktop Chrome'], - storageState: STORAGE_STATE, + storageState: ALBASTATE, }, testMatch: '**/tests/alba/**', testIgnore: '**/tests/admin/**', diff --git a/tests/admin/globalAdmin.setup.ts b/tests/admin/globalAdmin.setup.ts deleted file mode 100644 index 0adaced8..00000000 --- a/tests/admin/globalAdmin.setup.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { expect, test as setup } from '@playwright/test'; -import { STORAGE_STATE } from '../../playwright.config'; -import { postLoginNoUser } from '../mock/auth'; -import { mockMapper, mockResponse } from '../mock/mockResponse'; -import { loginTest } from './../logintest'; - -setup('로그인', async ({ page, baseURL }) => { - await page.evaluate((val) => - localStorage.setItem('login', JSON.stringify({ isLogin: true, token: 'Bearer ABC', isAdmin: true })), - ); - - await mockMapper({ page, url: 'auth/login', method: 'POST', response: postLoginNoUser }); - await mockMapper({ page, url: 'auth/join', method: 'POST', response: mockResponse(null) }); - - await loginTest({ page: page, baseURL: baseURL, isAdmin: true }); - expect(page.getByText('내 스케줄')).toBeVisible({ timeout: 10000 }); - - await page.waitForTimeout(3000); - - await page.context().storageState({ path: STORAGE_STATE }); -}); diff --git a/tests/admin/sidebar.spec.ts b/tests/admin/sidebar.spec.ts index 0aa35806..88e60018 100644 --- a/tests/admin/sidebar.spec.ts +++ b/tests/admin/sidebar.spec.ts @@ -1,28 +1,20 @@ import { expect, test } from '@playwright/test'; import { getMyinfo, getMyinfoNoGroup } from '../mock/getMyInfo'; -import { mockResponse } from '../mock/mockResponse'; +import { mockMapper, mockResponse } from '../mock/mockResponse'; test.describe('사이드바', () => { test('사이드바 : 그룹 있음', async ({ page, baseURL }) => { - await page.route('*/**/group', async (route) => { - if (route.request().method() === 'GET') { - await route.fulfill(mockResponse(getMyinfo)); - } - }); + await mockMapper({ page: page, url: 'group', method: 'GET', response: mockResponse(getMyinfo) }); await page.goto(`${baseURL}`); await page.getByLabel('메뉴').click(); await page.getByText('우리 매장 직원 목록').isVisible(); - expect(page.getByText('우리 매장 직원 목록')).toBeVisible({ timeout: 10000 }); + expect(page.getByText('우리 매장 직원 목록')).toBeVisible(); }); test('사이드바 : 그룹 없음', async ({ page, baseURL }) => { - await page.route('*/**/group', async (route) => { - if (route.request().method() === 'GET') { - await route.fulfill(mockResponse(getMyinfoNoGroup)); - } - }); + await mockMapper({ page: page, url: 'group', method: 'GET', response: mockResponse(getMyinfoNoGroup) }); await page.goto(`${baseURL}`); await page.getByLabel('메뉴').click(); diff --git a/tests/alba/globalAlba.setup.ts b/tests/alba/globalAlba.setup.ts deleted file mode 100644 index 680e6bc7..00000000 --- a/tests/alba/globalAlba.setup.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { expect, test as setup } from '@playwright/test'; -import { STORAGE_STATE } from '../../playwright.config'; -import { loginTest } from '../logintest'; - -setup('로그인', async ({ page, baseURL }) => { - await loginTest({ page: page, baseURL: baseURL, isAdmin: false }); - expect(page.getByText('내 스케줄')).toBeVisible({ timeout: 10000 }); - await page.waitForTimeout(3000); - await page.context().storageState({ path: STORAGE_STATE }); -}); diff --git a/tests/alba/invitation.spec.ts b/tests/alba/invitation.spec.ts index 0c6a6ce8..555810ba 100644 --- a/tests/alba/invitation.spec.ts +++ b/tests/alba/invitation.spec.ts @@ -1,21 +1,30 @@ import { expect, test } from '@playwright/test'; +import { getGroupInfo } from '../mock/getInvitation'; +import { mockMapper, mockResponse } from '../mock/mockResponse'; test.describe('초대장', () => { test('접속', async ({ page, baseURL }) => { + await mockMapper({ + page: page, + url: 'group/invitation/information*', + method: 'GET', + response: mockResponse(getGroupInfo), + }); + await mockMapper({ + page: page, + url: 'group/invitation', + method: 'POST', + response: mockResponse(null), + }); + // 접속 await page.goto(`${baseURL}/invited/123`); - const marketName = page.getByText('라이언 월드'); - await marketName.isVisible(); - expect(marketName).toBeVisible({ timeout: 10000 }); + expect(marketName).toBeVisible(); // 승인 - await page.getByRole('button', { name: '승인하기' }).click(); - const successMessage = page.getByText('그룹 가입에 성공했어요'); - await successMessage.isVisible(); - await page.waitForTimeout(1000); - expect(successMessage).toBeVisible({ timeout: 10000 }); + expect(successMessage).toBeVisible(); }); }); diff --git a/tests/login.spec.ts b/tests/login.spec.ts deleted file mode 100644 index 39d5ebe4..00000000 --- a/tests/login.spec.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { expect, test } from '@playwright/test'; -import { loginTest } from './logintest'; - -test.describe('온보딩 페이지', () => { - test('로그인', async ({ page, baseURL }) => { - await loginTest({ page: page, baseURL: baseURL, isAdmin: true }); - expect(page.getByText('내 스케줄')).toBeVisible({ timeout: 30000 }); - }); -}); diff --git a/tests/mock/auth.ts b/tests/mock/auth.ts index 4e7f0b2c..5de9a1fe 100644 --- a/tests/mock/auth.ts +++ b/tests/mock/auth.ts @@ -4,3 +4,12 @@ export const postLoginNoUser = { code: -10006, }), }; + +export const postLoginAdmin = { + token: 'Bearer ABC', + isAdmin: true, +}; +export const postLoginAlba = { + token: 'Bearer ABC', + isAdmin: false, +}; diff --git a/tests/mock/getInvitation.ts b/tests/mock/getInvitation.ts new file mode 100644 index 00000000..6a8d45fe --- /dev/null +++ b/tests/mock/getInvitation.ts @@ -0,0 +1,3 @@ +export const getGroupInfo = { + marketName: '라이언 월드', +};