spec/models/reactive_array_spec.rb in volt-0.5.18 vs spec/models/reactive_array_spec.rb in volt-0.6.0
- old
+ new
@@ -15,9 +15,52 @@
model._my_ary.insert(0,1,2)
expect(@changed).to eq(true)
end
+ it "should trigger changed from an insert in all places after the index" do
+ model = ReactiveValue.new(Model.new)
+ model._my_ary = [1,2,3]
+
+ count1 = 0
+ count2 = 0
+ model._my_ary[1].on('changed') { count1 += 1 }
+ model._my_ary[3].on('changed') { count2 += 1 }
+ expect(count1).to eq(0)
+ expect(count2).to eq(0)
+
+ model._my_ary.insert(1, 10)
+ expect(count1).to eq(1)
+ expect(count2).to eq(1)
+
+ expect(model._my_ary.cur).to eq([1,10,2,3])
+ end
+
+ it "should pass the index the item was inserted at" do
+ model = ReactiveValue.new(Model.new)
+ model._my_ary = [1,2,3]
+
+ model._my_ary.on('added') do |_, index|
+ expect(index).to eq(2)
+ end
+
+ model._my_ary.insert(2, 20)
+ end
+
+ it "should pass the index the item was inserted at with multiple inserted objects" do
+ model = ReactiveValue.new(Model.new)
+ model._my_ary = [1,2,3]
+
+ received = []
+ model._my_ary.on('added') do |_, index|
+ received << index
+ end
+
+ model._my_ary.insert(2, 20, 30)
+
+ expect(received).to eq([2, 3])
+ end
+
it "should trigger changed on methods of an array model that involve just one cell" do
model = ReactiveValue.new(ReactiveArray.new)
model << 1
model << 2
\ No newline at end of file