@@ -17,7 +17,7 @@ describe('Module: UniqueStaticBlockId', () => {
1717 ) ;
1818 } ) ;
1919
20- it ( 'should not report an error when two static blocks have differnt id' , async ( ) => {
20+ it ( 'should not report an error when two static blocks have different id' , async ( ) => {
2121 const sourceCode = `
2222 {% content_for "block", type: "text", id: "static-block1" %}
2323 {% content_for "block", type: "text", id: "static-block2" %}
@@ -52,4 +52,91 @@ describe('Module: UniqueStaticBlockId', () => {
5252
5353 expect ( offenses ) . to . have . length ( 0 ) ;
5454 } ) ;
55+
56+ it ( 'should not report an error when blocks share the same id but have different arbitrary params' , async ( ) => {
57+ const sourceCode = `
58+ {% content_for "block", type: "text", id: "header-menu", variant: "mobile" %}
59+ {% content_for "block", type: "text", id: "header-menu", variant: "navigation_bar" %}
60+ {% content_for "block", type: "text", id: "header-menu" %}
61+ ` ;
62+
63+ const offenses = await runLiquidCheck ( UniqueStaticBlockId , sourceCode ) ;
64+
65+ expect ( offenses ) . to . have . length ( 0 ) ;
66+ } ) ;
67+
68+ it ( 'should report an error when blocks share the same id and same arbitrary params' , async ( ) => {
69+ const sourceCode = `
70+ {% content_for "block", type: "text", id: "header-menu", variant: "mobile" %}
71+ {% content_for "block", type: "text", id: "header-menu", variant: "mobile" %}
72+ ` ;
73+
74+ const offenses = await runLiquidCheck ( UniqueStaticBlockId , sourceCode ) ;
75+
76+ expect ( offenses ) . to . have . length ( 1 ) ;
77+ expect ( offenses [ 0 ] . message ) . to . equal (
78+ "The id 'header-menu' is already being used by another static block" ,
79+ ) ;
80+ } ) ;
81+
82+ it ( 'should not report an error when blocks share the same id but have different values for the same param' , async ( ) => {
83+ const sourceCode = `
84+ {% content_for "block", type: "text", id: "sidebar", color: "blue" %}
85+ {% content_for "block", type: "text", id: "sidebar", color: "red" %}
86+ ` ;
87+
88+ const offenses = await runLiquidCheck ( UniqueStaticBlockId , sourceCode ) ;
89+
90+ expect ( offenses ) . to . have . length ( 0 ) ;
91+ } ) ;
92+
93+ it ( 'should report an error when blocks share the same id and multiple matching params' , async ( ) => {
94+ const sourceCode = `
95+ {% content_for "block", type: "text", id: "sidebar", color: "blue", size: "large" %}
96+ {% content_for "block", type: "text", id: "sidebar", color: "blue", size: "large" %}
97+ ` ;
98+
99+ const offenses = await runLiquidCheck ( UniqueStaticBlockId , sourceCode ) ;
100+
101+ expect ( offenses ) . to . have . length ( 1 ) ;
102+ expect ( offenses [ 0 ] . message ) . to . equal (
103+ "The id 'sidebar' is already being used by another static block" ,
104+ ) ;
105+ } ) ;
106+
107+ it ( 'should report an error when blocks have same params in different order' , async ( ) => {
108+ const sourceCode = `
109+ {% content_for "block", type: "text", id: "sidebar", color: "blue", size: "large" %}
110+ {% content_for "block", type: "text", id: "sidebar", size: "large", color: "blue" %}
111+ ` ;
112+
113+ const offenses = await runLiquidCheck ( UniqueStaticBlockId , sourceCode ) ;
114+
115+ expect ( offenses ) . to . have . length ( 1 ) ;
116+ expect ( offenses [ 0 ] . message ) . to . equal (
117+ "The id 'sidebar' is already being used by another static block" ,
118+ ) ;
119+ } ) ;
120+
121+ it ( 'should not report an error when any arbitrary param is a variable lookup' , async ( ) => {
122+ const sourceCode = `
123+ {% content_for "block", type: "text", id: "header-menu", variant: "mobile" %}
124+ {% content_for "block", type: "text", id: "header-menu", variant: some_variable %}
125+ ` ;
126+
127+ const offenses = await runLiquidCheck ( UniqueStaticBlockId , sourceCode ) ;
128+
129+ expect ( offenses ) . to . have . length ( 0 ) ;
130+ } ) ;
131+
132+ it ( 'should not report an error when two blocks use the same variable lookup' , async ( ) => {
133+ const sourceCode = `
134+ {% content_for "block", type: "text", id: "header-menu", variant: some_variable %}
135+ {% content_for "block", type: "text", id: "header-menu", variant: some_variable %}
136+ ` ;
137+
138+ const offenses = await runLiquidCheck ( UniqueStaticBlockId , sourceCode ) ;
139+
140+ expect ( offenses ) . to . have . length ( 0 ) ;
141+ } ) ;
55142} ) ;
0 commit comments