|
1 | 1 | import '@testing-library/jest-dom';
|
2 | 2 |
|
3 | 3 | import { Provider as MosaicProvider } from '@stoplight/mosaic';
|
4 |
| -import { HttpParamStyles, IHttpOperation } from '@stoplight/types'; |
| 4 | +import { HttpParamStyles, IHttpOperation, IMediaTypeContent } from '@stoplight/types'; |
5 | 5 | import { cleanup, render, screen, waitFor } from '@testing-library/react';
|
6 | 6 | import userEvent from '@testing-library/user-event';
|
7 | 7 | import fetchMock from 'jest-fetch-mock';
|
@@ -609,6 +609,62 @@ describe('TryIt', () => {
|
609 | 609 | expect(bodyHeader).not.toBeInTheDocument();
|
610 | 610 | });
|
611 | 611 |
|
| 612 | + it('does not hide panel when request body has no schema but has content', async () => { |
| 613 | + render( |
| 614 | + <TryItWithPersistence |
| 615 | + httpOperation={{ |
| 616 | + ...requestBodyEmptySchema, |
| 617 | + request: { |
| 618 | + body: { |
| 619 | + id: '?http-request-body?', |
| 620 | + contents: [ |
| 621 | + { |
| 622 | + ...requestBodyEmptySchema.request?.body?.contents?.at(0), |
| 623 | + mediaType: 'application/json', |
| 624 | + schema: undefined, |
| 625 | + } as IMediaTypeContent, |
| 626 | + ], |
| 627 | + }, |
| 628 | + }, |
| 629 | + method: 'POST', |
| 630 | + }} |
| 631 | + />, |
| 632 | + ); |
| 633 | + |
| 634 | + let bodyHeader = screen.queryByText('Body'); |
| 635 | + expect(bodyHeader).toBeInTheDocument(); |
| 636 | + }); |
| 637 | + |
| 638 | + it('send content-type header when request body has no schema but has content', async () => { |
| 639 | + render( |
| 640 | + <TryItWithPersistence |
| 641 | + httpOperation={{ |
| 642 | + ...requestBodyEmptySchema, |
| 643 | + request: { |
| 644 | + body: { |
| 645 | + id: '?http-request-body?', |
| 646 | + contents: [ |
| 647 | + { |
| 648 | + ...requestBodyEmptySchema.request?.body?.contents?.at(0), |
| 649 | + mediaType: 'application/json', |
| 650 | + schema: undefined, |
| 651 | + } as IMediaTypeContent, |
| 652 | + ], |
| 653 | + }, |
| 654 | + }, |
| 655 | + method: 'POST', |
| 656 | + }} |
| 657 | + />, |
| 658 | + ); |
| 659 | + |
| 660 | + clickSend(); |
| 661 | + await waitFor(() => expect(fetchMock).toHaveBeenCalled()); |
| 662 | + const requestInit = fetchMock.mock.calls[0][1]!; |
| 663 | + expect(requestInit.method).toMatch(/^post$/i); |
| 664 | + const headers = new Headers(requestInit.headers); |
| 665 | + expect(headers.get('Content-Type')).toBe('application/json'); |
| 666 | + }); |
| 667 | + |
612 | 668 | it('statically generates request body basing on request body schema', () => {
|
613 | 669 | render(<TryItWithPersistence httpOperation={requestBody} />);
|
614 | 670 |
|
|
0 commit comments