Welcome to mirror list, hosted at ThFree Co, Russian Federation.

embed_observabilities_examples.rb « observability « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c8d4e9e0d7edc421c3269590ec09c0285fbbf13e (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
# frozen_string_literal: true

RSpec.shared_examples 'embeds observability' do
  it 'renders iframe in description' do
    page.within('.description') do
      expect_observability_iframe(page.html)
    end
  end

  it 'renders iframe in comment' do
    expect(page).not_to have_css('.note-text')

    page.within('.js-main-target-form') do
      fill_in('note[note]', with: observable_url)
      click_button('Comment')
    end

    wait_for_requests

    page.within('.note-text') do
      expect_observability_iframe(page.html)
    end
  end
end

RSpec.shared_examples 'does not embed observability' do
  it 'does not render iframe in description' do
    page.within('.description') do
      expect_observability_iframe(page.html, to_be_nil: true)
    end
  end

  it 'does not render iframe in comment' do
    expect(page).not_to have_css('.note-text')

    page.within('.js-main-target-form') do
      fill_in('note[note]', with: observable_url)
      click_button('Comment')
    end

    wait_for_requests

    page.within('.note-text') do
      expect_observability_iframe(page.html, to_be_nil: true)
    end
  end
end

def expect_observability_iframe(html, to_be_nil: false)
  iframe = Nokogiri::HTML.parse(html).at_css('#observability-ui-iframe')

  expect(html).to include(observable_url)

  if to_be_nil
    expect(iframe).to be_nil
  else
    expect(iframe).not_to be_nil
    iframe_src = "#{expected_observable_url}&theme=light&username=#{user.username}&kiosk=inline-embed"
    expect(iframe.attributes['src'].value).to eq(iframe_src)
  end
end