Skip to content

Commit b57272e

Browse files
committed
initial commit
0 parents  commit b57272e

12 files changed

+343
-0
lines changed

.gitignore

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
### https://raw.github.com/github/gitignore/408c616ae0ad8f4b8101d8e876b9b67ac6b14059/Node.gitignore
2+
3+
# Logs
4+
logs
5+
*.log
6+
7+
# Runtime data
8+
pids
9+
*.pid
10+
*.seed
11+
12+
# Directory for instrumented libs generated by jscoverage/JSCover
13+
lib-cov
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
18+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
19+
.grunt
20+
21+
# node-waf configuration
22+
.lock-wscript
23+
24+
# Compiled binary addons (http://nodejs.org/api/addons.html)
25+
build/Release
26+
27+
# Dependency directory
28+
# Commenting this out is preferred by some people, see
29+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
30+
node_modules
31+
32+
33+
### https://raw.github.com/github/gitignore/408c616ae0ad8f4b8101d8e876b9b67ac6b14059/Global/JetBrains.gitignore
34+
35+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
36+
37+
*.iml
38+
39+
## Directory-based project format:
40+
.idea/
41+
# if you remove the above rule, at least ignore the following:
42+
43+
# User-specific stuff:
44+
# .idea/workspace.xml
45+
# .idea/tasks.xml
46+
# .idea/dictionaries
47+
48+
# Sensitive or high-churn files:
49+
# .idea/dataSources.ids
50+
# .idea/dataSources.xml
51+
# .idea/sqlDataSources.xml
52+
# .idea/dynamic.xml
53+
# .idea/uiDesigner.xml
54+
55+
# Gradle:
56+
# .idea/gradle.xml
57+
# .idea/libraries
58+
59+
# Mongo Explorer plugin:
60+
# .idea/mongoSettings.xml
61+
62+
## File-based project format:
63+
*.ipr
64+
*.iws
65+
66+
## Plugin-specific files:
67+
68+
# IntelliJ
69+
out/
70+
71+
# mpeltonen/sbt-idea plugin
72+
.idea_modules/
73+
74+
# JIRA plugin
75+
atlassian-ide-plugin.xml
76+
77+
# Crashlytics plugin (for Android Studio and IntelliJ)
78+
com_crashlytics_export_strings.xml
79+
crashlytics.properties
80+
crashlytics-build.properties
81+
82+
83+
84+
test/log

.testiumrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
launch=true

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- '0.10'

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2015 azu
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# todo-app-jquery-to-backbone
2+
3+
Refactoring todo app - migrate jquery to backbone.
4+
5+
- [slides/refactoring at gh-pages · hokaccha/slides](https://github.com/hokaccha/slides/tree/gh-pages/refactoring "slides/refactoring at gh-pages · hokaccha/slides")
6+
7+
Use [testium](https://github.com/groupon-testium/testium "testium") for E2E testing.
8+
9+
## Installation
10+
11+
```
12+
npm install
13+
```
14+
15+
## Usage
16+
17+
```
18+
npm test
19+
```
20+
21+
## Contributing
22+
23+
1. Fork it!
24+
2. Create your feature branch: `git checkout -b my-new-feature`
25+
3. Commit your changes: `git commit -am 'Add some feature'`
26+
4. Push to the branch: `git push origin my-new-feature`
27+
5. Submit a pull request :D
28+
29+
## License
30+
31+
MIT

app.css

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
body {
2+
font-family: 'Open Sans', sans-serif;
3+
color: #333;
4+
}
5+
.todo {
6+
width: 520px;
7+
margin: 0 auto;
8+
}
9+
h1 {
10+
font-size: 30px;
11+
}
12+
.todoText {
13+
width: 400px;
14+
}
15+
.todoBtn {
16+
width: 100px;
17+
}
18+
.todoList {
19+
margin: 15px 0 0 0;
20+
padding: 0;
21+
list-style: none;
22+
border-top: 1px dotted #4e3900;
23+
}
24+
.todoList li {
25+
font-size: 26px;
26+
margin: 15px 0;
27+
padding: 0 0 15px 0;
28+
width: 100%;
29+
position: relative;
30+
border-bottom: 1px dotted #4e3900;
31+
}
32+
.todoList input[type="checkbox"] {
33+
margin-right: 10px;
34+
vertical-align: middle;
35+
}
36+
.todoText {
37+
vertical-align: top;
38+
}
39+
.is-complete .todoText {
40+
text-decoration: line-through;
41+
color: #CCC;
42+
}
43+
44+
.removeBtn {
45+
color: #a5000c;
46+
cursor: pointer;
47+
position: absolute;
48+
right: 0;
49+
top: 5px;
50+
}
51+
.removeBtn:hover {
52+
opacity: 0.8;
53+
}

app.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
$(function() {
2+
var $form = $('.todoForm');
3+
var $list = $('.todoList');
4+
5+
$form.on('submit', function(e) {
6+
e.preventDefault();
7+
8+
var $input = $('input[type="text"]');
9+
var val = $input.val();
10+
11+
var $li = $('<li>');
12+
var $text = $('<span>').addClass('todoText').text(val);
13+
var $checkbox = $('<input type="checkbox">');
14+
var $remove = $('<i>').addClass('removeBtn fa fa-times');
15+
16+
$checkbox.on('click', function() {
17+
$li.toggleClass('is-complete');
18+
});
19+
20+
$remove.on('click', function() {
21+
if (!window.confirm('消しますよ')) return;
22+
$li.remove();
23+
});
24+
25+
$li.append($checkbox, $text, $remove);
26+
$list.append($li);
27+
28+
$input.val('');
29+
});
30+
});

index.html

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html lang="ja">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Sample</title>
6+
<script src="./vendor/jquery-1.11.2.min.js"></script>
7+
<script src="app.js"></script>
8+
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.5.0/pure-min.css">
9+
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css">
10+
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans">
11+
<link rel="stylesheet" href="app.css">
12+
</head>
13+
<body>
14+
15+
<div class="todo">
16+
<h1>Todos</h1>
17+
<form class="todoForm pure-form">
18+
<input type="text" class="todoText" placeholder="What needs to be done?">
19+
<input type="submit" class="todoBtn pure-button pure-button-primary" value="Add New">
20+
</form>
21+
22+
<ul class="todoList"></ul>
23+
</div>
24+
25+
</body>
26+
</html>

package.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "todo-app-jquery-to-backbone",
3+
"description": "Refactoring todo app.",
4+
"version": "1.0.0",
5+
"homepage": "https://github.com/coding-kata/todo-app-jquery-to-backbone/",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/coding-kata/todo-app-jquery-to-backbone.git"
9+
},
10+
"main": "index.js",
11+
"scripts": {
12+
"start":"http-server",
13+
"test": "mocha test/*.js"
14+
},
15+
"directories": {
16+
"test": "test/"
17+
},
18+
"author": "azu",
19+
"license": "MIT",
20+
"bugs": {
21+
"url": "https://github.com/coding-kata/todo-app-jquery-to-backbone/issues"
22+
},
23+
"devDependencies": {
24+
"espower-loader": "^0.10.0",
25+
"http-server": "^0.7.4",
26+
"intelli-espower-loader": "^0.6.0",
27+
"mocha": "^2.1.0",
28+
"phantomjs": "^1.9.13",
29+
"power-assert": "^0.10.1",
30+
"testium": "^2.3.0"
31+
}
32+
}

test/app-e2e-test.js

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

test/mocha.opts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--require intelli-espower-loader

vendor/jquery-1.11.2.min.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)