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

Commit f3aa37f

Browse files
authored
chore: instituting new code standards on prop ordering (#366)
* fix: resolving a bug where $ref responses weren't processed * fix: resovling descriptions on $ref examples being missing * chore: adding tests * chore: instituting new code standards on prop ordering
1 parent 341b6b5 commit f3aa37f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+340
-334
lines changed

packages/api-explorer/.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
"Params",
3434
"TextArea"
3535
]
36-
}]
36+
}],
37+
"react/jsx-sort-default-props": 2,
38+
"react/jsx-sort-props": 2,
39+
"react/sort-prop-types": 2
3740
}
3841
}

packages/api-explorer/__tests__/AuthBox.test.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ const multipleSecurities = require('./fixtures/multiple-securities/oas');
88
const oas = new Oas(multipleSecurities);
99

1010
const props = {
11+
auth: {},
12+
oauth: false,
13+
open: false,
1114
operation: oas.operation('/or-security', 'post'),
1215
onChange: () => {},
1316
onSubmit: () => {},
1417
toggle: () => {},
15-
open: false,
16-
oauth: false,
17-
auth: {},
1818
};
1919

2020
test('should not display if no auth', () => {

packages/api-explorer/__tests__/CodeSample.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const Oas = require('../src/lib/Oas');
77

88
const { Operation } = Oas;
99
const props = {
10-
setLanguage: () => {},
11-
operation: new Operation({}, '/pet/{id}', 'get'),
1210
formData: {},
1311
language: 'node',
12+
setLanguage: () => {},
13+
operation: new Operation({}, '/pet/{id}', 'get'),
1414
};
1515

1616
describe('tabs', () => {

packages/api-explorer/__tests__/Doc.test.jsx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ const oas = require('./fixtures/petstore/circular-oas');
1010
const multipleSecurities = require('./fixtures/multiple-securities/oas');
1111

1212
const props = {
13+
auth: {},
1314
doc: {
14-
title: 'Title',
15-
slug: 'slug',
16-
type: 'endpoint',
17-
swagger: { path: '/pet/{petId}' },
1815
api: { method: 'get' },
1916
formData: { path: { petId: '1' }, auth: { api_key: '' } },
2017
onSubmit: () => {},
18+
slug: 'slug',
19+
swagger: { path: '/pet/{petId}' },
20+
title: 'Title',
21+
type: 'endpoint',
2122
},
22-
oas,
23-
setLanguage: () => {},
2423
language: 'node',
25-
suggestedEdits: false,
24+
oas,
2625
oauth: false,
2726
onAuthChange: () => {},
28-
auth: {},
27+
setLanguage: () => {},
28+
suggestedEdits: false,
2929
tryItMetrics: () => {},
3030
};
3131

@@ -100,14 +100,14 @@ test('should work without a doc.swagger/doc.path/oas', () => {
100100
const doc = { title: 'title', slug: 'slug', type: 'basic' };
101101
const docComponent = shallow(
102102
<Doc
103+
auth={{}}
103104
doc={doc}
104-
setLanguage={() => {}}
105105
language="node"
106-
suggestedEdits
107106
oauth={false}
108-
tryItMetrics={() => {}}
109107
onAuthChange={() => {}}
110-
auth={{}}
108+
setLanguage={() => {}}
109+
suggestedEdits
110+
tryItMetrics={() => {}}
111111
/>,
112112
);
113113
expect(docComponent.find('Waypoint').length).toBe(1);
@@ -122,15 +122,15 @@ test('should still display `Content` with column-style layout', () => {
122122
const doc = { title: 'title', slug: 'slug', type: 'basic' };
123123
const docComponent = shallow(
124124
<Doc
125+
appearance={{ referenceLayout: 'column' }}
126+
auth={{}}
125127
doc={doc}
126-
setLanguage={() => {}}
127128
language="node"
128-
suggestedEdits
129-
appearance={{ referenceLayout: 'column' }}
130129
oauth={false}
131-
tryItMetrics={() => {}}
132130
onAuthChange={() => {}}
133-
auth={{}}
131+
setLanguage={() => {}}
132+
suggestedEdits
133+
tryItMetrics={() => {}}
134134
/>,
135135
);
136136
docComponent.setState({ showEndpoint: true });
@@ -171,6 +171,7 @@ describe('onSubmit', () => {
171171

172172
test('should make request on Submit', () => {
173173
const props2 = {
174+
auth: { petstore_auth: 'api-key' },
174175
doc: {
175176
title: 'Title',
176177
slug: 'slug',
@@ -185,11 +186,10 @@ describe('onSubmit', () => {
185186
},
186187
onSubmit: () => {},
187188
},
188-
oas,
189-
setLanguage: () => {},
190189
language: 'node',
190+
oas,
191191
oauth: false,
192-
auth: { petstore_auth: 'api-key' },
192+
setLanguage: () => {},
193193
};
194194

195195
const { fetch } = window;
@@ -253,10 +253,10 @@ describe('onSubmit', () => {
253253
const doc = mount(
254254
<Doc
255255
{...props}
256+
auth={{ api_key: 'api-key' }}
256257
tryItMetrics={() => {
257258
called = true;
258259
}}
259-
auth={{ api_key: 'api-key' }}
260260
/>,
261261
);
262262

@@ -374,14 +374,14 @@ test('should output with an error message if the endpoint fails to load', () =>
374374
const doc = mount(
375375
<Doc
376376
{...props}
377-
oas={brokenOas}
378377
doc={{
379378
title: 'title',
380379
slug: 'slug',
381380
type: 'endpoint',
382381
swagger: { path: '/path' },
383382
api: { method: 'post' },
384383
}}
384+
oas={brokenOas}
385385
/>,
386386
);
387387

packages/api-explorer/__tests__/Params.test.jsx

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ const booleanOas = new Oas(boolean);
1919
const stringOas = new Oas(string);
2020

2121
const props = {
22-
oas,
23-
operation,
2422
formData: {},
23+
oas,
2524
onChange: () => {},
2625
onSubmit: () => {},
26+
operation,
2727
};
2828

2929
const Params = createParams(oas);
@@ -177,31 +177,30 @@ function renderParams(schema, customProps) {
177177
);
178178
}
179179

180-
function testNumberClass(schema) {
181-
const clonedSchema = JSON.parse(JSON.stringify(schema));
182-
test(`${JSON.stringify(schema)} should have correct class`, () => {
183-
const params = renderParams(schema);
184-
185-
expect(params.find(`.field-${clonedSchema.type}.field-${clonedSchema.format}`).length).toBe(1);
186-
});
187-
}
188-
189180
test('should convert `mixed type` to string', () => {
190181
const params = renderParams({ type: 'mixed type' });
191182

192183
expect(params.find(`.field-string`).length).toBe(1);
193184
});
194185

195-
testNumberClass({ type: 'integer', format: 'int8' });
196-
testNumberClass({ type: 'integer', format: 'uint8' });
197-
testNumberClass({ type: 'integer', format: 'int16' });
198-
testNumberClass({ type: 'integer', format: 'uint16' });
199-
testNumberClass({ type: 'integer', format: 'int32' });
200-
testNumberClass({ type: 'integer', format: 'uint32' });
201-
testNumberClass({ type: 'integer', format: 'int64' });
202-
testNumberClass({ type: 'integer', format: 'uint64' });
203-
testNumberClass({ type: 'number', format: 'float' });
204-
testNumberClass({ type: 'number', format: 'double' });
186+
test.each([
187+
['integer', 'int8'],
188+
['integer', 'uint8'],
189+
['integer', 'int16'],
190+
['integer', 'uint16'],
191+
['integer', 'int32'],
192+
['integer', 'uint32'],
193+
['integer', 'int64'],
194+
['integer', 'uint64'],
195+
['number', 'float'],
196+
['number', 'double'],
197+
])('{ type: %s, format: %s } should have correct class', (type, format) => {
198+
const schema = { type, format };
199+
const clonedSchema = JSON.parse(JSON.stringify(schema));
200+
const params = renderParams(schema);
201+
202+
expect(params.find(`.field-${clonedSchema.type}.field-${clonedSchema.format}`).length).toBe(1);
203+
});
205204

206205
test('should not error if `integer|number` are missing `format`', () => {
207206
expect(() => {

packages/api-explorer/__tests__/PathUrl.test.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ const petstore = require('./fixtures/petstore/oas');
1111
const oas = new Oas(petstore);
1212

1313
const props = {
14-
oas,
15-
operation: oas.operation('/pet/{petId}', 'get'),
14+
apiKey: '',
1615
dirty: false,
1716
loading: false,
17+
oas,
18+
oauth: false,
1819
onChange: () => {},
19-
toggleAuth: () => {},
2020
onSubmit: () => {},
21-
oauth: false,
22-
apiKey: '',
21+
operation: oas.operation('/pet/{petId}', 'get'),
22+
toggleAuth: () => {},
2323
};
2424

2525
test('should display the path', () => {
@@ -69,8 +69,8 @@ test('button click should call onSubmit', () => {
6969
shallow(
7070
<PathUrl
7171
{...props}
72-
operation={new Operation({}, '/path', 'get', { operationId: '123' })}
7372
onSubmit={onSubmit}
73+
operation={new Operation({}, '/path', 'get', { operationId: '123' })}
7474
/>,
7575
)
7676
.find('button[type="submit"]')

packages/api-explorer/__tests__/Response.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const { Operation } = Oas;
99
const oas = new Oas(petstore);
1010

1111
const props = {
12-
result: null,
13-
operation: new Operation({}, '/pet', 'post'),
1412
hideResults: () => {},
13+
result: null,
1514
oas,
1615
oauth: false,
1716
onChange: () => {},
17+
operation: new Operation({}, '/pet', 'post'),
1818
};
1919

2020
describe('no result', () => {

packages/api-explorer/__tests__/ResponseBody.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const Oas = require('../src/lib/Oas');
1111
const { Operation } = Oas;
1212
const oas = new Oas(petstore);
1313
const props = {
14-
operation: new Operation({}, '/pet', 'post'),
1514
oauth: false,
15+
operation: new Operation({}, '/pet', 'post'),
1616
};
1717

1818
beforeEach(async () => {

packages/api-explorer/__tests__/ResponseExample.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ const Oas = require('../src/lib/Oas');
1111
const oas = new Oas(petstore);
1212

1313
const props = {
14-
result: null,
1514
oas,
16-
operation: oas.operation('/pet', 'post'),
1715
onChange: () => {},
16+
operation: oas.operation('/pet', 'post'),
17+
result: null,
1818
};
1919

2020
test('should show no examples if endpoint does not any', () => {

packages/api-explorer/__tests__/ResponseSchema.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const { Operation } = Oas;
99
const oas = new Oas(petstore);
1010

1111
const props = {
12-
operation: oas.operation('/pet/{petId}', 'get'),
1312
oas,
13+
operation: oas.operation('/pet/{petId}', 'get'),
1414
theme: 'light',
1515
};
1616

packages/api-explorer/__tests__/ResponseTabs.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ const Oas = require('../src/lib/Oas');
1111

1212
const oas = new Oas(petstore);
1313
const props = {
14+
hideResults: () => {},
1415
oas,
1516
operation: oas.operation('/pet', 'post'),
1617
responseTab: 'result',
1718
setTab: () => {},
18-
hideResults: () => {},
1919
};
2020

2121
beforeEach(async () => {
@@ -74,9 +74,9 @@ test('should call hideResults() on click', () => {
7474
const exampleTabs = shallow(
7575
<ResponseTabs
7676
{...props}
77+
hideResults={hideResults}
7778
oas={exampleResultsOas}
7879
operation={exampleResultsOas.operation('/results', 'get')}
79-
hideResults={hideResults}
8080
/>,
8181
);
8282

packages/api-explorer/__tests__/SecurityInput.test.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ const { mount, shallow } = require('enzyme');
33
const SecurityInput = require('../src/SecurityInput');
44

55
const baseProps = {
6-
onChange: () => {},
7-
oauth: false,
86
auth: {},
7+
oauth: false,
8+
onChange: () => {},
99
};
1010

1111
test('should render an Oauth2 component if type is oauth2', () => {
@@ -48,7 +48,7 @@ describe('oauth2', () => {
4848

4949
test('should disable the input if `oauth=true`', () => {
5050
const securityInput = mount(
51-
<SecurityInput {...props} {...baseProps} oauth auth={{ 'test-auth': 'test' }} />,
51+
<SecurityInput {...props} {...baseProps} auth={{ 'test-auth': 'test' }} oauth />,
5252
);
5353
expect(securityInput.find('input').prop('disabled')).toBe(true);
5454
});
@@ -63,7 +63,7 @@ describe('oauth2', () => {
6363
test('should display api key if set', () => {
6464
const apiKey = '123456';
6565
const securityInput = mount(
66-
<SecurityInput {...props} {...baseProps} oauth auth={{ 'test-auth': apiKey }} />,
66+
<SecurityInput {...props} {...baseProps} auth={{ 'test-auth': apiKey }} oauth />,
6767
);
6868

6969
expect(securityInput.find('input').prop('value')).toBe(apiKey);
@@ -151,7 +151,7 @@ describe('basic', () => {
151151
const user = 'user';
152152
const pass = 'pass';
153153
const securityInput = mount(
154-
<SecurityInput {...props} {...baseProps} oauth auth={{ 'test-basic': { user, pass } }} />,
154+
<SecurityInput {...props} {...baseProps} auth={{ 'test-basic': { user, pass } }} oauth />,
155155
);
156156

157157
expect(securityInput.find('input[name="user"]').prop('value')).toBe(user);

packages/api-explorer/__tests__/block-types/Embed.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('Embed', () => {
5959
};
6060
const embedInput = shallow(<Embed block={block} />);
6161
expect(embedInput.find('strong').html()).toBe(
62-
'<strong><img src="http://static.jsbin.com/images/favicon.png" class="favicon" alt=""/><a href="http://jsbin.com/fewilipowi/edit?js,output" target="_new">http://jsbin.com/fewilipowi/edit?js,output</a></strong>',
62+
'<strong><img alt="" class="favicon" src="http://static.jsbin.com/images/favicon.png"/><a href="http://jsbin.com/fewilipowi/edit?js,output" target="_new">http://jsbin.com/fewilipowi/edit?js,output</a></strong>',
6363
);
6464
});
6565
});

0 commit comments

Comments
 (0)