|
2 | 2 | "use strict"; |
3 | 3 | var injectBrowser = require('testium/mocha'); |
4 | 4 | var assert = require("power-assert"); |
| 5 | +var AppPage = require("./page-objects/app-page"); |
5 | 6 | var browser; |
6 | | -function addTodo(text) { |
7 | | - browser.setValue('.todoText', text); |
8 | | - browser.click('.todoBtn'); |
9 | | -} |
10 | 7 | describe("app-test", function () { |
11 | | - var text = 'todo text'; |
| 8 | + var inputText = 'todo text'; |
| 9 | + var page; |
12 | 10 | before(injectBrowser()); |
13 | 11 | beforeEach(function () { |
14 | 12 | browser = this.browser; |
15 | | - this.browser.navigateTo("/"); |
| 13 | + page = new AppPage(this.browser); |
16 | 14 | }); |
17 | 15 | context("when テキストボックスに文字を入れて送信した時", function () { |
18 | 16 | beforeEach(function () { |
19 | | - addTodo(text) |
| 17 | + page.addTodo(inputText) |
20 | 18 | }); |
21 | 19 | it("should li要素が作成されている", function () { |
22 | | - var list = browser.getElements('.todoList li'); |
23 | | - assert(list.length > 0); |
| 20 | + var list = page.getTodoItems(); |
| 21 | + assert(list.length === 1); |
24 | 22 | }); |
25 | 23 |
|
26 | 24 | it("should リストアイテムのテキストは送信したものと一致している", function () { |
27 | | - browser.assert.elementHasText('.todoList li', text) |
| 25 | + var todo = page.getTodoItems()[0]; |
| 26 | + var text = todo.get("text"); |
| 27 | + assert.equal(text, inputText); |
28 | 28 | }); |
29 | 29 | }); |
30 | | - describe("todoについて", function () { |
| 30 | + describe("todo", function () { |
31 | 31 | beforeEach(function () { |
32 | | - addTodo(text); |
| 32 | + page.addTodo(inputText); |
33 | 33 | }); |
34 | | - context("checkboxをクリックしたら", function () { |
35 | | - it("should `is-complete`が追加される", function () { |
36 | | - browser.click('.todoList li input[type="checkbox"]'); |
| 34 | + context("when click the checkbox", function () { |
| 35 | + it("should added `is-complete`", function () { |
| 36 | + var todo = page.getTodoItems()[0]; |
| 37 | + page.toggleTodo(todo); |
37 | 38 | browser.assert.elementExists(".is-complete"); |
38 | 39 | }); |
39 | 40 | }); |
40 | | - context("removeBtnをクリックして、confirmでキャンセルしても", function () { |
41 | | - it("li要素は消えない", function () { |
| 41 | + context("when click removeBtn, then cancel confirm", function () { |
| 42 | + it("should have todo item", function () { |
| 43 | + var todo = page.getTodoItems()[0]; |
42 | 44 | // confirmがfalseを返すようにする = キャンセル |
43 | 45 | browser.evaluate("return window.confirm = function() { return " + false + "; };"); |
44 | | - |
45 | | - browser.click('.todoList li .removeBtn'); |
46 | | - browser.assert.elementExists(".todoList li"); |
| 46 | + page.removeTodo(todo); |
| 47 | + assert(page.getTodoItems().length > 0); |
47 | 48 | }); |
48 | 49 | }); |
49 | | - context("removeBtnをクリックしてconfirmでOKしたら", function () { |
50 | | - it("li要素が消える", function () { |
| 50 | + context("when click removeBtn, then ok to confirm", function () { |
| 51 | + it("should have nottodo item", function () { |
| 52 | + var todo = page.getTodoItems()[0]; |
51 | 53 | // confirmがtrueを返すようにする = OK |
52 | 54 | browser.evaluate("return window.confirm = function() { return " + true + "; };"); |
53 | | - browser.click('.todoList li .removeBtn'); |
54 | | - browser.assert.elementDoesntExist(".todoList li"); |
| 55 | + page.removeTodo(todo); |
| 56 | + assert(page.getTodoItems().length === 0); |
55 | 57 | }); |
56 | 58 | }); |
57 | 59 | }); |
|
0 commit comments