open-vault/ui/tests/integration/components/toggle-button-test.js

33 lines
1.4 KiB
JavaScript
Raw Normal View History

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, click, find } from '@ember/test-helpers';
2018-04-03 14:16:57 +00:00
import hbs from 'htmlbars-inline-precompile';
module('Integration | Component | toggle button', function(hooks) {
setupRenderingTest(hooks);
2018-04-03 14:16:57 +00:00
test('toggle functionality', async function(assert) {
this.set('toggleTarget', {});
2018-04-03 14:16:57 +00:00
await render(hbs`{{toggle-button toggleTarget=toggleTarget toggleAttr="toggled"}}`);
2018-04-03 14:16:57 +00:00
assert.equal(find('button').textContent.trim(), 'More options', 'renders default closedLabel');
2018-04-03 14:16:57 +00:00
await click('button');
assert.equal(this.get('toggleTarget.toggled'), true, 'it toggles the attr on the target');
assert.equal(find('button').textContent.trim(), 'Hide options', 'renders default openLabel');
await click('button');
assert.equal(this.get('toggleTarget.toggled'), false, 'it toggles the attr on the target');
2018-04-03 14:16:57 +00:00
this.set('closedLabel', 'Open the options!');
this.set('openLabel', 'Close the options!');
await render(
hbs`{{toggle-button toggleTarget=toggleTarget toggleAttr="toggled" closedLabel=closedLabel openLabel=openLabel}}`
);
2018-04-03 14:16:57 +00:00
assert.equal(find('button').textContent.trim(), 'Open the options!', 'renders passed closedLabel');
await click('button');
assert.equal(find('button').textContent.trim(), 'Close the options!', 'renders passed openLabel');
});
2018-04-03 14:16:57 +00:00
});