|
| 1 | +/** |
| 2 | + * Copyright (c) HashiCorp, Inc. |
| 3 | + * SPDX-License-Identifier: MPL-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import { module, test } from 'qunit'; |
| 7 | +import { setupRenderingTest } from 'ember-qunit'; |
| 8 | +import { render } from '@ember/test-helpers'; |
| 9 | +import { hbs } from 'ember-cli-htmlbars'; |
| 10 | + |
| 11 | +module('Integration | Component | hds/layout/flex/item', function (hooks) { |
| 12 | + setupRenderingTest(hooks); |
| 13 | + |
| 14 | + test('it should render the component with a CSS class that matches the component name', async function (assert) { |
| 15 | + await render(hbs`<Hds::Layout::Flex::Item id="test-layout-flex-item" />`); |
| 16 | + assert.dom('#test-layout-flex-item').hasClass('hds-layout-flex-item'); |
| 17 | + }); |
| 18 | + |
| 19 | + // CONTENT |
| 20 | + |
| 21 | + test('it should render the yielded content', async function (assert) { |
| 22 | + await render( |
| 23 | + hbs`<Hds::Layout::Flex::Item id="test-layout-flex-item"><pre>test</pre></Hds::Layout::Flex::Item>` |
| 24 | + ); |
| 25 | + assert.dom('#test-layout-flex-item > pre').exists().hasText('test'); |
| 26 | + }); |
| 27 | + test('it should render as yielded contextual component', async function (assert) { |
| 28 | + await render( |
| 29 | + hbs`<Hds::Layout::Flex as |LF|><LF.Item id="test-layout-flex-item"><pre>test</pre></LF.Item></Hds::Layout::Flex>` |
| 30 | + ); |
| 31 | + assert.dom('#test-layout-flex-item > pre').exists().hasText('test'); |
| 32 | + }); |
| 33 | + |
| 34 | + // TAG |
| 35 | + |
| 36 | + test('it should render with a "div" element if @tag is not declared', async function (assert) { |
| 37 | + await render( |
| 38 | + hbs`<Hds::Layout::Flex as |LF|><LF.Item id="test-layout-flex-item" /></Hds::Layout::Flex>` |
| 39 | + ); |
| 40 | + assert.dom('#test-layout-flex-item').hasTagName('div'); |
| 41 | + }); |
| 42 | + test('it should render with the correct @tag declared', async function (assert) { |
| 43 | + await render( |
| 44 | + hbs`<Hds::Layout::Flex as |LF|><LF.Item id="test-layout-flex-item" @tag="span" /></Hds::Layout::Flex>` |
| 45 | + ); |
| 46 | + assert.dom('#test-layout-flex-item').hasTagName('span'); |
| 47 | + }); |
| 48 | + |
| 49 | + // BASIS / GROW / SHRINK |
| 50 | + |
| 51 | + test('it should render the element without specific classes or inline styles if no @basis/@grow/@shrink are declared', async function (assert) { |
| 52 | + await render( |
| 53 | + hbs`<Hds::Layout::Flex as |LF|><LF.Item id="test-layout-flex-item" /></Hds::Layout::Flex>` |
| 54 | + ); |
| 55 | + assert |
| 56 | + .dom('#test-layout-flex-item') |
| 57 | + .doesNotHaveClass(/hds-layout-flex-item--grow-/); |
| 58 | + assert |
| 59 | + .dom('#test-layout-flex-item') |
| 60 | + .doesNotHaveClass(/hds-layout-flex-item--shrink-/); |
| 61 | + assert.dom('#test-layout-flex-item').doesNotHaveAttribute('style'); |
| 62 | + }); |
| 63 | + test('it should render the correct CSS class if the @basis prop is declared as 0', async function (assert) { |
| 64 | + await render( |
| 65 | + hbs`<Hds::Layout::Flex as |LF|> |
| 66 | + <LF.Item id="test-layout-flex-item-1" @basis={{0}} /> |
| 67 | + </Hds::Layout::Flex>` |
| 68 | + ); |
| 69 | + assert |
| 70 | + .dom('#test-layout-flex-item-1') |
| 71 | + .doesNotHaveAttribute('style') |
| 72 | + .hasClass('hds-layout-flex-item--basis-0'); |
| 73 | + }); |
| 74 | + test('it should render the correct inline styles if the @basis prop is declared as string', async function (assert) { |
| 75 | + await render( |
| 76 | + hbs`<Hds::Layout::Flex as |LF|> |
| 77 | + <LF.Item id="test-layout-flex-item-1" @basis="5%" /> |
| 78 | + <LF.Item id="test-layout-flex-item-2" @basis="100px" /> |
| 79 | + <LF.Item id="test-layout-flex-item-3" @basis="auto" /> |
| 80 | + <LF.Item id="test-layout-flex-item-4" @basis="max-content" /> |
| 81 | + </Hds::Layout::Flex>` |
| 82 | + ); |
| 83 | + assert |
| 84 | + .dom('#test-layout-flex-item-1') |
| 85 | + .hasAttribute('style', 'flex-basis: 5%;') |
| 86 | + .hasStyle({ flexBasis: '5%' }); |
| 87 | + assert |
| 88 | + .dom('#test-layout-flex-item-2') |
| 89 | + .hasAttribute('style', 'flex-basis: 100px;') |
| 90 | + .hasStyle({ flexBasis: '100px' }); |
| 91 | + assert |
| 92 | + .dom('#test-layout-flex-item-3') |
| 93 | + .hasAttribute('style', 'flex-basis: auto;') |
| 94 | + .hasStyle({ flexBasis: 'auto' }); |
| 95 | + assert |
| 96 | + .dom('#test-layout-flex-item-4') |
| 97 | + .hasAttribute('style', 'flex-basis: max-content;') |
| 98 | + .hasStyle({ flexBasis: 'max-content' }); |
| 99 | + }); |
| 100 | + test('it should render the correct CSS class if the @grow/@shrink props are declared as boolean or 0/1', async function (assert) { |
| 101 | + await render( |
| 102 | + hbs`<Hds::Layout::Flex as |LF|> |
| 103 | + <LF.Item id="test-layout-flex-item-1" @grow={{false}} @shrink={{false}} /> |
| 104 | + <LF.Item id="test-layout-flex-item-2" @grow={{0}} @shrink={{0}} /> |
| 105 | + <LF.Item id="test-layout-flex-item-3" @grow={{true}} @shrink={{true}} /> |
| 106 | + <LF.Item id="test-layout-flex-item-4" @grow={{1}} @shrink={{1}} /> |
| 107 | + </Hds::Layout::Flex>` |
| 108 | + ); |
| 109 | + assert |
| 110 | + .dom('#test-layout-flex-item-1') |
| 111 | + .doesNotHaveAttribute('style') |
| 112 | + .hasClass('hds-layout-flex-item--grow-0') |
| 113 | + .hasClass('hds-layout-flex-item--shrink-0'); |
| 114 | + assert |
| 115 | + .dom('#test-layout-flex-item-2') |
| 116 | + .doesNotHaveAttribute('style') |
| 117 | + .hasClass('hds-layout-flex-item--grow-0') |
| 118 | + .hasClass('hds-layout-flex-item--shrink-0'); |
| 119 | + assert |
| 120 | + .dom('#test-layout-flex-item-3') |
| 121 | + .doesNotHaveAttribute('style') |
| 122 | + .hasClass('hds-layout-flex-item--grow-1') |
| 123 | + .hasClass('hds-layout-flex-item--shrink-1'); |
| 124 | + assert |
| 125 | + .dom('#test-layout-flex-item-4') |
| 126 | + .doesNotHaveAttribute('style') |
| 127 | + .hasClass('hds-layout-flex-item--grow-1') |
| 128 | + .hasClass('hds-layout-flex-item--shrink-1'); |
| 129 | + }); |
| 130 | + test('it should render the correct inline styles if the @grow/@shrink props are declared as strings/numbers', async function (assert) { |
| 131 | + await render( |
| 132 | + hbs`<Hds::Layout::Flex as |LF|> |
| 133 | + <LF.Item id="test-layout-flex-item-1" @grow="0" @shrink="0" /> |
| 134 | + <LF.Item id="test-layout-flex-item-2" @grow="1" @shrink="1" /> |
| 135 | + <LF.Item id="test-layout-flex-item-3" @grow={{2}} @shrink={{2}} /> |
| 136 | + <LF.Item id="test-layout-flex-item-4" @grow="initial" @shrink="initial" /> |
| 137 | + </Hds::Layout::Flex>` |
| 138 | + ); |
| 139 | + assert |
| 140 | + .dom('#test-layout-flex-item-1') |
| 141 | + .hasAttribute('style', 'flex-grow: 0; flex-shrink: 0;') |
| 142 | + .hasStyle({ flexGrow: '0', flexShrink: '0' }); |
| 143 | + assert |
| 144 | + .dom('#test-layout-flex-item-2') |
| 145 | + .hasAttribute('style', 'flex-grow: 1; flex-shrink: 1;') |
| 146 | + .hasStyle({ flexGrow: '1', flexShrink: '1' }); |
| 147 | + assert |
| 148 | + .dom('#test-layout-flex-item-3') |
| 149 | + .hasAttribute('style', 'flex-grow: 2; flex-shrink: 2;') |
| 150 | + .hasStyle({ flexGrow: '2', flexShrink: '2' }); |
| 151 | + assert |
| 152 | + .dom('#test-layout-flex-item-4') |
| 153 | + .hasAttribute('style', 'flex-grow: initial; flex-shrink: initial;') |
| 154 | + // grow=0 and shrink=1 are the CSS defaults (initial) |
| 155 | + .hasStyle({ flexGrow: '0', flexShrink: '1' }); |
| 156 | + }); |
| 157 | + |
| 158 | + // ENABLE COLLAPSE BELOW CONTENT SIZE |
| 159 | + |
| 160 | + test('it should render the element without specific classes if no @enableCollapseBelowContentSize is declared', async function (assert) { |
| 161 | + await render( |
| 162 | + hbs`<Hds::Layout::Flex as |LF|><LF.Item id="test-layout-flex-item" /></Hds::Layout::Flex>` |
| 163 | + ); |
| 164 | + assert |
| 165 | + .dom('#test-layout-flex-item') |
| 166 | + .doesNotHaveClass( |
| 167 | + '.hds-layout-flex-item--enable-collapse-below-content-size' |
| 168 | + ); |
| 169 | + }); |
| 170 | + test('it should render the correct CSS class if the @enableCollapseBelowContentSize prop is declared', async function (assert) { |
| 171 | + await render( |
| 172 | + hbs`<Hds::Layout::Flex as |LF|><LF.Item id="test-layout-flex-item" @enableCollapseBelowContentSize={{true}} /></Hds::Layout::Flex>` |
| 173 | + ); |
| 174 | + assert |
| 175 | + .dom('#test-layout-flex-item') |
| 176 | + .hasClass('hds-layout-flex-item--enable-collapse-below-content-size'); |
| 177 | + }); |
| 178 | +}); |
0 commit comments