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

user_uploads_designs_spec.rb « design_management « issues « projects « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 29a27992a0d5c95dc7370b666bcdd8ab21c08531 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'User uploads new design', :js do
  include DesignManagementTestHelpers

  let(:project) { create(:project_empty_repo, :public) }
  let(:user) { project.owner }
  let(:issue) { create(:issue, project: project) }

  before do
    sign_in(user)
  end

  context 'design_management_moved flag disabled' do
    before do
      enable_design_management(feature_enabled)
      stub_feature_flags(design_management_moved: false)
      visit project_issue_path(project, issue)

      click_link 'Designs'

      wait_for_requests
    end

    context "when the feature is available" do
      let(:feature_enabled) { true }

      it 'uploads designs' do
        upload_design(logo_fixture, count: 1)

        expect(page).to have_selector('.js-design-list-item', count: 1)

        within first('#designs-tab .js-design-list-item') do
          expect(page).to have_content('dk.png')
        end

        upload_design(gif_fixture, count: 2)

        # Known bug in the legacy implementation: new designs are inserted
        # in the beginning on the frontend.
        expect(page).to have_selector('.js-design-list-item', count: 2)
        expect(page.all('.js-design-list-item').map(&:text)).to eq(['banana_sample.gif', 'dk.png'])
      end
    end

    context 'when the feature is not available' do
      let(:feature_enabled) { false }

      it 'shows the message about requirements' do
        expect(page).to have_content("To upload designs, you'll need to enable LFS.")
      end
    end
  end

  context 'design_management_moved flag enabled' do
    before do
      enable_design_management(feature_enabled)
      stub_feature_flags(design_management_moved: true)
      visit project_issue_path(project, issue)
    end

    context "when the feature is available" do
      let(:feature_enabled) { true }

      it 'uploads designs' do
        upload_design(logo_fixture, count: 1)

        expect(page).to have_selector('.js-design-list-item', count: 1)

        within first('[data-testid="designs-root"] .js-design-list-item') do
          expect(page).to have_content('dk.png')
        end

        upload_design(gif_fixture, count: 2)

        expect(page).to have_selector('.js-design-list-item', count: 2)
        expect(page.all('.js-design-list-item').map(&:text)).to eq(['dk.png', 'banana_sample.gif'])
      end
    end

    context 'when the feature is not available' do
      let(:feature_enabled) { false }

      it 'shows the message about requirements' do
        expect(page).to have_content("To upload designs, you'll need to enable LFS.")
      end
    end
  end

  def logo_fixture
    Rails.root.join('spec', 'fixtures', 'dk.png')
  end

  def gif_fixture
    Rails.root.join('spec', 'fixtures', 'banana_sample.gif')
  end

  def upload_design(fixture, count:)
    attach_file(:design_file, fixture, match: :first, make_visible: true)

    wait_for('designs uploaded') do
      issue.reload.designs.count == count
    end
  end
end