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

Commit

Permalink
Tidy up test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Nov 2, 2017
1 parent 2b78989 commit 25976d4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 140 deletions.
59 changes: 19 additions & 40 deletions packages/api-explorer-ui/__tests__/CodeSampleResponse.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('hideResults', () => {
});

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

expect(codeSampleResponseTabs.find('span').length).toBe(0);
Expand All @@ -87,18 +87,16 @@ describe('tabs', () => {
test('should switch tabs', () => {
const codeSampleResponseTabs = shallow(<CodeSampleResponseTabs {...props} oas={oas} />);

const resultTab = codeSampleResponseTabs.find('a').first();
const metadataTab = codeSampleResponseTabs.find('a').last();
const resultTab = codeSampleResponseTabs.find('a[data-tab="result"]');
const metadataTab = codeSampleResponseTabs.find('a[data-tab="metadata"]');

expect(codeSampleResponseTabs.state('selectedTab')).toBe('result');
expect(resultTab.hasClass('hub-reference-results-header-item tabber-tab selected')).toEqual(
true,
);
expect(resultTab.hasClass('selected')).toEqual(true);

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

expect(codeSampleResponseTabs.state('selectedTab')).toBe('metadata');
expect(resultTab.hasClass('hub-reference-results-header-item tabber-tab')).toEqual(true);
expect(codeSampleResponseTabs.find('a[data-tab="result"]').hasClass('selected')).toEqual(false);

resultTab.simulate('click', { preventDefault() {} });
expect(codeSampleResponseTabs.state('selectedTab')).toBe('result');
Expand All @@ -109,11 +107,7 @@ describe('Results body', () => {
test('should display result body by default', () => {
const codeSampleResponseTabs = shallow(<CodeSampleResponseTabs {...props} oas={oas} />);

expect(
codeSampleResponseTabs.containsMatchingElement(
<div className="cm-s-tomorrow-night codemirror-highlight" />,
),
).toEqual(true);
expect(codeSampleResponseTabs.find('.cm-s-tomorrow-night.codemirror-highlight').length).toBe(1);
});

test('should not display responseBody if isBinary is true', async () => {
Expand Down Expand Up @@ -143,8 +137,10 @@ describe('Results body', () => {
).toEqual(true);
});

test('should display message if OAuth is incorrect or expired', async () => {
const oauthInvalidResponse = {
let oauthInvalidResponse;

beforeEach(async () => {
oauthInvalidResponse = {
result: await parseResponse(
{
log: {
Expand All @@ -156,12 +152,15 @@ describe('Results body', () => {
},
},
new Response('{}', {
headers: { 'content-disposition': 'attachment' },
headers: {},
status: 401,
}),
),
operation: oas.operation('/pet', 'post'),
};
});

test('should display message if OAuth is incorrect or expired without oauthUrl', async () => {
const codeSampleResponseTabs = shallow(
<CodeSampleResponseTabs {...oauthInvalidResponse} oas={oas} />,
);
Expand All @@ -174,25 +173,7 @@ describe('Results body', () => {
).toEqual(true);
});

test('should display message if OAuth is expired', async () => {
const oauthInvalidResponse = {
result: await parseResponse(
{
log: {
entries: [
{
request: { url: 'http://petstore.swagger.io/v2/pet', method: 'POST', headers: [] },
},
],
},
},
new Response('{}', {
headers: { 'content-disposition': 'attachment' },
status: 401,
}),
),
operation: oas.operation('/pet', 'post'),
};
test('should display message if OAuth is expired with oauthUrl', async () => {
const codeSampleResponseTabs = shallow(
<CodeSampleResponseTabs
{...oauthInvalidResponse}
Expand Down Expand Up @@ -228,7 +209,7 @@ describe('Results body', () => {
},
},
new Response('{}', {
headers: { 'content-disposition': 'attachment' },
headers: {},
status: 401,
}),
),
Expand All @@ -245,7 +226,7 @@ describe('Results body', () => {
});

describe('examples', () => {
test('if endpoint has an example tabs and body should show', () => {
test('if endpoint has an example, tabs and body should show', () => {
const oas2 = new Oas(example);
const props4 = {
result: null,
Expand All @@ -257,14 +238,12 @@ describe('examples', () => {
const secondTab = codeSampleResponseTabs.find('a').last();

expect(codeSampleResponseTabs.state('exampleTab')).toBe(0);
expect(firstTab.hasClass('hub-reference-results-header-item tabber-tab selected')).toEqual(
true,
);
expect(firstTab.hasClass('selected')).toEqual(true);

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

expect(codeSampleResponseTabs.state('exampleTab')).toBe(1);
expect(firstTab.hasClass('hub-reference-results-header-item tabber-tab')).toEqual(true);
expect(codeSampleResponseTabs.find('a').first().hasClass('selected')).toEqual(false);

expect(firstTab.find('span.httpsuccess').length).toBe(1);
expect(secondTab.find('span.httperror').length).toBe(1);
Expand Down
106 changes: 6 additions & 100 deletions packages/api-explorer-ui/__tests__/Response.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,107 +2,13 @@ const React = require('react');
const { shallow } = require('enzyme');

const Response = require('../src/Response');
// const Oas = require('../src/lib/Oas');
//
// const { Operation } = Oas;
const Oas = require('../src/lib/Oas');
const petstore = require('./fixtures/petstore/oas.json');

const props = {
operation: {
responses: {
'200': {
content: {
'application/json': {
schema: {
type: 'array',
items: {
properties: {
category: {
properties: {
id: { type: 'integer', format: 'int64' },
name: { type: 'string' },
},
type: 'object',
xml: { name: 'Pet' },
},

id: { type: 'integer', format: 'int64' },
name: { type: 'string', example: 'doggie' },
photoUrls: {
type: ' array',
items: { type: 'string' },
xml: { name: 'photoUrl', wrapped: true },
},
status: {
type: 'string',
description: 'pet status in the store',
enum: ['available', 'pending', 'sold'],
},
tags: {
items: {
type: 'object',
properties: {
id: { type: 'integer', format: 'int64' },
name: { type: 'string' },
},
xml: { name: 'Tag' },
},
type: 'array',
xml: { name: 'tag', wrapped: true },
},
},
required: ['name', 'photoUrls'],
},
},
},
'application/xml': {
schema: {
items: {
properties: {
category: {
properties: {
id: { type: 'integer', format: 'int64' },
name: { type: 'string' },
},
type: 'object',
xml: { name: 'Category' },
},
const oas = new Oas(petstore);

id: { type: 'integer', format: 'int64' },
name: { type: 'string', example: 'doggie' },
photoUrls: {
type: ' array',
items: { type: 'string' },
xml: { name: 'photoUrl', wrapped: true },
},
status: {
type: 'string',
description: 'pet status in the store',
enum: ['available', 'pending', 'sold'],
},
tags: {
items: {
type: 'object',
properties: {
id: { type: 'integer', format: 'int64' },
name: { type: 'string' },
},
xml: { name: 'Tag' },
},
type: 'array',
xml: { name: 'tag', wrapped: true },
},
},
required: ['name', 'photoUrls'],
},
},
},
},
description: 'successful operation',
},
'400': { description: 'Invalid status value' },
},
},
// new Operation({}, '/pet/findByStatus', 'get'),
const props = {
operation: oas.operation('/pet/{petId}', 'get')
};

describe('selectedStatus', () => {
Expand All @@ -121,6 +27,6 @@ describe('Response', () => {
test('should display Response schema', () => {
const response = shallow(<Response {...props} />);

expect(response.find('p.desc').length).toBe(1);
expect(response.find('p.desc').text()).toBe(props.operation.responses['200'].description);
});
});

0 comments on commit 25976d4

Please sign in to comment.