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-edit-controller tests and tranlsation (#892)
- Add abstract-edit-controller unit tests - Add translations for `showDisplayDialog` action - Add translations for `update` action on exceptions and failed promise
- Loading branch information
Showing
3 changed files
with
149 additions
and
5 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
128 changes: 128 additions & 0 deletions
128
tests/unit/controllers/abstract-edit-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,128 @@ | ||
import { moduleFor, test } from 'ember-qunit'; | ||
import Ember from 'ember'; | ||
import tHelper from 'ember-i18n/helper'; | ||
import localeConfig from 'ember-i18n/config/en'; | ||
|
||
moduleFor('controller:abstract-edit-controller', 'Unit | Controller | abstract-edit-controller', { | ||
needs: [ | ||
'service:i18n', | ||
'locale:en/translations', | ||
'locale:en/config', | ||
'util:i18n/missing-message', | ||
'util:i18n/compile-template', | ||
'config:environment' | ||
], | ||
beforeEach() { | ||
// set the locale and the config | ||
this.container.lookup('service:i18n').set('locale', 'en'); | ||
this.registry.register('locale:en/config', localeConfig); | ||
|
||
// manually inject the i18n service as initialzer does not run | ||
// in unit test | ||
Ember.getOwner(this).inject('controller', 'i18n', 'service:i18n'); | ||
|
||
// register t helper | ||
this.registry.register('helper:t', tHelper); | ||
} | ||
}); | ||
|
||
test('cancelButtonText', function(assert) { | ||
assert.equal(this.subject().get('cancelButtonText'), 'Return'); | ||
}); | ||
|
||
test('cancelButtonText hasDirtyAttributes', function(assert) { | ||
let controller = this.subject({ | ||
model: { | ||
hasDirtyAttributes: true | ||
} | ||
}); | ||
|
||
assert.equal(controller.get('cancelButtonText'), 'Cancel'); | ||
}); | ||
|
||
test('disabledAction', function(assert) { | ||
assert.equal(this.subject().get('disabledAction'), 'showDisabledDialog'); | ||
}); | ||
|
||
test('disabledAction invalid', function(assert) { | ||
let controller = this.subject({ | ||
model: { | ||
isValid: true | ||
} | ||
}); | ||
|
||
assert.strictEqual(controller.get('disabledAction'), undefined); | ||
}); | ||
|
||
test('isNewOrDeleted', function(assert) { | ||
assert.strictEqual(this.subject().get('isNewOrDeleted'), undefined); | ||
}); | ||
|
||
test('isNewOrDeleted new', function(assert) { | ||
let controller = this.subject({ | ||
model: { | ||
isNew: true, | ||
isDeleted: false | ||
} | ||
}); | ||
|
||
assert.strictEqual(controller.get('isNewOrDeleted'), true); | ||
}); | ||
|
||
test('isNewOrDeleted deleted', function(assert) { | ||
let controller = this.subject({ | ||
model: { | ||
isNew: false, | ||
isDeleted: true | ||
} | ||
}); | ||
|
||
assert.strictEqual(controller.get('isNewOrDeleted'), true); | ||
}); | ||
|
||
test('updateButtonText', function(assert) { | ||
assert.equal(this.subject().get('updateButtonText'), 'Update'); | ||
}); | ||
|
||
test('updateButtonText isNew', function(assert) { | ||
let controller = this.subject({ | ||
model: { | ||
isNew: true | ||
} | ||
}); | ||
|
||
assert.equal(controller.get('updateButtonText'), 'Add'); | ||
}); | ||
|
||
test('actions.showDisabledDialog message', function(assert) { | ||
let alertMessage, alertTitle; | ||
let controller = this.subject(); | ||
|
||
controller.displayAlert = function stub(title, message) { | ||
alertTitle = title; | ||
alertMessage = message; | ||
}; | ||
|
||
controller.send('showDisabledDialog'); | ||
|
||
assert.equal(alertTitle, 'Warning!!!!'); | ||
assert.equal(alertMessage, 'Please fill in required fields (marked with *) and correct the errors before saving.'); | ||
}); | ||
|
||
test('actions.update exception message', function(assert) { | ||
let alertMessage, alertTitle; | ||
let controller = this.subject(); | ||
|
||
controller.beforeUpdate = function() { | ||
throw 'Test'; | ||
}; | ||
controller.displayAlert = function stub(title, message) { | ||
alertTitle = title; | ||
alertMessage = message; | ||
}; | ||
|
||
controller.send('update'); | ||
|
||
assert.equal(alertTitle, 'Error!!!!'); | ||
assert.equal(alertMessage, 'An error occurred while attempting to save: "Test"'); | ||
}); |