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

- old
+ new

@@ -50,44 +50,59 @@ } }) end def default_cell_height - return UITableViewAutomaticDimension if TestHelper.ios8 + return UITableViewAutomaticDimension if TestHelper.gte_ios8 return 97.0 if TestHelper.ios7 # Normally 44, but 97 because of `row_height` designation end def default_header_height # Thanks, Apple. - return -1.0 if TestHelper.ios8 + return -1.0 if TestHelper.gte_ios8 return 23.0 if TestHelper.ios7 return 22.0 if TestHelper.ios6 end + def default_footer_height + # Couldn't alias_method inside of a Bacon::Context so I'm defining this + # method to just call default_header_height. I'm reasonably sure that + # the defaults are the same for section headers and footers. + default_header_height + 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", 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: "Table cell group 1", :footer => "Footer for table cell group 1", cells: [ ] + }, { + title: "Table cell group 2", :footer => "Footer for table cell group 2", cells: [ cell_factory ] + }, { + title: "Table cell group 3", :footer => "Footer for 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", :footer => "Footer for 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: [ ] - },{ + }, { title: "Custom section title 2", title_view: CustomTitleView.new, title_view_height: 50, cells: [ ] - },{ + }, { title: "Action With Index Path Group", cells: [ cell_factory(title: "IndexPath Group 1", action: :tests_index_path) ] }, { title: "Action With A Proc", cells: [ proc_cell ] - },{ + }, { title: "test 40", title_view: DynamicHeightTitleView40, cells: [] }, { title: "test 121", title_view: DynamicHeightTitleView121, cells: [] + }, { + footer: "Custom section footer 1", footer_view: CustomFooterView, cells: [ ] + }, { + footer: "Custom section footer 2", footer_view: CustomFooterView.new, footer_view_height: 50, cells: [ ] + }, { + footer: "Footer test 40", footer_view: DynamicHeightFooterView40, cells: [] + }, { + footer: "Footer test 121", footer_view: DynamicHeightFooterView121, cells: [] }] end @subject.on_load @@ -97,11 +112,11 @@ @subject.update_table_data end it "should have the right number of sections" do - @subject.numberOfSectionsInTableView(@subject.table_view).should == 10 + @subject.numberOfSectionsInTableView(@subject.table_view).should == 14 end it "should set the section titles" do @subject.tableView(@subject.table_view, titleForHeaderInSection:0).should == "Table cell group 1" @subject.tableView(@subject.table_view, titleForHeaderInSection:1).should == "Table cell group 2" @@ -109,21 +124,30 @@ @subject.tableView(@subject.table_view, titleForHeaderInSection:3).should == "Table cell group 4" @subject.tableView(@subject.table_view, titleForHeaderInSection:4).should == "Custom section title 1" @subject.tableView(@subject.table_view, titleForHeaderInSection:5).should == "Custom section title 2" end + it "should set the section footers" do + @subject.tableView(@subject.table_view, titleForFooterInSection:0).should == "Footer for table cell group 1" + @subject.tableView(@subject.table_view, titleForFooterInSection:1).should == "Footer for table cell group 2" + @subject.tableView(@subject.table_view, titleForFooterInSection:2).should == "Footer for table cell group 3" + @subject.tableView(@subject.table_view, titleForFooterInSection:3).should == "Footer for table cell group 4" + @subject.tableView(@subject.table_view, titleForFooterInSection:10).should == "Custom section footer 1" + @subject.tableView(@subject.table_view, titleForFooterInSection:11).should == "Custom section footer 2" + end + it "should create the right number of cells" do @subject.tableView(@subject.table_view, numberOfRowsInSection:0).should == 0 @subject.tableView(@subject.table_view, numberOfRowsInSection:1).should == 1 @subject.tableView(@subject.table_view, numberOfRowsInSection:2).should == 2 @subject.tableView(@subject.table_view, numberOfRowsInSection:3).should == 4 @subject.tableView(@subject.table_view, numberOfRowsInSection:4).should == 0 @subject.tableView(@subject.table_view, numberOfRowsInSection:5).should == 0 end it "should create the jumplist" do - @subject.mock! :table_data_index, do + @subject.mock!(:table_data_index) do Array("A".."Z") end @subject.sectionIndexTitlesForTableView(@subject.table_view).should == Array("A".."Z") end @@ -221,9 +245,35 @@ end it "should set the height of a title view when the method `height` is implemented" do @subject.tableView(@subject.table_view, heightForHeaderInSection:8).should == 40.0 @subject.tableView(@subject.table_view, heightForHeaderInSection:9).should == 121.0 + end + end + + describe("section with custom footer_view") do + + it "should use the correct class for section view" do + cell = @subject.tableView(@subject.table_view, viewForFooterInSection: 10) + cell.should.be.kind_of(CustomFooterView) + end + + it "should use the default section height if none is specified" do + @subject.tableView(@subject.table_view, heightForFooterInSection: 10).should == default_footer_height + end + + it "should use the set footer_view_height if one is specified" do + @subject.tableView(@subject.table_view, heightForFooterInSection: 11).should == 50.0 + end + + it "should use the instantiated section view if one is specified" do + cell = @subject.tableView(@subject.table_view, viewForFooterInSection: 11) + cell.should.be.kind_of(CustomFooterView) + end + + it "should set the height of a title view when the method `height` is implemented" do + @subject.tableView(@subject.table_view, heightForFooterInSection: 12).should == 40.0 + @subject.tableView(@subject.table_view, heightForFooterInSection: 13).should == 121.0 end end describe "header view modifications" do