Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
feat: improved support for response examples (#1027)
Browse files Browse the repository at this point in the history
* feat: improved support for response examples

* chore: package file cleanup

* test: fixing some broken tests

* chore(deps): upgrading oas to 5.1.0
  • Loading branch information
erunion authored Nov 6, 2020
1 parent 0de5c32 commit d22a5cf
Show file tree
Hide file tree
Showing 27 changed files with 2,046 additions and 1,798 deletions.
58 changes: 48 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/api-explorer/__tests__/AuthBox.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Oas = require('oas/tooling');

const AuthBox = require('../src/AuthBox');

const multipleSecurities = require('./__fixtures__/multiple-securities/oas');
const multipleSecurities = require('./__fixtures__/multiple-securities/oas.json');

const oas = new Oas(multipleSecurities);

Expand Down
19 changes: 10 additions & 9 deletions packages/api-explorer/__tests__/ExampleTabs.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ const React = require('react');
const { shallow, mount } = require('enzyme');
const Oas = require('oas/tooling');

const example = require('./__fixtures__/example-results/oas');

const example = require('./__fixtures__/example-results/oas.json');
const ExampleTabs = require('../src/ExampleTabs');
const getResponseExamples = require('../src/lib/get-response-examples');

const oas = new Oas(example);
const props = {
examples: getResponseExamples(oas.operation('/results', 'get'), oas),
selected: 0,
setExampleTab: () => {},
setCurrentTab: () => {},
};

beforeAll(async () => {
props.examples = await oas.operation('/results', 'get').getResponseExamples();
});

test('if endpoint has an example, tabs should show', () => {
const exampleTabs = mount(<ExampleTabs {...props} />);

Expand All @@ -26,15 +27,15 @@ test('should select matching tab by index', () => {
expect(exampleTabs.find('a').first().hasClass('selected')).toBe(true);
});

test('should call setExampleTab on click', () => {
const setExampleTab = jest.fn();
const exampleTabs = mount(<ExampleTabs {...props} setExampleTab={setExampleTab} />);
test('should call setCurrentTab on click', () => {
const setCurrentTab = jest.fn();
const exampleTabs = mount(<ExampleTabs {...props} setCurrentTab={setCurrentTab} />);

const secondTab = exampleTabs.find('a').last();

secondTab.simulate('click', { preventDefault() {} });

expect(setExampleTab.mock.calls[0][0]).toBe(2);
expect(setCurrentTab.mock.calls[0][0]).toBe(2);
});

test('should display status codes', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-explorer/__tests__/PathUrl.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const PathUrl = require('../src/PathUrl');
const { splitPath } = PathUrl;

const { Operation } = Oas;
const petstore = require('./__fixtures__/petstore/oas');
const petstore = require('./__fixtures__/petstore/oas.json');

const oas = new Oas(petstore);

Expand Down
2 changes: 1 addition & 1 deletion packages/api-explorer/__tests__/Response.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const React = require('react');
const { shallow, mount } = require('enzyme');
const Oas = require('oas/tooling');

const petstore = require('./__fixtures__/petstore/oas');
const petstore = require('./__fixtures__/petstore/oas.json');

const Response = require('../src/Response');

Expand Down
2 changes: 1 addition & 1 deletion packages/api-explorer/__tests__/ResponseBody.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { mount } = require('enzyme');
const FetchResponse = require('node-fetch').Response;
const Oas = require('oas/tooling');

const petstore = require('./__fixtures__/petstore/oas');
const petstore = require('./__fixtures__/petstore/oas.json');

const parseResponse = require('../src/lib/parse-response');
const ResponseBody = require('../src/ResponseBody');
Expand Down
Loading

0 comments on commit d22a5cf

Please sign in to comment.