|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +import { expect, test, beforeAll } from 'vitest'; |
| 4 | +import { ComponentDefinition } from '../../src/components/interfaces'; |
| 5 | +import { buildProject } from './test-helpers'; |
| 6 | + |
| 7 | +let codeEditor: ComponentDefinition; |
| 8 | + |
| 9 | +beforeAll(() => { |
| 10 | + const result = buildProject('string-intersection'); |
| 11 | + expect(result).toHaveLength(1); |
| 12 | + [codeEditor] = result; |
| 13 | +}); |
| 14 | + |
| 15 | +test('string intersection union should be treated as primitive string type', () => { |
| 16 | + const languageProp = codeEditor.properties.find(def => def.name === 'language'); |
| 17 | + |
| 18 | + // The new getPrimitiveType function should identify this as a string type |
| 19 | + expect(languageProp?.type).toBe('string'); |
| 20 | +}); |
| 21 | + |
| 22 | +test('string intersection values should include "string" for custom values', () => { |
| 23 | + const languageProp = codeEditor.properties.find(def => def.name === 'language'); |
| 24 | + |
| 25 | + if (languageProp?.inlineType?.type === 'union') { |
| 26 | + // Should contain literal values |
| 27 | + expect(languageProp.inlineType.values).toContain('javascript'); |
| 28 | + expect(languageProp.inlineType.values).toContain('html'); |
| 29 | + |
| 30 | + // Should contain "string" to indicate custom values are allowed |
| 31 | + expect(languageProp.inlineType.values).toContain('string'); |
| 32 | + |
| 33 | + // Should not contain raw intersection syntax |
| 34 | + const hasRawIntersection = languageProp.inlineType.values.some( |
| 35 | + (value: string) => value.includes('string &') || value.includes('_?:') |
| 36 | + ); |
| 37 | + expect(hasRawIntersection).toBe(false); |
| 38 | + } |
| 39 | +}); |
| 40 | + |
| 41 | +test('union type name should be preserved in inlineType', () => { |
| 42 | + const languageProp = codeEditor.properties.find(def => def.name === 'language'); |
| 43 | + |
| 44 | + expect(languageProp?.inlineType?.name).toBe('CodeEditorProps.Language'); |
| 45 | + expect(languageProp?.inlineType?.type).toBe('union'); |
| 46 | +}); |
0 commit comments