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

Commit

Permalink
Add another test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Nov 6, 2017
1 parent 8309729 commit 76b1351
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
33 changes: 27 additions & 6 deletions packages/api-explorer-ui/__tests__/Response.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const React = require('react');
const { shallow } = require('enzyme');
// const extensions = require('../../readme-oas-extensions');
const { shallow, mount } = require('enzyme');
const petstore = require('./fixtures/petstore/oas');

const Response = require('../src/Response');
Expand All @@ -9,23 +8,24 @@ const Oas = require('../src/lib/Oas');
const { Operation } = Oas;
const oas = new Oas(petstore);

const noResult = {
const props = {
result: null,
operation: new Operation({}, '/pet', 'post'),
hideResults: () => {},
oas,
};

describe('no result', () => {
test('nothing should render', () => {
const codeSampleResponseTabs = shallow(<Response {...noResult} oas={oas} />);
const codeSampleResponseTabs = shallow(<Response {...props} />);

expect(codeSampleResponseTabs.find('span').length).toBe(0);
});
});

describe('setTab', () => {
test('setTab should change state of selectedTab', () => {
const doc = shallow(<Response {...noResult} oas={oas} />);
const doc = shallow(<Response {...props} />);

expect(doc.state('responseTab')).toBe('result');

Expand All @@ -41,7 +41,7 @@ describe('setTab', () => {

describe('exampleTab', () => {
test('exampleTab should change state of exampleTab', () => {
const doc = shallow(<Response {...noResult} oas={oas} />);
const doc = shallow(<Response {...props} />);

expect(doc.state('exampleTab')).toBe(0);

Expand All @@ -50,3 +50,24 @@ describe('exampleTab', () => {
expect(doc.state('exampleTab')).toBe(1);
});
});

test('should show different component tabs based on state', () => {
const doc = mount(
<Response
{...props}
result={{
status: 200,
responseBody: JSON.stringify({ a: 1 }),
requestHeaders: [],
method: 'post',
responseHeaders: [],
}}
/>,
);
expect(doc.find('ResponseBody').length).toBe(1);
doc.instance().setTab('metadata');

// I want to do the below assertion instead, but it's not working
// expect(doc.find('ResponseMetadata').length).toBe(1);
expect(doc.html().includes('Response Headers')).toBe(true);
});
6 changes: 2 additions & 4 deletions packages/api-explorer-ui/src/Response.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ class Response extends React.Component {

render() {
const { result, oas, operation, oauthUrl, hideResults } = this.props;

const { responseTab, exampleTab } = this.state;

const { responseTab } = this.state;
const securities = operation.prepareSecurity();

return (
Expand Down Expand Up @@ -67,7 +65,7 @@ class Response extends React.Component {
operation={operation}
result={result}
oas={oas}
selected={exampleTab}
selected={this.state.exampleTab}
setExampleTab={this.setExampleTab}
/>
</div>
Expand Down

0 comments on commit 76b1351

Please sign in to comment.