Skip to content

Commit

Permalink
Completed data-binding specs for basic date_time fields
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyObtiva committed Nov 7, 2020
1 parent 107c264 commit 300ebc7
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/glimmer/swt/widget_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,16 @@ def widget_property_listener_installers
}
end
},
Java::OrgEclipseSwtWidgets::DateTime =>
[:year, :month, :day, :hours, :minutes, :seconds].reduce({}) do |hash, attribute|
hash.merge(
attribute => lambda do |observer|
on_widget_selected { |selection_event|
observer.call(get_attribute(attribute))
}
end
)
end,
}
end

Expand Down
64 changes: 64 additions & 0 deletions spec/lib/glimmer/dsl/swt/glimmer__date_time__spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,38 @@ class Person
expect(@date_time.year).to eq(2038)
expect(@date_time.month).to eq(11)
expect(@date_time.day).to eq(29)

@date_time.year = 2020
event = Event.new
event.display = @date_time.swt_widget.getDisplay
event.item = @date_time.swt_widget
event.widget = @date_time.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@date_time.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(person.dob.year).to eq(2020)

@date_time.month = 7
event = Event.new
event.display = @date_time.swt_widget.getDisplay
event.item = @date_time.swt_widget
event.widget = @date_time.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@date_time.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(person.dob.month).to eq(7)

@date_time.day = 18
event = Event.new
event.display = @date_time.swt_widget.getDisplay
event.item = @date_time.swt_widget
event.widget = @date_time.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@date_time.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(person.dob.day).to eq(18)

person.dob = Time.new(2033, 3, 2, 12, 47, 32)
expect(@date_time.year).to eq(2033)
expect(@date_time.month).to eq(3)
expect(@date_time.day).to eq(2)
end

it "renders date time with default :date style, data-binding hour, minute, second" do
Expand All @@ -57,6 +89,38 @@ class Person
expect(@date_time.hours).to eq(12)
expect(@date_time.minutes).to eq(47)
expect(@date_time.seconds).to eq(32)

@date_time.hours = 20
event = Event.new
event.display = @date_time.swt_widget.getDisplay
event.item = @date_time.swt_widget
event.widget = @date_time.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@date_time.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(person.dob.hour).to eq(20)

@date_time.minutes = 7
event = Event.new
event.display = @date_time.swt_widget.getDisplay
event.item = @date_time.swt_widget
event.widget = @date_time.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@date_time.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(person.dob.min).to eq(7)

@date_time.seconds = 18
event = Event.new
event.display = @date_time.swt_widget.getDisplay
event.item = @date_time.swt_widget
event.widget = @date_time.swt_widget
event.type = Glimmer::SWT::SWTProxy[:selection]
@date_time.swt_widget.notifyListeners(Glimmer::SWT::SWTProxy[:selection], event)
expect(person.dob.sec).to eq(18)

person.dob = Time.new(2033, 3, 2, 2, 4, 2)
expect(@date_time.hours).to eq(2)
expect(@date_time.minutes).to eq(4)
expect(@date_time.seconds).to eq(2)
end

end
Expand Down

0 comments on commit 300ebc7

Please sign in to comment.