decide.nolog.cz/tests/integration/components/create-options-test.js

100 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-12-29 01:27:37 +01:00
import { run } from '@ember/runloop';
2018-12-29 20:35:04 +01:00
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, findAll, blur, fillIn, focus } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
2018-12-29 20:35:04 +01:00
module('Integration | Component | create options', function(hooks) {
setupRenderingTest(hooks);
2018-12-29 20:35:04 +01:00
hooks.beforeEach(function() {
this.store = this.owner.lookup('service:store');
});
2016-02-08 23:46:30 +01:00
2018-12-29 20:35:04 +01:00
test('shows validation errors if options are not unique (makeAPoll)', async function(assert) {
assert.expect(5);
// validation is based on validation of every option fragment
// which validates according to poll model it belongs to
// therefore each option needs to be pushed to poll model to have it as
// it's owner
let poll;
run(() => {
poll = this.store.createRecord('poll', {
2023-10-15 17:32:11 +02:00
pollType: 'MakeAPoll',
2018-12-29 20:35:04 +01:00
});
2016-02-09 01:16:18 +01:00
});
2023-10-15 17:32:11 +02:00
this.set('poll', poll);
2018-12-29 20:35:04 +01:00
this.set('options', poll.get('options'));
2023-10-15 17:32:11 +02:00
await render(hbs`
<CreateOptions
@options={{this.options}}
@isDateTime={{false}}
@isFindADate={{this.poll.isFindADate}}
@isMakeAPoll={{this.poll.isMakeAPoll}}
/>
`);
2018-12-29 20:35:04 +01:00
assert.dom('.form-group').exists({ count: 2 }, 'assumption: renders two form groups');
2018-12-29 20:35:04 +01:00
await fillIn('.form-group:nth-child(1) input', 'foo');
await blur('.form-group:nth-child(1) input');
await fillIn('.form-group:nth-child(2) input', 'foo');
await blur('.form-group:nth-child(2) input');
assert.dom('.form-group:nth-child(2) input')
.hasClass('is-invalid', 'second input field has validation error');
assert.dom('.form-group:nth-child(2) .invalid-feedback')
.exists('validation error is shown');
2018-12-29 20:35:04 +01:00
await fillIn(findAll('input')[0], 'bar');
await blur(findAll('input')[0]);
assert.dom('.form-group .invalid-feedback')
.doesNotExist('there is no validation error anymore after a unique value is entered');
assert.dom('.form-group .is-invalid')
.doesNotExist('.is-invalid classes are removed');
2016-02-09 01:16:18 +01:00
});
2018-12-29 20:35:04 +01:00
test('shows validation errors if option is empty (makeAPoll)', async function(assert) {
// validation is based on validation of every option fragment
// which validates according to poll model it belongs to
// therefore each option needs to be pushed to poll model to have it as
// it's owner
let poll;
run(() => {
poll = this.store.createRecord('poll', {
2023-10-15 17:32:11 +02:00
pollType: 'MakeAPoll',
2018-12-29 20:35:04 +01:00
});
2016-02-09 01:16:18 +01:00
});
2023-10-15 17:32:11 +02:00
this.set('poll', poll);
2018-12-29 20:35:04 +01:00
this.set('options', poll.get('options'));
2023-10-15 17:32:11 +02:00
await render(hbs`
<CreateOptions
@options={{this.options}}
@isDateTime={{false}}
@isFindADate={{this.poll.isFindADate}}
@isMakeAPoll={{this.poll.isMakeAPoll}}
/>
`);
2018-12-29 20:35:04 +01:00
assert.equal(
findAll('.form-group.has-error').length, 0
);
await focus(findAll('input')[0]);
await blur(findAll('input')[0]);
await focus(findAll('input')[1]);
await blur(findAll('input')[1]);
assert.dom('.form-group .invalid-feedback').exists({ count: 2 });
2018-12-29 20:35:04 +01:00
await fillIn(findAll('input')[0], 'foo');
await blur(findAll('input')[0]);
assert.dom('.form-group .invalid-feedback').exists({ count: 1 });
2018-12-29 20:35:04 +01:00
await fillIn(findAll('input')[1], 'bar');
await blur(findAll('input')[1]);
assert.dom('.form-group .invalid-feedback').doesNotExist();
2016-02-09 01:16:18 +01:00
});
2016-02-08 23:46:30 +01:00
});