|
| 1 | +import { click, fillIn, focus, blur, triggerEvent, triggerKeyEvent, waitFor, waitUntil } from '@ember/test-helpers'; |
| 2 | +import { findWithAssert, scrollTo, selectFiles } from 'ember-native-dom-helpers'; |
| 3 | +import { moduleForComponent, test } from 'ember-qunit'; |
| 4 | +import hbs from 'htmlbars-inline-precompile'; |
| 5 | + |
| 6 | +moduleForComponent('foo-bar', 'Integration | Component | foo bar', { |
| 7 | + integration: true |
| 8 | +}); |
| 9 | + |
| 10 | +test('it renders', async function(assert) { |
| 11 | + this.render(hbs`{{foo-bar}}`); |
| 12 | + |
| 13 | + await click('.foo', {}); |
| 14 | + assert.equal(this.element.querySelector('.foo').id, 'foo'); |
| 15 | + await fillIn('.foo input', 'bar'); |
| 16 | + await blur('.foo input'); |
| 17 | + assert.equal(this.element.querySelector('.foo').textContent.trim(), 'foo'); |
| 18 | +}); |
| 19 | + |
| 20 | +test('it renders again', function(assert) { |
| 21 | + this.render(hbs`{{foo-bar}}`); |
| 22 | + |
| 23 | + let selector = '.foo input'; |
| 24 | + assert.equal(this.element.querySelectorAll(selector).length, 1); |
| 25 | + assert.equal(this.element.querySelector(selector).value, 'foo'); |
| 26 | + assert.ok(this.element.querySelector('.foo').classList.contains('selected')); |
| 27 | +}); |
| 28 | + |
| 29 | +test('and again', async function(assert) { |
| 30 | + this.render(hbs`{{foo-bar}}`); |
| 31 | + |
| 32 | + await tap('foo'); |
| 33 | + let el = findWithAssert('.foo input'); |
| 34 | + |
| 35 | + await fillIn(el, value); |
| 36 | + await triggerEvent('.foo input', 'change'); |
| 37 | + await triggerKeyEvent('bar', 'keypress', 13, modifiers); |
| 38 | + |
| 39 | + await focus('.foo input'); |
| 40 | + await blur('.foo input'); |
| 41 | + |
| 42 | + assert.ok(this.element.querySelectorAll('.baz')[1].classList.contains('selected')); |
| 43 | +}); |
| 44 | + |
| 45 | +test('and yet again', async function(assert) { |
| 46 | + this.render(hbs`{{foo-bar}}`); |
| 47 | + |
| 48 | + await scrollTo(document, 10, 20); |
| 49 | + await selectFiles('input[type=file]', [new Blob(['texters'], { type: 'plain/text' })]); |
| 50 | + await waitUntil(() => this.element.querySelector('.foo.active')); |
| 51 | + await waitFor('.bar.selected'); |
| 52 | + assert.ok(true); |
| 53 | +}); |
0 commit comments