|
1 | 1 | // oxlint-disable unicorn/no-useless-spread |
2 | 2 | /* eslint-disable react/prop-types */ |
3 | | -import userEvent from '@testing-library/user-event'; |
| 3 | +import userEvent, { UserEvent } from '@testing-library/user-event'; |
4 | 4 |
|
| 5 | +import { mockWaffleFlags } from '@src/data/apiHooks.mock'; |
| 6 | +import { RenderResult } from '@testing-library/react'; |
5 | 7 | import { |
6 | 8 | act, |
7 | 9 | render, |
@@ -319,6 +321,52 @@ describe('<AddComponent />', () => { |
319 | 321 | }); |
320 | 322 | }); |
321 | 323 |
|
| 324 | + const createPdfBlock = async ( |
| 325 | + { getByRole, queryAllByRole, user }: { |
| 326 | + getByRole: RenderResult['getByRole'] |
| 327 | + queryAllByRole: RenderResult['queryAllByRole'], |
| 328 | + user: UserEvent, |
| 329 | + }, |
| 330 | + ) => { |
| 331 | + const advancedBtn = getByRole('button', { |
| 332 | + name: new RegExp(`${messages.buttonText.defaultMessage} Advanced`, 'i'), |
| 333 | + }); |
| 334 | + |
| 335 | + await user.click(advancedBtn); |
| 336 | + |
| 337 | + const dialog = getByRole('dialog'); |
| 338 | + const pdfOption = within(dialog).getByLabelText('PDF'); |
| 339 | + await user.click(pdfOption); |
| 340 | + const confirmation = within(dialog).getByText('Select'); |
| 341 | + await user.click(confirmation); |
| 342 | + await waitFor(() => expect(queryAllByRole('dialog')).toEqual([])); |
| 343 | + }; |
| 344 | + |
| 345 | + it('adds a PDF block from the advanced selection in modal as an mfe-editable block', async () => { |
| 346 | + const user = userEvent.setup(); |
| 347 | + const { getByRole, queryAllByRole } = renderComponent(); |
| 348 | + await createPdfBlock({ getByRole, queryAllByRole, user }); |
| 349 | + expect(handleCreateNewCourseXBlockMock).toHaveBeenCalled(); |
| 350 | + expect(handleCreateNewCourseXBlockMock).toHaveBeenCalledWith({ |
| 351 | + parentLocator: '123', |
| 352 | + type: COMPONENT_TYPES.pdf, |
| 353 | + }, expect.any(Function)); |
| 354 | + }); |
| 355 | + |
| 356 | + it('adds a PDF block and launches the legacy iframe editor', async () => { |
| 357 | + const user = userEvent.setup(); |
| 358 | + mockWaffleFlags({ useNewPdfEditor: false }); |
| 359 | + const { getByRole, queryAllByRole } = renderComponent(); |
| 360 | + await createPdfBlock({ getByRole, queryAllByRole, user }); |
| 361 | + expect(handleCreateNewCourseXBlockMock).toHaveBeenCalled(); |
| 362 | + expect(handleCreateNewCourseXBlockMock).toHaveBeenCalledWith({ |
| 363 | + parentLocator: '123', |
| 364 | + type: COMPONENT_TYPES.pdf, |
| 365 | + // Setting the category and not supplying an additional function launches the traditional editor. |
| 366 | + category: COMPONENT_TYPES.pdf, |
| 367 | + }); |
| 368 | + }); |
| 369 | + |
322 | 370 | it('verifies "Text" component selection in modal', async () => { |
323 | 371 | const user = userEvent.setup(); |
324 | 372 | const { getByRole, getByText } = renderComponent(); |
|
0 commit comments