Skip to content

Commit

Permalink
Modernize test suite part 1 (#1089)
Browse files Browse the repository at this point in the history
  • Loading branch information
cibernox authored Apr 15, 2018
1 parent 51e4411 commit 26ccb12
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 229 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"loader.js": "^4.6.0",
"memory-scroll": "0.9.1",
"mocha": "2.5.3",
"qunit-dom": "^0.6.2",
"simple-git": "^1.10.0",
"testdouble": "^3.2.6"
},
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/all-public-pages-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, module } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { visit, click, currentURL } from '@ember/test-helpers';
import { find } from 'ember-native-dom-helpers';
import { find } from '@ember/test-helpers';

module('Acceptance | All Public Pages', function(hooks) {
setupApplicationTest(hooks);
Expand Down
105 changes: 52 additions & 53 deletions tests/acceptance/helpers-test.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions tests/integration/components/power-select/a11y-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { numbers, groupedNumbers, countriesWithDisabled } from '../constants';
import { clickTrigger, findContains } from 'ember-power-select/test-support/helpers';
import { find, findAll, keyEvent } from 'ember-native-dom-helpers';
import { triggerKeyEvent } from '@ember/test-helpers';
import { find, findAll } from 'ember-native-dom-helpers';

module('Integration | Component | Ember Power Select (Accesibility)', function(hooks) {
setupRenderingTest(hooks);
Expand Down Expand Up @@ -117,7 +118,7 @@ module('Integration | Component | Ember Power Select (Accesibility)', function(h
clickTrigger();
assert.equal(findContains('.ember-power-select-option', 'one').attributes['aria-current'].value, 'true', 'the highlighted option has aria-current=true');
assert.equal(findAll('.ember-power-select-option[aria-current="false"]').length, numbers.length - 1, 'All other options have aria-current=false');
keyEvent('.ember-power-select-search-input', 'keydown', 40);
await triggerKeyEvent('.ember-power-select-search-input', 'keydown', 40);
assert.equal(findContains('.ember-power-select-option', 'one').attributes['aria-current'].value, 'false', 'the first option has now aria-current=false');
assert.equal(findContains('.ember-power-select-option', 'two').attributes['aria-current'].value, 'true', 'the second option has now aria-current=false');
});
Expand All @@ -135,7 +136,7 @@ module('Integration | Component | Ember Power Select (Accesibility)', function(h
clickTrigger();
assert.equal(findContains('.ember-power-select-option', 'one').attributes['aria-current'].value, 'true', 'the highlighted option has aria-current=true');
assert.equal(findAll('.ember-power-select-option[aria-current="false"]').length, numbers.length - 1, 'All other options have aria-current=false');
keyEvent('.ember-power-select-search-input', 'keydown', 40);
await triggerKeyEvent('.ember-power-select-search-input', 'keydown', 40);
assert.equal(findContains('.ember-power-select-option', 'one').attributes['aria-current'].value, 'false', 'the first option has now aria-current=false');
assert.equal(findContains('.ember-power-select-option', 'two').attributes['aria-current'].value, 'true', 'the second option has now aria-current=false');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { render, settled } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { typeInSearch, clickTrigger } from 'ember-power-select/test-support/helpers';
import { numbers, countries } from '../constants';
import { find, findAll, click } from 'ember-native-dom-helpers';
import { click } from '@ember/test-helpers';
import { find, findAll } from 'ember-native-dom-helpers';
import RSVP from 'rsvp';

module('Integration | Component | Ember Power Select (Custom search function)', function(hooks) {
Expand Down Expand Up @@ -320,13 +321,13 @@ module('Integration | Component | Ember Power Select (Custom search function)',
{{/power-select}}
`);

clickTrigger();
await clickTrigger();
typeInSearch('teen');
assert.equal(findAll('.ember-power-select-option').length, 7, 'Results are filtered');
assert.equal(find('.ember-power-select-search-input').value, 'teen');
click('#different-node');
await click('#different-node');

clickTrigger();
await clickTrigger();
assert.equal(findAll('.ember-power-select-option').length, 1, 'Results have been cleared');
assert.equal(find('.ember-power-select-option').textContent.trim(), 'Type to search');
assert.equal(find('.ember-power-select-search-input').value, '', 'The searchbox was cleared');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import hbs from 'htmlbars-inline-precompile';
import { countries } from '../constants';
import { groupedNumbers } from '../constants';
import { clickTrigger } from 'ember-power-select/test-support/helpers';
import { find, findAll, click, focus } from 'ember-native-dom-helpers';
import { click, focus } from '@ember/test-helpers';
import { find, findAll } from 'ember-native-dom-helpers';
import { get } from '@ember/object';
import Component from '@ember/component';
import { isPresent } from '@ember/utils';
Expand Down Expand Up @@ -161,9 +162,9 @@ module('Integration | Component | Ember Power Select (Customization using compon
{{/power-select}}
`);

clickTrigger();
click('.custom-before-options2-button');
click('.custom-after-options2-button');
await clickTrigger();
await click('.custom-before-options2-button');
await click('.custom-after-options2-button');
assert.equal(counter, 2, 'The action inside the extra hash has been called twice');
});

Expand Down
41 changes: 21 additions & 20 deletions tests/integration/components/power-select/disabled-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import hbs from 'htmlbars-inline-precompile';
import { run } from '@ember/runloop';
import { clickTrigger, typeInSearch } from 'ember-power-select/test-support/helpers';
import { numbers, countriesWithDisabled } from '../constants';
import { find, findAll, triggerEvent, keyEvent, click, focus } from 'ember-native-dom-helpers';
import { triggerEvent, triggerKeyEvent, click, focus } from '@ember/test-helpers';
import { find, findAll } from 'ember-native-dom-helpers';

module('Integration | Component | Ember Power Select (Disabled)', function(hooks) {
setupRenderingTest(hooks);
Expand All @@ -22,9 +23,9 @@ module('Integration | Component | Ember Power Select (Disabled)', function(hooks

let trigger = find('.ember-power-select-trigger');
assert.ok(trigger.attributes['aria-disabled'].value, 'true', 'The trigger has `aria-disabled=true`');
clickTrigger();
await clickTrigger();
assert.notOk(find('.ember-power-select-dropdown'), 'The select is still closed');
keyEvent('.ember-power-select-trigger', 'keydown', 13);
await triggerKeyEvent('.ember-power-select-trigger', 'keydown', 13);
assert.notOk(find('.ember-power-select-dropdown'), 'The select is still closed');
});

Expand All @@ -50,8 +51,8 @@ module('Integration | Component | Ember Power Select (Disabled)', function(hooks
{{/power-select}}
`);

clickTrigger();
triggerEvent('.ember-power-select-option[aria-disabled="true"]', 'mouseover');
await clickTrigger();
await triggerEvent('.ember-power-select-option[aria-disabled="true"]', 'mouseover');
assert.equal(find('.ember-power-select-option[aria-disabled="true"]').attributes['aria-current'].value, 'false', 'The hovered option was not highlighted because it\'s disabled');
});

Expand All @@ -65,9 +66,9 @@ module('Integration | Component | Ember Power Select (Disabled)', function(hooks
{{/power-select}}
`);

clickTrigger();
keyEvent('.ember-power-select-search-input', 'keydown', 40);
keyEvent('.ember-power-select-search-input', 'keydown', 40);
await clickTrigger();
await triggerKeyEvent('.ember-power-select-search-input', 'keydown', 40);
await triggerKeyEvent('.ember-power-select-search-input', 'keydown', 40);
assert.equal(find('.ember-power-select-option[aria-current="true"]').textContent.trim(), 'LV: Latvia', 'The hovered option was not highlighted because it\'s disabled');
});

Expand Down Expand Up @@ -129,10 +130,10 @@ module('Integration | Component | Ember Power Select (Disabled)', function(hooks
{{/power-select}}
`);

clickTrigger();
await clickTrigger();
typeInSearch('Br');
assert.notOk(find('.ember-power-select-option[aria-current="true"]'), 'Nothing is highlighted');
keyEvent('.ember-power-select-search-input', 'keydown', 13);
await triggerKeyEvent('.ember-power-select-search-input', 'keydown', 13);
assert.notOk(find('.ember-power-select-dropdown'), 'The select is closed');
assert.equal(find('.ember-power-select-trigger').textContent.trim(), '', 'Nothing was selected');
});
Expand All @@ -147,7 +148,7 @@ module('Integration | Component | Ember Power Select (Disabled)', function(hooks
{{/power-select}}
`);

clickTrigger();
await clickTrigger();
typeInSearch('o'); // Finds ["Portugal", "United Kingdom"]
assert.equal(findAll('.ember-power-select-option').length, 2, 'There is two results');
assert.equal(findAll('.ember-power-select-option[aria-disabled="true"]').length, 1, 'One is disabled');
Expand All @@ -167,9 +168,9 @@ module('Integration | Component | Ember Power Select (Disabled)', function(hooks
`);

let trigger = find('.ember-power-select-trigger');
focus(trigger);
await focus(trigger);
assert.notOk(find('.ember-power-select-dropdown'), 'The dropdown is closed');
keyEvent(trigger, 'keydown', 85); // u
await triggerKeyEvent(trigger, 'keydown', 85); // u
assert.notOk(find('.ember-power-select-dropdown'), 'The dropdown is still closed');
assert.equal(trigger.textContent.trim(), 'United Kingdom', '"United Kingdom" has been selected');
});
Expand Down Expand Up @@ -199,7 +200,7 @@ module('Integration | Component | Ember Power Select (Disabled)', function(hooks
{{/power-select}}
`);

clickTrigger();
await clickTrigger();
assert.equal(findAll('.ember-power-select-group[aria-disabled="true"]').length, 1, 'one group is disabled');
typeInSearch('fiv');
assert.equal(findAll('.ember-power-select-group[aria-disabled="true"]').length, 1, 'one group is still disabled');
Expand Down Expand Up @@ -231,12 +232,12 @@ module('Integration | Component | Ember Power Select (Disabled)', function(hooks
{{/power-select}}
`);

clickTrigger();
await clickTrigger();
assert.equal(find('.ember-power-select-option[aria-current="true"]').textContent.trim(), 'one');
assert.notOk(find('.ember-power-select-option[aria-selected="true"]'), 'No option is selected');
triggerEvent(findAll('.ember-power-select-option')[8], 'mouseover');
await triggerEvent(findAll('.ember-power-select-option')[8], 'mouseover');
assert.equal(find('.ember-power-select-option[aria-current="true"]').textContent.trim(), 'one');
click(findAll('.ember-power-select-option')[9]);
await click(findAll('.ember-power-select-option')[9]);
assert.notOk(find('.ember-power-select-option[aria-selected="true"]'), 'Noting was selected');
});

Expand Down Expand Up @@ -268,7 +269,7 @@ module('Integration | Component | Ember Power Select (Disabled)', function(hooks
{{/power-select}}
`);

clickTrigger();
await clickTrigger();
assert.ok(find('.ember-power-select-dropdown'), 'The select is open');
run(() => this.set('isDisabled', true));
assert.notOk(find('.ember-power-select-dropdown'), 'The select is now closed');
Expand All @@ -284,8 +285,8 @@ module('Integration | Component | Ember Power Select (Disabled)', function(hooks
{{/power-select}}
`);

clickTrigger();
click(findAll('.ember-power-select-option')[1]);
await clickTrigger();
await click(findAll('.ember-power-select-option')[1]);
assert.equal(find('.ember-power-select-trigger').textContent.trim(), 'two', 'The option is selected');
assert.equal(find('.ember-power-select-trigger').attributes['aria-disabled'].value, 'true');
});
Expand Down
Loading

0 comments on commit 26ccb12

Please sign in to comment.