BigW Consortium Gitlab

markdown.rb 1.97 KB
Newer Older
1 2 3 4
module SharedMarkdown
  include Spinach::DSL

  def header_should_have_correct_id_and_link(level, text, id, parent = ".wiki")
5
    node = find("#{parent} h#{level} a##{id}")
6
    expect(node[:href]).to eq "##{id}"
7 8 9

    # Work around a weird Capybara behavior where calling `parent` on a node
    # returns the whole document, not the node's actual parent element
10
    expect(find(:xpath, "#{node.path}/..").text).to eq text
11 12 13 14 15
  end

  step 'Header "Description header" should have correct id and link' do
    header_should_have_correct_id_and_link(1, 'Description header', 'description-header')
  end
16

17
  step 'I should not see the Markdown preview' do
Vinnie Okada committed
18
    expect(find('.gfm-form .js-md-preview')).not_to be_visible
19 20
  end

21
  step 'The Markdown preview tab should say there is nothing to do' do
22
    page.within('.gfm-form') do
23 24 25
      find('.js-md-preview-button').click
      expect(find('.js-md-preview')).to have_content('Nothing to preview.')
    end
26 27 28
  end

  step 'I should not see the Markdown text field' do
Vinnie Okada committed
29
    expect(find('.gfm-form textarea')).not_to be_visible
30 31
  end

32
  step 'I should see the Markdown write tab' do
Vinnie Okada committed
33
    expect(find('.gfm-form')).to have_css('.js-md-write-button', visible: true)
34 35 36
  end

  step 'I should see the Markdown preview' do
Vinnie Okada committed
37
    expect(find('.gfm-form')).to have_css('.js-md-preview', visible: true)
38 39
  end

40
  step 'The Markdown preview tab should display rendered Markdown' do
41
    page.within('.gfm-form') do
42
      find('.js-md-preview-button').click
Vinnie Okada committed
43
      expect(find('.js-md-preview')).to have_css('img.emoji', visible: true)
44
    end
45 46
  end

47 48
  step 'I write a description like ":+1: Nice"' do
    find('.gfm-form').fill_in 'Description', with: ':+1: Nice'
49 50 51
  end

  step 'I preview a description text like "Bug fixed :smile:"' do
52
    page.within('.gfm-form') do
53
      fill_in 'Description', with: 'Bug fixed :smile:'
Vinnie Okada committed
54
      find('.js-md-preview-button').click
55 56 57 58 59 60
    end
  end

  step 'I haven\'t written any description text' do
    find('.gfm-form').fill_in 'Description', with: ''
  end
61
end