summaryrefslogtreecommitdiff
path: root/spec/support/helpers/features/snippet_helpers.rb
blob: c26849a9680023a56ed1f309a25d214a9bdd6801 (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
# frozen_string_literal: true

# These helpers help you interact within the Editor Lite (single-file editor, snippets, etc.).
#
module Spec
  module Support
    module Helpers
      module Features
        module SnippetSpecHelpers
          include ActionView::Helpers::JavaScriptHelper
          include Spec::Support::Helpers::Features::EditorLiteSpecHelpers

          def snippet_description_locator
            'snippet-description'
          end

          def snippet_blob_path_locator
            'snippet_file_name'
          end

          def snippet_description_view_selector
            '.snippet-header .snippet-description'
          end

          def snippet_description_field_collapsed
            find('.js-description-input').find('input,textarea')
          end

          def snippet_get_first_blob_path
            page.find_field('snippet_file_name', match: :first).value
          end

          def snippet_get_first_blob_value
            page.find('.gl-editor-lite', match: :first)
          end

          def snippet_description_value
            page.find_field(snippet_description_locator).value
          end

          def snippet_fill_in_visibility(text)
            page.find('#visibility-level-setting').choose(text)
          end

          def snippet_fill_in_title(value)
            fill_in 'snippet-title', with: value
          end

          def snippet_fill_in_description(value)
            # Click placeholder first to expand full description field
            snippet_description_field_collapsed.click
            fill_in snippet_description_locator, with: value
          end

          def snippet_fill_in_content(value)
            page.within('.gl-editor-lite') do
              el = find('.inputarea')
              el.send_keys value
            end
          end

          def snippet_fill_in_file_name(value)
            fill_in(snippet_blob_path_locator, match: :first, with: value)
          end

          def snippet_fill_in_form(title: nil, content: nil, file_name: nil, description: nil, visibility: nil)
            snippet_fill_in_title(title) if title

            snippet_fill_in_description(description) if description

            snippet_fill_in_file_name(file_name) if file_name

            snippet_fill_in_content(content) if content

            snippet_fill_in_visibility(visibility) if visibility
          end
        end
      end
    end
  end
end