|
| 1 | +import { module, test } from 'qunit'; |
| 2 | +import { setupRenderingTest } from 'ember-qunit'; |
| 3 | +import { render, setupOnerror } from '@ember/test-helpers'; |
| 4 | +import { hbs } from 'ember-cli-htmlbars'; |
| 5 | + |
| 6 | +module('Integration | Component | o-s-s/empty-state', function (hooks) { |
| 7 | + setupRenderingTest(hooks); |
| 8 | + |
| 9 | + test('it renders with default properties', async function (assert) { |
| 10 | + await render(hbs`<OSS::EmptyState @title="No Data" @subtitle="Try again later" />`); |
| 11 | + |
| 12 | + assert.dom('div.font-color-gray-900').hasText('No Data'); |
| 13 | + assert.dom('div.font-color-gray-500').hasText('Try again later'); |
| 14 | + }); |
| 15 | + |
| 16 | + test('it renders with a badge icon', async function (assert) { |
| 17 | + this.set('image', 'fa-thumbs-up'); |
| 18 | + await render(hbs`<OSS::EmptyState @title="No Data" @subtitle="Try again later" @badgeIcon={{this.image}} />`); |
| 19 | + |
| 20 | + assert.dom('div.font-color-gray-900').hasText('No Data'); |
| 21 | + assert.dom('div.font-color-gray-500').hasText('Try again later'); |
| 22 | + assert.dom('.upf-badge').exists(); |
| 23 | + }); |
| 24 | + |
| 25 | + test('it supports named-block usage for image', async function (assert) { |
| 26 | + await render(hbs` |
| 27 | + <OSS::EmptyState @title="No Data" @subtitle="Try again later"> |
| 28 | + <:image> |
| 29 | + <img src="/test-image.png" alt="Test Image" /> |
| 30 | + </:image> |
| 31 | + </OSS::EmptyState> |
| 32 | + `); |
| 33 | + |
| 34 | + assert.dom('div.font-color-gray-900').hasText('No Data'); |
| 35 | + assert.dom('div.font-color-gray-500').hasText('Try again later'); |
| 36 | + assert.dom('img').exists(); |
| 37 | + }); |
| 38 | + |
| 39 | + test('it supports named-block usage for actions', async function (assert) { |
| 40 | + await render(hbs` |
| 41 | + <OSS::EmptyState @title="No Data" @subtitle="Try again later"> |
| 42 | + <:actions> |
| 43 | + <button type="button">Retry</button> |
| 44 | + </:actions> |
| 45 | + </OSS::EmptyState> |
| 46 | + `); |
| 47 | + |
| 48 | + assert.dom('div.font-color-gray-900').hasText('No Data'); |
| 49 | + assert.dom('div.font-color-gray-500').hasText('Try again later'); |
| 50 | + assert.dom('button').hasText('Retry'); |
| 51 | + }); |
| 52 | + |
| 53 | + module('component size', function (hooks) { |
| 54 | + test('it applies md sizes by default', async function (assert) { |
| 55 | + await render(hbs`<OSS::EmptyState @title="No Data" @subtitle="Try again later" />`); |
| 56 | + assert.dom('div.font-color-gray-900').hasClass('font-size-lg'); |
| 57 | + assert.dom('div.font-color-gray-500').hasClass('font-size-md'); |
| 58 | + }); |
| 59 | + |
| 60 | + test('it applies md sizes when given a wrong size', async function (assert) { |
| 61 | + await render(hbs`<OSS::EmptyState @title="No Data" @subtitle="Try again later" @size="wrong" />`); |
| 62 | + assert.dom('div.font-color-gray-900').hasClass('font-size-lg'); |
| 63 | + assert.dom('div.font-color-gray-500').hasClass('font-size-md'); |
| 64 | + }); |
| 65 | + |
| 66 | + test('it applies md sizes when specified', async function (assert) { |
| 67 | + await render(hbs`<OSS::EmptyState @title="No Data" @subtitle="Try again later" @size="md" />`); |
| 68 | + assert.dom('div.font-color-gray-900').hasClass('font-size-lg'); |
| 69 | + assert.dom('div.font-color-gray-500').hasClass('font-size-md'); |
| 70 | + }); |
| 71 | + |
| 72 | + test('it applies sm sizes when specified', async function (assert) { |
| 73 | + await render(hbs`<OSS::EmptyState @title="No Data" @subtitle="Try again later" @size="sm" />`); |
| 74 | + assert.dom('div.font-color-gray-900').hasClass('font-size-md'); |
| 75 | + assert.dom('div.font-color-gray-500').hasClass('font-size-sm'); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + module('error management', function (hooks) { |
| 80 | + test('it throws an error if the @title parameter is not passed', async function (assert) { |
| 81 | + setupOnerror((err: any) => { |
| 82 | + assert.equal(err.message, 'Assertion Failed: [component][OSS::EmptyState] The title parameter is mandatory'); |
| 83 | + }); |
| 84 | + |
| 85 | + await render(hbs`<OSS::EmptyState @subtitle="Try again later" />`); |
| 86 | + }); |
| 87 | + |
| 88 | + test('it throws an error if the @subtitle parameter is not passed', async function (assert) { |
| 89 | + setupOnerror((err: any) => { |
| 90 | + assert.equal(err.message, 'Assertion Failed: [component][OSS::EmptyState] The subtitle parameter is mandatory'); |
| 91 | + }); |
| 92 | + |
| 93 | + await render(hbs`<OSS::EmptyState @title="No Data" />`); |
| 94 | + }); |
| 95 | + }); |
| 96 | +}); |
0 commit comments