diff --git a/features/notes_manage.feature b/features/notes_manage.feature new file mode 100644 index 00000000..ec8c5b36 --- /dev/null +++ b/features/notes_manage.feature @@ -0,0 +1,48 @@ +Feature: View, add, remove notes + + In order to manage my notes + As a Tracks user + I want to view, add, and remove notes + + Background: + Given the following user record + | login | password | is_admin | + | testuser | secret | false | + + Scenario: View notes + Given I have logged in as "testuser" with password "secret" + And I have two projects with one note each + When I go to the notes page + Then 2 notes should be visible + And the badge should show 2 + + @focus + Scenario: Add a new note + Given I have logged in as "testuser" with password "secret" + And I have one project "Pass Final Exam" with no notes + When I add note "My Note A" from the "Pass Final Exam" project page + Then I should see note "My Note A" on the "Pass Final Exam" project page + And I should see note "My Note A" on the notes page + Then the badge should show 1 + + Scenario: Delete note from notes page + Given I have logged in as "testuser" with password "secret" + And I have a project "Pass Final Exam" with 2 notes + When I go to the notes page + And I delete the first note + Then the first note should disappear + Then the badge should show 1 + + Scenario: Link to note + Given I have logged in as "testuser" with password "secret" + And I have one project "Pass Final Exam" with 1 note + When I visit the "Pass Final Exam" project page + And I click the icon next to the note + Then I should see the note text + + Scenario: Toggle notes + Given I have logged in as "testuser" with password "secret" + And I have two projects with one note each + When I go to the notes page + And I click Toggle Notes + Then the body of the notes should be shown diff --git a/features/step_definitions/note_steps.rb b/features/step_definitions/note_steps.rb new file mode 100644 index 00000000..69a3e2b7 --- /dev/null +++ b/features/step_definitions/note_steps.rb @@ -0,0 +1,137 @@ +Given /^I have two projects with one note each$/ do + project_a = @current_user.projects.create!(:name => 'project A') + project_a.notes.create!(:user_id => @current_user.id, :body => 'note for project A') + project_b = @current_user.projects.create!(:name => 'project B') + project_b.notes.create!(:user_id => @current_user.id, :body => 'note for project B') +end + +Then /^(.*) notes should be visible$/ do |number| + # count number of project_notes + count = 0 + response.should have_xpath("//div[@class='project_notes']") { |nodes| nodes.each { |n| count += 1 }} + count.should == number.to_i +end + +Then "the badge should show (.*)" do |number| + badge = -1 + response.should have_xpath("//span[@id='badge_count']") do |node| + badge = node.first.content.to_i + end + badge.should == number.to_i +end + +When /^I click Toggle Notes$/ do + click_link 'Toggle notes' +end + +Given /^I have one project "([^\"]*)" with no notes$/ do |project_name| + @current_user.projects.create!(:name => project_name) +end + +When /^I add note "([^\"]*)" from the "([^\"]*)" project page$/ do |note, project| + project = Project.find_by_name(project) + project.notes.create!(:user_id => @current_user.id, :body => note) +end + +Then /^I should see note "([^\"]*)" on the "([^\"]*)" project page$/ do |note, project| + project = Project.find_by_name(project) + visit project_path(project) + Then "I should see \"#{note}\"" +end + +Then /^I should see note "([^\"]*)" on the notes page$/ do |note| + visit notes_path + Then "I should see \"#{note}\"" +end + +Given /^I have a project "([^\"]*)" with 2 notes$/ do |arg1| + pending +end + +When /^I delete the first note$/ do + pending +end + +Given /^I have one project "([^\"]*)" with 1 note$/ do |arg1| + pending +end + +When /^I visit the "([^\"]*)" project page$/ do |arg1| + pending +end + +When /^I click the icon next to the note$/ do + pending +end + +Then /^I should see the note text$/ do + pending +end + +#------ + +Given "Luis has one project Pass Final Exam with no notes" do +@exam_project = @luis.projects.create!(:name => 'Pass Final Exam') +end + +Given "Luis has one project Pass Final Exam with 1 note" do +Given "Luis has one project Pass Final Exam with no notes" +@exam_project.notes.create!(:user_id => @luis.id, :body => 'exam note 1') +end + +Given "Luis has one project Pass Final Exam with 2 notes" do +Given "Luis has one project Pass Final Exam with 1 note" +@exam_project.notes.create!(:user_id => @luis.id, :body => 'exam note 2') +end + +When "Luis visits the notes page" do +visits '/notes' +end + +When "Luis adds a note from the Pass Final Exam project page" do +When "Luis visits the Pass Final Exam project page" +clicks_link 'Add a note', :wait => :ajax +fills_in 'new_note_body', :with => 'new exam note' +clicks_button 'Add note', :wait => :ajax +end + +When "Luis visits the Pass Final Exam project page" do +visits "/projects/#{@exam_project.to_param}" +end + +When "Luis deletes the first note" do +selenium.click "css=a.delete_note" +selenium.get_confirmation.should =~ /delete/ +end + +When "clicks the icon next to the note" do +selenium.click "css=a.link_to_notes" +wait_for_page_to_load +end + +When "Luis clicks Toggle Notes" do +clicks_link 'Toggle notes', :wait => :effects +end + +Then "the body of the notes should be shown" do + pending +end + +Then "Luis should see the note on the Pass Final Exam project page" do +should_see "new exam note" +end + +Then "Luis should see the note on the notes page" do +visits '/notes' +should_see "new exam note" +end + +Then "the first note should disappear" do +wait_for_ajax_and_effects +should_not_see 'exam note 1' +end + + +Then "he should see the note text" do +should_see 'exam note 1' +end diff --git a/features/support/paths.rb b/features/support/paths.rb index 1a1137e1..b4ecce8e 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -12,6 +12,8 @@ module NavigationHelpers "/users/new" when /the login page/ login_path + when /the notes page/ + notes_path # Add more page name => path mappings here @@ -22,4 +24,4 @@ module NavigationHelpers end end -World(NavigationHelpers) \ No newline at end of file +World(NavigationHelpers) diff --git a/test/test_helper.rb b/test/test_helper.rb index c34d707f..97139bed 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -144,4 +144,4 @@ class ActionController::IntegrationTest assert_response_and_body 401, "401 Unauthorized: Only admin users are allowed access to this function." end -end \ No newline at end of file +end