fix: move titleize to helpers

This commit is contained in:
Cédric Fabianski 2019-05-07 17:59:06 +02:00
parent 9ebd0b4580
commit 1eef4c0eb8
No known key found for this signature in database
GPG Key ID: 189A0D6C64F9E873
3 changed files with 13 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import { SecuritySchemesModel } from '../../services/models';
import { H2, MiddlePanel, Row, Section, ShareLink } from '../../common-elements'; import { H2, MiddlePanel, Row, Section, ShareLink } from '../../common-elements';
import { OpenAPISecurityScheme } from '../../types'; import { OpenAPISecurityScheme } from '../../types';
import { titleize } from '../../utils/helpers';
import { Markdown } from '../Markdown/Markdown'; import { Markdown } from '../Markdown/Markdown';
import { StyledMarkdownBlock } from '../Markdown/styled.elements'; import { StyledMarkdownBlock } from '../Markdown/styled.elements';
@ -84,12 +85,7 @@ export class SecurityDefs extends React.PureComponent<SecurityDefsProps> {
</tr> </tr>
{scheme.apiKey ? ( {scheme.apiKey ? (
<tr> <tr>
<th> <th> {titleize(scheme.apiKey.in || '')} parameter name:</th>
{' '}
{(scheme.apiKey.in || '').charAt(0).toUpperCase() +
(scheme.apiKey.in || '').slice(1)}{' '}
parameter name:
</th>
<td> {scheme.apiKey.name} </td> <td> {scheme.apiKey.name} </td>
</tr> </tr>
) : scheme.http ? ( ) : scheme.http ? (

View File

@ -1,5 +1,5 @@
import slugify from 'slugify'; import slugify from 'slugify';
import { mapWithLast, appendToMdHeading, mergeObjects, safeSlugify } from '../helpers'; import { appendToMdHeading, mapWithLast, mergeObjects, safeSlugify, titleize } from '../helpers';
describe('Utils', () => { describe('Utils', () => {
describe('helpers', () => { describe('helpers', () => {
@ -68,5 +68,11 @@ describe('Utils', () => {
expect(mergeObjects({}, obj1, obj2)).toEqual({ a: ['C'], b: ['D'] }); expect(mergeObjects({}, obj1, obj2)).toEqual({ a: ['C'], b: ['D'] });
}); });
}); });
describe('titleize', () => {
test('should return the string with the first letter capitalized', () => {
expect(titleize('my title')).toEqual('My title');
});
});
}); });
}); });

View File

@ -165,3 +165,7 @@ export function resolveUrl(url: string, to: string) {
export function getBasePath(serverUrl: string): string { export function getBasePath(serverUrl: string): string {
return new URL(serverUrl).pathname; return new URL(serverUrl).pathname;
} }
export function titleize(text: string) {
return text.charAt(0).toUpperCase() + text.slice(1);
}