Commit 948ecefe authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch 'acunskis-group-label-migration' into 'master'

E2E test: Implement group comparison

See merge request gitlab-org/gitlab!62084
parents 9c08975c 5abcf1ec
...@@ -73,7 +73,9 @@ module QA ...@@ -73,7 +73,9 @@ module QA
autoload :Issue, 'qa/resource/issue' autoload :Issue, 'qa/resource/issue'
autoload :ProjectIssueNote, 'qa/resource/project_issue_note' autoload :ProjectIssueNote, 'qa/resource/project_issue_note'
autoload :Project, 'qa/resource/project' autoload :Project, 'qa/resource/project'
autoload :Label, 'qa/resource/label' autoload :LabelBase, 'qa/resource/label_base'
autoload :ProjectLabel, 'qa/resource/project_label'
autoload :GroupLabel, 'qa/resource/group_label'
autoload :MergeRequest, 'qa/resource/merge_request' autoload :MergeRequest, 'qa/resource/merge_request'
autoload :ProjectImportedFromGithub, 'qa/resource/project_imported_from_github' autoload :ProjectImportedFromGithub, 'qa/resource/project_imported_from_github'
autoload :MergeRequestFromFork, 'qa/resource/merge_request_from_fork' autoload :MergeRequestFromFork, 'qa/resource/merge_request_from_fork'
......
...@@ -211,7 +211,6 @@ module QA ...@@ -211,7 +211,6 @@ module QA
module Resource module Resource
autoload :License, 'qa/ee/resource/license' autoload :License, 'qa/ee/resource/license'
autoload :Epic, 'qa/ee/resource/epic' autoload :Epic, 'qa/ee/resource/epic'
autoload :GroupLabel, 'qa/ee/resource/group_label'
autoload :GroupIteration, 'qa/ee/resource/group_iteration' autoload :GroupIteration, 'qa/ee/resource/group_iteration'
autoload :ImportRepoWithCICD, 'qa/ee/resource/import_repo_with_ci_cd' autoload :ImportRepoWithCICD, 'qa/ee/resource/import_repo_with_ci_cd'
autoload :PipelineSubscriptions, 'qa/ee/resource/pipeline_subscriptions' autoload :PipelineSubscriptions, 'qa/ee/resource/pipeline_subscriptions'
......
...@@ -22,7 +22,7 @@ module QA ...@@ -22,7 +22,7 @@ module QA
end end
attribute :label do attribute :label do
QA::EE::Resource::GroupLabel.fabricate_via_api! do |group_label| QA::Resource::GroupLabel.fabricate_via_api! do |group_label|
group_label.group = board.group group_label.group = board.group
group_label.title = label_title group_label.title = label_title
end end
......
...@@ -8,16 +8,14 @@ module QA ...@@ -8,16 +8,14 @@ module QA
module Project module Project
class LabelBoardList < BaseBoardList class LabelBoardList < BaseBoardList
attribute :label do attribute :label do
QA::Resource::Label.fabricate_via_api! do |label| QA::Resource::ProjectLabel.fabricate_via_api! do |label|
label.project = board.project label.project = board.project
label.title = 'Testing' label.title = 'Testing'
end end
end end
def api_post_body def api_post_body
super.merge({ super.merge({ label_id: label.id })
label_id: label.id
})
end end
end end
end end
......
# frozen_string_literal: true
require 'securerandom'
module QA
module EE
module Resource
class GroupLabel < Base
attr_accessor :description, :color
attribute :id
attribute :title
attribute :group do
Group.fabricate_via_api! do |resource|
resource.name = 'group-with-label'
end
end
def initialize
@title = "qa-test-#{SecureRandom.hex(8)}"
@description = 'This is a test group label'
@color = '#6655FF'
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
"/groups/#{group.id}/labels"
end
def api_post_body
{
color: @color,
name: @title,
description: @description
}
end
end
end
end
end
...@@ -14,6 +14,29 @@ module QA ...@@ -14,6 +14,29 @@ module QA
attribute :name attribute :name
attribute :full_path attribute :full_path
# Get group labels
#
# @return [Array<QA::Resource::GroupLabel>]
def labels
parse_body(api_get_from("#{api_get_path}/labels")).map do |label|
GroupLabel.new.tap do |resource|
resource.api_client = api_client
resource.group = self
resource.id = label[:id]
resource.title = label[:name]
resource.description = label[:description]
resource.color = label[:color]
end
end
end
# API get path
#
# @return [String]
def api_get_path
raise NotImplementedError
end
# API post path # API post path
# #
# @return [String] # @return [String]
......
# frozen_string_literal: true
module QA
module Resource
class GroupLabel < LabelBase
attribute :group do
Group.fabricate! do |resource|
resource.name = 'group-with-label'
end
end
def fabricate!
raise NotImplementedError
end
def api_post_path
"/groups/#{group.id}/labels"
end
def api_get_path
"/groups/#{group.id}/labels/#{id}"
end
end
end
end
...@@ -4,17 +4,15 @@ require 'securerandom' ...@@ -4,17 +4,15 @@ require 'securerandom'
module QA module QA
module Resource module Resource
class Label < Base # Base label class for GroupLabel and ProjectLabel
attr_accessor :description, :color #
class LabelBase < Base
attr_accessor :title, :description, :color
attribute :id attribute :id
attribute :title attribute :description_html
attribute :text_color
attribute :project do attribute :subscribed
Project.fabricate! do |resource|
resource.name = 'project-with-label'
end
end
def initialize def initialize
@title = "qa-test-#{SecureRandom.hex(8)}" @title = "qa-test-#{SecureRandom.hex(8)}"
...@@ -23,38 +21,67 @@ module QA ...@@ -23,38 +21,67 @@ module QA
end end
def fabricate! def fabricate!
project.visit!
Page::Project::Menu.perform(&:go_to_labels)
Page::Label::Index.perform(&:click_new_label_button) Page::Label::Index.perform(&:click_new_label_button)
Page::Label::New.perform do |new_page| Page::Label::New.perform do |new_page|
new_page.fill_title(@title) new_page.fill_title(title)
new_page.fill_description(@description) new_page.fill_description(description)
new_page.fill_color(@color) new_page.fill_color(color)
new_page.click_label_create_button new_page.click_label_create_button
end end
end end
# Resource web url
#
# @param [Hash] resource
# @return [String]
def resource_web_url(resource) def resource_web_url(resource)
super super
rescue ResourceURLMissingError rescue ResourceURLMissingError
# this particular resource does not expose a web_url property # this particular resource does not expose a web_url property
end end
def api_get_path # Params for label creation
raise NotImplementedError, "The Labels API doesn't expose a single-resource endpoint so this method cannot be properly implemented." #
# @return [Hash]
def api_post_body
{
name: title,
color: color,
description: description
}
end end
def api_post_path # Object comparison
"/projects/#{project.id}/labels" #
# @param [QA::Resource::GroupBase] other
# @return [Boolean]
def ==(other)
other.is_a?(LabelBase) && comparable_label == other.comparable_label
end end
def api_post_body # Override inspect for a better rspec failure diff output
{ #
color: @color, # @return [String]
name: @title def inspect
} JSON.pretty_generate(comparable_label)
end
# protected
# Return subset of fields for comparing groups
#
# @return [Hash]
def comparable_label
reload! unless api_response
api_response.slice(
:name,
:description,
:description_html,
:color,
:text_color,
:subscribed
)
end end
end end
end end
......
# frozen_string_literal: true
module QA
module Resource
class ProjectLabel < LabelBase
attribute :project do
Project.fabricate! do |resource|
resource.name = 'project-with-label'
end
end
def fabricate!
project.visit!
Page::Project::Menu.perform(&:go_to_labels)
super
end
def api_post_path
"/projects/#{project.id}/labels"
end
def api_get_path
"/projects/#{project.id}/labels/#{id}"
end
end
end
end
...@@ -37,8 +37,9 @@ module QA ...@@ -37,8 +37,9 @@ module QA
let(:imported_group) do let(:imported_group) do
Resource::Group.new.tap do |group| Resource::Group.new.tap do |group|
group.api_client = api_client group.api_client = api_client
group.sandbox = sandbox
group.path = source_group.path group.path = source_group.path
end end.reload!
end end
let(:imported_subgroup) do let(:imported_subgroup) do
...@@ -46,7 +47,7 @@ module QA ...@@ -46,7 +47,7 @@ module QA
group.api_client = api_client group.api_client = api_client
group.sandbox = imported_group group.sandbox = imported_group
group.path = subgroup.path group.path = subgroup.path
end end.reload!
end end
def staging? def staging?
...@@ -59,6 +60,17 @@ module QA ...@@ -59,6 +60,17 @@ module QA
end end
before do before do
Resource::GroupLabel.fabricate_via_api! do |label|
label.api_client = api_client
label.group = source_group
label.title = "source-group-#{SecureRandom.hex(4)}"
end
Resource::GroupLabel.fabricate_via_api! do |label|
label.api_client = api_client
label.group = subgroup
label.title = "subgroup-#{SecureRandom.hex(4)}"
end
sandbox.add_member(user, Resource::Members::AccessLevel::MAINTAINER) sandbox.add_member(user, Resource::Members::AccessLevel::MAINTAINER)
source_group.add_member(user, Resource::Members::AccessLevel::MAINTAINER) source_group.add_member(user, Resource::Members::AccessLevel::MAINTAINER)
...@@ -72,15 +84,22 @@ module QA ...@@ -72,15 +84,22 @@ module QA
testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1785', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1785',
exclude: { job: ['ce:relative_url', 'ee:relative_url'] }, exclude: { job: ['ce:relative_url', 'ee:relative_url'] },
issue_1: "https://gitlab.com/gitlab-org/gitlab/-/issues/330344", issue_1: "https://gitlab.com/gitlab-org/gitlab/-/issues/330344",
issue_2: "https://gitlab.com/gitlab-org/gitlab/-/issues/331252" issue_2: "https://gitlab.com/gitlab-org/gitlab/-/issues/331252",
issue_3: "https://gitlab.com/gitlab-org/gitlab/-/issues/331704"
) do ) do
Page::Group::BulkImport.perform do |import_page| Page::Group::BulkImport.perform do |import_page|
import_page.import_group(source_group.path, sandbox.path) import_page.import_group(source_group.path, sandbox.path)
aggregate_failures do aggregate_failures do
expect(import_page).to have_imported_group(source_group.path, wait: 120) expect(import_page).to have_imported_group(source_group.path, wait: 120)
expect(imported_group).to eq(source_group) expect(imported_group).to eq(source_group)
expect(imported_subgroup).to eq(subgroup) expect(imported_subgroup).to eq(subgroup)
# TODO: Improve validation logic with some potential retry mechanism built in to custom rspec matcher
# https://gitlab.com/gitlab-org/gitlab/-/issues/331704
# expect(imported_group.labels).to include(*source_group.labels)
expect(imported_subgroup.labels).to include(*subgroup.labels)
end end
end end
end end
......
...@@ -16,7 +16,11 @@ module QA ...@@ -16,7 +16,11 @@ module QA
Flow::Login.sign_in Flow::Login.sign_in
end end
it 'creates a basic merge request', :smoke, testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1850' do it(
'creates a basic merge request',
:smoke,
testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1850'
) do
Resource::MergeRequest.fabricate_via_browser_ui! do |merge_request| Resource::MergeRequest.fabricate_via_browser_ui! do |merge_request|
merge_request.project = project merge_request.project = project
merge_request.title = merge_request_title merge_request.title = merge_request_title
...@@ -29,14 +33,17 @@ module QA ...@@ -29,14 +33,17 @@ module QA
end end
end end
it 'creates a merge request with a milestone and label', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/514' do it(
'creates a merge request with a milestone and label',
testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/514'
) do
gitlab_account_username = "@#{Runtime::User.username}" gitlab_account_username = "@#{Runtime::User.username}"
milestone = Resource::ProjectMilestone.fabricate_via_api! do |milestone| milestone = Resource::ProjectMilestone.fabricate_via_api! do |milestone|
milestone.project = project milestone.project = project
end end
label = Resource::Label.fabricate_via_api! do |label| label = Resource::ProjectLabel.fabricate_via_api! do |label|
label.project = project label.project = project
label.title = 'label' label.title = 'label'
end end
......
...@@ -24,7 +24,7 @@ module QA ...@@ -24,7 +24,7 @@ module QA
new_label_same_scope_multi_colon, new_label_same_scope_multi_colon,
new_label_different_scope_multi_colon new_label_different_scope_multi_colon
].each do |label| ].each do |label|
Resource::Label.fabricate_via_api! do |l| Resource::ProjectLabel.fabricate_via_api! do |l|
l.project = issue.project l.project = issue.project
l.title = label l.title = label
end end
...@@ -33,14 +33,19 @@ module QA ...@@ -33,14 +33,19 @@ module QA
issue.visit! issue.visit!
end end
it 'correctly applies simple and multiple colon scoped pairs labels', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1171' do it(
'correctly applies simple and multiple colon scoped pairs labels',
testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1171'
) do
Page::Project::Issue::Show.perform do |show| Page::Project::Issue::Show.perform do |show|
show.select_labels_and_refresh([ show.select_labels_and_refresh(
new_label_same_scope, [
new_label_different_scope, new_label_same_scope,
new_label_same_scope_multi_colon, new_label_different_scope,
new_label_different_scope_multi_colon new_label_same_scope_multi_colon,
]) new_label_different_scope_multi_colon
]
)
aggregate_failures do aggregate_failures do
expect(show).to have_label(new_label_same_scope) expect(show).to have_label(new_label_same_scope)
......
...@@ -54,7 +54,7 @@ module QA ...@@ -54,7 +54,7 @@ module QA
end end
Flow::Pipeline.wait_for_latest_pipeline(pipeline_condition: 'succeeded') Flow::Pipeline.wait_for_latest_pipeline(pipeline_condition: 'succeeded')
@label = Resource::Label.fabricate_via_api! do |new_label| @label = Resource::ProjectLabel.fabricate_via_api! do |new_label|
new_label.project = @project new_label.project = @project
new_label.title = "test severity 3" new_label.title = "test severity 3"
end end
...@@ -88,7 +88,10 @@ module QA ...@@ -88,7 +88,10 @@ module QA
end end
end end
it 'creates an issue from vulnerability details', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1228' do it(
'creates an issue from vulnerability details',
testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1228'
) do
Page::Project::Menu.perform(&:click_on_vulnerability_report) Page::Project::Menu.perform(&:click_on_vulnerability_report)
EE::Page::Project::Secure::SecurityDashboard.perform do |security_dashboard| EE::Page::Project::Secure::SecurityDashboard.perform do |security_dashboard|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment