spec/unit/web_spec.rb in ProMotion-1.2.1 vs spec/unit/web_spec.rb in ProMotion-2.0.0.rc1

- old
+ new

@@ -32,11 +32,11 @@ wait_for_change @webscreen, 'is_load_finished' do @webscreen.html.should =~ /mixi/ end end - it "should called on_request hook" do + it "should call on_request hook" do @webscreen.open_url(NSURL.URLWithString('http://mixi.jp/')) wait_for_change @webscreen, 'on_request' do @webscreen.on_request_args[0].is_a?(NSURLRequest).should == true # on_request is called when @webscreen request for some iframe @@ -44,48 +44,13 @@ end end end - describe "when use on_request hook by web brigde rpc" do + describe "when loading a static html file" do before do - class TestWebScreenWithRPC < TestWebScreen - attr_accessor :on_request, :on_request_args - - def on_request(request, type) - self.on_request_args = [request, type] - self.on_request = true - # return false to prevent loadRequest - false - end - end - stub_request(:get, "http://mixi.jp/"). - to_return(body: "<html><body>[mixi]</body></html>", content_type: "text/html") # Simulate AppDelegate setup of web screen - @webscreen = TestWebScreenWithRPC.new modal: true, nav_bar: true, external_links: false - end - - it "should called on_request hook" do - # simulate web bridge request from html links - @webscreen.open_url(NSURL.URLWithString('webbridge://method')) - - wait_for_change @webscreen, 'on_request' do - request = @webscreen.on_request_args[0] - # on_request is called when @webscreen request for some iframe - request.URL.absoluteString.should == 'webbridge://method' - end - - wait 0.3 do - # it should not load request when return false in on_request - !!(@webscreen.is_load_finished.should) == false - end - end - end - - describe "when load static html file" do - before do - # Simulate AppDelegate setup of web screen @webscreen = TestWebScreen.new modal: true, nav_bar: true, external_links: false @webscreen.set_content("WebScreen.html") end it "should get the url of content" do @@ -98,9 +63,38 @@ it "should load the about html page" do wait_for_change @webscreen, 'is_load_finished' do @webscreen.is_load_finished.should == true end + end + end + + describe "when setting attributes" do + it "should have a default values" do + webscreen = TestWebScreen.new() + webscreen.web.dataDetectorTypes.should == UIDataDetectorTypeNone + webscreen.web.scalesPageToFit.should == false + webscreen.external_links.should == false + end + + it "should set a single data detector" do + webscreen = TestWebScreen.new(detector_types: :phone) + webscreen.web.dataDetectorTypes.should == UIDataDetectorTypePhoneNumber + end + + it "should set multiple data detectors" do + webscreen = TestWebScreen.new(detector_types: [:phone, :link]) + webscreen.web.dataDetectorTypes.should == UIDataDetectorTypePhoneNumber | UIDataDetectorTypeLink + end + + it "should set the scaling mode of the screen" do + webscreen = TestWebScreen.new(scale_to_fit: true) + webscreen.web.scalesPageToFit.should == true + end + + it "should have the ability to open links externally" do + webscreen = TestWebScreen.new(external_links: true) + webscreen.external_links.should == true end end end