From fcc7df7af3a413ba0fed94bd00cf500b1e043221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Roma=C5=84ski?= Date: Thu, 4 Aug 2022 17:24:28 +0200 Subject: [PATCH] test: add tests to cover fix for double title displaying case --- .../__tests__/MarkdownRenderer.test.ts | 18 ++++++++++++++ src/services/__tests__/models/ApiInfo.test.ts | 24 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/services/__tests__/MarkdownRenderer.test.ts b/src/services/__tests__/MarkdownRenderer.test.ts index 669a8fb0..777822c0 100644 --- a/src/services/__tests__/MarkdownRenderer.test.ts +++ b/src/services/__tests__/MarkdownRenderer.test.ts @@ -97,4 +97,22 @@ describe('Markdown renderer', () => { expect(part.component).toBe(TestComponent); expect(part.props).toEqual({ children: ' Test Test ' }); }); + + test('should properly extract title from text', () => { + const rawTexts = ['text before\n# Test', 'text before\n # Test', 'text before\n# Test\n']; + rawTexts.forEach(text => { + const headings = renderer.extractHeadings(text); + expect(headings).toHaveLength(1); + expect(headings[0].name).toEqual('Test'); + expect(headings[0].description).toEqual(''); + }); + + const rawTexts2 = ['# Test \n text after', '# Test \ntext after']; + rawTexts2.forEach(text => { + const headings = renderer.extractHeadings(text); + expect(headings).toHaveLength(1); + expect(headings[0].name).toEqual('Test'); + expect(headings[0].description).toEqual('text after'); + }); + }); }); diff --git a/src/services/__tests__/models/ApiInfo.test.ts b/src/services/__tests__/models/ApiInfo.test.ts index 4a67139e..867d50e9 100644 --- a/src/services/__tests__/models/ApiInfo.test.ts +++ b/src/services/__tests__/models/ApiInfo.test.ts @@ -47,6 +47,30 @@ describe('Models', () => { expect(info.summary).toEqual('Test summary\nsome text\n## Heading\n test'); }); + test('should correctly populate description when 2nd line is started by white space', () => { + parser.spec = { + openapi: '3.0.0', + info: { + description: 'text before\n # Test', + }, + } as any; + + const info = new ApiInfoModel(parser); + expect(info.description).toEqual('text before\n'); + }); + + test('should correctly populate description when 2nd line is only white space', () => { + parser.spec = { + openapi: '3.0.0', + info: { + description: 'text before\n \n # Test', + }, + } as any; + + const info = new ApiInfoModel(parser); + expect(info.description).toEqual('text before\n'); + }); + test('should correctly populate license identifier', () => { parser.spec = { openapi: '3.1.0',