|
| 1 | +import { render } from '@1024pix/ember-testing-library'; |
| 2 | +import { click } from '@ember/test-helpers'; |
| 3 | +import EvaluationSentResultsModal from 'mon-pix/components/campaigns/assessment/results/evaluation-sent-results-modal'; |
| 4 | +import { module, test } from 'qunit'; |
| 5 | +import sinon from 'sinon'; |
| 6 | + |
| 7 | +import setupIntlRenderingTest from '../../../../../helpers/setup-intl-rendering'; |
| 8 | + |
| 9 | +module('Integration | Component | evaluation-sent-results-modal', function (hooks) { |
| 10 | + setupIntlRenderingTest(hooks); |
| 11 | + |
| 12 | + module('when showModal is true', function () { |
| 13 | + test('should display modal', async function (assert) { |
| 14 | + // given |
| 15 | + const showModal = true; |
| 16 | + const trainings = [ |
| 17 | + { |
| 18 | + title: 'Mon super training 1', |
| 19 | + link: 'https://training.net/', |
| 20 | + type: 'webinaire', |
| 21 | + locale: 'fr-fr', |
| 22 | + duration: { hours: 6 }, |
| 23 | + editorName: "Ministère de l'éducation nationale et de la jeunesse. Liberté égalité fraternité", |
| 24 | + editorLogoUrl: |
| 25 | + 'https://images.pix.fr/contenu-formatif/editeur/logo-ministere-education-nationale-et-jeunesse.svg', |
| 26 | + }, |
| 27 | + { |
| 28 | + title: 'Mon super training 2', |
| 29 | + link: 'https://training.net/', |
| 30 | + type: 'webinaire', |
| 31 | + locale: 'fr-fr', |
| 32 | + duration: { hours: 8 }, |
| 33 | + editorName: "Ministère de l'éducation nationale et de la jeunesse. Liberté égalité fraternité", |
| 34 | + editorLogoUrl: |
| 35 | + 'https://images.pix.fr/contenu-formatif/editeur/logo-ministere-education-nationale-et-jeunesse.svg', |
| 36 | + }, |
| 37 | + { |
| 38 | + title: 'Mon super training 3', |
| 39 | + link: 'https://training.net/', |
| 40 | + type: 'webinaire', |
| 41 | + locale: 'fr-fr', |
| 42 | + duration: { hours: 10 }, |
| 43 | + editorName: "Ministère de l'éducation nationale et de la jeunesse. Liberté égalité fraternité", |
| 44 | + editorLogoUrl: |
| 45 | + 'https://images.pix.fr/contenu-formatif/editeur/logo-ministere-education-nationale-et-jeunesse.svg', |
| 46 | + }, |
| 47 | + ]; |
| 48 | + |
| 49 | + // when |
| 50 | + const screen = await render( |
| 51 | + <template><EvaluationSentResultsModal @showModal={{showModal}} @trainings={{trainings}} /></template>, |
| 52 | + ); |
| 53 | + |
| 54 | + // then |
| 55 | + assert.dom(screen.getByRole('dialog')).exists(); |
| 56 | + assert.strictEqual(screen.getAllByRole('heading', { level: 3 }).length, 3); |
| 57 | + assert.dom(screen.getByRole('heading', { name: trainings[0].title, level: 3 })).exists(); |
| 58 | + assert.dom(screen.getByRole('heading', { name: trainings[1].title, level: 3 })).exists(); |
| 59 | + assert.dom(screen.getByRole('heading', { name: trainings[2].title, level: 3 })).exists(); |
| 60 | + }); |
| 61 | + |
| 62 | + module('when click on close button', function () { |
| 63 | + test('should call onCloseButtonClick method', async function (assert) { |
| 64 | + // given |
| 65 | + const showModal = true; |
| 66 | + const onCloseButtonClick = sinon.stub(); |
| 67 | + const screen = await render( |
| 68 | + <template> |
| 69 | + <EvaluationSentResultsModal @showModal={{showModal}} @onCloseButtonClick={{onCloseButtonClick}} /> |
| 70 | + </template>, |
| 71 | + ); |
| 72 | + |
| 73 | + // when |
| 74 | + await click(screen.getByRole('button', { name: 'Fermer' })); |
| 75 | + |
| 76 | + // then |
| 77 | + sinon.assert.calledOnce(onCloseButtonClick); |
| 78 | + assert.ok(true); |
| 79 | + }); |
| 80 | + }); |
| 81 | + |
| 82 | + module('when click on close and send results button', function () { |
| 83 | + test('should call onCloseButtonClick method', async function (assert) { |
| 84 | + // given |
| 85 | + const showModal = true; |
| 86 | + const onCloseButtonClick = sinon.stub(); |
| 87 | + const screen = await render( |
| 88 | + <template> |
| 89 | + <EvaluationSentResultsModal @showModal={{showModal}} @onCloseButtonClick={{onCloseButtonClick}} /> |
| 90 | + </template>, |
| 91 | + ); |
| 92 | + |
| 93 | + // when |
| 94 | + await click(screen.getByRole('button', { name: 'Fermer et revenir aux résultats' })); |
| 95 | + |
| 96 | + // then |
| 97 | + sinon.assert.calledOnce(onCloseButtonClick); |
| 98 | + assert.ok(true); |
| 99 | + }); |
| 100 | + }); |
| 101 | + }); |
| 102 | + |
| 103 | + module('when showModal is false', function () { |
| 104 | + test('should not display modal', async function (assert) { |
| 105 | + // given |
| 106 | + const showModal = false; |
| 107 | + |
| 108 | + // when |
| 109 | + const screen = await render(<template><EvaluationSentResultsModal @showModal={{showModal}} /></template>); |
| 110 | + |
| 111 | + // then |
| 112 | + assert.dom(screen.queryByRole('dialog')).doesNotExist(); |
| 113 | + }); |
| 114 | + }); |
| 115 | +}); |
0 commit comments