|
1 | 1 | import { render } from '@1024pix/ember-testing-library'; |
2 | | -import { click, triggerKeyEvent } from '@ember/test-helpers'; |
| 2 | +import { click, settled, triggerEvent, triggerKeyEvent } from '@ember/test-helpers'; |
3 | 3 | import { hbs } from 'ember-cli-htmlbars'; |
4 | 4 | import { t } from 'ember-intl/test-support'; |
5 | 5 | import { module, test } from 'qunit'; |
@@ -167,6 +167,52 @@ module('Integration | Component | user logged menu', function (hooks) { |
167 | 167 | assert.dom(screen.queryByRole('link', { name: t('navigation.user.account') })).doesNotExist(); |
168 | 168 | }); |
169 | 169 |
|
| 170 | + test('should hide user menu when a link is clicked with a pointer device', async function (assert) { |
| 171 | + // given |
| 172 | + const screen = await render(hbs`<UserLoggedMenu />`); |
| 173 | + const buttonMenu = screen.getByRole('button', { |
| 174 | + name: `Hermione ${t('navigation.user-logged-menu.details')}`, |
| 175 | + }); |
| 176 | + await click(buttonMenu); |
| 177 | + |
| 178 | + // when |
| 179 | + const link = screen.getByRole('link', { name: t('navigation.main.help') }); |
| 180 | + link.dispatchEvent(new PointerEvent('click', { bubbles: true, pointerType: 'mouse' })); |
| 181 | + await settled(); |
| 182 | + |
| 183 | + // then |
| 184 | + assert |
| 185 | + .dom( |
| 186 | + screen.getByRole('button', { |
| 187 | + name: `Hermione ${t('navigation.user-logged-menu.details')}`, |
| 188 | + expanded: false, |
| 189 | + }), |
| 190 | + ) |
| 191 | + .exists(); |
| 192 | + }); |
| 193 | + |
| 194 | + test('should keep user menu open when a link is activated with the keyboard', async function (assert) { |
| 195 | + // given |
| 196 | + const screen = await render(hbs`<UserLoggedMenu />`); |
| 197 | + const buttonMenu = screen.getByRole('button', { |
| 198 | + name: `Hermione ${t('navigation.user-logged-menu.details')}`, |
| 199 | + }); |
| 200 | + await click(buttonMenu); |
| 201 | + |
| 202 | + // when |
| 203 | + await triggerEvent(screen.getByRole('link', { name: t('navigation.main.help') }), 'click', { detail: 0 }); |
| 204 | + |
| 205 | + // then |
| 206 | + assert |
| 207 | + .dom( |
| 208 | + screen.getByRole('button', { |
| 209 | + name: `Hermione ${t('navigation.user-logged-menu.details')}`, |
| 210 | + expanded: true, |
| 211 | + }), |
| 212 | + ) |
| 213 | + .exists(); |
| 214 | + }); |
| 215 | + |
170 | 216 | module('Link to "My tests"', function () { |
171 | 217 | module('when user has at least one participation', function (hooks) { |
172 | 218 | hooks.beforeEach(function () { |
|
0 commit comments