Skip to content

Commit 7716472

Browse files
committed
Added tests for ListProperty.
1 parent f802cf4 commit 7716472

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

__tests__/properties.coffee

+49-4
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,59 @@ test 'Throw an error when the required list property get null.', ->
248248
expect(-> property.toJs null).toThrow exceptions.ValueRequiredError
249249
expect(-> property.toDb property: null).toThrow exceptions.ValueRequiredError
250250

251-
test 'Convert the value of the list property to the list.', ->
251+
test 'Convert the value of the string list property to the list.', ->
252252
property = new properties.ListProperty
253253
itemClass: properties.StringProperty
254254
property.propertyName = 'property'
255255
instance =
256-
property: ['item']
257-
expect(property.toJs(['item'])).toEqual ['item']
258-
expect(property.toDb(instance)).toEqual ['item']
256+
property: ['itemA', 'itemB']
257+
expect(property.toJs(['itemA', 'itemB'])).toEqual ['itemA', 'itemB']
258+
expect(property.toDb(instance)).toEqual ['itemA', 'itemB']
259+
260+
test 'Convert the value of the integer list property to the list.', ->
261+
property = new properties.ListProperty
262+
itemClass: properties.IntegerProperty
263+
property.propertyName = 'property'
264+
instance =
265+
property: [2, 3]
266+
expect(property.toJs([2, 3])).toEqual [2, 3]
267+
expect(property.toDb(instance)).toEqual [2, 3]
268+
269+
test 'Convert the value of the float list property to the list.', ->
270+
property = new properties.ListProperty
271+
itemClass: properties.FloatProperty
272+
property.propertyName = 'property'
273+
instance =
274+
property: [3.1, 3.3]
275+
expect(property.toJs([3.1, 3.3])).toEqual [3.1, 3.3]
276+
expect(property.toDb(instance)).toEqual [3.1, 3.3]
277+
278+
test 'Convert the value of the boolean list property to the list.', ->
279+
property = new properties.ListProperty
280+
itemClass: properties.BooleanProperty
281+
property.propertyName = 'property'
282+
instance =
283+
property: [yes, no]
284+
expect(property.toJs([yes, no])).toEqual [yes, no]
285+
expect(property.toDb(instance)).toEqual [yes, no]
286+
287+
test 'Convert the value of the date list property to the list.', ->
288+
property = new properties.ListProperty
289+
itemClass: properties.DateProperty
290+
property.propertyName = 'property'
291+
instance =
292+
property: [new Date('2019-01-29T06:01:00.000Z')]
293+
expect(property.toJs(['2019-01-29T06:01:00.000Z'])).toEqual [new Date('2019-01-29T06:01:00.000Z')]
294+
expect(property.toDb(instance)).toEqual ['2019-01-29T06:01:00.000Z']
295+
296+
test 'Direct pass the value of object list properties to the list.', ->
297+
property = new properties.ListProperty
298+
itemClass: properties.ObjectProperty
299+
property.propertyName = 'property'
300+
instance =
301+
property: [{a: yes}]
302+
expect(property.toJs([{a: yes}])).toEqual [{a: yes}]
303+
expect(property.toDb(instance)).toEqual [{a: yes}]
259304

260305

261306
# Object property

0 commit comments

Comments
 (0)