summaryrefslogtreecommitdiff
path: root/features/steps/project/issues/award_emoji.rb
blob: 1b14659b4dfb7ccdedba8a383e13c46c731bf6b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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

  step 'I click the thumbsup award Emoji' do
    page.within '.awards' do
      thumbsup = page.first('.award-control')
      thumbsup.click
      thumbsup.hover
    end
  end

  step 'I click to emoji-picker' do
    page.within '.awards' do
      page.find('.js-add-award').click
    end
  end

  step 'I click to emoji in the picker' do
    page.within '.emoji-menu-content' do
      page.first('.js-emoji-btn').click
    end
  end

  step 'I can remove it by clicking to icon' do
    page.within '.awards' do
      expect do
        page.find('.js-emoji-btn.active').click
        sleep 0.3
      end.to change{ page.all(".award-control.js-emoji-btn").size }.from(3).to(2)
    end
  end

  step 'I can see the activity and food categories' do
    page.within '.emoji-menu' do
      expect(page).not_to have_selector 'Activity'
      expect(page).not_to have_selector 'Food'
    end
  end

  step 'I have award added' do
    page.within '.awards' do
      expect(page).to have_selector '.js-emoji-btn'
      expect(page.find('.js-emoji-btn.active .js-counter')).to have_content '1'
      expect(page).to have_css(".js-emoji-btn.active[data-original-title='me']")
    end
  end

  step 'I have no awards added' do
    page.within '.awards' do
      expect(page).to have_selector '.award-control.js-emoji-btn'
      expect(page.all('.award-control.js-emoji-btn').size).to eq(2)

      # Check tooltip data
      page.all('.award-control.js-emoji-btn').each do |element|
        expect(element['title']).to eq("")
      end

      page.all('.award-control .js-counter').each do |element|
        expect(element).to have_content '0'
      end
    end
  end

  step 'project "Shop" has issue "Bugfix"' do
    @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:'
      click_button 'Comment'
    end
  end

  step 'I search "hand"' do
    page.within('.emoji-menu-content') do
      fill_in 'emoji_search', with: 'hand'
    end
  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

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

  step 'The search field is focused' do
    expect(page).to have_selector('#emoji_search')
    expect(page.evaluate_script('document.activeElement.id')).to eq('emoji_search')
  end
end