Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: render schema title if it exists #877

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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