|
1 | 1 | import { module, test } from 'qunit'; |
2 | 2 | import { setupRenderingTest } from 'dummy/tests/helpers'; |
3 | | -import { click, render } from '@ember/test-helpers'; |
| 3 | +import { click, render, settled } from '@ember/test-helpers'; |
4 | 4 | import { hbs } from 'ember-cli-htmlbars'; |
5 | 5 |
|
6 | 6 | module('Integration | Component | tab-navigation', function (hooks) { |
@@ -98,6 +98,59 @@ module('Integration | Component | tab-navigation', function (hooks) { |
98 | 98 | assert.dom('[data-tab-navigation-more]').doesNotExist(); |
99 | 99 | }); |
100 | 100 |
|
| 101 | + test('it preserves uncontrolled active tab when tabs are refreshed with the same ids', async function (assert) { |
| 102 | + this.set('tabs', [ |
| 103 | + { id: 'overview', label: 'Overview' }, |
| 104 | + { id: 'positions', label: 'Positions' }, |
| 105 | + { id: 'devices', label: 'Devices' }, |
| 106 | + ]); |
| 107 | + |
| 108 | + await render(hbs` |
| 109 | + <TabNavigation @tabs={{this.tabs}} as |activeTab|> |
| 110 | + {{activeTab.label}} |
| 111 | + </TabNavigation> |
| 112 | + `); |
| 113 | + |
| 114 | + await click('[role="tab"][data-tab-id="positions"]'); |
| 115 | + assert.dom('.tab-content').hasText('Positions'); |
| 116 | + |
| 117 | + this.set('tabs', [ |
| 118 | + { id: 'overview', label: 'Overview refreshed' }, |
| 119 | + { id: 'positions', label: 'Positions refreshed' }, |
| 120 | + { id: 'devices', label: 'Devices refreshed' }, |
| 121 | + ]); |
| 122 | + await settled(); |
| 123 | + |
| 124 | + assert.dom('.tab-content').hasText('Positions refreshed'); |
| 125 | + assert.dom('[role="tab"][data-tab-id="positions"]').hasClass('tab-item--active'); |
| 126 | + }); |
| 127 | + |
| 128 | + test('it falls back to the first tab when uncontrolled active tab is removed', async function (assert) { |
| 129 | + this.set('tabs', [ |
| 130 | + { id: 'overview', label: 'Overview' }, |
| 131 | + { id: 'positions', label: 'Positions' }, |
| 132 | + { id: 'devices', label: 'Devices' }, |
| 133 | + ]); |
| 134 | + |
| 135 | + await render(hbs` |
| 136 | + <TabNavigation @tabs={{this.tabs}} as |activeTab|> |
| 137 | + {{activeTab.label}} |
| 138 | + </TabNavigation> |
| 139 | + `); |
| 140 | + |
| 141 | + await click('[role="tab"][data-tab-id="positions"]'); |
| 142 | + assert.dom('.tab-content').hasText('Positions'); |
| 143 | + |
| 144 | + this.set('tabs', [ |
| 145 | + { id: 'overview', label: 'Overview refreshed' }, |
| 146 | + { id: 'devices', label: 'Devices refreshed' }, |
| 147 | + ]); |
| 148 | + await settled(); |
| 149 | + |
| 150 | + assert.dom('.tab-content').hasText('Overview refreshed'); |
| 151 | + assert.dom('[role="tab"][data-tab-id="overview"]').hasClass('tab-item--active'); |
| 152 | + }); |
| 153 | + |
101 | 154 | test('it moves overflowing array tabs into a More menu', async function (assert) { |
102 | 155 | availableWidth = 142; |
103 | 156 | this.set('tabs', [ |
|
0 commit comments