summaryrefslogtreecommitdiff
path: root/qa/qa/resource/label.rb
blob: b5e88d8aefc7c486bfe690c2ffff873b93efd0b1 (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

require 'securerandom'

module QA
  module Resource
    class Label < Base
      attr_accessor :description, :color

      attribute :id
      attribute :title

      attribute :project do
        Project.fabricate! do |resource|
          resource.name = 'project-with-label'
        end
      end

      def initialize
        @title = "qa-test-#{SecureRandom.hex(8)}"
        @description = 'This is a test label'
        @color = '#0033CC'
      end

      def fabricate!
        project.visit!

        Page::Project::Menu.perform(&:go_to_labels)
        Page::Label::Index.perform(&:click_new_label_button)

        Page::Label::New.perform do |page|
          page.fill_title(@title)
          page.fill_description(@description)
          page.fill_color(@color)
          page.click_label_create_button
        end
      end

      def resource_web_url(resource)
        super
      rescue ResourceURLMissingError
        # this particular resource does not expose a web_url property
      end

      def api_get_path
        raise NotImplementedError, "The Labels API doesn't expose a single-resource endpoint so this method cannot be properly implemented."
      end

      def api_post_path
        "/projects/#{project.id}/labels"
      end

      def api_post_body
        {
          color: @color,
          name: @title
        }
      end
    end
  end
end