require 'spec_helper'

feature "Event streaming", js: true do
  let!(:author) { FactoryGirl.create :user }
  let!(:paper) { author.papers.create! short_title: 'foo bar', journal: Journal.create! }
  let(:upload_task) { author.papers.first.tasks_for_type(UploadManuscriptTask).first }

  before do
    sign_in_page = SignInPage.visit
    sign_in_page.sign_in author.email
  end

  scenario "On the dashboard page" do
    # Weird race condition if this test doesn't run first.
    sleep 0.3
    expect(page).to have_no_selector(".completed")
    upload_task.completed = true
    upload_task.save
    expect(page).to have_css(".card-completed", count: 1)
  end

  scenario "On the edit paper page" do
    EditPaperPage.visit paper
    expect(page).to have_no_selector(".completed")
    upload_task.completed = true
    upload_task.save
    expect(page).to have_css(".card-completed", count: 1)
  end

end

require 'spec_helper'

feature "Event streaming", js: true do
  let!(:author) { FactoryGirl.create :user }
  let!(:paper) { author.papers.create! short_title: 'foo bar', journal: Journal.create! }

  before do
    sign_in_page = SignInPage.visit
    sign_in_page.sign_in author.email
  end

  scenario "On the dashboard page" do
    expect(page).to have_no_selector(".completed")
    t = author.papers.first.tasks_for_type(UploadManuscriptTask).first
    t.completed = true
    t.save
    expect(page).to have_css(".card-completed", count: 1)
  end

end

--- 
+++ 
@@ -3,6 +3,7 @@
 feature "Event streaming", js: true do
   let!(:author) { FactoryGirl.create :user }
   let!(:paper) { author.papers.create! short_title: 'foo bar', journal: Journal.create! }
+  let(:upload_task) { author.papers.first.tasks_for_type(UploadManuscriptTask).first }
 
   before do
     sign_in_page = SignInPage.visit
@@ -10,10 +11,19 @@
   end
 
   scenario "On the dashboard page" do
+    # Weird race condition if this test doesn't run first.
+    sleep 0.3
     expect(page).to have_no_selector(".completed")
-    t = author.papers.first.tasks_for_type(UploadManuscriptTask).first
-    t.completed = true
-    t.save
+    upload_task.completed = true
+    upload_task.save
+    expect(page).to have_css(".card-completed", count: 1)
+  end
+
+  scenario "On the edit paper page" do
+    EditPaperPage.visit paper
+    expect(page).to have_no_selector(".completed")
+    upload_task.completed = true
+    upload_task.save
     expect(page).to have_css(".card-completed", count: 1)
   end
 
Add edit page spec and sleep for race condition.
