-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#55] refactor tests to new qunit api
Resolves #55
- Loading branch information
Showing
15 changed files
with
102 additions
and
119 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,84 @@ | ||
import { test } from 'qunit'; | ||
import { | ||
click, | ||
currentURL, | ||
find, | ||
fillIn, | ||
visit | ||
} from 'ember-native-dom-helpers'; | ||
import { authenticateSession } from 'mir/tests/helpers/ember-simple-auth'; | ||
import moduleForAcceptance from 'mir/tests/helpers/module-for-acceptance'; | ||
import { module, test } from 'qunit'; | ||
import { setupApplicationTest } from 'ember-qunit'; | ||
import { click, currentURL, fillIn, visit } from '@ember/test-helpers'; | ||
import { authenticateSession } from 'ember-simple-auth/test-support'; | ||
|
||
moduleForAcceptance('Acceptance | media/new'); | ||
module('Application | media/new', function(hooks) { | ||
setupApplicationTest(hooks); | ||
|
||
test('unauthenticated user cannot visit /media/new', async function(assert) { | ||
await visit('/media/new'); | ||
assert.equal(currentURL(), '/login'); | ||
}); | ||
|
||
test('authenticated user can visit /media/new', async function(assert) { | ||
authenticateSession(this.application, { | ||
userId: 1, | ||
otherData: 'some-data' | ||
test('unauthenticated user cannot visit /media/new', async function(assert) { | ||
await visit('/media/new'); | ||
assert.equal(currentURL(), '/login'); | ||
}); | ||
await visit('/media/new'); | ||
assert.equal(currentURL(), '/media/new'); | ||
}); | ||
|
||
test('authenticated user cant add invalid media', async function(assert) { | ||
authenticateSession(this.application, { | ||
userId: 1, | ||
otherData: 'some-data' | ||
}); | ||
await visit('/media/new'); | ||
await click('button'); | ||
assert.equal(currentURL(), '/media/new'); | ||
}); | ||
module('authenticated user', function(hooks) { | ||
hooks.beforeEach(function() { | ||
authenticateSession({ | ||
userId: 1, | ||
otherData: 'some-data' | ||
}); | ||
}); | ||
|
||
test('authenticated user abort can abort creating media', async function(assert) { | ||
assert.expect(3); | ||
// create an OAuth token w/ ember-cli-mirage | ||
server.create('media'); | ||
// authenticate user | ||
authenticateSession(this.application, { | ||
userId: 1, | ||
otherData: 'some-data' | ||
}); | ||
// count how many media currently exist | ||
await visit('/'); | ||
let numMedia = find('.ma-MediaListItem').length; | ||
// visit create media page | ||
await visit('/media/new'); | ||
assert.equal(currentURL(), '/media/new', 'user lands on new route'); | ||
await fillIn('[name=title]', 'asdf title'); | ||
await fillIn('[name=url]', 'http://t.co'); | ||
// abort creation | ||
await visit('/'); // dont click back because it'll break test runner | ||
assert.equal(currentURL(), '/', 'user lands on home route'); | ||
let resultNumMedia = find('.ma-MediaListItem').length; | ||
assert.equal(numMedia, resultNumMedia, 'a new media was not created'); | ||
}); | ||
test('can visit /media/new', async function(assert) { | ||
await visit('/media/new'); | ||
assert.equal(currentURL(), '/media/new'); | ||
}); | ||
|
||
test('authenticated user can add and delete valid media', async function(assert) { | ||
assert.expect(3); | ||
// create an OAuth token w/ ember-cli-mirage | ||
server.create('media'); | ||
// authenticate user | ||
authenticateSession(this.application, { | ||
userId: 1, | ||
otherData: 'some-data' | ||
}); | ||
await visit('/media/new'); | ||
await fillIn('[name=title]', 'asdf title'); | ||
await fillIn('[name=url]', 'http://t.co'); | ||
await click('button'); | ||
assert.equal(currentURL(), '/', 'user lands on home route'); | ||
let msg = find('.container').textContent; | ||
assert.notEqual(msg.match(/Song title /), null); | ||
// delete new media | ||
await click('.ma-MediaListItem .ma-MediaListItem-delete'); | ||
let numMedia = find('.ma-MediaListItem'); | ||
assert.equal(numMedia, null, 'media was deleted'); | ||
}); | ||
test('cant add invalid media', async function(assert) { | ||
await visit('/media/new'); | ||
await click('button'); | ||
assert.equal(currentURL(), '/media/new'); | ||
}); | ||
|
||
test('can abort creating media', async function(assert) { | ||
assert.expect(3); | ||
// create an OAuth media w/ ember-cli-mirage | ||
server.create('media'); | ||
// count how many media currently exist | ||
await visit('/'); | ||
let numMedia = this.element.querySelectorAll('.ma-MediaListItem').length; | ||
// visit create media page | ||
await visit('/media/new'); | ||
assert.equal(currentURL(), '/media/new', 'user lands on new route'); | ||
await fillIn('[name=title]', 'asdf title'); | ||
await fillIn('[name=url]', 'http://t.co'); | ||
// abort creation | ||
await visit('/'); // dont click back because it'll break test runner | ||
assert.equal(currentURL(), '/', 'user lands on home route'); | ||
let resultNumMedia = this.element.querySelectorAll('.ma-MediaListItem') | ||
.length; | ||
assert.equal(numMedia, resultNumMedia, 'a new media was not created'); | ||
}); | ||
|
||
test('can add and delete valid media', async function(assert) { | ||
assert.expect(3); | ||
// create an OAuth token w/ ember-cli-mirage | ||
await visit('/media/new'); | ||
await fillIn('[name=title]', 'asdf title'); | ||
await fillIn('[name=url]', 'http://t.co'); | ||
await click('button'); | ||
assert.equal(currentURL(), '/', 'user lands on home route'); | ||
let expected = this.element.querySelector('.ma-MediaListItem').length; | ||
let msg = this.element.querySelector('.container').textContent; | ||
assert.notEqual(msg.match(/asdf title/), null); | ||
// delete new media | ||
await click('.ma-MediaListItem .ma-MediaListItem-delete'); | ||
let result = this.element.querySelector('.ma-MediaListItem').length; | ||
assert.equal(result, expected, 'media was deleted'); | ||
}); | ||
|
||
test('ma-create-media can gracefully handle errors', async function(assert) { | ||
assert.expect(1); | ||
// create an OAuth token w/ ember-cli-mirage | ||
server.create('media'); | ||
// authenticate user | ||
authenticateSession(this.application, { | ||
userId: 1, | ||
otherData: 'some-data' | ||
test('ma-create-media can gracefully handle errors', async function(assert) { | ||
assert.expect(1); | ||
// create an OAuth token w/ ember-cli-mirage | ||
// server.create('media'); | ||
await visit('/media/new'); | ||
await fillIn('[name=title]', 'test-force-500-error'); | ||
await fillIn('[name=url]', 'http://t.co'); | ||
await click('button'); | ||
let msg = this.element | ||
.querySelector('.ma-ErrorsHandler-errors') | ||
.textContent.trim(); | ||
assert.notEqual(msg.match(/An error occurred/), null); | ||
}); | ||
}); | ||
await visit('/media/new'); | ||
await fillIn('[name=title]', 'test-force-500-error'); | ||
await fillIn('[name=url]', 'http://t.co'); | ||
await click('button'); | ||
let msg = find('.ma-ErrorsHandler-errors').textContent.trim(); | ||
assert.notEqual(msg.match(/An error occurred/), null); | ||
}); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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