From 8cb9d9ecf3a9c73b05dbb1e1ad0fce04611898b1 Mon Sep 17 00:00:00 2001 From: Ava Wroten Date: Sun, 15 Mar 2020 15:35:42 -0500 Subject: [PATCH] Weee more tests --- ember-ui/app/components/meal-list.hbs | 1 + .../components/sortable-item-accessible.hbs | 4 +- .../integration/components/meal-list-test.js | 25 ++++++- .../sortable-item-accessible-test.js | 70 ++++++++++++++++++- 4 files changed, 95 insertions(+), 5 deletions(-) diff --git a/ember-ui/app/components/meal-list.hbs b/ember-ui/app/components/meal-list.hbs index 78b0180..11f7545 100644 --- a/ember-ui/app/components/meal-list.hbs +++ b/ember-ui/app/components/meal-list.hbs @@ -3,6 +3,7 @@ @models={{this.sortedItems}} tabindex="0" class="shadow-md bg-gray-200 outline-none border border-gray-400 focus:border-teal-400 focus:shadow-lg" + data-test-id='meal-list-wrapper' as |groupHasFocus selectedIndex groupActions|> + data-test-id='sort-up'> {{/if}} diff --git a/ember-ui/tests/integration/components/meal-list-test.js b/ember-ui/tests/integration/components/meal-list-test.js index 2bb91c9..91ffb4a 100644 --- a/ember-ui/tests/integration/components/meal-list-test.js +++ b/ember-ui/tests/integration/components/meal-list-test.js @@ -1,7 +1,7 @@ import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; import { setupMirage } from 'ember-cli-mirage/test-support'; -import { render } from '@ember/test-helpers'; +import { render, find, findAll, click, settled } from '@ember/test-helpers'; import { hbs } from 'ember-cli-htmlbars'; module('Integration | Component | meal-list', function(hooks) { @@ -16,7 +16,28 @@ module('Integration | Component | meal-list', function(hooks) { assert.dom('[data-test-id=meal-item]').exists({ count: 2 }); }); - // TODO Add sortable tests + test('it can focus list wrapper', async function(assert) { + await render(hbs``); + let element = find('[data-test-id=meal-list-wrapper]') + await element.focus(); + + assert.equal(element, document.activeElement); + }); + + test('it can reorder items via sort up/down links', async function(assert) { + await render(hbs``); + let element = find('[data-test-id=meal-list-wrapper]') + await element.focus(); + await settled(); + await click('[data-test-id=sort-down]'); + + assert.dom(findAll('[data-test-id=meal-name]')[0]).includesText('Meal 2'); + assert.dom(findAll('[data-test-id=meal-name]')[1]).includesText('Meal 1'); + + await click('[data-test-id=sort-up]'); + assert.dom(findAll('[data-test-id=meal-name]')[0]).includesText('Meal 1'); + assert.dom(findAll('[data-test-id=meal-name]')[1]).includesText('Meal 2'); + }); async function initMeals() { let store = this.owner.lookup('service:store'); diff --git a/ember-ui/tests/integration/components/sortable-item-accessible-test.js b/ember-ui/tests/integration/components/sortable-item-accessible-test.js index b50d5de..6c47cbf 100644 --- a/ember-ui/tests/integration/components/sortable-item-accessible-test.js +++ b/ember-ui/tests/integration/components/sortable-item-accessible-test.js @@ -1,6 +1,6 @@ import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; -import { render } from '@ember/test-helpers'; +import { render, click } from '@ember/test-helpers'; import { hbs } from 'ember-cli-htmlbars'; module('Integration | Component | sortable-item-accessible', function(hooks) { @@ -15,4 +15,72 @@ module('Integration | Component | sortable-item-accessible', function(hooks) { assert.equal(this.element.textContent.trim(), 'yielded text'); }); + + test('it does not yield sort buttons by default', async function(assert) { + await render(hbs``); + + assert.dom('[data-test-id=sort-up]').doesNotExist(); + assert.dom('[data-test-id=sort-down]').doesNotExist(); + }); + + test('it does not yield sort buttons if group does not have focus', async function(assert) { + await render(hbs` + + `); + + assert.dom('[data-test-id=sort-up]').doesNotExist(); + assert.dom('[data-test-id=sort-down]').doesNotExist(); + }); + + test('it does not yield sort buttons if indices dont match', async function(assert) { + await render(hbs` + + `); + + assert.dom('[data-test-id=sort-up]').doesNotExist(); + assert.dom('[data-test-id=sort-down]').doesNotExist(); + }); + + test('it shows sort buttons when group has focus and indicies match', async function(assert) { + this.mockFunction = () => {}; + + await render(hbs` + + `); + + assert.dom('[data-test-id=sort-up]').exists(); + assert.dom('[data-test-id=sort-down]').exists(); + }); + + test('it handles actions', async function(assert) { + this.mockUp = () => { assert.step('up'); }; + this.mockDown = () => { assert.step('down'); }; + this.mockBlur = () => { assert.step('blur'); }; + + await render(hbs` + + `); + + await click('[data-test-id=sort-up]'); + await click('[data-test-id=sort-down]'); + + assert.verifySteps(['up', 'blur', 'down']); + }); });