-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update tests to new module/setupTest qunit-dom format
- Loading branch information
1 parent
0ee3320
commit 0b62d4c
Showing
31 changed files
with
2,823 additions
and
2,763 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,61 @@ | ||
import {test} from 'qunit'; | ||
import {make, build, buildList, mockFindRecord} from 'ember-data-factory-guy'; | ||
import moduleForAcceptance from '../helpers/module-for-acceptance'; | ||
import { module, test } from 'qunit'; | ||
import { build, buildList, make, mockFindRecord, setupFactoryGuy } from 'ember-data-factory-guy'; | ||
import { setupApplicationTest } from "ember-qunit"; | ||
import { visit } from '@ember/test-helpers'; | ||
|
||
moduleForAcceptance('Acceptance | Employee View ( model-fragments )'); | ||
// NOTE | ||
// FactoryGuy before and after setup is in moduleForAcceptance helper | ||
module('Acceptance | Employee View ( model-fragments )', function(hooks) { | ||
setupApplicationTest(hooks); | ||
setupFactoryGuy(hooks); | ||
|
||
test("Show employee by make(ing) a model ( with hasMany fragment added manually ) and using returns with that model", async function(assert) { | ||
let departmentEmployments = buildList('department-employment', 2).get(); | ||
let employee = make('employee', { departmentEmployments }); | ||
test("Show employee by make(ing) a model ( with hasMany fragment added manually ) and using returns with that model", async function(assert) { | ||
let departmentEmployments = buildList('department-employment', 2).get(); | ||
let employee = make('employee', {departmentEmployments}); | ||
|
||
mockFindRecord('employee').returns({ model: employee }); | ||
await visit('/employee/' + employee.get('id')); | ||
mockFindRecord('employee').returns({model: employee}); | ||
await visit('/employee/' + employee.get('id')); | ||
|
||
assert.ok(find('.name').text().match(`${employee.get('name.firstName')} ${employee.get('name.lastName')}`)); | ||
assert.equal(find('.department-employment').length, 2, "fragment array works"); | ||
}); | ||
assert.dom('.name').containsText(`${employee.get('name.firstName')} ${employee.get('name.lastName')}`); | ||
assert.dom('.department-employment').exists({count: 2}, "fragment array works"); | ||
}); | ||
|
||
test("Show employee by make(ing) a model ( with belongsTo fragment added manually ) and using returns with that model", async function(assert) { | ||
let name = make('name', { firstName: 'Joe', lastName: 'Black' }); | ||
let employee = make('employee', { name }); | ||
test("Show employee by make(ing) a model ( with belongsTo fragment added manually ) and using returns with that model", async function(assert) { | ||
let name = make('name', {firstName: 'Joe', lastName: 'Black'}); | ||
let employee = make('employee', {name}); | ||
|
||
mockFindRecord('employee').returns({ model: employee }); | ||
await visit('/employee/' + employee.get('id')); | ||
mockFindRecord('employee').returns({model: employee}); | ||
await visit('/employee/' + employee.get('id')); | ||
|
||
assert.ok(find('.name').text().match(`${employee.get('name.firstName')} ${employee.get('name.lastName')}`)); | ||
}); | ||
assert.dom('.name').containsText(`${employee.get('name.firstName')} ${employee.get('name.lastName')}`); | ||
}); | ||
|
||
test("Show employee by make(ing) a model and using returns with that model", async function(assert) { | ||
let employee = make('employee', 'with_department_employments'); | ||
test("Show employee by make(ing) a model and using returns with that model", async function(assert) { | ||
let employee = make('employee', 'with_department_employments'); | ||
|
||
mockFindRecord('employee').returns({ model: employee }); | ||
await visit('/employee/' + employee.get('id')); | ||
mockFindRecord('employee').returns({model: employee}); | ||
await visit('/employee/' + employee.get('id')); | ||
|
||
assert.ok(find('.name').text().match(`${employee.get('name.firstName')} ${employee.get('name.lastName')}`)); | ||
assert.equal(find('.department-employment').length, 2, "fragment array works"); | ||
}); | ||
assert.dom('.name').containsText(`${employee.get('name.firstName')} ${employee.get('name.lastName')}`); | ||
assert.dom('.department-employment').exists({count: 2}, "fragment array works"); | ||
}); | ||
|
||
test("Show employee by build(ing) json and using returns with that json", async function(assert) { | ||
let employee = build('employee', 'with_department_employments'); | ||
test("Show employee by build(ing) json and using returns with that json", async function(assert) { | ||
let employee = build('employee', 'with_department_employments'); | ||
|
||
mockFindRecord('employee').returns({ json: employee }); | ||
await visit('/employee/' + employee.get('id')); | ||
mockFindRecord('employee').returns({json: employee}); | ||
await visit('/employee/' + employee.get('id')); | ||
|
||
assert.ok(find('.name').text().match(`${employee.get('name').first_name} ${employee.get('name').last_name}`)); | ||
assert.equal(find('.department-employment').length, 2, "fragment array works"); | ||
}); | ||
assert.dom('.name').containsText(`${employee.get('name').first_name} ${employee.get('name').last_name}`); | ||
assert.dom('.department-employment').exists({count: 2}, "fragment array works"); | ||
}); | ||
|
||
test("Show employee by build(ing) json ( with hasMany fragment added manually ) and using returns with that json", async function(assert) { | ||
let departmentEmployments = buildList('department-employment', 2).get(); | ||
let employee = build('employee', { departmentEmployments }); | ||
test("Show employee by build(ing) json ( with hasMany fragment added manually ) and using returns with that json", async function(assert) { | ||
let departmentEmployments = buildList('department-employment', 2).get(); | ||
let employee = build('employee', {departmentEmployments}); | ||
|
||
mockFindRecord('employee').returns({ json: employee }); | ||
await visit('/employee/' + employee.get('id')); | ||
mockFindRecord('employee').returns({json: employee}); | ||
await visit('/employee/' + employee.get('id')); | ||
|
||
assert.ok(find('.name').text().match(`${employee.get('name').first_name} ${employee.get('name').last_name}`)); | ||
assert.equal(find('.department-employment').length, 2, "fragment array works"); | ||
assert.dom('.name').containsText(`${employee.get('name').first_name} ${employee.get('name').last_name}`); | ||
assert.dom('.department-employment').exists({count: 2}, "fragment array works"); | ||
}); | ||
}); |
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,30 +1,32 @@ | ||
import {test} from 'qunit'; | ||
import FactoryGuy, {makeList, mockFindAll} from 'ember-data-factory-guy'; | ||
import moduleForAcceptance from '../helpers/module-for-acceptance'; | ||
import { module, test } from 'qunit'; | ||
import { setupApplicationTest } from "ember-qunit"; | ||
import FactoryGuy, { makeList, mockFindAll, setupFactoryGuy } from 'ember-data-factory-guy'; | ||
import { visit } from '@ember/test-helpers'; | ||
|
||
moduleForAcceptance('Acceptance | Profiles View'); | ||
// NOTE | ||
// FactoryGuy before and after setup is in moduleForAcceptance helper | ||
module('Acceptance | Profiles View', function(hooks) { | ||
setupApplicationTest(hooks); | ||
setupFactoryGuy(hooks); | ||
|
||
test("Handles differently cased attributes", async function(assert) { | ||
let description = 'mylittlepony', | ||
camelCaseDescription = "myLittlePony", | ||
snake_case_description = "my_little_pony"; | ||
test("Handles differently cased attributes", async function(assert) { | ||
let description = 'mylittlepony', | ||
camelCaseDescription = "myLittlePony", | ||
snake_case_description = "my_little_pony"; | ||
|
||
mockFindAll('profile', 1, { description, camelCaseDescription, snake_case_description }); | ||
mockFindAll('profile', 1, {description, camelCaseDescription, snake_case_description}); | ||
|
||
await visit('/profiles'); | ||
await visit('/profiles'); | ||
|
||
assert.equal(find('.profile:first [data-field=description]').text(), description); | ||
assert.equal(find('.profile:first [data-field=camelCaseDescription]').text(), camelCaseDescription); | ||
assert.equal(find('.profile:first [data-field=snake_case_description]').text(), snake_case_description); | ||
}); | ||
assert.dom('.profile:nth-child(1) [data-field=description]').hasText(description); | ||
assert.dom('.profile:nth-child(1) [data-field=camelCaseDescription]').hasText(camelCaseDescription); | ||
assert.dom('.profile:nth-child(1) [data-field=snake_case_description]').hasText(snake_case_description); | ||
}); | ||
|
||
test("Using FactoryGuy.cacheOnlyMode", async function(assert) { | ||
makeList("profile", 2); | ||
FactoryGuy.cacheOnlyMode(); | ||
test("Using FactoryGuy.cacheOnlyMode", async function(assert) { | ||
makeList("profile", 2); | ||
FactoryGuy.cacheOnlyMode(); | ||
|
||
await visit('/profiles'); | ||
await visit('/profiles'); | ||
|
||
assert.equal(find('.profile').length, 2); | ||
assert.dom('.profile').exists({count: 2}); | ||
}); | ||
}); |
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,104 +1,104 @@ | ||
import {test} from 'qunit'; | ||
import {make, makeList, buildList, mockQuery} from 'ember-data-factory-guy'; | ||
import moduleForAcceptance from '../helpers/module-for-acceptance'; | ||
import { module, test } from 'qunit'; | ||
import { buildList, make, makeList, mockQuery, setupFactoryGuy } from 'ember-data-factory-guy'; | ||
import { setupApplicationTest } from "ember-qunit"; | ||
import { click, fillIn, visit } from '@ember/test-helpers'; | ||
|
||
moduleForAcceptance('Acceptance | User Search'); | ||
module('Acceptance | User Search', function(hooks) { | ||
setupApplicationTest(hooks); | ||
setupFactoryGuy(hooks); | ||
|
||
// NOTE | ||
// FactoryGuy before and after setup is in moduleForAcceptance helper | ||
var search = async function(name) { | ||
await fillIn('input.user-name', name); | ||
return click('button.find-user'); | ||
}; | ||
|
||
var search = function(name) { | ||
fillIn('input.user-name', name); | ||
return click('button.find-user'); | ||
}; | ||
test("mockQuery without params matches store.query with any parameters", async function(assert) { | ||
let dude = buildList('user', {name: 'Dude'}); | ||
|
||
test("mockQuery without params matches store.query with any parameters", async function(assert) { | ||
let dude = buildList('user', { name: 'Dude' }); | ||
// no query parameters set in the mock so it will match | ||
// a query for {name: "Bif"} and return the dude | ||
mockQuery('user').returns({json: dude}); | ||
|
||
// no query parameters set in the mock so it will match | ||
// a query for {name: "Bif"} and return the dude | ||
mockQuery('user').returns({ json: dude }); | ||
await visit('/search'); | ||
await search("Bif"); // still returns dude | ||
|
||
await visit('/search'); | ||
await search("Bif"); // still returns dude | ||
assert.dom('.user .name').containsText("Dude"); | ||
}); | ||
|
||
assert.ok(find('.user .name').length === 1); | ||
assert.ok(find('.user .name').text().match("Dude")); | ||
}); | ||
test("mockQuery with params matches store.query with those parameters", async function(assert) { | ||
let dude = buildList('user', {name: 'Dude'}); | ||
|
||
test("mockQuery with params matches store.query with those parameters", async function(assert) { | ||
let dude = buildList('user', { name: 'Dude' }); | ||
// asking to mock only exact match of 'user' | ||
// with these parameters: {name: "Dude"} | ||
mockQuery('user', {name: "Dude"}).returns({json: dude}); | ||
|
||
// asking to mock only exact match of 'user' | ||
// with these parameters: {name: "Dude"} | ||
mockQuery('user', { name: "Dude" }).returns({ json: dude }); | ||
await visit('/search'); | ||
await search("Dude"); // still returns dude | ||
|
||
await visit('/search'); | ||
await search("Dude"); // still returns dude | ||
assert.dom('.user .name').exists({count: 1}); | ||
assert.dom('.user .name').containsText("Dude"); | ||
}); | ||
|
||
assert.ok(find('.user .name').length === 1); | ||
assert.ok(find('.user .name').text().match("Dude")); | ||
}); | ||
test("reusing mockQuery to return different results with different parameters", async function(assert) { | ||
let sillyPeople = buildList('user', {name: 'Bo'}, {name: "Bif"}); | ||
|
||
test("reusing mockQuery to return different results with different parameters", async function(assert) { | ||
let sillyPeople = buildList('user', { name: 'Bo' }, { name: "Bif" }); | ||
// nothing is returned with these parameters: {name: "Dude"} | ||
let mock = mockQuery('user', {name: "Dude"}); | ||
|
||
// nothing is returned with these parameters: {name: "Dude"} | ||
let mock = mockQuery('user', { name: "Dude" }); | ||
await visit('/search'); | ||
await search("Dude"); | ||
|
||
await visit('/search'); | ||
await search("Dude"); | ||
assert.dom('.user .name').doesNotExist(); | ||
|
||
assert.ok(find('.user .name').length === 0); | ||
mock.withParams({name: "silly"}).returns({json: sillyPeople}); | ||
await search("silly"); | ||
|
||
mock.withParams({ name: "silly" }).returns({ json: sillyPeople }); | ||
await search("silly"); | ||
assert.dom('.user .name').exists({count: 2}, "2 names"); | ||
assert.dom('.user:nth-child(1) .name').containsText("Bo"); | ||
assert.dom('.user:nth-child(2) .name').containsText("Bif"); | ||
}); | ||
|
||
assert.ok(find('.user .name').length === 2); | ||
assert.ok(find('.user .name:first').text().match("Bo")); | ||
assert.ok(find('.user .name:last').text().match("Bif")); | ||
}); | ||
test("using returns( models )", async function(assert) { | ||
let bobs = makeList("bob", 2); | ||
|
||
test("using returns( models )", async function(assert) { | ||
let bobs = makeList("bob", 2); | ||
mockQuery('user', {name: "bob"}).returns({models: bobs}); | ||
|
||
mockQuery('user', { name: "bob" }).returns({ models: bobs }); | ||
await visit('/search'); | ||
await search("bob"); | ||
|
||
await visit('/search'); | ||
await search("bob"); | ||
assert.dom('.user').exists({count: 2}); | ||
}); | ||
|
||
assert.ok(find('.user').length === 2); | ||
}); | ||
test("using returns( ids )", async function(assert) { | ||
let bob = make("bob"); | ||
make("user"); | ||
|
||
test("using returns( ids )", async function(assert) { | ||
let bob = make("bob"); | ||
make("user"); | ||
mockQuery('user').returns({ids: [bob.id]}); | ||
|
||
mockQuery('user').returns({ ids: [bob.id] }); | ||
await visit('/search'); | ||
await search("user2"); | ||
|
||
await visit('/search'); | ||
await search("user2"); | ||
assert.dom('.user').exists({count: 1}); | ||
assert.dom('.user .name').containsText("Bob"); | ||
}); | ||
|
||
assert.ok(find('.user').length === 1); | ||
assert.ok(find('.user .name').text().match("Bob")); | ||
}); | ||
|
||
test('Load meta data returned from the server', async function(assert) { | ||
let users = buildList('user', 1).add({ meta: { previous: '/search?page=1', next: '/search?page=3' } }); | ||
mockQuery('user').returns({ json: users }); | ||
test('Load meta data returned from the server', async function(assert) { | ||
let users = buildList('user', 1).add({meta: {previous: '/search?page=1', next: '/search?page=3'}}); | ||
mockQuery('user').returns({json: users}); | ||
|
||
await visit('/search'); | ||
await search("Anyone"); | ||
await visit('/search'); | ||
await search("Anyone"); | ||
|
||
assert.equal(find('.meta').length, 2); | ||
}); | ||
assert.dom('.meta').exists({count: 2}); | ||
}); | ||
|
||
test("using fails to mock a failed query", async function(assert) { | ||
let errors = { errors: { description: ['invalid'] } }; | ||
mockQuery('user').fails({ status: 422, response: errors }); | ||
test("using fails to mock a failed query", async function(assert) { | ||
let errors = {errors: {description: ['invalid']}}; | ||
mockQuery('user').fails({status: 422, response: errors}); | ||
|
||
await visit('/search'); | ||
await search("Allen"); | ||
await visit('/search'); | ||
await search("Allen"); | ||
|
||
assert.ok(find('.results').text().match('Errors')); | ||
assert.dom('.results').containsText('Errors'); | ||
}); | ||
}); |
Oops, something went wrong.