-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RFC][NI] Minor fix in uni-select (#188)
* Minor fix in uni-select * Switched context * Add additional testing
- Loading branch information
1 parent
4687521
commit 8cd370e
Showing
3 changed files
with
85 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,111 @@ | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import { find, findAll } from 'ember-native-dom-helpers'; | ||
|
||
moduleForComponent('uni-select', 'Integration | Component | uni select', { | ||
integration: true | ||
integration: true, | ||
beforeEach() { | ||
this.set('options', [ | ||
{ key: 'pt', value: 'Portugal' }, | ||
{ key: 'it', value: 'Italy' }, | ||
{ key: 'nl', value: 'Nederlands' }, | ||
{ key: 'en', value: 'England' } | ||
]); | ||
this.set('disabledOptions', [ | ||
{ key: 1, value: 'Uno', disabled: true }, | ||
{ key: 2, value: 'Dos', disabled: true }, | ||
{ key: 3, value: 'Tres', disabled: false }, | ||
{ key: 4, value: 'Cuatro' } | ||
]); | ||
this.set('aliasOptions', [ | ||
{ key: 1, value: 'long explanation for one', alias: 'one' }, | ||
{ key: 2, value: 'long explanation for two', alias: 'two' } | ||
]); | ||
this.set('placeholder', 'Pick me!'); | ||
} | ||
}); | ||
|
||
test('it renders', function(assert) { | ||
test('It renders', function(assert) { | ||
assert.expect(2); | ||
|
||
this.render(hbs`{{uni-select options=options}}`); | ||
|
||
assert.ok(find('.uni-select'), 'It renders the select'); | ||
assert.ok(findAll('.uni-select__option').length, 4, 'It renders the four options'); | ||
}); | ||
|
||
test('It renders with placeholder', function(assert) { | ||
assert.expect(2); | ||
|
||
this.render(hbs`{{uni-select options=options placeholder=placeholder}}`); | ||
|
||
assert.ok(find('.uni-select'), 'It renders the select'); | ||
assert.ok(findAll('.uni-select__option').length, 5, 'It renders the four options and the placeholder'); | ||
}); | ||
|
||
test('It ignores the placeholder when there is a selected option', function(assert) { | ||
assert.expect(1); | ||
|
||
let options = [ | ||
{ key: 'pt', value: 'Portugal' }, | ||
{ key: 'it', value: 'Italy' }, | ||
{ key: 'nl', value: 'Nederlands' }, | ||
{ key: 'en', value: 'England' } | ||
]; | ||
this.set('options', options); | ||
this.set('selected', this.get('options.firstObject.key')); | ||
this.render(hbs`{{uni-select options=options selected=selected placeholder=placeholder}}`); | ||
|
||
this.render(hbs`{{uni-select options=options}}`); | ||
assert.ok(findAll('.uni-select__option').length, 4, 'It renders the four options and ignores the placeholder'); | ||
}); | ||
|
||
test('It renders disabled options', function(assert) { | ||
assert.expect(1); | ||
|
||
this.render(hbs`{{uni-select options=disabledOptions placeholder=placeholder}}`); | ||
|
||
assert.ok(findAll('.uni-select__option:disabled').length, 2, 'It renders the two disabled options'); | ||
}); | ||
|
||
test('It renders the yielded content', function(assert) { | ||
assert.expect(this.get('options.length')); | ||
|
||
this.render(hbs` | ||
{{#uni-select options=options as |option|}} | ||
{{option.key}} | ||
{{/uni-select}} | ||
`); | ||
|
||
let options = findAll('.uni-select__option'); | ||
|
||
assert.notEqual(this.$().text().trim(), ''); | ||
this.get('options').forEach(({ key }, index) => { | ||
assert.ok(options[index].textContent.trim(), key, 'It renders the option key as the yielded content'); | ||
}); | ||
}); | ||
|
||
test('it renders placeholder - useAlias', function(assert) { | ||
test('It renders placeholder using the useAlias flag', function(assert) { | ||
assert.expect(2); | ||
|
||
let options = [ | ||
{ key: 1, value: 'long explanation for one', alias: 'one' }, | ||
{ key: 2, value: 'long explanation for two', alias: 'two' } | ||
]; | ||
this.set('options', options); | ||
this.set('useAlias', true); | ||
this.set('placeholder', 'Pick me!'); | ||
|
||
this.render(hbs`{{uni-select options=options useAlias=useAlias placeholder=placeholder}}`); | ||
this.render(hbs`{{uni-select options=aliasOptions useAlias=useAlias placeholder=placeholder}}`); | ||
|
||
assert.equal(this.$('select.uni-select').val(), null); | ||
assert.equal(this.$('div.uni-select').text().trim(), 'Pick me!'); | ||
assert.equal(find('div.uni-select').textContent.trim(), 'Pick me!'); | ||
}); | ||
|
||
test('it renders right value with no placeholder - useAlias', function(assert) { | ||
test('It renders the first available value when a placeholder is not provided and the useAlias flag is set to true', function(assert) { | ||
assert.expect(2); | ||
|
||
let options = [ | ||
{ key: 1, value: 'long explanation for one', alias: 'one' }, | ||
{ key: 2, value: 'long explanation for two', alias: 'two' } | ||
]; | ||
this.set('options', options); | ||
this.set('useAlias', true); | ||
|
||
this.render(hbs`{{uni-select options=options useAlias=useAlias}}`); | ||
this.render(hbs`{{uni-select options=aliasOptions useAlias=useAlias}}`); | ||
|
||
assert.equal(this.$('select.uni-select').val(), 1); | ||
assert.equal(this.$('div.uni-select').text().trim(), 'one'); | ||
assert.equal(find('div.uni-select').textContent.trim(), 'one'); | ||
}); | ||
|
||
test('it renders selected alias - useAlias', function(assert) { | ||
test('It renders the alias of the selected option', function(assert) { | ||
assert.expect(2); | ||
|
||
let options = [ | ||
{ key: 1, value: 'long explanation for one', alias: 'one' }, | ||
{ key: 2, value: 'long explanation for two', alias: 'two' } | ||
]; | ||
this.set('options', options); | ||
this.set('useAlias', true); | ||
this.set('placeholder', 'Pick me!'); | ||
this.set('selected', 2); | ||
|
||
this.render(hbs`{{uni-select options=options useAlias=useAlias selected=selected placeholder=placeholder}}`); | ||
this.render(hbs`{{uni-select options=aliasOptions useAlias=useAlias selected=selected placeholder=placeholder}}`); | ||
|
||
assert.equal(this.$('select.uni-select').val(), 2); | ||
assert.equal(this.$('div.uni-select').text().trim(), 'two'); | ||
assert.equal(find('div.uni-select').textContent.trim(), 'two'); | ||
}); |