Commit b80865b7 authored by Sofia Vistas's avatar Sofia Vistas Committed by Mark Lapierre

Add negatable predicate methods

Prior to this change, the matchers would need
in some cases to wait for the condition to return true and
the negate it. This can add up to 10 seconds each time.

This MR, instead of executing the page object's matcher method, uses
a custom matcher for match_when_negated that reads more naturally
and avoids using negative predicate methods such as has_no_file
in the end to end test.
parent 00112e67
tmp/
.ruby-version
.tool-versions
.ruby-gemset
urls.yml
......@@ -16,6 +16,12 @@ module QA
has_element?(:iteration_issue_link, issue_title: issue.title)
end
end
def has_no_issue?(issue)
within_element(:iteration_issues_container) do
has_no_element?(:iteration_issue_link, issue_title: issue.title)
end
end
end
end
end
......
......@@ -108,6 +108,10 @@ module QA
has_element?(:design_file_name, text: filename)
end
def has_no_design?(filename)
has_no_element?(:design_file_name, text: filename)
end
def has_created_icon?
has_element?(:design_status_icon, status: 'file-addition-solid')
end
......
......@@ -69,7 +69,7 @@ module QA
end
end
def has_no_assignee_named?(username)
def has_no_assignee?(username)
within_element(:assignee_block) do
has_no_text?(username, wait: 120)
end
......
......@@ -46,8 +46,16 @@ module QA
has_no_element?(:file_name_content, text: name)
end
def has_file_content?(text)
has_element?(:file_content, text: text)
def has_file_content?(file_content, file_number = nil)
if file_number
within_element_by_index(:file_content, file_number - 1) do
has_text?(file_content)
end
else
within_element(:file_content) do
has_text?(file_content)
end
end
end
end
end
......
......@@ -79,6 +79,10 @@ module QA
def has_issue?(issue)
has_element? :issue_container, issue_title: issue.title
end
def has_no_issue?(issue)
has_no_element? :issue_container, issue_title: issue.title
end
end
end
end
......
......@@ -49,6 +49,10 @@ module QA
has_element? :pipeline_url_link
end
def has_no_pipeline?
has_no_element? :pipeline_url_link
end
def click_run_pipeline_button
click_element :run_pipeline_button, Page::Project::Pipeline::New
end
......
......@@ -72,6 +72,10 @@ module QA
has_element? :child_pipeline
end
def has_no_child_pipeline?
has_no_element? :child_pipeline
end
def click_job(job_name)
click_element(:job_link, text: job_name)
end
......
......@@ -59,6 +59,10 @@ module QA
has_element?(:wiki_page_content, content)
end
def has_no_content?(content)
has_no_element?(:wiki_page_content, content)
end
def has_no_page?
has_element? :create_first_page_link
end
......
......@@ -40,12 +40,12 @@ module QA
issue.set_issue_assignees(assignee_ids: [user2.id])
expect(show).to have_assignee(user2.name)
expect(show).to have_no_assignee_named(user1.name)
expect(show).not_to have_assignee(user1.name)
issue.set_issue_assignees(assignee_ids: [])
expect(show).to have_no_assignee_named(user1.name)
expect(show).to have_no_assignee_named(user2.name)
expect(show).not_to have_assignee(user1.name)
expect(show).not_to have_assignee(user2.name)
end
end
end
......
......@@ -37,7 +37,7 @@ module QA
show.click_remove_related_issue_button
expect(show).to have_no_text(issue_2.title, wait: max_wait)
expect(show).not_to have_text(issue_2.title, wait: max_wait)
end
end
end
......
......@@ -16,13 +16,13 @@ module QA
Page::Dashboard::Snippet::Show.perform do |snippet|
expect(snippet).to have_snippet_title('Project snippet')
expect(snippet).to have_no_snippet_description
expect(snippet).not_to have_snippet_description
expect(snippet).to have_visibility_type(/private/i)
expect(snippet).to have_file_name('markdown_file.md')
expect(snippet).to have_file_content('Snippet heading')
expect(snippet).to have_file_content('Gitlab link')
expect(snippet).to have_no_file_content('###')
expect(snippet).to have_no_file_content('https://gitlab.com/')
expect(snippet).not_to have_file_content('###')
expect(snippet).not_to have_file_content('https://gitlab.com/')
end
end
end
......
......@@ -46,8 +46,8 @@ module QA
aggregate_failures 'file names and contents' do
expect(snippet).to have_file_name('Original file name')
expect(snippet).to have_file_content('Original file content')
expect(snippet).to have_no_file_name('Second file name')
expect(snippet).to have_no_file_content('Second file content')
expect(snippet).not_to have_file_name('Second file name')
expect(snippet).not_to have_file_content('Second file content')
end
end
end
......
......@@ -19,7 +19,7 @@ module QA
it 'user adds a CI variable', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/395' do
Page::Project::Settings::CiVariables.perform do |ci_variable|
expect(ci_variable).to have_text('VARIABLE_KEY')
expect(ci_variable).to have_no_text('some_CI_variable')
expect(ci_variable).not_to have_text('some_CI_variable')
ci_variable.click_reveal_ci_variable_value_button
......
......@@ -54,7 +54,7 @@ module QA
Page::Project::Job::Show.perform do |job|
aggregate_failures 'main CI is not overridden' do
expect(job.output).to have_no_content("#{unexpected_text}")
expect(job.output).not_to have_content("#{unexpected_text}")
expect(job.output).to have_content("#{expected_text}")
end
end
......
......@@ -112,7 +112,7 @@ module QA
Page::Project::Packages::Index.perform do |index|
aggregate_failures 'package deletion' do
expect(index).to have_content("Package deleted successfully")
expect(index).to have_no_package(package_name)
expect(index).not_to have_package(package_name)
end
end
end
......
......@@ -80,7 +80,7 @@ module QA
Page::Project::Packages::Index.perform do |index|
expect(index).to have_content("Package deleted successfully")
expect(index).to have_no_package(package_name)
expect(index).not_to have_package(package_name)
end
end
end
......
......@@ -118,7 +118,7 @@ module QA
Page::Project::Packages::Index.perform do |index|
expect(index).to have_content("Package deleted successfully")
expect(index).to have_no_package(package_name)
expect(index).not_to have_package(package_name)
end
end
end
......
......@@ -96,7 +96,7 @@ module QA
Page::Project::Packages::Index.perform do |index|
expect(index).to have_content("Package deleted successfully")
expect(index).to have_no_package(package_name)
expect(index).not_to have_package(package_name)
end
end
end
......
......@@ -69,7 +69,7 @@ module QA
Page::Project::Packages::Index.perform do |index|
expect(index).to have_content("Package deleted successfully")
expect(index).to have_no_package(package_name)
expect(index).not_to have_package(package_name)
end
end
end
......
......@@ -84,7 +84,7 @@ module QA
Page::Project::Packages::Index.perform do |index|
expect(index).to have_content("Package deleted successfully")
expect(index).to have_no_package(package_name)
expect(index).not_to have_package(package_name)
end
end
end
......
......@@ -104,7 +104,7 @@ module QA
Page::Project::Packages::Index.perform do |index|
aggregate_failures do
expect(index).to have_content("Package deleted successfully")
expect(index).to have_no_package(package_name)
expect(index).not_to have_package(package_name)
end
end
end
......
......@@ -88,7 +88,7 @@ module QA
Page::Project::Pipeline::Show.perform do |show|
expect(show).to have_passed
expect(show).to have_no_job("downstream_job")
expect(show).not_to have_job("downstream_job")
show.expand_child_pipeline
......
......@@ -50,8 +50,8 @@ module QA
expect(snippet).to have_file_name(file_name)
expect(snippet).to have_file_content('Geo snippet heading')
expect(snippet).to have_file_content('GitLab link')
expect(snippet).to have_no_file_content('###')
expect(snippet).to have_no_file_content('https://gitlab.com/')
expect(snippet).not_to have_file_content('###')
expect(snippet).not_to have_file_content('https://gitlab.com/')
end
end
end
......
# frozen_string_literal: true
module Matchers
module HaveAssignee
RSpec::Matchers.define :have_assignee do |assignee|
match do |page_object|
page_object.has_assignee?(assignee)
end
match_when_negated do |page_object|
page_object.has_no_assignee?(assignee)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveChildPipeline
RSpec::Matchers.define :have_child_pipeline do
match do |page_object|
page_object.has_child_pipeline?
end
match_when_negated do |page_object|
page_object.has_no_child_pipeline?
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveContent
RSpec::Matchers.define :have_content do |content|
match do |page_object|
page_object.has_content?(content)
end
match_when_negated do |page_object|
page_object.has_no_content?(content)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveDesign
RSpec::Matchers.define :have_design do |design|
match do |page_object|
page_object.has_design?(design)
end
match_when_negated do |page_object|
page_object.has_no_design?(design)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveElement
RSpec::Matchers.define :have_element do |element, **kwargs|
match do |page_object|
page_object.has_element?(element, **kwargs)
end
match_when_negated do |page_object|
page_object.has_no_element?(element, **kwargs)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveFileContent
RSpec::Matchers.define :have_file_content do |file_content, file_number|
match do |page_object|
page_object.has_file_content?(file_content, file_number)
end
match_when_negated do |page_object|
page_object.has_no_file_content?(file_content, file_number)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveIssue
RSpec::Matchers.define :have_issue do |issue|
match do |page_object|
page_object.has_issue?(issue)
end
match_when_negated do |page_object|
page_object.has_no_issue?(issue)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveJob
RSpec::Matchers.define :have_job do |job|
match do |page_object|
page_object.has_job?(job)
end
match_when_negated do |page_object|
page_object.has_no_job?(job)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HavePackage
RSpec::Matchers.define :have_package do |package|
match do |page_object|
page_object.has_package?(package)
end
match_when_negated do |page_object|
page_object.has_no_package?(package)
end
end
end
end
# frozen_string_literal: true
module Matchers
module HavePipeline
RSpec::Matchers.define :have_pipeline do
match do |page_object|
page_object.has_pipeline?
end
match_when_negated do |page_object|
page_object.has_no_pipeline?
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveRelatedIssueItem
RSpec::Matchers.define :have_related_issue_item do
match do |page_object|
page_object.has_related_issue_item?
end
match_when_negated do |page_object|
page_object.has_no_related_issue_item?
end
end
end
end
# frozen_string_literal: true
module Matchers
module HaveSnippetDescription
RSpec::Matchers.define :have_snippet_description do |description|
match do |page_object|
page_object.has_snippet_description?(description)
end
match_when_negated do |page_object|
page_object.has_no_snippet_description?
end
end
end
end
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