Skip to content

Commit

Permalink
Add support for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Coquereau committed Feb 6, 2014
1 parent cb05102 commit f60d5c7
Show file tree
Hide file tree
Showing 10 changed files with 4,462 additions and 98 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/node_modules
/vendor/*
!/vendor/loader.js
!/vendor/sinon.js

# misc
/.sass-cache
Expand Down
40 changes: 18 additions & 22 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- build:css(tmp/result) /assets/app.min.css -->
<!-- @if tests=false -->
<link rel="stylesheet" href="/assets/app.css">
<!-- @endif -->
<!-- @if tests=true -->
<link rel="stylesheet" href="/vendor/mocha/mocha.css">
<!-- @endif -->
<!-- endbuild -->

<!-- for more details visit: https://github.com/yeoman/grunt-usemin -->
Expand Down Expand Up @@ -58,29 +63,18 @@
<!-- endbuild -->

<!-- @if tests=true -->
<link rel="stylesheet" href="/vendor/qunit/qunit/qunit.css">
<script src="/vendor/qunit/qunit/qunit.js"></script>

<style>
#ember-testing-container {
position: absolute;
background: white;
bottom: 0;
right: 0;
width: 640px;
height: 384px;
overflow: auto;
z-index: 9999;
border: 1px solid #ccc;
}
#ember-testing {
zoom: 50%;
}
</style>
<!--<link rel="stylesheet" href="/vendor/qunit/qunit/qunit.css">
<script src="/vendor/qunit/qunit/qunit.js"></script>-->
<script src="/vendor/mocha/mocha.js"></script>
<script src="/vendor/chai/chai.js"></script>
<script src="/vendor/sinon.js"></script>
<script src="/vendor/ember-mocha-adapter/adapter.js"></script>
<script>Ember.Test.adapter = Ember.Test.MochaAdapter.create();</script>
<!-- @endif -->

</head>
<body class="index">
<!-- @if tests=false -->
<!--[if lt IE 8]>
<p class="browsehappy">
You are using an <strong>outdated</strong> browser. Please
Expand All @@ -99,14 +93,16 @@
</div>
</div>
</div>

<!-- @endif -->
<!-- @if tests=true -->
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<div id="mocha"></div>
<div id="ember-testing"></div>

<script src="/tests/tests.js"></script>
<script src="/tests/test_helper.js"></script>
<script src="/tests/test_loader.js"></script>
<script src="/testem.js"></script>
<script>mocha.run();</script>
<!-- @endif -->

<!-- @if tests=false -->
Expand Down
3 changes: 3 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"ember-data": "~1.0.0-beta.6",
"ember-resolver": "git://github.com/stefanpenner/ember-jj-abrams-resolver.git#master",
"ic-ajax": "~0.2",
"ember-mocha-adapter": "~0.1.2",
"ember-testing-httpRespond": "~0.1.1",
"mocha": "~1.17.0",
"chai": "~1.8.1",
"moment": "~2.4.0"
},
"resolutions": {
Expand Down
34 changes: 17 additions & 17 deletions tests/acceptance/component_test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
var App;
// var App;

module('Acceptances - Component', {
setup: function(){
App = startApp();
},
teardown: function() {
Ember.run(App, 'destroy');
}
});
// module('Acceptances - Component', {
// setup: function(){
// App = startApp();
// },
// teardown: function() {
// Ember.run(App, 'destroy');
// }
// });

test('component output is rendered', function(){
expect(2);
// test('component output is rendered', function(){
// expect(2);

visit('/component-test').then(function(){
var list = find('.pretty-color');
equal(list.length, 3);
equal(list.first().text(), 'Pretty Color: purple\n');
});
});
// visit('/component-test').then(function(){
// var list = find('.pretty-color');
// equal(list.length, 3);
// equal(list.first().text(), 'Pretty Color: purple\n');
// });
// });

30 changes: 15 additions & 15 deletions tests/acceptance/helper_test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
var App;
// var App;

module("Acceptances - Helper", {
setup: function(){
App = startApp();
},
teardown: function() {
Ember.run(App, 'destroy');
}
});
// module("Acceptances - Helper", {
// setup: function(){
// App = startApp();
// },
// teardown: function() {
// Ember.run(App, 'destroy');
// }
// });

test("helper output is rendered", function(){
expect(1);
// test("helper output is rendered", function(){
// expect(1);

visit('/helper-test').then(function(){
ok(exists("h3:contains('My name is Ember.')"));
});
});
// visit('/helper-test').then(function(){
// ok(exists("h3:contains('My name is Ember.')"));
// });
// });

38 changes: 19 additions & 19 deletions tests/acceptance/index_test.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
var App;
// var App;

module('Acceptances - Index', {
setup: function(){
App = startApp();
},
teardown: function() {
Ember.run(App, 'destroy');
}
});
// module('Acceptances - Index', {
// setup: function(){
// App = startApp();
// },
// teardown: function() {
// Ember.run(App, 'destroy');
// }
// });

test('index renders', function(){
expect(3);
// test('index renders', function(){
// expect(3);

visit('/').then(function(){
var title = find('h2#title');
var list = find('ul li');
// visit('/').then(function(){
// var title = find('h2#title');
// var list = find('ul li');

equal(title.text(), 'Welcome to Ember.js');
// equal(title.text(), 'Welcome to Ember.js');

equal(list.length, 3);
equal(list.text(), 'redyellowblue');
});
});
// equal(list.length, 3);
// equal(list.text(), 'redyellowblue');
// });
// });
8 changes: 8 additions & 0 deletions tests/helpers/start_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ function startApp(attrs) {
App = Application.create(attributes);
App.setupForTesting();
App.injectTestHelpers();
// Setup mocha
mocha.globals(['Ember', 'DS', 'App', 'MD5', 'server', 'expect']);
mocha.timeout(5);
// Setup Chai
chai.Assertion.includeStack = true;
window.expect = chai.expect;
// Setup Sinon
server = sinon.fakeServer.create();
});

App.reset(); // this shouldn't be needed, i want to be able to "start an app at a specific URL"
Expand Down
36 changes: 18 additions & 18 deletions tests/unit/components/pretty_color_test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { test , moduleForComponent } from 'appkit/tests/helpers/module_for';
// import { test , moduleForComponent } from 'appkit/tests/helpers/module_for';

moduleForComponent('pretty-color');
// moduleForComponent('pretty-color');

test("changing colors", function(){
var component = this.subject();
// test("changing colors", function(){
// var component = this.subject();

Ember.run(function(){
component.set('name','red');
});
// Ember.run(function(){
// component.set('name','red');
// });

// first call to $() renders the component.
equal(this.$().attr('style'), 'color: red;');
// // first call to $() renders the component.
// equal(this.$().attr('style'), 'color: red;');

Ember.run(function(){
component.set('name', 'green');
});
// Ember.run(function(){
// component.set('name', 'green');
// });

equal(this.$().attr('style'), 'color: green;');
});
// equal(this.$().attr('style'), 'color: green;');
// });


test("className", function(){
// first call to this.$() renders the component.
ok(this.$().is('.pretty-color'));
});
// test("className", function(){
// // first call to this.$() renders the component.
// ok(this.$().is('.pretty-color'));
// });
11 changes: 4 additions & 7 deletions tests/unit/routes/index_test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { test , moduleFor } from 'appkit/tests/helpers/module_for';

import Index from 'appkit/routes/index';
import Index from 'appkit/routes/application';

moduleFor('route:index', "Unit - IndexRoute");
describe('route:application :: unit', function(){
it('should pass', function(){

test("it exists", function(){
ok(this.subject() instanceof Index);
});
});

test("#model", function(){
deepEqual(this.subject().model(), ['red', 'yellow', 'blue']);
});
Loading

0 comments on commit f60d5c7

Please sign in to comment.