2021-03-31 22:34:20 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import { render } from '@ember/test-helpers';
|
|
|
|
import { hbs } from 'ember-cli-htmlbars';
|
|
|
|
|
|
|
|
const template = hbs`
|
2022-10-18 15:46:02 +00:00
|
|
|
{{#if (is-empty-value this.inputValue hasDefault=this.defaultValue)}}
|
2021-03-31 22:34:20 +00:00
|
|
|
Empty
|
|
|
|
{{else}}
|
|
|
|
Full
|
|
|
|
{{/if}}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const emptyObject = {};
|
|
|
|
|
|
|
|
const nonEmptyObject = { thing: 0 };
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Integration | Helper | is-empty-value', function (hooks) {
|
2021-03-31 22:34:20 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it is truthy if the value evaluated is undefined and no default', async function (assert) {
|
2021-03-31 22:34:20 +00:00
|
|
|
this.set('inputValue', undefined);
|
2021-10-14 20:14:33 +00:00
|
|
|
this.set('defaultValue', false);
|
2021-03-31 22:34:20 +00:00
|
|
|
|
|
|
|
await render(template);
|
|
|
|
|
2021-04-26 16:23:57 +00:00
|
|
|
assert.dom(this.element).hasText('Empty');
|
2021-03-31 22:34:20 +00:00
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it is truthy if the value evaluated is an empty string and no default', async function (assert) {
|
2021-03-31 22:34:20 +00:00
|
|
|
this.set('inputValue', '');
|
2021-10-14 20:14:33 +00:00
|
|
|
this.set('defaultValue', false);
|
2021-03-31 22:34:20 +00:00
|
|
|
|
|
|
|
await render(template);
|
|
|
|
|
2021-04-26 16:23:57 +00:00
|
|
|
assert.dom(this.element).hasText('Empty');
|
2021-03-31 22:34:20 +00:00
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it is truthy if the value evaluated is an empty object and no default', async function (assert) {
|
2021-03-31 22:34:20 +00:00
|
|
|
this.set('inputValue', emptyObject);
|
2021-10-14 20:14:33 +00:00
|
|
|
this.set('defaultValue', false);
|
2021-03-31 22:34:20 +00:00
|
|
|
|
|
|
|
await render(template);
|
|
|
|
|
2021-04-26 16:23:57 +00:00
|
|
|
assert.dom(this.element).hasText('Empty');
|
2021-03-31 22:34:20 +00:00
|
|
|
});
|
2021-10-14 20:14:33 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it is falsy if the value evaluated is not an empty object and no default', async function (assert) {
|
2021-03-31 22:34:20 +00:00
|
|
|
this.set('inputValue', nonEmptyObject);
|
2021-10-14 20:14:33 +00:00
|
|
|
this.set('defaultValue', false);
|
2021-03-31 22:34:20 +00:00
|
|
|
|
|
|
|
await render(template);
|
|
|
|
|
2021-04-26 16:23:57 +00:00
|
|
|
assert.dom(this.element).hasText('Full');
|
2021-03-31 22:34:20 +00:00
|
|
|
});
|
2021-10-14 20:14:33 +00:00
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it is falsy if the value evaluated is empty but a default exists', async function (assert) {
|
2021-10-14 20:14:33 +00:00
|
|
|
this.set('defaultValue', 'Some default');
|
|
|
|
this.set('inputValue', emptyObject);
|
|
|
|
|
|
|
|
await render(template);
|
|
|
|
assert.dom(this.element).hasText('Full', 'shows default when value is empty object');
|
|
|
|
|
|
|
|
this.set('inputValue', '');
|
|
|
|
await render(template);
|
|
|
|
assert.dom(this.element).hasText('Full', 'shows default when value is empty string');
|
|
|
|
|
|
|
|
this.set('inputValue', undefined);
|
|
|
|
await render(template);
|
|
|
|
assert.dom(this.element).hasText('Full', 'shows default when value is undefined');
|
|
|
|
});
|
2021-03-31 22:34:20 +00:00
|
|
|
});
|