spec/unit/tables/table_module_spec.rb in ProMotion-2.0.1 vs spec/unit/tables/table_module_spec.rb in ProMotion-2.1.0.beta1

- old
+ new

@@ -3,11 +3,12 @@ def cell_factory(args={}) { title: "Basic", action: :basic_cell_tapped, arguments: { id: 1 } }.merge!(args) end def custom_cell - @image = UIImage.imageNamed("list") + @image ||= UIImage.imageNamed("list") + @pattern_image_color ||= UIColor.colorWithPatternImage(@image) cell_factory({ title: "Crazy Full Featured Cell", subtitle: "This is way too huge..see note", arguments: { data: [ "lots", "of", "data" ] }, action: :tapped_cell_1, @@ -27,26 +28,42 @@ url: "http://placekitten.com/200/300", placeholder: "some-local-image", size: 50, radius: 15 }, - style: { - masks_to_bounds: true, - background_color: UIColor.colorWithPatternImage(@image) + properties: { + content_view: { + background_color: @pattern_image_color, + }, + layer: { + masks_to_bounds: true, + }, } }) end + def default_cell_height + return UITableViewAutomaticDimension if TestHelper.ios8 + return 44.0 if TestHelper.ios7 + end + + def default_header_height + # Thanks, Apple. + return -1.0 if TestHelper.ios8 + return 23.0 if TestHelper.ios7 + return 22.0 if TestHelper.ios6 + end + before do @subject = TestTableScreen.new @subject.mock! :table_data do [{ title: "Table cell group 1", cells: [ ] },{ title: "Table cell group 2", cells: [ cell_factory ] },{ - title: "Table cell group 3", cells: [ cell_factory(title: "3-1"), cell_factory({title: "3-2", style: { background_color: UIColor.blueColor } }) ] + title: "Table cell group 3", cells: [ cell_factory(title: "3-1"), cell_factory({title: "3-2", properties: { background_color: UIColor.blueColor } }) ] },{ title: "Table cell group 4", cells: [ custom_cell, cell_factory(title: "4-2"), cell_factory(title: "4-3"), cell_factory(title: "4-4") ] },{ title: "Custom section title 1", title_view: CustomTitleView, cells: [ ] },{ @@ -99,11 +116,11 @@ cell.should.be.kind_of(UITableViewCell) cell.textLabel.text.should == "3-2" end it "should return the table's cell height if none is given" do - @subject.tableView(@subject.table_view, heightForRowAtIndexPath:@ip).should == 44.0 # Built-in default + @subject.tableView(@subject.table_view, heightForRowAtIndexPath:@ip).should == default_cell_height end it "should allow setting a custom cell height" do @subject.tableView(@subject.table_view, heightForRowAtIndexPath:@custom_ip).should.be > 0.0 @subject.tableView(@subject.table_view, heightForRowAtIndexPath:@custom_ip).should == custom_cell[:height].to_f @@ -138,15 +155,16 @@ # tap(@subject.table_view, :at => location, :times => number_of_taps, :touches => number_of_fingers) # end it "should set a custom cell background image" do @image.should.not.be.nil - ip = NSIndexPath.indexPathForRow(0, inSection: 3) # Cell 2-1 + ip = NSIndexPath.indexPathForRow(0, inSection: 3) # Cell 4-1 cell = @subject.tableView(@subject.table_view, cellForRowAtIndexPath: ip) cell.should.be.kind_of(UITableViewCell) - cell.backgroundColor.should.be.kind_of(UIColor) - cell.backgroundColor.should == UIColor.colorWithPatternImage(@image) + cell.layer.masksToBounds.should == true + cell.contentView.backgroundColor.should.be.kind_of(UIColor) + cell.contentView.backgroundColor.should == @pattern_image_color end it "should set a custom cell background color" do cell = @subject.tableView(@subject.table_view, cellForRowAtIndexPath: @ip) cell.should.be.kind_of(UITableViewCell) @@ -160,11 +178,10 @@ cell = @subject.tableView(@subject.table_view, viewForHeaderInSection: 4) cell.should.be.kind_of(CustomTitleView) end it "should use the default section height if none is specified" do - header_height = (UIDevice.currentDevice.systemVersion.to_f >= 7.0) ? 23.0 : 22.0 - @subject.tableView(@subject.table_view, heightForHeaderInSection:4).should == header_height # Built-in default + @subject.tableView(@subject.table_view, heightForHeaderInSection:4).should == default_header_height end it "should use the set title_view_height if one is specified" do @subject.tableView(@subject.table_view, heightForHeaderInSection:5).should == 50.0 end