Last active
April 1, 2018 09:38
-
-
Save 16Yongjin/41b9bec89044eebad0bd7fd1fb5c3339 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Page = require('./helpers/page') | |
| // 각 테스트마다 사용할 페이지 객체 | |
| let page | |
| // 각 테스트 케이스전에 실행할 코드 | |
| beforeEach(async () => { | |
| // Custome Helper 클래스의 정적 메서드로 Helper 페이지 인스턴스 생성 (사실 프록시) | |
| page = await Page.build() | |
| await page.goto('localhost:3000') | |
| }) | |
| afterEach(async () => { | |
| await page.close() | |
| }) | |
| describe('When logged in', async () => { | |
| // 로그인하고 블로그 작성 버튼 누르기 | |
| beforeEach(async () => { | |
| await page.login() | |
| await page.click('a.btn-floating') | |
| }) | |
| test('can see blog create form', async () => { | |
| const label = await page.getContentsOf('form label') | |
| expect(label).toEqual('Blog Title') | |
| }) | |
| // describe 안 describe, beforeEach를 재활용한다. | |
| describe('and using valid inputs', async () => { | |
| // 제목과 내용 입력하기 | |
| beforeEach(async () => { | |
| await page.type('.title input', 'My Title') | |
| await page.type('.content input', 'My Content') | |
| await page.click('form button') | |
| }) | |
| test('Submitting takes user to review screen', async () => { | |
| const text = await page.getContentsOf('form h5') | |
| expect(text).toEqual('Please confirm your entries') | |
| }) | |
| test('Submitting then saving adds blogs to index page', async () => { | |
| await page.click('button.green') | |
| await page.waitFor('.card') | |
| const title = await page.getContentsOf('.card-title') | |
| const content = await page.getContentsOf('p') | |
| expect(title).toEqual('My Title') | |
| expect(content).toEqual('My Content') | |
| }) | |
| }) | |
| describe('and using invalid inputs', async () => { | |
| beforeEach(async () => { | |
| await page.click('form button') | |
| }) | |
| test('the form shows an error message', async () => { | |
| const titleError = await page.getContentsOf('.title .red-text') | |
| const contentError = await page.getContentsOf('.content .red-text') | |
| expect(titleError).toEqual('You must provide a value') | |
| expect(contentError).toEqual('You must provide a value') | |
| }) | |
| }) | |
| }) | |
| describe('User is not logged in', async () => { | |
| // 객체 하나로 명료성을 지키며 AJAX 요청을 보낼 수 있다. | |
| const actions = [ | |
| { | |
| method: 'get', | |
| path: '/api/blogs' | |
| }, | |
| { | |
| method: 'post', | |
| path: '/api/blogs', | |
| data: { | |
| title: 'My Title', | |
| content: 'My Content' | |
| } | |
| } | |
| ] | |
| test('Blog related actoins are prohibited', async () => { | |
| const results = await page.execRequests(actions) | |
| results.forEach(res => expect(res).toEqual({ error: 'You must log in!' })) | |
| }) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment