<%= render '/admin/shared/messages' %> diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 1489d2860..4314cf823 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -16,6 +16,7 @@ delayed/web/application.css ie.js admin.js + admin-actions-autosave.js character-counter.js auto-updater.js details.js diff --git a/features/admin/moderator_tags_a_petition.feature b/features/admin/moderator_tags_a_petition.feature index fb2d6003c..bb72dc820 100644 --- a/features/admin/moderator_tags_a_petition.feature +++ b/features/admin/moderator_tags_a_petition.feature @@ -54,3 +54,18 @@ Feature: A moderator user updates records notes And I should see "Petition has been successfully updated" When I follow "Tags" Then the "DWP" checkbox should not be checked + + @javascript + Scenario: Adding tags to an open petition + Given an open petition exists with action: "Solidarity with the Unions" + And a tag exists with name: "DWP" + When I am on the admin all petitions page + And I follow "Solidarity with the Unions" + Then I leave the form alone for 1000ms + And I follow "Tags" + Then the "DWP" JS enabled govuk style checkbox should not be checked + When I check "DWP" + Then I leave the form alone for 1000ms + And I wait for the petition tags to save + Then I reload the page + Then the "DWP" JS enabled govuk style checkbox should be checked diff --git a/features/admin/notes.feature b/features/admin/notes.feature index a2215c989..2a1868433 100644 --- a/features/admin/notes.feature +++ b/features/admin/notes.feature @@ -20,11 +20,26 @@ Feature: A moderator user updates records notes And I follow "Notes" Then I should see "I think we can debate this, will check with unions select committee first" + @javascript + Scenario: Adding notes to an open petition as you type + Given an open petition exists with action: "Solidarity with the Unions" + When I am on the admin all petitions page + And I follow "Solidarity with the Unions" + And I follow "Notes" + Then I should see a "Notes" textarea field + And the markup should be valid + When I fill in "Notes" with "I am just mulling this over" + And I stop typing for 1000ms + And I wait for the petition notes to save + Then I reload the page + Then I should see "I am just mulling this over" + Scenario: Adding notes to an in moderation petition Given an sponsored petition exists with action: "Solidarity with the Unions" When I am on the admin all petitions page And I follow "Solidarity with the Unions" And I follow "Notes" + Then I should see a "Notes" textarea field And the markup should be valid When I fill in "Notes" with "I think we can debate this, will check with unions select committee first" diff --git a/features/step_definitions/moderator_tags_a_petition.rb b/features/step_definitions/moderator_tags_a_petition.rb new file mode 100644 index 000000000..4bf091057 --- /dev/null +++ b/features/step_definitions/moderator_tags_a_petition.rb @@ -0,0 +1,28 @@ +When(/^I leave the form alone for (\d+)ms$/) do |ms| + page.find('//body').click + sleep(ms.to_f / 1000) +end + +Then(/^I wait for the petition tags to save$/) do + Timeout.timeout(Capybara.default_max_wait_time) do + loop until finished_ajax_requests? + end +end + +Then /^the "([^"]*)" JS enabled govuk style checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector| + with_scope(selector) do + field_checked = find_field(label, visible: false)['checked'] + expect(field_checked).to be_falsey + end +end + +Then /^the "([^"]*)" JS enabled govuk style checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector| + with_scope(selector) do + field_checked = find_field(label, visible: false)['checked'] + expect(field_checked).to be_truthy + end +end + +def finished_ajax_requests? + !page.find('//body')[:class].include?('ajax-active') +end diff --git a/features/step_definitions/notes_steps.rb b/features/step_definitions/notes_steps.rb new file mode 100644 index 000000000..26783e8ef --- /dev/null +++ b/features/step_definitions/notes_steps.rb @@ -0,0 +1,14 @@ +When(/^I stop typing for (\d+)ms$/) do |ms| + page.find('//body').click + sleep(ms.to_f / 1000) +end + +Then(/^I wait for the petition notes to save$/) do + Timeout.timeout(Capybara.default_max_wait_time) do + loop until finished_ajax_requests? + end +end + +def finished_ajax_requests? + !page.find('//body')[:class].include?('ajax-active') +end diff --git a/features/step_definitions/reload_page.rb b/features/step_definitions/reload_page.rb new file mode 100644 index 000000000..1f6d7119f --- /dev/null +++ b/features/step_definitions/reload_page.rb @@ -0,0 +1,3 @@ +Then(/^I reload the page$/) do + visit current_url +end