Skip to content

Commit

Permalink
Spec passes! empty tables work.
Browse files Browse the repository at this point in the history
  • Loading branch information
austinseraphin committed Apr 25, 2015
1 parent dd7b91a commit 35a9f52
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/tables.rb
@@ -1,6 +1,6 @@
class Table_Test < UIViewController

attr_reader :table
attr_reader :table, :data

Phonetics = %w[alpha bravo charlie delta echo foxtrat golf hotel india juliet kilo lima mike november oscar papa quebec romeo siera tango uniform victor whiskey x-ray yankee zulu]

Expand Down
74 changes: 59 additions & 15 deletions lib/project/test.rb
Expand Up @@ -80,7 +80,7 @@ def self.quiet=(q)
},
UINavigationBar: {
accessibility_label: nil,
accessibility_traits: ->(t){A11y::Test.nonstandard(t)},
accessibility_traits: :nonstandard,
accessibility_elements_hidden: false,
should_group_accessibility_children: true,
accessibility_identifier: [String, "You must set the accessibility_identifier to the title of the view. You can set the title of the view controller or of the navigation item."],
Expand Down Expand Up @@ -151,12 +151,12 @@ def self.quiet=(q)
},
UISwitch: {
accessibility_label: nil,
accessibility_traits: ->(t){A11y::Test.nonstandard(t, custom: UIAccessibilityTraitButton, message: "You can use :button.")},
accessibility_traits: :nonstandard,
accessibility_value: [String, "You must set the accessibility_value to \"1\" or \"0\""]
},
UITabBar: {
accessibility_label: nil,
accessibility_traits: ->(t){A11y::Test.nonstandard(t)},
accessibility_traits: :nonstandard,
should_group_accessibility_children: true,
is_accessibility_element: false,
options: {
Expand All @@ -166,7 +166,7 @@ def self.quiet=(q)
},
UITabBarButton: {
accessibility_label: [String, "You must set the title of this button. You can se tthe title of the UITabBarItem."],
accessibility_traits: ->(t){A11y::Test.nonstandard(t, apple: Bignum, custom: UIAccessibilityTraitButton, message: "You can use :button.")},
accessibility_traits: :nonstandard,
},
UITabBarController: {
accessibility_label: nil,
Expand All @@ -177,10 +177,10 @@ def self.quiet=(q)
}
},
UITableView: {
accessibility_label: [String, "You must set the accessibility_label to the default contents of the table view, for example \"Empty List\""],
accessibility_traits: ->(t){A11y::Test.nonstandard(t)},
accessibility_label: ->(t){table_label(t)},
accessibility_traits: :nonstandard,
should_group_accessibility_children: true,
is_accessibility_element: false
is_accessibility_element: ->(t){ table_is_element(t)}
},
UITableViewCell: {
accessibility_label: :ignore,
Expand All @@ -200,27 +200,27 @@ def self.quiet=(q)
},
UITableTextAccessibilityElement: {
accessibility_label: [String, "Set the accessibility_label to the text of the view."],
accessibility_traits: UIAccessibilityTraitStaticText,
accessibility_traits: :ignore,
accessibility_value: String,
},
UITableViewHeaderFooterView: {
accessibility_label: [String, "Set the accessibility_label to tell VoiceOver what to read. You can do this with the textLabel.text property."]
},
UITextField: {
accessibility_label: nil,
accessibility_traits: ->(t){A11y::Test.nonstandard(t, apple: Fixnum)},
accessibility_traits: :nonstandard,
accessibility_value: [:something, "You must set the text of the textfield."],
is_accessibility_element: false
},
UIAccessibilityTextFieldElement: {
accessibility_label: nil,
accessibility_traits: ->(t){A11y::Test.nonstandard(t, apple: Fixnum)},
accessibility_traits: :nonstandard,
accessibility_value: [:something, "You must set the text of the textfield."],
is_accessibility_element: true
},
UIToolbar: {
accessibility_label: nil,
accessibility_traits: ->(t){A11y::Test.nonstandard(t)},
accessibility_traits: :nonstandard,
should_group_accessibility_children: true,
is_accessibility_element:false,
options: {
Expand Down Expand Up @@ -288,16 +288,17 @@ def self.quiet=(q)
options: {recurse: false}
}
Tests[:UITableView] = {
accessibility_label: nil,
accessibility_traits: ->(t){A11y::Test.nonstandard(t)},
accessibility_label: ->(t){table_label(t)},
accessibility_traits: :nonstandard,
should_group_accessibility_children: true,
is_accessibility_element: false
is_accessibility_element: ->(t){table_is_element(t)}
}
Tests[:UITableViewCell] = {
accessibility_label: :ignore,
accessibility_value: :ignore,
should_group_accessibility_children: true,
is_accessibility_element: false,
accessibility_elements_hidden: :ignore,
options: {
recurse: false,
test: :tableViewCell
Expand Down Expand Up @@ -372,6 +373,36 @@ def self.tabBarViewController(controller)
result
end

def self.table_is_element(table)
if table.empty?
unless table.accessibility_element?
A11y::Test::Log.add(Path, "You must set is_accessibility_element to true for an empty table.")
return false
end
else
if table.accessibility_element?
A11y::Test::Log.add(Path, "You must set is_accessibility_element to false for a table with data.")
return false
end
end
true
end

def self.table_label(table)
if table.empty?
unless table.accessibility_label.is_a?(String)
A11y::Test::Log.add(Path, "You must set the accessibility label to what you want VoiceOver to say instead of an empty table.")
return false
end
else
unless table.accessibility_label.nil?
A11y::Test::Log.add(Path, "You must set the accessibility label to nil.")
return false
end
end
true
end

def self.tableViewCell(cell)
return true if cell.accessibility_label||cell.textLabel.text
A11y::Test::Log.add(Path, "Please set the accessibility_label of the UITableViewCell. You can do this by setting the textLabel.text property.")
Expand Down Expand Up @@ -412,14 +443,15 @@ def self.run_test(obj, attribute, expected, message=nil)
return true if expected==:ignore
value=obj.send(attribute) if obj.respond_to?(attribute)
return value if expected==:something
return nonstandard(value) if expected==:nonstandard
result=true
if expected.class==Class
if value.class!=expected
result=false
message||="#{attribute} must have an object of type #{expected} instead of #{value}"
end
elsif expected.kind_of?(Proc)
r=expected.call(value)
r=expected.call(obj)
unless r
result=false
message||="The test function for #{attribute} failed."
Expand Down Expand Up @@ -510,3 +542,15 @@ def accessible?
end
class UITableView
def empty?
cells=0
numberOfSections.times do |section|
cells+=numberOfRowsInSection(section)
end
cells==0
end
end
3 changes: 3 additions & 0 deletions spec/test.rb
Expand Up @@ -204,6 +204,9 @@ def pickerView(view, numberOfRowsInComponent: component)
it "UITableView" do
controller=Spec_Table_Test.alloc.initWithNibName(nil, bundle: nil)
controller.view.should.be.accessible
controller.data.clear
controller.table.reloadData
controller.view.should.be.accessible
end

it "UITableViewCell" do
Expand Down

0 comments on commit 35a9f52

Please sign in to comment.