award_emoji.rb 2.73 KB
Newer Older
Valery Sizov's avatar
Valery Sizov committed
1 2 3 4 5 6 7 8 9 10
class Spinach::Features::AwardEmoji < Spinach::FeatureSteps
  include SharedAuthentication
  include SharedProject
  include SharedPaths
  include Select2Helper

  step 'I visit "Bugfix" issue page' do
    visit namespace_project_issue_path(@project.namespace, @project, @issue)
  end

11 12
  step 'I click the thumbsup award Emoji' do
    page.within '.awards' do
Phil Hughes's avatar
Phil Hughes committed
13
      thumbsup = page.first('.award-control')
14 15 16 17 18
      thumbsup.click
      thumbsup.hover
    end
  end

Valery Sizov's avatar
Valery Sizov committed
19
  step 'I click to emoji-picker' do
Phil Hughes's avatar
Phil Hughes committed
20 21
    page.within '.awards' do
      page.find('.js-add-award').click
Valery Sizov's avatar
Valery Sizov committed
22 23 24 25
    end
  end

  step 'I click to emoji in the picker' do
Valery Sizov's avatar
Valery Sizov committed
26
    page.within '.emoji-menu-content' do
Phil Hughes's avatar
Phil Hughes committed
27
      page.first('.js-emoji-btn').click
Valery Sizov's avatar
Valery Sizov committed
28 29 30 31
    end
  end

  step 'I can remove it by clicking to icon' do
32
    page.within '.awards' do
Valery Sizov's avatar
Valery Sizov committed
33
      expect do
Phil Hughes's avatar
Phil Hughes committed
34
        page.find('.js-emoji-btn.active').click
Valery Sizov's avatar
Valery Sizov committed
35
        sleep 0.3
Phil Hughes's avatar
Phil Hughes committed
36
      end.to change{ page.all(".award-control.js-emoji-btn").size }.from(3).to(2)
Valery Sizov's avatar
Valery Sizov committed
37 38 39
    end
  end

Valery Sizov's avatar
Valery Sizov committed
40 41
  step 'I can see the activity and food categories' do
    page.within '.emoji-menu' do
42 43
      expect(page).not_to have_selector 'Activity'
      expect(page).not_to have_selector 'Food'
Valery Sizov's avatar
Valery Sizov committed
44 45 46
    end
  end

Valery Sizov's avatar
Valery Sizov committed
47
  step 'I have award added' do
48
    page.within '.awards' do
Phil Hughes's avatar
Phil Hughes committed
49 50
      expect(page).to have_selector '.js-emoji-btn'
      expect(page.find('.js-emoji-btn.active .js-counter')).to have_content '1'
51
      expect(page).to have_css(".js-emoji-btn.active[data-original-title='me']")
52 53 54 55 56
    end
  end

  step 'I have no awards added' do
    page.within '.awards' do
Phil Hughes's avatar
Phil Hughes committed
57 58
      expect(page).to have_selector '.award-control.js-emoji-btn'
      expect(page.all('.award-control.js-emoji-btn').size).to eq(2)
59 60

      # Check tooltip data
Phil Hughes's avatar
Phil Hughes committed
61
      page.all('.award-control.js-emoji-btn').each do |element|
62 63 64
        expect(element['title']).to eq("")
      end

Phil Hughes's avatar
Phil Hughes committed
65
      page.all('.award-control .js-counter').each do |element|
66 67
        expect(element).to have_content '0'
      end
Valery Sizov's avatar
Valery Sizov committed
68 69 70 71
    end
  end

  step 'project "Shop" has issue "Bugfix"' do
72 73 74 75 76 77 78
    @project = Project.find_by(name: 'Shop')
    @issue = create(:issue, title: 'Bugfix', project: project)
  end

  step 'I leave comment with a single emoji' do
    page.within('.js-main-target-form') do
      fill_in 'note[note]', with: ':smile:'
Phil Hughes's avatar
Phil Hughes committed
79
      click_button 'Comment'
80
    end
Valery Sizov's avatar
Valery Sizov committed
81
  end
Valery Sizov's avatar
Valery Sizov committed
82 83

  step 'I search "hand"' do
Phil Hughes's avatar
Phil Hughes committed
84
    fill_in 'emoji_search', with: 'hand'
Valery Sizov's avatar
Valery Sizov committed
85 86 87 88 89 90 91
  end

  step 'I see search result for "hand"' do
    page.within '.emoji-menu-content' do
      expect(page).to have_selector '[data-emoji="raised_hand"]'
    end
  end
92

93 94 95 96
  step 'The emoji menu is visible' do
    page.find(".emoji-menu.is-visible")
  end

97
  step 'The search field is focused' do
Annabel Dunstone's avatar
Annabel Dunstone committed
98 99
    expect(page).to have_selector('#emoji_search')
    expect(page.evaluate_script('document.activeElement.id')).to eq('emoji_search')
100
  end
Valery Sizov's avatar
Valery Sizov committed
101
end