|
| 1 | +import { clickByText, render } from '@1024pix/ember-testing-library'; |
| 2 | +import { click } from '@ember/test-helpers'; |
| 3 | +import DuplicateTraining from 'pix-admin/components/trainings/duplicate-training'; |
| 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 | Trainings | Duplicate training', function (hooks) { |
| 10 | + setupIntlRenderingTest(hooks); |
| 11 | + |
| 12 | + const duplicateTraining = sinon.stub().resolves(true); |
| 13 | + |
| 14 | + test('it should render the duplicate training modal', async function (assert) { |
| 15 | + // when |
| 16 | + const screen = await render(<template><DuplicateTraining @onSubmit={{duplicateTraining}} /></template>); |
| 17 | + const duplicateButton = screen.getByRole('button', { name: 'Dupliquer ce contenu formatif' }); |
| 18 | + await click(duplicateButton); |
| 19 | + |
| 20 | + // then |
| 21 | + assert.dom(await screen.findByText('Dupliquer le contenu formatif ?')).exists(); |
| 22 | + assert.dom(screen.getByText('Cette action dupliquera le contenu formatif avec ses déclencheurs.')).exists(); |
| 23 | + assert.dom(await screen.findByRole('button', { name: 'Valider' })).exists(); |
| 24 | + assert.dom(screen.getByRole('button', { name: 'Annuler' })).exists(); |
| 25 | + assert.dom(screen.getByRole('button', { name: 'Fermer' })).exists(); |
| 26 | + }); |
| 27 | + |
| 28 | + test('it should call the duplicate method on click on submit', async function (assert) { |
| 29 | + await render(<template><DuplicateTraining @onSubmit={{duplicateTraining}} /></template>); |
| 30 | + |
| 31 | + // when |
| 32 | + await clickByText('Valider'); |
| 33 | + |
| 34 | + // then |
| 35 | + sinon.assert.calledOnce(duplicateTraining); |
| 36 | + assert.ok(true); |
| 37 | + }); |
| 38 | +}); |
0 commit comments