Some awesome WebScreen tests.

This commit is contained in:
Mark Rickert
2013-06-17 19:10:26 -04:00
parent aa2f43a132
commit abcccaf9a2
4 changed files with 155 additions and 0 deletions

1
resources/WebScreen.html Normal file
View File

@@ -0,0 +1 @@
<h1>Test</h1>

View File

@@ -0,0 +1,113 @@
describe "ProMotion::TestWebScreen functionality" do
tests PM::TestWebScreen
# Override controller to properly instantiate
def controller
rotate_device to: :portrait, button: :bottom
@webscreen ||= TestWebScreen.new(nav_bar: true)
@webscreen.main_controller
end
after do
@webscreen = nil
end
it "should have the proper html content" do
file_name = "WebScreen.html"
@webscreen.set_content(file_name)
@loaded_file = File.read(File.join(NSBundle.mainBundle.resourcePath, file_name))
wait 0.5 do
@webscreen.html.should == @loaded_file
end
end
it "should allow you to navigate to a website" do
@webscreen.set_content(NSURL.URLWithString("http://www.google.com"))
wait 1.0 do
@webscreen.html.include?('<form action="/search"').should == true
end
end
# it "should have a navigation bar" do
# @map.navigationController.should.be.kind_of(UINavigationController)
# end
# it "should have the map properly centered" do
# center_coordinate = @map.center
# center_coordinate.latitude.should == 35.090648651123
# center_coordinate.longitude.should == -82.965972900391
# end
# it "should move the map center" do
# @map.center = {latitude: 35.07496, longitude: -82.95916, animated: true}
# wait 0.75 do
# center_coordinate = @map.center
# center_coordinate.latitude.should == 35.07496
# center_coordinate.longitude.should == -82.95916
# end
# end
# it "should select an annotation" do
# @map.selected_annotations.should == nil
# @map.select_annotation(@map.annotations.first, true)
# wait 0.75 do
# @map.selected_annotations.count.should == 1
# end
# end
# it "should select another annotation and check that the title is correct" do
# @map.selected_annotations.should == nil
# @map.select_annotation(@map.annotations[1], true)
# wait 0.75 do
# @map.selected_annotations.count.should == 1
# end
# @map.selected_annotations.first.title.should == "Turtleback Falls"
# @map.selected_annotations.first.subtitle.should == "Nantahala National Forest"
# end
# it "should deselect selected annotations" do
# @map.select_annotation(@map.annotations.last, true)
# wait 0.75 do
# # @map.selected_annotations.count.should == 1
# end
# @map.deselect_annotations
# wait 0.75 do
# @map.selected_annotations.should == nil
# end
# end
# it "should add an annotation and be able to zoom immediately" do
# ann = {
# longitude: -82.966093558105,
# latitude: 35.092520895652,
# title: "Something Else"
# }
# @map.annotations.count.should == 5
# @map.add_annotation ann
# @map.annotations.count.should == 6
# @map.set_region @map.region(coordinate: @map.annotations.last.coordinate, span: [0.05, 0.05])
# @map.select_annotation @map.annotations.last
# end
# it "should be able to overwrite all annotations" do
# anns = [{
# longitude: -122.029620,
# latitude: 37.331789,
# title: "My Cool Pin"
# },{
# longitude: -80.8498118 ,
# latitude: 35.2187218,
# title: "My Cool Pin"
# }]
# @map.annotations.count.should == 5
# @map.add_annotations anns
# @map.annotations.count.should == 2
# end
end

View File

@@ -0,0 +1,22 @@
class TestWebScreen < PM::WebScreen
title "WebScreen Test"
attr_accessor :load_started, :load_failed, :load_finished, :load_failed_error
def load_started
self.load_started = true
end
def load_finished
self.load_finished = true
end
def load_failed(error)
puts "Load Failed: #{error.localizedDescription}"
puts error.localizedFailureReason
self.load_failed = true
self.load_failed_error = error
end
end

19
spec/unit/web_spec.rb Normal file
View File

@@ -0,0 +1,19 @@
describe "web screen properties" do
before do
# Simulate AppDelegate setup of map screen
@webscreen = TestWebScreen.new modal: true, nav_bar: true, external_links: false
@webscreen.set_content("WebScreen.html")
end
it "should have a UIWebView as the primary view" do
@webscreen.web.class.should == UIWebView
end
it "should load the about html page" do
wait 0.5 do
@webscreen.load_finished.should == true
end
end
end