From: Tom Hughes Date: Tue, 8 Jan 2013 22:11:54 +0000 (+0000) Subject: Update tests for layout changes X-Git-Tag: live~5144 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/ed699548e64fc96289b6b04ccd5303692baafffa?ds=sidebyside Update tests for layout changes --- diff --git a/test/functional/changeset_controller_test.rb b/test/functional/changeset_controller_test.rb index 21cae1f00..9ed9f2959 100644 --- a/test/functional/changeset_controller_test.rb +++ b/test/functional/changeset_controller_test.rb @@ -1735,7 +1735,7 @@ EOF assert_template "list" # Now check that all 20 (or however many were returned) changesets are in the html assert_select "h1", :text => "Changesets", :count => 1 - assert_select "table[id='changeset_list'] tr", :count => changesets.size + assert_select "div[id='changeset_list'] ul", :count => changesets.size changesets.each do |changeset| # FIXME this test needs rewriting - test for table contents end diff --git a/test/functional/diary_entry_controller_test.rb b/test/functional/diary_entry_controller_test.rb index d799ddf5a..52356d913 100644 --- a/test/functional/diary_entry_controller_test.rb +++ b/test/functional/diary_entry_controller_test.rb @@ -103,16 +103,20 @@ class DiaryEntryControllerTest < ActionController::TestCase assert_select "title", :text => /New Diary Entry/, :count => 1 end assert_select "body", :count => 1 do - assert_select "div#content", :count => 1 do - assert_select "h1", :text => "New Diary Entry", :count => 1 - # We don't care about the layout, we just care about the form fields - # that are available - assert_select "form[action='/diary/new']", :count => 1 do - assert_select "input[id=diary_entry_title][name='diary_entry[title]']", :count => 1 - assert_select "textarea#diary_entry_body[name='diary_entry[body]']", :count => 1 - assert_select "input#latitude[name='diary_entry[latitude]'][type=text]", :count => 1 - assert_select "input#longitude[name='diary_entry[longitude]'][type=text]", :count => 1 - assert_select "input[name=commit][type=submit][value=Save]", :count => 1 + assert_select "div.wrapper", :count => 1 do + assert_select "div.content-heading", :count => 1 do + assert_select "h1", :text => "New Diary Entry", :count => 1 + end + assert_select "div#content", :count => 1 do + # We don't care about the layout, we just care about the form fields + # that are available + assert_select "form[action='/diary/new']", :count => 1 do + assert_select "input[id=diary_entry_title][name='diary_entry[title]']", :count => 1 + assert_select "textarea#diary_entry_body[name='diary_entry[body]']", :count => 1 + assert_select "input#latitude[name='diary_entry[latitude]'][type=text]", :count => 1 + assert_select "input#longitude[name='diary_entry[longitude]'][type=text]", :count => 1 + assert_select "input[name=commit][type=submit][value=Save]", :count => 1 + end end end end @@ -135,8 +139,10 @@ class DiaryEntryControllerTest < ActionController::TestCase assert_response :not_found assert_select "html", :count => 1 do assert_select "body", :count => 1 do - assert_select "div#content", :count => 1 do - assert_select "h2", :text => "No entry with the id: 9999", :count => 1 + assert_select "div.wrapper", :count => 1 do + assert_select "div.content-heading", :count => 1 do + assert_select "h2", :text => "No entry with the id: 9999", :count => 1 + end end end end @@ -150,18 +156,22 @@ class DiaryEntryControllerTest < ActionController::TestCase assert_select "title", :text => /Edit diary entry/, :count => 1 end assert_select "body", :count => 1 do - assert_select "div#content", :count => 1 do - assert_select "h1", :text => /Edit diary entry/, :count => 1 - assert_select "form[action='/user/#{entry.user.display_name}/diary/#{entry.id}/edit'][method=post]", :count => 1 do - assert_select "input#diary_entry_title[name='diary_entry[title]'][value='#{entry.title}']", :count => 1 - assert_select "textarea#diary_entry_body[name='diary_entry[body]']", :text => entry.body, :count => 1 - assert_select "select#diary_entry_language_code", :count => 1 - assert_select "input#latitude[name='diary_entry[latitude]']", :count => 1 - assert_select "input#longitude[name='diary_entry[longitude]']", :count => 1 - assert_select "input[name=commit][type=submit][value=Save]", :count => 1 - assert_select "input[name=commit][type=submit][value=Edit]", :count => 1 - assert_select "input[name=commit][type=submit][value=Preview]", :count => 1 - assert_select "input", :count => 7 + assert_select "div.wrapper", :count => 1 do + assert_select "div.content-heading", :count => 1 do + assert_select "h1", :text => /Edit diary entry/, :count => 1 + end + assert_select "div#content", :count => 1 do + assert_select "form[action='/user/#{entry.user.display_name}/diary/#{entry.id}/edit'][method=post]", :count => 1 do + assert_select "input#diary_entry_title[name='diary_entry[title]'][value='#{entry.title}']", :count => 1 + assert_select "textarea#diary_entry_body[name='diary_entry[body]']", :text => entry.body, :count => 1 + assert_select "select#diary_entry_language_code", :count => 1 + assert_select "input#latitude[name='diary_entry[latitude]']", :count => 1 + assert_select "input#longitude[name='diary_entry[longitude]']", :count => 1 + assert_select "input[name=commit][type=submit][value=Save]", :count => 1 + assert_select "input[name=commit][type=submit][value=Edit]", :count => 1 + assert_select "input[name=commit][type=submit][value=Preview]", :count => 1 + assert_select "input", :count => 7 + end end end end @@ -189,16 +199,20 @@ class DiaryEntryControllerTest < ActionController::TestCase assert_select "title", :text => /Users' diaries | /, :count => 1 end assert_select "body", :count => 1 do - assert_select "div#content", :count => 1 do - assert_select "h2", :text => /#{entry.user.display_name}'s diary/, :count => 1 - assert_select "b", :text => /#{new_title}/, :count => 1 - # This next line won't work if the text has been run through the htmlize function - # due to formatting that could be introduced - assert_select "p", :text => /#{new_body}/, :count => 1 - assert_select "abbr[class=geo][title=#{number_with_precision(new_latitude, :precision => 4)}; #{number_with_precision(new_longitude, :precision => 4)}]", :count => 1 - # As we're not logged in, check that you cannot edit - #print @response.body - assert_select "a[href='/user/#{entry.user.display_name}/diary/#{entry.id}/edit']", :text => "Edit this entry", :count => 1 + assert_select "div.wrapper", :count => 1 do + assert_select "div.content-heading", :count => 1 do + assert_select "h2", :text => /#{entry.user.display_name}'s diary/, :count => 1 + end + assert_select "div#content", :count => 1 do + assert_select "div.post_heading", :text => /#{new_title}/, :count => 1 + # This next line won't work if the text has been run through the htmlize function + # due to formatting that could be introduced + assert_select "p", :text => /#{new_body}/, :count => 1 + assert_select "abbr[class=geo][title=#{number_with_precision(new_latitude, :precision => 4)}; #{number_with_precision(new_longitude, :precision => 4)}]", :count => 1 + # As we're not logged in, check that you cannot edit + #print @response.body + assert_select "a[href='/user/#{entry.user.display_name}/diary/#{entry.id}/edit']", :text => "Edit this entry", :count => 1 + end end end end @@ -214,16 +228,20 @@ class DiaryEntryControllerTest < ActionController::TestCase assert_select "title", :text => /Users' diaries | /, :count => 1 end assert_select "body", :count => 1 do - assert_select "div#content", :count => 1 do - assert_select "h2", :text => /#{users(:normal_user).display_name}'s diary/, :count => 1 - assert_select "b", :text => /#{new_title}/, :count => 1 - # This next line won't work if the text has been run through the htmlize function - # due to formatting that could be introduced - assert_select "p", :text => /#{new_body}/, :count => 1 - assert_select "abbr[class=geo][title=#{number_with_precision(new_latitude, :precision => 4)}; #{number_with_precision(new_longitude, :precision => 4)}]", :count => 1 - # As we're not logged in, check that you cannot edit - assert_select "span[class=hidden show_if_user_#{entry.user.id}]", :count => 1 do - assert_select "a[href='/user/#{entry.user.display_name}/diary/#{entry.id}/edit']", :text => "Edit this entry", :count => 1 + assert_select "div.wrapper", :count => 1 do + assert_select "div.content-heading", :count => 1 do + assert_select "h2", :text => /#{users(:normal_user).display_name}'s diary/, :count => 1 + end + assert_select "div#content", :count => 1 do + assert_select "div.post_heading", :text => /#{new_title}/, :count => 1 + # This next line won't work if the text has been run through the htmlize function + # due to formatting that could be introduced + assert_select "p", :text => /#{new_body}/, :count => 1 + assert_select "abbr[class=geo][title=#{number_with_precision(new_latitude, :precision => 4)}; #{number_with_precision(new_longitude, :precision => 4)}]", :count => 1 + # As we're not logged in, check that you cannot edit + assert_select "span[class=hidden show_if_user_#{entry.user.id}]", :count => 1 do + assert_select "a[href='/user/#{entry.user.display_name}/diary/#{entry.id}/edit']", :text => "Edit this entry", :count => 1 + end end end end diff --git a/test/integration/client_application_test.rb b/test/integration/client_application_test.rb index 9ab32ca78..f34a9c430 100644 --- a/test/integration/client_application_test.rb +++ b/test/integration/client_application_test.rb @@ -22,8 +22,8 @@ class ClientApplicationTest < ActionController::IntegrationTest assert_template 'user/account' # check that the form to allow new client application creations exists - assert_in_body do - assert_select "a[href='/user/test2/oauth_clients']" + assert_in_heading do + assert_select "ul.secondary-actions li a[href='/user/test2/oauth_clients']" end # now we follow the link to the oauth client list @@ -36,8 +36,10 @@ class ClientApplicationTest < ActionController::IntegrationTest # now we follow the link to the new oauth client page get '/user/test2/oauth_clients/new' assert_response :success - assert_in_body do + assert_in_heading do assert_select "h1", "Register a new application" + end + assert_in_body do assert_select "form[action='/user/test2/oauth_clients']" do [ :name, :url, :callback_url, :support_url ].each do |inp| assert_select "input[name=?]", "client_application[#{inp}]" @@ -74,6 +76,20 @@ class ClientApplicationTest < ActionController::IntegrationTest # tests, as its too tied into the HTTP headers and stuff that it signs. end + ## + # utility method to make the HTML screening easier to read. + def assert_in_heading + assert_select "html:root" do + assert_select "body" do + assert_select "div.wrapper" do + assert_select "div.content-heading" do + yield + end + end + end + end + end + ## # utility method to make the HTML screening easier to read. def assert_in_body diff --git a/test/integration/user_diaries_test.rb b/test/integration/user_diaries_test.rb index fab05894f..23687fa8e 100644 --- a/test/integration/user_diaries_test.rb +++ b/test/integration/user_diaries_test.rb @@ -38,10 +38,14 @@ class UserDiariesTest < ActionController::IntegrationTest # that need to be tested, which can't be tested in the functional tests assert_select "html:root" do assert_select "body" do - assert_select "div#content" do - assert_select "h1", "New Diary Entry" - assert_select "form[action='/diary/new']" do - assert_select "input[id=diary_entry_title]" + assert_select "div.wrapper", :count => 1 do + assert_select "div.content-heading", :count => 1 do + assert_select "h1", "New Diary Entry" + end + assert_select "div#content" do + assert_select "form[action='/diary/new']" do + assert_select "input[id=diary_entry_title]" + end end end end