|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { TopLevelSection } from '../../../src/context/ContextType'; |
| 3 | +import { OutputSectionFieldHoverProvider } from '../../../src/hover/OutputSectionFieldHoverProvider'; |
| 4 | +import { createMockContext } from '../../utils/MockContext'; |
| 5 | + |
| 6 | +describe('OutputSectionFieldHoverProvider', () => { |
| 7 | + const outputSectionFieldHoverProvider = new OutputSectionFieldHoverProvider(); |
| 8 | + |
| 9 | + describe('Output Section Field Hover', () => { |
| 10 | + it('should return Description documentation when hovering on Description attribute', () => { |
| 11 | + const mockContext = createMockContext(TopLevelSection.Outputs, 'MyOutput', { |
| 12 | + text: 'Description', |
| 13 | + propertyPath: ['Outputs', 'MyOutput', 'Description'], |
| 14 | + }); |
| 15 | + |
| 16 | + const result = outputSectionFieldHoverProvider.getInformation(mockContext); |
| 17 | + |
| 18 | + expect(result).toContain('**Description (optional)**'); |
| 19 | + expect(result).toContain('A `String` type that describes the output value'); |
| 20 | + expect(result).toContain('between 0 and 1024 bytes in length'); |
| 21 | + expect(result).toContain("You can't use a parameter or function to specify the description"); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should return Value documentation when hovering on Value attribute', () => { |
| 25 | + const mockContext = createMockContext(TopLevelSection.Outputs, 'MyOutput', { |
| 26 | + text: 'Value', |
| 27 | + propertyPath: ['Outputs', 'MyOutput', 'Value'], |
| 28 | + }); |
| 29 | + |
| 30 | + const result = outputSectionFieldHoverProvider.getInformation(mockContext); |
| 31 | + |
| 32 | + expect(result).toContain('**Value (required)**'); |
| 33 | + expect(result).toContain('The value of the property returned by the [describe-stacks]'); |
| 34 | + expect(result).toContain( |
| 35 | + 'The value of an output can include literals, parameter references, pseudo parameters, a mapping value, or intrinsic functions', |
| 36 | + ); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should return Export documentation when hovering on Export attribute', () => { |
| 40 | + const mockContext = createMockContext(TopLevelSection.Outputs, 'MyOutput', { |
| 41 | + text: 'Export', |
| 42 | + propertyPath: ['Outputs', 'MyOutput', 'Export'], |
| 43 | + }); |
| 44 | + |
| 45 | + const result = outputSectionFieldHoverProvider.getInformation(mockContext); |
| 46 | + |
| 47 | + expect(result).toContain('**Export (optional)**'); |
| 48 | + expect(result).toContain('The name of the resource output to be exported for a cross-stack reference'); |
| 49 | + expect(result).toContain('You can use intrinsic functions to customize the Name value of an export'); |
| 50 | + expect(result).toContain('Get exported outputs from a deployed CloudFormation stack'); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should return undefined for non-output attributes', () => { |
| 54 | + const mockContext = createMockContext(TopLevelSection.Outputs, 'MyOutput', { |
| 55 | + text: 'InvalidAttribute', |
| 56 | + propertyPath: ['Outputs', 'MyOutput', 'InvalidAttribute'], |
| 57 | + }); |
| 58 | + |
| 59 | + const result = outputSectionFieldHoverProvider.getInformation(mockContext); |
| 60 | + |
| 61 | + expect(result).toBeUndefined(); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should return undefined for empty text', () => { |
| 65 | + const mockContext = createMockContext(TopLevelSection.Outputs, 'MyOutput', { |
| 66 | + text: '', |
| 67 | + propertyPath: ['Outputs', 'MyOutput'], |
| 68 | + }); |
| 69 | + |
| 70 | + const result = outputSectionFieldHoverProvider.getInformation(mockContext); |
| 71 | + |
| 72 | + expect(result).toBeUndefined(); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should return undefined for parameter attributes (case sensitivity)', () => { |
| 76 | + const mockContext = createMockContext(TopLevelSection.Outputs, 'MyOutput', { |
| 77 | + text: 'Type', |
| 78 | + propertyPath: ['Outputs', 'MyOutput', 'Type'], |
| 79 | + }); |
| 80 | + |
| 81 | + const result = outputSectionFieldHoverProvider.getInformation(mockContext); |
| 82 | + |
| 83 | + expect(result).toBeUndefined(); |
| 84 | + }); |
| 85 | + |
| 86 | + it('should return undefined for resource attributes', () => { |
| 87 | + const mockContext = createMockContext(TopLevelSection.Outputs, 'MyOutput', { |
| 88 | + text: 'DependsOn', |
| 89 | + propertyPath: ['Outputs', 'MyOutput', 'DependsOn'], |
| 90 | + }); |
| 91 | + |
| 92 | + const result = outputSectionFieldHoverProvider.getInformation(mockContext); |
| 93 | + |
| 94 | + expect(result).toBeUndefined(); |
| 95 | + }); |
| 96 | + |
| 97 | + it('should be case sensitive for attribute names', () => { |
| 98 | + const mockContext = createMockContext(TopLevelSection.Outputs, 'MyOutput', { |
| 99 | + text: 'description', |
| 100 | + propertyPath: ['Outputs', 'MyOutput', 'description'], |
| 101 | + }); |
| 102 | + |
| 103 | + const result = outputSectionFieldHoverProvider.getInformation(mockContext); |
| 104 | + |
| 105 | + expect(result).toBeUndefined(); |
| 106 | + }); |
| 107 | + }); |
| 108 | + |
| 109 | + describe('isOutputSectionField static method', () => { |
| 110 | + it('should return true for valid output attributes', () => { |
| 111 | + const validAttributes = ['Description', 'Value', 'Export']; |
| 112 | + |
| 113 | + for (const attribute of validAttributes) { |
| 114 | + expect(OutputSectionFieldHoverProvider.isOutputSectionField(attribute)).toBe(true); |
| 115 | + } |
| 116 | + }); |
| 117 | + |
| 118 | + it('should return false for invalid output attributes', () => { |
| 119 | + const invalidAttributes = [ |
| 120 | + 'InvalidAttribute', |
| 121 | + 'Type', |
| 122 | + 'Default', |
| 123 | + 'Properties', |
| 124 | + 'Condition', |
| 125 | + 'DependsOn', |
| 126 | + 'description', |
| 127 | + 'value', |
| 128 | + 'export', |
| 129 | + '', |
| 130 | + 'Name', // This is a property of Export, not a top-level output attribute |
| 131 | + ]; |
| 132 | + |
| 133 | + for (const attribute of invalidAttributes) { |
| 134 | + expect(OutputSectionFieldHoverProvider.isOutputSectionField(attribute)).toBe(false); |
| 135 | + } |
| 136 | + }); |
| 137 | + |
| 138 | + it('should return false for parameter attributes', () => { |
| 139 | + const parameterAttributes = [ |
| 140 | + 'Type', |
| 141 | + 'Default', |
| 142 | + 'AllowedValues', |
| 143 | + 'AllowedPattern', |
| 144 | + 'MinLength', |
| 145 | + 'MaxLength', |
| 146 | + 'MinValue', |
| 147 | + 'MaxValue', |
| 148 | + 'NoEcho', |
| 149 | + 'ConstraintDescription', |
| 150 | + ]; |
| 151 | + |
| 152 | + for (const attribute of parameterAttributes) { |
| 153 | + expect(OutputSectionFieldHoverProvider.isOutputSectionField(attribute)).toBe(false); |
| 154 | + } |
| 155 | + }); |
| 156 | + |
| 157 | + it('should return false for resource attributes', () => { |
| 158 | + const resourceAttributes = [ |
| 159 | + 'CreationPolicy', |
| 160 | + 'DeletionPolicy', |
| 161 | + 'UpdatePolicy', |
| 162 | + 'UpdateReplacePolicy', |
| 163 | + 'Condition', |
| 164 | + 'DependsOn', |
| 165 | + 'Metadata', |
| 166 | + ]; |
| 167 | + |
| 168 | + for (const attribute of resourceAttributes) { |
| 169 | + expect(OutputSectionFieldHoverProvider.isOutputSectionField(attribute)).toBe(false); |
| 170 | + } |
| 171 | + }); |
| 172 | + }); |
| 173 | +}); |
0 commit comments