BigW Consortium Gitlab

notes_on_personal_snippets_spec.rb 3.49 KB
Newer Older
1 2
require 'spec_helper'

3
describe 'Comments on personal snippets', :js do
4 5
  include NoteInteractionHelpers

6 7 8 9 10 11 12 13 14 15 16
  let!(:user)    { create(:user) }
  let!(:snippet) { create(:personal_snippet, :public) }
  let!(:snippet_notes) do
    [
      create(:note_on_personal_snippet, noteable: snippet, author: user),
      create(:note_on_personal_snippet, noteable: snippet)
    ]
  end
  let!(:other_note) { create(:note_on_personal_snippet) }

  before do
17
    sign_in user
18 19 20 21 22
    visit snippet_path(snippet)
  end

  subject { page }

23
  context 'when viewing the snippet detail page' do
24 25 26
    it 'contains notes for a snippet with correct action icons' do
      expect(page).to have_selector('#notes-list li', count: 2)

27 28
      open_more_actions_dropdown(snippet_notes[0])

29 30 31 32 33 34 35
      # comment authored by current user
      page.within("#notes-list li#note_#{snippet_notes[0].id}") do
        expect(page).to have_content(snippet_notes[0].note)
        expect(page).to have_selector('.js-note-delete')
        expect(page).to have_selector('.note-emoji-button')
      end

36
      find('body').click # close dropdown
37 38
      open_more_actions_dropdown(snippet_notes[1])

39 40 41 42 43 44 45
      page.within("#notes-list li#note_#{snippet_notes[1].id}") do
        expect(page).to have_content(snippet_notes[1].note)
        expect(page).not_to have_selector('.js-note-delete')
        expect(page).to have_selector('.note-emoji-button')
      end
    end
  end
46 47 48 49

  context 'when submitting a note' do
    it 'shows a valid form' do
      is_expected.to have_css('.js-main-target-form', visible: true, count: 1)
50 51
      expect(find('.js-main-target-form .js-comment-button').value)
        .to eq('Comment')
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

      page.within('.js-main-target-form') do
        expect(page).not_to have_link('Cancel')
      end
    end

    it 'previews a note' do
      fill_in 'note[note]', with: 'This is **awesome**!'
      find('.js-md-preview-button').click

      page.within('.new-note .md-preview') do
        expect(page).to have_content('This is awesome!')
        expect(page).to have_selector('strong')
      end
    end

    it 'creates a note' do
      fill_in 'note[note]', with: 'This is **awesome**!'
      click_button 'Comment'

      expect(find('div#notes')).to have_content('This is awesome!')
    end
74 75 76 77 78 79 80 81 82 83 84 85 86

    it 'should not have autocomplete' do
      wait_for_requests

      find('#note_note').native.send_keys('')
      fill_in 'note[note]', with: '@'

      wait_for_requests

      # This selector probably won't be in place even if autocomplete was enabled
      # but we want to make sure
      expect(page).not_to have_selector('.atwho-view')
    end
87 88 89 90
  end

  context 'when editing a note' do
    it 'changes the text' do
91
      find('.js-note-edit').click
92 93 94 95 96 97 98

      page.within('.current-note-edit-form') do
        fill_in 'note[note]', with: 'new content'
        find('.btn-save').click
      end

      page.within("#notes-list li#note_#{snippet_notes[0].id}") do
99 100
        edited_text = find('.edited-text')

101 102
        expect(page).to have_css('.note_edited_ago')
        expect(page).to have_content('new content')
103
        expect(edited_text).to have_selector('.note_edited_ago')
104 105 106 107 108 109
      end
    end
  end

  context 'when deleting a note' do
    it 'removes the note from the snippet detail page' do
110 111
      open_more_actions_dropdown(snippet_notes[0])

112
      page.within("#notes-list li#note_#{snippet_notes[0].id}") do
113
        accept_confirm { click_on 'Delete comment' }
114 115
      end

116
      wait_for_requests
117 118 119 120

      expect(page).not_to have_selector("#notes-list li#note_#{snippet_notes[0].id}")
    end
  end
121
end