summaryrefslogtreecommitdiff
path: root/spec/features/issues/markdown_toolbar_spec.rb
blob: 634ea111dc1aa0b9995b0cdbf8439b50f49090f4 (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
require 'rails_helper'

feature 'Issue markdown toolbar', js: true do
  let(:project) { create(:project, :public) }
  let(:issue)   { create(:issue, project: project) }
  let(:user)    { create(:user) }

  before do
    sign_in(user)

    visit project_issue_path(project, issue)
  end

  it "doesn't include first new line when adding bold" do
    find('#note-body').native.send_keys('test')
    find('#note-body').native.send_key(:enter)
    find('#note-body').native.send_keys('bold')

    page.evaluate_script('document.querySelectorAll(".js-main-target-form #note-body")[0].setSelectionRange(4, 9)')

    first('.toolbar-btn').click

    expect(find('#note-body')[:value]).to eq("test\n**bold**\n")
  end

  it "doesn't include first new line when adding underline" do
    find('#note-body').native.send_keys('test')
    find('#note-body').native.send_key(:enter)
    find('#note-body').native.send_keys('underline')

    page.evaluate_script('document.querySelectorAll(".js-main-target-form #note-body")[0].setSelectionRange(4, 50)')

    find('.toolbar-btn:nth-child(2)').click

    expect(find('#note-body')[:value]).to eq("test\n*underline*\n")
  end
end