Skip to content

Commit

Permalink
test: 테스트 코드
Browse files Browse the repository at this point in the history
  • Loading branch information
localgaji committed Nov 6, 2023
1 parent 9c31cbc commit 17971c5
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 75 deletions.
32 changes: 17 additions & 15 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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/**',
Expand Down
21 changes: 0 additions & 21 deletions tests/admin/globalAdmin.setup.ts

This file was deleted.

16 changes: 4 additions & 12 deletions tests/admin/sidebar.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
10 changes: 0 additions & 10 deletions tests/alba/globalAlba.setup.ts

This file was deleted.

25 changes: 17 additions & 8 deletions tests/alba/invitation.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
9 changes: 0 additions & 9 deletions tests/login.spec.ts

This file was deleted.

9 changes: 9 additions & 0 deletions tests/mock/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
3 changes: 3 additions & 0 deletions tests/mock/getInvitation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const getGroupInfo = {
marketName: '라이언 월드',
};

0 comments on commit 17971c5

Please sign in to comment.