|
1 | 1 | import { module, test } from 'qunit'; |
2 | 2 | import { setupIntl } from 'ember-intl/test-support'; |
3 | 3 | import { setupRenderingTest } from 'ember-qunit'; |
4 | | -import { render } from '@ember/test-helpers'; |
| 4 | +import { render, settled } from '@ember/test-helpers'; |
| 5 | +// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 6 | +import { tracked } from '@glimmer/tracking'; |
5 | 7 | import ExerciseSteps from 'brn/components/exercise-steps'; |
6 | 8 |
|
| 9 | +// Helper: walk through LISTEN → INTERACT so `setLastMode` populates |
| 10 | +// the component's internal `modes` array with both entries. Without |
| 11 | +// this, modeForTask stays DISABLED regardless of interactReady and |
| 12 | +// STATE_LOCKED wins in taskBtnClass. |
| 13 | +class StepState { |
| 14 | + @tracked step = 'listen'; |
| 15 | + @tracked ready = false; |
| 16 | +} |
| 17 | + |
| 18 | +async function walkToInteract(state) { |
| 19 | + state.step = 'interact'; |
| 20 | + await settled(); |
| 21 | +} |
| 22 | + |
7 | 23 | module('Integration | Component | exercise-steps', function (hooks) { |
8 | 24 | setupRenderingTest(hooks); |
9 | 25 | setupIntl(hooks, 'en-us'); |
10 | 26 |
|
11 | | - test('it renders', async function (assert) { |
12 | | - // Set any properties with this.set('myProperty', 'value'); |
13 | | - // Handle any actions with this.set('myAction', function(val) { ... }); |
14 | | - |
| 27 | + test('it renders three step buttons', async function (assert) { |
15 | 28 | await render(<template><ExerciseSteps /></template>); |
16 | 29 |
|
17 | 30 | assert.dom('button').exists({ count: 3 }); |
18 | 31 | }); |
| 32 | + |
| 33 | + test('solve button gets the "next" style once interactReady is true during Interact', async function (assert) { |
| 34 | + const state = new StepState(); |
| 35 | + await render( |
| 36 | + <template> |
| 37 | + <ExerciseSteps |
| 38 | + @activeStep={{state.step}} |
| 39 | + @visible={{true}} |
| 40 | + @interactReady={{state.ready}} |
| 41 | + /> |
| 42 | + </template>, |
| 43 | + ); |
| 44 | + |
| 45 | + await walkToInteract(state); |
| 46 | + state.ready = true; |
| 47 | + await settled(); |
| 48 | + |
| 49 | + assert |
| 50 | + .dom('button:nth-of-type(3)') |
| 51 | + .hasClass('exercise-step-btn--next', 'solve button lights up as next step'); |
| 52 | + }); |
| 53 | + |
| 54 | + test('solve button stays default when interactReady is false during Interact', async function (assert) { |
| 55 | + const state = new StepState(); |
| 56 | + await render( |
| 57 | + <template> |
| 58 | + <ExerciseSteps |
| 59 | + @activeStep={{state.step}} |
| 60 | + @visible={{true}} |
| 61 | + @interactReady={{state.ready}} |
| 62 | + /> |
| 63 | + </template>, |
| 64 | + ); |
| 65 | + |
| 66 | + await walkToInteract(state); |
| 67 | + |
| 68 | + assert |
| 69 | + .dom('button:nth-of-type(3)') |
| 70 | + .doesNotHaveClass( |
| 71 | + 'exercise-step-btn--next', |
| 72 | + 'solve button is not highlighted yet', |
| 73 | + ); |
| 74 | + }); |
| 75 | + |
| 76 | + test('solve button exposes the ready-when-you-are hint via title', async function (assert) { |
| 77 | + // ember-intl in this test env returns the `t:<key>` placeholder when |
| 78 | + // the translation is not loaded (see doctor-feedback/component-test.gjs |
| 79 | + // for the same pattern). We just verify the hint key is wired up. |
| 80 | + await render( |
| 81 | + <template> |
| 82 | + <ExerciseSteps @activeStep="interact" @visible={{true}} /> |
| 83 | + </template>, |
| 84 | + ); |
| 85 | + |
| 86 | + assert |
| 87 | + .dom('button:nth-of-type(3)') |
| 88 | + .hasAttribute( |
| 89 | + 'title', |
| 90 | + 't:control_exercises.solve_hint', |
| 91 | + 'solve button binds the hint translation key', |
| 92 | + ); |
| 93 | + }); |
19 | 94 | }); |
0 commit comments