|
| 1 | +import path from 'path'; |
| 2 | +import { render } from '@asyncapi/generator-react-sdk'; |
| 3 | +import { Parser, fromFile } from '@asyncapi/parser'; |
| 4 | +import { getQueryParams } from '@asyncapi/generator-helpers'; |
| 5 | +import { QueryParamsVariables } from '../../components/QueryParamsVariables.js'; |
| 6 | + |
| 7 | +const parser = new Parser(); |
| 8 | +const asyncapiFilePath = path.resolve( |
| 9 | + __dirname, |
| 10 | + '../../../../../../helpers/test/__fixtures__/asyncapi-websocket-query.yml' |
| 11 | +); |
| 12 | + |
| 13 | +describe('QueryParamsVariables component (integration with AsyncAPI document)', () => { |
| 14 | + let parsedAsyncAPIDocument; |
| 15 | + |
| 16 | + beforeAll(async () => { |
| 17 | + const parseResult = await fromFile(parser, asyncapiFilePath).parse(); |
| 18 | + parsedAsyncAPIDocument = parseResult.document; |
| 19 | + }); |
| 20 | + |
| 21 | + test('renders correctly with query parameters', () => { |
| 22 | + const channels = parsedAsyncAPIDocument.channels(); |
| 23 | + const queryParamsObject = getQueryParams(channels); |
| 24 | + const queryParamsArray = queryParamsObject ? Array.from(queryParamsObject.entries()) : []; |
| 25 | + const result = render(<QueryParamsVariables queryParams={queryParamsArray} />); |
| 26 | + expect(result.trim()).toMatchSnapshot(); |
| 27 | + }); |
| 28 | + |
| 29 | + test('renders nothing when queryParams is null', () => { |
| 30 | + const result = render(<QueryParamsVariables queryParams={null} />); |
| 31 | + expect(result.trim()).toMatchSnapshot(); |
| 32 | + }); |
| 33 | + |
| 34 | + test('renders nothing when queryParams is undefined', () => { |
| 35 | + const result = render(<QueryParamsVariables />); |
| 36 | + expect(result.trim()).toMatchSnapshot(); |
| 37 | + }); |
| 38 | + |
| 39 | + test('renders nothing when queryParams is an empty array', () => { |
| 40 | + const result = render(<QueryParamsVariables queryParams={[]} />); |
| 41 | + expect(result.trim()).toMatchSnapshot(); |
| 42 | + }); |
| 43 | +}); |
0 commit comments