|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { runLiquidCheck } from '../../test'; |
| 3 | +import { MissingSchema } from './index'; |
| 4 | +import { Config } from '../../types'; |
| 5 | + |
| 6 | +describe('MissingSchema', () => { |
| 7 | + it('should report an error when schema tag is missing on a theme app extension', async () => { |
| 8 | + const config: Config = { |
| 9 | + context: 'app', |
| 10 | + checks: [], |
| 11 | + rootUri: '', |
| 12 | + settings: {}, |
| 13 | + }; |
| 14 | + |
| 15 | + const sourceCode = ` |
| 16 | + <footer class="footer"> |
| 17 | + {% for block in section.blocks %} |
| 18 | + {% case block.type %} |
| 19 | + {% when 'link' %} |
| 20 | + <div class="link" {{ block.shopify_attributes }}> |
| 21 | + {{ block.settings.linktext | link_to: block.settings.linkurl }} |
| 22 | + </div> |
| 23 | +
|
| 24 | + {% when 'custom-text' %} |
| 25 | + <div class="text" {{ block.shopify_attributes }}> |
| 26 | + {{ block.settings.custom-text-field }} |
| 27 | + </div> |
| 28 | + {% endcase %} |
| 29 | + {% endfor %} |
| 30 | + </footer> |
| 31 | + `; |
| 32 | + |
| 33 | + const offenses = await runLiquidCheck(MissingSchema, sourceCode); |
| 34 | + expect(offenses).to.have.lengthOf(1); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should not report when the schema is present on a theme app extension', async () => { |
| 38 | + const config: Config = { |
| 39 | + context: 'app', |
| 40 | + checks: [], |
| 41 | + rootUri: '', |
| 42 | + settings: {}, |
| 43 | + }; |
| 44 | + const sourceCode = ` |
| 45 | +<footer class="footer"> |
| 46 | + {% for block in section.blocks %} |
| 47 | + {% case block.type %} |
| 48 | + {% when 'link' %} |
| 49 | + <div class="link" {{ block.shopify_attributes }}> |
| 50 | + {{ block.settings.linktext | link_to: block.settings.linkurl }} |
| 51 | + </div> |
| 52 | +
|
| 53 | + {% when 'custom-text' %} |
| 54 | + <div class="text" {{ block.shopify_attributes }}> |
| 55 | + {{ block.settings.custom-text-field }} |
| 56 | + </div> |
| 57 | + {% endcase %} |
| 58 | + {% endfor %} |
| 59 | +</footer> |
| 60 | +
|
| 61 | +{% schema %} |
| 62 | +{ |
| 63 | + "name": "Footer", |
| 64 | + "max_blocks": 8, |
| 65 | + "blocks": [ |
| 66 | + { |
| 67 | + "type": "link", |
| 68 | + "name": "Link", |
| 69 | + "settings": [ |
| 70 | + { |
| 71 | + "id": "linkurl", |
| 72 | + "type": "url", |
| 73 | + "label": "URL link" |
| 74 | + }, |
| 75 | + { |
| 76 | + "id": "linktext", |
| 77 | + "type": "text", |
| 78 | + "label": "Link text" |
| 79 | + } |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "type": "custom-text", |
| 84 | + "name": "Custom Text", |
| 85 | + "settings": [ |
| 86 | + { |
| 87 | + "id": "custom-text-field", |
| 88 | + "type": "textarea", |
| 89 | + "label": "Text" |
| 90 | + } |
| 91 | + ] |
| 92 | + } |
| 93 | + ] |
| 94 | +} |
| 95 | +{% endschema %}`; |
| 96 | + |
| 97 | + const offenses = await runLiquidCheck(MissingSchema, sourceCode); |
| 98 | + expect(offenses).to.have.lengthOf(0); |
| 99 | + }); |
| 100 | +}); |
0 commit comments