From 7c14541d2bb9735402086c951730344fa5203278 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sat, 12 Dec 2015 23:42:52 +0100 Subject: Add feature specs for note polling Ref. #4032, !2084 --- spec/features/issues/note_polling_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 spec/features/issues/note_polling_spec.rb diff --git a/spec/features/issues/note_polling_spec.rb b/spec/features/issues/note_polling_spec.rb new file mode 100644 index 00000000000..1698a0a3e5d --- /dev/null +++ b/spec/features/issues/note_polling_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +feature 'Issue notes polling' do + let!(:project) { create(:project, :public) } + let!(:issue) { create(:issue, project: project) } + + background do + visit namespace_project_issue_path(project.namespace, project, issue) + end + + scenario 'Another user adds a comment to an issue', js: true do + note = create(:note_on_issue, noteable: issue, + project_id: project.project_id, + note: 'Looks good!') + sleep 16 # refresh interval in notes.js.coffee, 15 seconds + expect(page).to have_selector("#note_#{note.id}", text: 'Looks good!') + end +end -- cgit v1.2.1 From 9470d05c70c15df75ae6be45812967abf89ae59a Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sun, 13 Dec 2015 00:39:47 +0100 Subject: Add spinach test for note polling This also increases capybara timeout to 15 seconds (note polling interval). Capybara will look for new note for this period of time. --- features/project/issues/issues.feature | 6 ++++++ features/steps/project/issues/issues.rb | 10 ++++++++++ features/support/capybara.rb | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/features/project/issues/issues.feature b/features/project/issues/issues.feature index f08b30e0b88..ab234bc7507 100644 --- a/features/project/issues/issues.feature +++ b/features/project/issues/issues.feature @@ -197,3 +197,9 @@ Feature: Project Issues And I should not see labels field And I submit new issue "500 error on profile" Then I should see issue "500 error on profile" + + @javascript + Scenario: Another user adds a comment to issue I'm currently viewing + Given I visit issue page "Release 0.4" + And another user adds a comment with text "Yay!" to issue "Release 0.4" + Then I should see a new comment with text "Yay!" diff --git a/features/steps/project/issues/issues.rb b/features/steps/project/issues/issues.rb index a13044c3ae1..4a7ff21d385 100644 --- a/features/steps/project/issues/issues.rb +++ b/features/steps/project/issues/issues.rb @@ -284,6 +284,16 @@ class Spinach::Features::ProjectIssues < Spinach::FeatureSteps end end + step 'another user adds a comment with text "Yay!" to issue "Release 0.4"' do + issue = Issue.find_by!(title: 'Release 0.4') + create(:note_on_issue, noteable: issue, note: 'Yay!') + end + + step 'I should see a new comment with text "Yay!"' do + page.within '#notes' do + expect(page).to have_content('Yay!') + end + end def filter_issue(text) fill_in 'issue_search', with: text end diff --git a/features/support/capybara.rb b/features/support/capybara.rb index 31dbf0feb2f..4156c7ec484 100644 --- a/features/support/capybara.rb +++ b/features/support/capybara.rb @@ -2,7 +2,7 @@ require 'spinach/capybara' require 'capybara/poltergeist' # Give CI some extra time -timeout = (ENV['CI'] || ENV['CI_SERVER']) ? 90 : 10 +timeout = (ENV['CI'] || ENV['CI_SERVER']) ? 90 : 15 Capybara.javascript_driver = :poltergeist Capybara.register_driver :poltergeist do |app| -- cgit v1.2.1 From 3e789eab8be93c45685c417488da102d996209ba Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Sun, 13 Dec 2015 00:44:45 +0100 Subject: Add minor fixes in note polling specs --- spec/features/issues/note_polling_spec.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/features/issues/note_polling_spec.rb b/spec/features/issues/note_polling_spec.rb index 1698a0a3e5d..5cf3dcf8904 100644 --- a/spec/features/issues/note_polling_spec.rb +++ b/spec/features/issues/note_polling_spec.rb @@ -9,10 +9,8 @@ feature 'Issue notes polling' do end scenario 'Another user adds a comment to an issue', js: true do - note = create(:note_on_issue, noteable: issue, - project_id: project.project_id, - note: 'Looks good!') - sleep 16 # refresh interval in notes.js.coffee, 15 seconds + note = create(:note_on_issue, noteable: issue, note: 'Looks good!') + sleep 15 # refresh interval in notes.js.coffee is 15 seconds expect(page).to have_selector("#note_#{note.id}", text: 'Looks good!') end end -- cgit v1.2.1 From 6fb120d1b0ad8adee7c5c431c7f8a399a2da5cea Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 14 Dec 2015 09:41:30 +0100 Subject: Assign notes object to a variable --- app/views/projects/notes/_notes_with_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/notes/_notes_with_form.html.haml b/app/views/projects/notes/_notes_with_form.html.haml index 99c1b0fa43e..eb378b42603 100644 --- a/app/views/projects/notes/_notes_with_form.html.haml +++ b/app/views/projects/notes/_notes_with_form.html.haml @@ -7,4 +7,4 @@ = render "projects/notes/form", view: diff_view :javascript - new Notes("#{namespace_project_notes_path(namespace_id: @project.namespace, target_id: @noteable.id, target_type: @noteable.class.name.underscore)}", #{@notes.map(&:id).to_json}, #{Time.now.to_i}, "#{diff_view}") + var notes = new Notes("#{namespace_project_notes_path(namespace_id: @project.namespace, target_id: @noteable.id, target_type: @noteable.class.name.underscore)}", #{@notes.map(&:id).to_json}, #{Time.now.to_i}, "#{diff_view}") -- cgit v1.2.1 From 8fe821cfa5acea2a4ab1fce7f35a76455d5a1cac Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Mon, 14 Dec 2015 09:41:59 +0100 Subject: Trigger notes refresh in specs instead of waiting for ajax --- spec/features/issues/note_polling_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/issues/note_polling_spec.rb b/spec/features/issues/note_polling_spec.rb index 5cf3dcf8904..e4efdbe2421 100644 --- a/spec/features/issues/note_polling_spec.rb +++ b/spec/features/issues/note_polling_spec.rb @@ -10,7 +10,7 @@ feature 'Issue notes polling' do scenario 'Another user adds a comment to an issue', js: true do note = create(:note_on_issue, noteable: issue, note: 'Looks good!') - sleep 15 # refresh interval in notes.js.coffee is 15 seconds + page.execute_script('notes.refresh();') expect(page).to have_selector("#note_#{note.id}", text: 'Looks good!') end end -- cgit v1.2.1