summaryrefslogtreecommitdiff
path: root/qa/qa/specs/features/browser_ui/3_create/web_ide/add_file_template_spec.rb
blob: 07dbf39a8a3cccc074203edbc6832662fa806cdd (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
82
83
84
85
86
87
88
# frozen_string_literal: true

module QA
  context 'Create' do
    describe 'Web IDE file templates' do
      include Runtime::Fixtures

      def login
        Runtime::Browser.visit(:gitlab, Page::Main::Login)
        Page::Main::Login.act { sign_in_using_credentials }
      end

      before(:all) do
        login

        @project = Factory::Resource::Project.fabricate! do |project|
          project.name = 'file-template-project'
          project.description = 'Add file templates via the Web IDE'
        end
        @project.visit!

        # Add a file via the regular Files view because the Web IDE isn't
        # available unless there is a file present
        Page::Project::Show.act { create_new_file! }
        Page::File::Form.perform do |page|
          page.add_name('dummy')
          page.add_content('Enable the Web IDE')
          page.commit_changes
        end

        Page::Main::Menu.act { sign_out }
      end

      templates = [
        {
          file_name: '.gitignore',
          name: 'Android',
          api_path: 'gitignores',
          api_key: 'Android'
        },
        {
          file_name: '.gitlab-ci.yml',
          name: 'Julia',
          api_path: 'gitlab_ci_ymls',
          api_key: 'Julia'
        },
        {
          file_name: 'Dockerfile',
          name: 'Python',
          api_path: 'dockerfiles',
          api_key: 'Python'
        },
        {
          file_name: 'LICENSE',
          name: 'Mozilla Public License 2.0',
          api_path: 'licenses',
          api_key: 'mpl-2.0'
        }
      ]

      templates.each do |template|
        it "user adds #{template[:file_name]} via file template #{template[:name]}" do
          content = fetch_template_from_api(template[:api_path], template[:api_key])

          login
          @project.visit!

          Page::Project::Show.act { open_web_ide! }
          Page::Project::WebIDE::Edit.perform do |page|
            page.create_new_file_from_template template[:file_name], template[:name]

            expect(page.has_file?(template[:file_name])).to be_truthy
          end

          expect(page).to have_button('Undo')
          expect(page).to have_content(content[0..100])

          Page::Project::WebIDE::Edit.perform do |page|
            page.commit_changes
          end

          expect(page).to have_content(template[:file_name])
          expect(page).to have_content(content[0..100])
        end
      end
    end
  end
end