|
| 1 | +import { describe, beforeEach, it, expect } from 'vitest'; |
| 2 | +import { DocumentManager } from '../../documents'; |
| 3 | +import { HoverProvider } from '../HoverProvider'; |
| 4 | +import { MetafieldDefinitionMap } from '@shopify/theme-check-common'; |
| 5 | +import { GetSnippetDefinitionForURI, SnippetDefinition } from '../../liquidDoc'; |
| 6 | + |
| 7 | +describe('Module: RenderSnippetHoverProvider', async () => { |
| 8 | + let provider: HoverProvider; |
| 9 | + let getSnippetDefinition: GetSnippetDefinitionForURI; |
| 10 | + const mockSnippetDefinition: SnippetDefinition = { |
| 11 | + name: 'product-card', |
| 12 | + liquidDoc: { |
| 13 | + parameters: [ |
| 14 | + { |
| 15 | + name: 'title', |
| 16 | + description: 'The title of the product', |
| 17 | + type: 'string', |
| 18 | + }, |
| 19 | + { |
| 20 | + name: 'border-radius', |
| 21 | + description: 'The border radius in px', |
| 22 | + type: 'number', |
| 23 | + }, |
| 24 | + ], |
| 25 | + }, |
| 26 | + }; |
| 27 | + |
| 28 | + const createProvider = (getSnippetDefinition: GetSnippetDefinitionForURI) => { |
| 29 | + return new HoverProvider( |
| 30 | + new DocumentManager(), |
| 31 | + { |
| 32 | + filters: async () => [], |
| 33 | + objects: async () => [], |
| 34 | + tags: async () => [], |
| 35 | + systemTranslations: async () => ({}), |
| 36 | + }, |
| 37 | + async (_rootUri: string) => ({} as MetafieldDefinitionMap), |
| 38 | + async () => ({}), |
| 39 | + async () => [], |
| 40 | + getSnippetDefinition, |
| 41 | + ); |
| 42 | + }; |
| 43 | + |
| 44 | + beforeEach(async () => { |
| 45 | + getSnippetDefinition = async () => mockSnippetDefinition; |
| 46 | + provider = createProvider(getSnippetDefinition); |
| 47 | + }); |
| 48 | + |
| 49 | + describe('hover', () => { |
| 50 | + it('should return snippet definition with all parameters', async () => { |
| 51 | + await expect(provider).to.hover( |
| 52 | + `{% render 'product-car█d' %}`, |
| 53 | + '### product-card\n\n**Parameters:**\n- `title`: string - The title of the product\n- `border-radius`: number - The border radius in px', |
| 54 | + ); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should return an H3 with snippet name if no LiquidDocDefinition found', async () => { |
| 58 | + getSnippetDefinition = async () => ({ name: 'unknown-snippet' }); |
| 59 | + provider = createProvider(getSnippetDefinition); |
| 60 | + await expect(provider).to.hover(`{% render 'unknown-sni█ppet' %}`, '### unknown-snippet'); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should return nothing if not in render tag', async () => { |
| 64 | + await expect(provider).to.hover(`{% assign asdf = 'snip█pet' %}`, null); |
| 65 | + await expect(provider).to.hover(`{{ 'snip█pet' }}`, null); |
| 66 | + }); |
| 67 | + }); |
| 68 | +}); |
0 commit comments