debian-mirror-gitlab/spec/frontend/blob/openapi/index_spec.js

30 lines
988 B
JavaScript
Raw Normal View History

2022-11-25 23:54:43 +05:30
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
2023-04-23 21:23:45 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2022-07-16 23:28:13 +05:30
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
import renderOpenApi from '~/blob/openapi';
2023-04-23 21:23:45 +05:30
import { HTTP_STATUS_OK } from '~/lib/utils/http_status';
2022-07-16 23:28:13 +05:30
describe('OpenAPI blob viewer', () => {
const id = 'js-openapi-viewer';
const mockEndpoint = 'some/endpoint';
2022-11-25 23:54:43 +05:30
let mock;
2022-07-16 23:28:13 +05:30
2022-11-25 23:54:43 +05:30
beforeEach(async () => {
2022-07-16 23:28:13 +05:30
setHTMLFixture(`<div id="${id}" data-endpoint="${mockEndpoint}"></div>`);
2023-04-23 21:23:45 +05:30
mock = new MockAdapter(axios).onGet().reply(HTTP_STATUS_OK);
2022-11-25 23:54:43 +05:30
await renderOpenApi();
2022-07-16 23:28:13 +05:30
});
afterEach(() => {
resetHTMLFixture();
2022-11-25 23:54:43 +05:30
mock.restore();
2022-07-16 23:28:13 +05:30
});
it('initializes SwaggerUI with the correct configuration', () => {
2022-11-25 23:54:43 +05:30
expect(document.body.innerHTML).toContain(
2023-04-23 21:23:45 +05:30
`<iframe src="${TEST_HOST}/-/sandbox/swagger" sandbox="allow-scripts allow-popups allow-forms" frameborder="0" width="100%" height="1000"></iframe>`,
2022-11-25 23:54:43 +05:30
);
2022-07-16 23:28:13 +05:30
});
});