Skip to content

Commit

Permalink
Merge pull request #33 from amiel/acceptance-testing
Browse files Browse the repository at this point in the history
Set up some acceptance testing
  • Loading branch information
amiel authored Jun 30, 2017
2 parents 8640b28 + e7eae5a commit 71c0e93
Show file tree
Hide file tree
Showing 23 changed files with 789 additions and 131 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
globals: {
server: true,
},
root: true,
parserOptions: {
ecmaVersion: 2017,
Expand Down
32 changes: 0 additions & 32 deletions .jshintrc

This file was deleted.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
"ember-cli-htmlbars": "^1.1.1",
"ember-cli-htmlbars-inline-precompile": "^0.4.0",
"ember-cli-inject-live-reload": "^1.4.1",
"ember-cli-mirage": "^0.3.3",
"ember-cli-qunit": "^4.0.0",
"ember-cli-shims": "^1.1.0",
"ember-cli-sri": "^2.1.0",
"ember-cli-uglify": "^1.2.0",
"ember-data": "^2.14.3",
"ember-disable-prototype-extensions": "^1.1.0",
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^1.0.0",
Expand Down
3 changes: 3 additions & 0 deletions tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
globals: {
server: true,
},
env: {
embertest: true
}
Expand Down
52 changes: 0 additions & 52 deletions tests/.jshintrc

This file was deleted.

14 changes: 14 additions & 0 deletions tests/acceptance/basic-url-template-test-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('Acceptance | basic url template test');

test('visiting /posts', function(assert) {
server.createList('post', 5);

visit('/posts');

andThen(() => {
assert.equal(find('#posts .post').length, '5');
});
});
4 changes: 4 additions & 0 deletions tests/dummy/app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import DS from "ember-data";
import UrlTemplates from "ember-data-url-templates";

export default DS.JSONAPIAdapter.extend(UrlTemplates);
9 changes: 4 additions & 5 deletions tests/dummy/app/adapters/post.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import DS from "ember-data";
import UrlTemplates from "ember-data-url-templates";
import ApplicationAdapter from './application';

export default DS.RESTAdapter.extend(UrlTemplates, {
urlTemplate: "{+host}{/namespace}/my-post{/id}",
namespace: 'api'
export default ApplicationAdapter.extend({
urlTemplate: "{+host}{/namespace}/my-posts{/id}",
namespace: 'api',
});
2 changes: 0 additions & 2 deletions tests/dummy/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import config from './config/environment';

let App;

Ember.MODEL_FACTORY_INJECTIONS = true;

App = Ember.Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
Expand Down
5 changes: 3 additions & 2 deletions tests/dummy/app/models/comment.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import comment from 'ember-data-url-templates/models/comment';
import DS from 'ember-data';

export default comment;
export default DS.Model.extend({
});
8 changes: 6 additions & 2 deletions tests/dummy/app/models/post.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import post from 'dummy/models/post';
import DS from 'ember-data';

export default post;
const { attr } = DS;

export default DS.Model.extend({
title: attr('string'),
});
1 change: 1 addition & 0 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Router = Ember.Router.extend({
});

Router.map(function() {
this.route('posts');
});

export default Router;
3 changes: 0 additions & 3 deletions tests/dummy/app/routes/application.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import Ember from "ember";

export default Ember.Route.extend({
model: function() {
return this.store.find('post');
}
});
7 changes: 7 additions & 0 deletions tests/dummy/app/routes/posts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Ember from 'ember';

export default Ember.Route.extend({
model() {
return this.store.findAll('post');
},
});
6 changes: 1 addition & 5 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{{!-- The following component displays Ember's default welcome message. --}}
{{welcome-page}}
{{!-- Feel free to remove this! --}}

{{outlet}}
{{outlet}}
9 changes: 9 additions & 0 deletions tests/dummy/app/templates/posts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1>Posts</h1>

<div id="posts">
{{#each model as |post|}}
<div id="post-{{post.id}}" class="post">
{{post.title}}
</div>
{{/each}}
</div>
28 changes: 28 additions & 0 deletions tests/dummy/mirage/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export default function() {

this.get('/api/my-posts', 'post');

// These comments are here to help you get started. Feel free to delete them.

/*
Config (with defaults).
Note: these only affect routes defined *after* them!
*/

// this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server
// this.namespace = ''; // make this `/api`, for example, if your API is namespaced
// this.timing = 400; // delay for each request, automatically set to 0 during testing

/*
Shorthand cheatsheet:
this.get('/posts');
this.post('/posts');
this.get('/posts/:id');
this.put('/posts/:id'); // or this.patch
this.del('/posts/:id');
http://www.ember-cli-mirage.com/docs/v0.3.x/shorthands/
*/
}
7 changes: 7 additions & 0 deletions tests/dummy/mirage/factories/post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Factory, faker } from 'ember-cli-mirage';

export default Factory.extend({
title(i) {
return `Post #${i}: ${faker.lorem.words()}`;
},
});
4 changes: 4 additions & 0 deletions tests/dummy/mirage/models/post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Model } from 'ember-cli-mirage';

export default Model.extend({
});
11 changes: 11 additions & 0 deletions tests/dummy/mirage/scenarios/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function(/* server */) {

/*
Seed your development database using your factories.
This data will not be loaded in your tests.
Make sure to define a factory for each model you want to create.
*/

// server.createList('post', 10);
}
4 changes: 4 additions & 0 deletions tests/dummy/mirage/serializers/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { JSONAPISerializer } from 'ember-cli-mirage';

export default JSONAPISerializer.extend({
});
3 changes: 3 additions & 0 deletions tests/helpers/destroy-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ import Ember from 'ember';

export default function destroyApp(application) {
Ember.run(application, 'destroy');
if (window.server) {
window.server.shutdown();
}
}
Loading

0 comments on commit 71c0e93

Please sign in to comment.