step "the original user should see a join request message" do
  Capybara.session_name = :default
  #request_text = page.evaluate_script(%|t('join_request.body', {email: '#{@other_user.email}'})|)
  request_title = page.evaluate_script(%|t('join_request.existing_user.title')|)
  request_title.should be_present
  page.should have_content request_title
  page.should have_content "UOther" # spec/factories/user
end

step "the original user should not see the join request anymore" do
  Capybara.session_name = :default
  request_text = page.evaluate_script(%|t('join_request.body', {email: '#{@other_user.email}'})|)
  request_text.should be_present
  page.should_not have_content request_text
end

step "another user scans the QR code on the table" do
  step 'there is another signed in user user'
  user_visit '/'
  when_ember_is_ready do
    page.execute_script "MozoUser.__container__.lookup('route:application').transitionTo('table','#{@table.id}')"
  end
end

step "the original user should see the other user added below the active list" do
  page.evaluate_script(%|$('.list-user-total-container').length|).should eq 2
end

step "the original user approves the other user's join request" do
  find('.join-request-approve').click
end

step "the original user rejects the other user's join request" do
  find('.join-request-reject').click
end

step "the other user clicks the show me the menu button" do
  find('.show-menu-button').click
end

step "the other user should see a join table waiting message" do
  #waiting_text = I18n.t('') #TODO: make better user client translation system, similar to supplier
  waiting_text = page.evaluate_script(%|t('join_request.requestor.waiting_for_approval')|)
  page.should have_content waiting_text
end


step "the other user should see a join reject message" do
  Capybara.session_name = :other_user
  reject_text = page.evaluate_script(%|t('join_request.requestor.join_request_rejected')|)
  reject_text.should be_present
  reject_text.should_not include 'translation'
  page.should have_content reject_text
end

step "the other user should be added to the active list" do
  sleep 1
  @other_user.reload
  @list.reload
  @other_user.active_list_id.should == @list.id
  @list.user_ids.should =~ [@user.id, @other_user.id]
end

step "the other user should not be added to the active list" do
  sleep 1
  @other_user.reload
  @list.reload
  @other_user.active_list_id.should be_nil
  @list.user_ids.should == [@user.id]
end

step "the other user should be redirected to active list it just joined" do
  Capybara.session_name = :other_user
  ember_route_should_be '/active-list'
end
