Commit 5abcf1ec authored by Andrejs Cunskis's avatar Andrejs Cunskis Committed by Sanad Liaquat

E2E test: Implement group comparison

parent 78412844
......@@ -73,7 +73,9 @@ module QA
autoload :Issue, 'qa/resource/issue'
autoload :ProjectIssueNote, 'qa/resource/project_issue_note'
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 :ProjectImportedFromGithub, 'qa/resource/project_imported_from_github'
autoload :MergeRequestFromFork, 'qa/resource/merge_request_from_fork'
......
......@@ -211,7 +211,6 @@ module QA
module Resource
autoload :License, 'qa/ee/resource/license'
autoload :Epic, 'qa/ee/resource/epic'
autoload :GroupLabel, 'qa/ee/resource/group_label'
autoload :GroupIteration, 'qa/ee/resource/group_iteration'
autoload :ImportRepoWithCICD, 'qa/ee/resource/import_repo_with_ci_cd'
autoload :PipelineSubscriptions, 'qa/ee/resource/pipeline_subscriptions'
......
......@@ -22,7 +22,7 @@ module QA
end
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.title = label_title
end
......
......@@ -8,16 +8,14 @@ module QA
module Project
class LabelBoardList < BaseBoardList
attribute :label do
QA::Resource::Label.fabricate_via_api! do |label|
QA::Resource::ProjectLabel.fabricate_via_api! do |label|
label.project = board.project
label.title = 'Testing'
end
end
def api_post_body
super.merge({
label_id: label.id
})
super.merge({ label_id: label.id })
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
attribute :name
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
#
# @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'
module QA
module Resource
class Label < Base
attr_accessor :description, :color
# Base label class for GroupLabel and ProjectLabel
#
class LabelBase < Base
attr_accessor :title, :description, :color
attribute :id
attribute :title
attribute :project do
Project.fabricate! do |resource|
resource.name = 'project-with-label'
end
end
attribute :description_html
attribute :text_color
attribute :subscribed
def initialize
@title = "qa-test-#{SecureRandom.hex(8)}"
......@@ -23,38 +21,67 @@ module QA
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 |new_page|
new_page.fill_title(@title)
new_page.fill_description(@description)
new_page.fill_color(@color)
new_page.fill_title(title)
new_page.fill_description(description)
new_page.fill_color(color)
new_page.click_label_create_button
end
end
# Resource web url
#
# @param [Hash] resource
# @return [String]
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."
# Params for label creation
#
# @return [Hash]
def api_post_body
{
name: title,
color: color,
description: description
}
end
def api_post_path
"/projects/#{project.id}/labels"
# Object comparison
#
# @param [QA::Resource::GroupBase] other
# @return [Boolean]
def ==(other)
other.is_a?(LabelBase) && comparable_label == other.comparable_label
end
def api_post_body
{
color: @color,
name: @title
}
# Override inspect for a better rspec failure diff output
#
# @return [String]
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
......
# 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
let(:imported_group) do
Resource::Group.new.tap do |group|
group.api_client = api_client
group.sandbox = sandbox
group.path = source_group.path
end
end.reload!
end
let(:imported_subgroup) do
......@@ -46,7 +47,7 @@ module QA
group.api_client = api_client
group.sandbox = imported_group
group.path = subgroup.path
end
end.reload!
end
def staging?
......@@ -59,6 +60,17 @@ module QA
end
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)
source_group.add_member(user, Resource::Members::AccessLevel::MAINTAINER)
......@@ -72,15 +84,22 @@ module QA
testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1785',
exclude: { job: ['ce:relative_url', 'ee:relative_url'] },
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
Page::Group::BulkImport.perform do |import_page|
import_page.import_group(source_group.path, sandbox.path)
aggregate_failures do
expect(import_page).to have_imported_group(source_group.path, wait: 120)
expect(imported_group).to eq(source_group)
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
......
......@@ -16,7 +16,11 @@ module QA
Flow::Login.sign_in
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|
merge_request.project = project
merge_request.title = merge_request_title
......@@ -29,14 +33,17 @@ module QA
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}"
milestone = Resource::ProjectMilestone.fabricate_via_api! do |milestone|
milestone.project = project
end
label = Resource::Label.fabricate_via_api! do |label|
label = Resource::ProjectLabel.fabricate_via_api! do |label|
label.project = project
label.title = 'label'
end
......
......@@ -24,7 +24,7 @@ module QA
new_label_same_scope_multi_colon,
new_label_different_scope_multi_colon
].each do |label|
Resource::Label.fabricate_via_api! do |l|
Resource::ProjectLabel.fabricate_via_api! do |l|
l.project = issue.project
l.title = label
end
......@@ -33,14 +33,19 @@ module QA
issue.visit!
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|
show.select_labels_and_refresh([
new_label_same_scope,
new_label_different_scope,
new_label_same_scope_multi_colon,
new_label_different_scope_multi_colon
])
show.select_labels_and_refresh(
[
new_label_same_scope,
new_label_different_scope,
new_label_same_scope_multi_colon,
new_label_different_scope_multi_colon
]
)
aggregate_failures do
expect(show).to have_label(new_label_same_scope)
......
......@@ -54,7 +54,7 @@ module QA
end
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.title = "test severity 3"
end
......@@ -88,7 +88,10 @@ module QA
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)
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