This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add abstract controller unit tests and translations (#900)
* Add abstract-delete tests and ember-sinon-qunit - Add unit tests for controller abstract-delete-controller - Add dependency(devDependency) for ember-sinon-qunit for use in stubbing methods for proper test coverage * Add unit tests abstract-paged-controller - Add unit tests from abstract-paged-controller - Update documentation with `@todo` about possible unintended behavior of the `sortByKey` action The tests in this commit preserve the behavior as implemented. It is possible that `sortByKey` should also set `nextStartKey` and `startKey` to `null` as well. * Add unit tests for abstract-report-controller - Add unit tests for abstract-report-controller * Add translations for _notifyReportError - Add translations for `_notifyReportError` in abstract-report-controller - Add unit test for `_notifyReportError` * Add translations for _setReportTitle - Add translations for `_setReportTitle` in abstract-report-controller - Add unit tests for `_setReportTitle` with translations
- Loading branch information
Showing
6 changed files
with
469 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { moduleFor } from 'ember-qunit'; | ||
import test from 'ember-sinon-qunit/test-support/test'; | ||
import Ember from 'ember'; | ||
import DS from 'ember-data'; | ||
|
||
moduleFor('controller:abstract-delete-controller', 'Unit | Controller | abstract-delete-controller', { | ||
unit: true, | ||
testModel(attrs) { | ||
return Ember.run(() => { | ||
this.register('model:test', DS.Model); | ||
return this.store().createRecord('test', attrs); | ||
}); | ||
}, | ||
store() { | ||
return this.container.lookup('service:store'); | ||
}, | ||
sendStub(controller) { | ||
let once = false; | ||
let originalSend = controller.send.bind(controller); | ||
return (arg) => { | ||
if (once) { | ||
return; | ||
} | ||
|
||
once = true; | ||
originalSend(arg); | ||
}; | ||
} | ||
}); | ||
|
||
test('actions.cancel', function(assert) { | ||
let controller = this.subject(); | ||
let send = this.stub(controller, 'send', this.sendStub(controller)); | ||
|
||
controller.send('cancel'); | ||
|
||
assert.equal(send.getCall(0).args[0], 'cancel'); | ||
assert.equal(send.getCall(1).args[0], 'closeModal', 'Should close modal'); | ||
}); | ||
|
||
test('actions.delete', function(assert) { | ||
let controller = this.subject({ | ||
model: this.testModel({ | ||
save: () => {}, | ||
unloadRecord: () => {} | ||
}) | ||
}); | ||
let send = this.stub(controller, 'send', this.sendStub(controller)); | ||
let save = this.stub(controller.get('model'), 'save', () => { | ||
return new Ember.RSVP.Promise((resolve) => resolve()); | ||
}); | ||
let unloadRecord = this.stub(controller.get('model'), 'unloadRecord'); | ||
|
||
Ember.run(() => controller.send('delete')); | ||
|
||
assert.equal(send.getCall(0).args[0], 'delete'); | ||
assert.ok(save.calledOnce, 'Should save model'); | ||
assert.strictEqual(controller.get('model.archived'), true, 'Should archive model'); | ||
assert.ok(unloadRecord.calledOnce, 'Should unload record of model'); | ||
assert.equal(send.getCall(1).args[0], 'closeModal', 'Should close modal'); | ||
}); |
154 changes: 154 additions & 0 deletions
154
tests/unit/controllers/abstract-paged-controller-test.js
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 |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import { moduleFor, test } from 'ember-qunit'; | ||
import sinonTest from 'ember-sinon-qunit/test-support/test'; | ||
import Ember from 'ember'; | ||
import DS from 'ember-data'; | ||
|
||
moduleFor('controller:abstract-paged-controller', 'Unit | Controller | abstract-paged-controller', { | ||
unit: true, | ||
testModel(attrs) { | ||
return Ember.run(() => { | ||
this.register('model:test', DS.Model); | ||
return this.store().createRecord('test', attrs); | ||
}); | ||
}, | ||
store() { | ||
return this.container.lookup('service:store'); | ||
} | ||
}); | ||
|
||
test('showActions', function(assert) { | ||
let controller = this.subject({ | ||
canAdd: false, | ||
canEdit: true, | ||
canDelete: false | ||
}); | ||
|
||
assert.strictEqual(controller.get('showActions'), true); | ||
}); | ||
|
||
test('disablePreviousPage', function(assert) { | ||
let controller = this.subject(); | ||
|
||
assert.strictEqual(controller.get('disablePreviousPage'), true); | ||
}); | ||
|
||
test('disablePreviousPage false', function(assert) { | ||
let controller = this.subject({ | ||
previousStartKey: 'test' | ||
}); | ||
|
||
assert.strictEqual(controller.get('disablePreviousPage'), false); | ||
}); | ||
|
||
test('disableNextPage', function(assert) { | ||
let controller = this.subject(); | ||
|
||
assert.strictEqual(controller.get('disableNextPage'), true); | ||
}); | ||
|
||
test('disableNextPage false', function(assert) { | ||
let controller = this.subject({ | ||
nextStartKey: 'test' | ||
}); | ||
|
||
assert.strictEqual(controller.get('disableNextPage'), false); | ||
}); | ||
|
||
test('showPagination', function(assert) { | ||
let controller = this.subject({ | ||
previousStartKey: 'test' | ||
}); | ||
|
||
assert.strictEqual(controller.get('showPagination'), true); | ||
}); | ||
|
||
test('showPagination false', function(assert) { | ||
let controller = this.subject(); | ||
|
||
assert.strictEqual(controller.get('showPagination'), false); | ||
}); | ||
|
||
test('hasRecords', function(assert) { | ||
let controller = this.subject({ | ||
model: this.testModel({ | ||
length: 1 | ||
}) | ||
}); | ||
|
||
assert.strictEqual(controller.get('hasRecords'), true); | ||
}); | ||
|
||
test('hasRecords false', function(assert) { | ||
let controller = this.subject({ | ||
model: this.testModel({ | ||
length: 0 | ||
}) | ||
}); | ||
|
||
assert.strictEqual(controller.get('hasRecords'), false); | ||
}); | ||
|
||
test('hasRecords false empty', function(assert) { | ||
assert.strictEqual(this.subject().get('hasRecords'), false); | ||
}); | ||
|
||
sinonTest('actions.nextPage', function(assert) { | ||
let controller = this.subject({ | ||
nextStartKey: 'next', | ||
previousStartKeys: ['prev1', 'prev2'], | ||
firstKey: 'first' | ||
}); | ||
let showProgressModal = this.stub(controller, 'showProgressModal'); | ||
|
||
controller.send('nextPage'); | ||
|
||
assert.strictEqual(controller.get('previousStartKey'), 'first', 'Should set previousStartKey'); | ||
assert.deepEqual(controller.get('previousStartKeys'), ['prev1', 'prev2', 'first'], 'Should set previousStartKeys'); | ||
assert.strictEqual(controller.get('startKey'), 'next', 'Should set startKey'); | ||
assert.ok(showProgressModal.calledOnce, 'Should show progress modal'); | ||
}); | ||
|
||
sinonTest('actions.previousPage', function(assert) { | ||
let controller = this.subject({ | ||
previousStartKey: 'prev', | ||
previousStartKeys: ['prev1', 'prev2', 'prev3'] | ||
}); | ||
let showProgressModal = this.stub(controller, 'showProgressModal'); | ||
|
||
controller.send('previousPage'); | ||
|
||
assert.strictEqual(controller.get('startKey'), 'prev', 'Should set startKey'); | ||
assert.strictEqual(controller.get('previousStartKey'), 'prev2', 'Should set previousStartKey'); | ||
assert.deepEqual(controller.get('previousStartKeys'), ['prev1'], 'Should set previousStartKey'); | ||
assert.ok(showProgressModal.calledOnce, 'Should show progress modal'); | ||
}); | ||
|
||
/** | ||
* @todo verify that not clearing `nextStartKey` and `firstKey` | ||
* is the intended behavior | ||
*/ | ||
sinonTest('actions.sortByKey', function(assert) { | ||
let controller = this.subject({ | ||
nextStartKey: 'next', | ||
previousStartKey: 'prev', | ||
previousStartKeys: ['prev1', 'prev2'], | ||
firstKey: 'first', | ||
startKey: 'start' | ||
}); | ||
let showProgressModal = this.stub(controller, 'showProgressModal'); | ||
|
||
controller.send('sortByKey', 'sort', 'desc'); | ||
|
||
// These two assertions preserve current implementation | ||
assert.strictEqual(controller.get('nextStartKey'), 'next', 'Should not change nextStartKey'); | ||
assert.strictEqual(controller.get('firstKey'), 'first', 'Should not change firstKey'); | ||
|
||
assert.strictEqual(controller.get('startKey'), null, 'Should clear startKey'); | ||
assert.deepEqual(controller.get('previousStartKeys'), [], 'Should clear previousStartKeys'); | ||
assert.strictEqual(controller.get('previousStartKey'), null, 'Should clear previousStartKey'); | ||
|
||
assert.strictEqual(controller.get('sortDesc'), 'desc', 'Should set sortDesc'); | ||
assert.strictEqual(controller.get('sortKey'), 'sort', 'Should set sortKey'); | ||
|
||
assert.ok(showProgressModal.calledOnce, 'Should show progress modal'); | ||
}); |
Oops, something went wrong.