Skip to content

Commit

Permalink
fix: render schema title if it exists (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethaasan committed Feb 1, 2024
1 parent d98cabc commit 9b73229
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ npm-debug.log*
lerna-debug.log*
/**/*.tgz
/.idea/
.vscode
13 changes: 13 additions & 0 deletions library/src/helpers/__tests__/__snapshots__/schema.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SchemaHelpers .applicatorSchemaName should not render title because title is null 1`] = `"first case:"`;

exports[`SchemaHelpers .applicatorSchemaName should not render title because title is null 2`] = `"other cases:"`;

exports[`SchemaHelpers .applicatorSchemaName should not render title because title is undefined 1`] = `"first case:"`;

exports[`SchemaHelpers .applicatorSchemaName should not render title because title is undefined 2`] = `"other cases:"`;

exports[`SchemaHelpers .applicatorSchemaName should render title 1`] = `"first case title example:"`;

exports[`SchemaHelpers .applicatorSchemaName should render title 2`] = `"other cases title example:"`;
56 changes: 56 additions & 0 deletions library/src/helpers/__tests__/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -869,4 +869,60 @@ describe('SchemaHelpers', () => {
expect(result).toEqual(expected);
});
});

describe('.applicatorSchemaName', () => {
const FIRST_CASE = 'first case';
const OTHER_CASES = 'other cases';

test('should not render title because title is null', () => {
expect(
SchemaHelpers.applicatorSchemaName(
0,
FIRST_CASE,
OTHER_CASES,
null as never,
),
).toMatchSnapshot();

expect(
SchemaHelpers.applicatorSchemaName(
1,
FIRST_CASE,
OTHER_CASES,
null as never,
),
).toMatchSnapshot();
});

test('should not render title because title is undefined', () => {
expect(
SchemaHelpers.applicatorSchemaName(
0,
FIRST_CASE,
OTHER_CASES,
undefined,
),
).toMatchSnapshot();

expect(
SchemaHelpers.applicatorSchemaName(
1,
FIRST_CASE,
OTHER_CASES,
undefined,
),
).toMatchSnapshot();
});

test('should render title', () => {
const TITLE = 'title example';
expect(
SchemaHelpers.applicatorSchemaName(0, FIRST_CASE, OTHER_CASES, TITLE),
).toMatchSnapshot();

expect(
SchemaHelpers.applicatorSchemaName(1, FIRST_CASE, OTHER_CASES, TITLE),
).toMatchSnapshot();
});
});
});
2 changes: 1 addition & 1 deletion library/src/helpers/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class SchemaHelpers {
otherCases: string,
title?: string,
) {
const suffix = (title !== null && ` ${title}:`) || `:`;
const suffix = title ? ` ${title}:` : ':';
if (idx === 0) {
return `${firstCase}${suffix}`;
} else {
Expand Down

0 comments on commit 9b73229

Please sign in to comment.