Skip to content

Commit c683d73

Browse files
committed
fix: 补充wxif单测case
1 parent e56ba47 commit c683d73

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

packages/webpack-plugin/test/platform/common/wx-if.spec.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,105 @@ describe('template if should transform correct', function () {
141141
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,' +
142142
'(true && someVar)?createElement(getComponent("mpx-text"), null,"1"):null)')
143143
})
144+
145+
it('should handle static true wx:if with dynamic wx:elif', function () {
146+
const input = '<view><text wx:if="{{true}}">1</text><text wx:elif="{{condition}}">2</text></view>'
147+
const wxOutput = compileTemplateToWx(input)
148+
expect(wxOutput).toBe('<view><text>1</text></view>')
149+
150+
const iosOutput = compileTemplateToIos(input)
151+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,createElement(getComponent("mpx-text"), null,"1"))')
152+
})
153+
154+
it('should handle static true wx:if with static true wx:elif', function () {
155+
const input = '<view><text wx:if="{{true}}">1</text><text wx:elif="{{true}}">2</text></view>'
156+
const wxOutput = compileTemplateToWx(input)
157+
expect(wxOutput).toBe('<view><text>1</text></view>')
158+
159+
const iosOutput = compileTemplateToIos(input)
160+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,createElement(getComponent("mpx-text"), null,"1"))')
161+
})
162+
163+
it('should handle static true wx:if with static false wx:elif', function () {
164+
const input = '<view><text wx:if="{{true}}">1</text><text wx:elif="{{false}}">2</text></view>'
165+
const wxOutput = compileTemplateToWx(input)
166+
expect(wxOutput).toBe('<view><text>1</text></view>')
167+
168+
const iosOutput = compileTemplateToIos(input)
169+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,createElement(getComponent("mpx-text"), null,"1"))')
170+
})
171+
172+
it('should handle static false wx:if with dynamic wx:elif', function () {
173+
const input = '<view><text wx:if="{{false}}">1</text><text wx:elif="{{condition}}">2</text></view>'
174+
const wxOutput = compileTemplateToWx(input)
175+
expect(wxOutput).toBe('<view><text wx:if="{{condition}}">2</text></view>')
176+
177+
const iosOutput = compileTemplateToIos(input)
178+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,(condition)?createElement(getComponent("mpx-text"), null,"2"):null)')
179+
})
180+
181+
it('should handle static false wx:if with static true wx:elif', function () {
182+
const input = '<view><text wx:if="{{false}}">1</text><text wx:elif="{{true}}">2</text></view>'
183+
const wxOutput = compileTemplateToWx(input)
184+
expect(wxOutput).toBe('<view><text>2</text></view>')
185+
186+
const iosOutput = compileTemplateToIos(input)
187+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,createElement(getComponent("mpx-text"), null,"2"))')
188+
})
189+
190+
it('should handle static false wx:if with static false wx:elif', function () {
191+
const input = '<view><text wx:if="{{false}}">1</text><text wx:elif="{{false}}">2</text></view>'
192+
const wxOutput = compileTemplateToWx(input)
193+
expect(wxOutput).toBe('<view></view>')
194+
195+
const iosOutput = compileTemplateToIos(input)
196+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null)')
197+
})
198+
199+
it('should handle static true wx:if with wx:elif and wx:else', function () {
200+
const input = '<view><text wx:if="{{true}}">1</text><text wx:elif="{{condition}}">2</text><text wx:else>3</text></view>'
201+
const wxOutput = compileTemplateToWx(input)
202+
expect(wxOutput).toBe('<view><text>1</text></view>')
203+
204+
const iosOutput = compileTemplateToIos(input)
205+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,createElement(getComponent("mpx-text"), null,"1"))')
206+
})
207+
208+
it('should handle static false wx:if with static true wx:elif and wx:else', function () {
209+
const input = '<view><text wx:if="{{false}}">1</text><text wx:elif="{{true}}">2</text><text wx:else>3</text></view>'
210+
const wxOutput = compileTemplateToWx(input)
211+
expect(wxOutput).toBe('<view><text>2</text></view>')
212+
213+
const iosOutput = compileTemplateToIos(input)
214+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,createElement(getComponent("mpx-text"), null,"2"))')
215+
})
216+
217+
it('should handle static false wx:if with static false wx:elif and wx:else', function () {
218+
const input = '<view><text wx:if="{{false}}">1</text><text wx:elif="{{false}}">2</text><text wx:else>3</text></view>'
219+
const wxOutput = compileTemplateToWx(input)
220+
expect(wxOutput).toBe('<view><text>3</text></view>')
221+
222+
const iosOutput = compileTemplateToIos(input)
223+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,createElement(getComponent("mpx-text"), null,"3"))')
224+
})
225+
226+
it('should handle dynamic wx:if with static false wx:elif and wx:else', function () {
227+
const input = '<view><text wx:if="{{condition}}">1</text><text wx:elif="{{false}}">2</text><text wx:else>3</text></view>'
228+
const wxOutput = compileTemplateToWx(input)
229+
expect(wxOutput).toBe('<view><text wx:if="{{condition}}">1</text><text wx:else>3</text></view>')
230+
231+
const iosOutput = compileTemplateToIos(input)
232+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,(condition)?createElement(getComponent("mpx-text"), null,"1"):createElement(getComponent("mpx-text"), null,"3"))')
233+
})
234+
235+
it('should handle dynamic wx:if with static true wx:elif and wx:else', function () {
236+
const input = '<view><text wx:if="{{condition}}">1</text><text wx:elif="{{true}}">2</text><text wx:else>3</text></view>'
237+
const wxOutput = compileTemplateToWx(input)
238+
expect(wxOutput).toBe('<view><text wx:if="{{condition}}">1</text><text wx:else>2</text></view>')
239+
240+
const iosOutput = compileTemplateToIos(input)
241+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,(condition)?createElement(getComponent("mpx-text"), null,"1"):createElement(getComponent("mpx-text"), null,"2"))')
242+
})
144243
})
145244

146245
describe('error cases', () => {

0 commit comments

Comments
 (0)