Commit 09be9304 authored by Ramya Authappan's avatar Ramya Authappan

Merge branch 'tmslvnkc/wiki/refactor' into 'master'

Refactoring old wiki testing code

Closes gitlab-org/quality/testcases#271, gitlab-org/quality/testcases#275, and gitlab-org/quality/testcases#267

See merge request gitlab-org/gitlab!31716
parents bd1b1061 d6b0917b
- if (@page && @page.persisted?)
- if can?(current_user, :create_wiki, @project)
= link_to project_wikis_new_path(@project), class: "add-new-wiki btn btn-success", role: "button" do
= link_to project_wikis_new_path(@project), class: "add-new-wiki btn btn-success", role: "button", data: { qa_selector: 'new_page_button' } do
= s_("Wiki|New page")
= link_to project_wiki_history_path(@project, @page), class: "btn", role: "button" do
= link_to project_wiki_history_path(@project, @page), class: "btn", role: "button", data: { qa_selector: 'page_history_button' } do
= s_("Wiki|Page history")
- if can?(current_user, :create_wiki, @project) && @page.latest? && @valid_encoding
= link_to project_wiki_edit_path(@project, @page), class: "btn js-wiki-edit", role: "button" do
= link_to project_wiki_edit_path(@project, @page), class: "btn js-wiki-edit", role: "button", data: { qa_selector: 'edit_page_button' } do
= _("Edit")
......@@ -5,7 +5,7 @@
= icon('angle-double-right')
- git_access_url = project_wikis_git_access_path(@project)
= link_to git_access_url, class: active_nav_link?(path: 'wikis#git_access') ? 'active' : '' do
= link_to git_access_url, class: active_nav_link?(path: 'wikis#git_access') ? 'active' : '', data: { qa_selector: 'clone_repository_link' } do
= icon('cloud-download', class: 'append-right-5')
%span= _("Clone repository")
......
......@@ -9,7 +9,7 @@
= icon('angle-double-left')
.nav-text.flex-fill
%h2.wiki-page-title= @page.human_title
%h2.wiki-page-title{ data: { qa_selector: 'wiki_page_title' } }= @page.human_title
%span.wiki-last-edit-by
- if @page.last_version
= (_("Last edited by %{name}") % { name: "<strong>#{@page.last_version.author_name}</strong>" }).html_safe
......
......@@ -80,7 +80,6 @@ module QA
autoload :User, 'qa/resource/user'
autoload :ProjectMilestone, 'qa/resource/project_milestone'
autoload :Members, 'qa/resource/members'
autoload :Wiki, 'qa/resource/wiki'
autoload :File, 'qa/resource/file'
autoload :Fork, 'qa/resource/fork'
autoload :SSHKey, 'qa/resource/ssh_key'
......@@ -112,6 +111,10 @@ module QA
module Settings
autoload :HashedStorage, 'qa/resource/settings/hashed_storage'
end
module Wiki
autoload :ProjectPage, 'qa/resource/wiki/project_page'
end
end
##
......@@ -327,7 +330,6 @@ module QA
module Wiki
autoload :Edit, 'qa/page/project/wiki/edit'
autoload :New, 'qa/page/project/wiki/new'
autoload :Show, 'qa/page/project/wiki/show'
autoload :GitAccess, 'qa/page/project/wiki/git_access'
end
......
......@@ -5,14 +5,32 @@ module QA
module Project
module Wiki
class Edit < Page::Base
view 'app/views/projects/wikis/_main_links.html.haml' do
element :new_page_link, 'New page' # rubocop:disable QA/ElementWithPattern
element :page_history_link, 'Page history' # rubocop:disable QA/ElementWithPattern
element :edit_page_link, 'Edit' # rubocop:disable QA/ElementWithPattern
view 'app/views/projects/wikis/_form.html.haml' do
element :wiki_title_textbox
element :wiki_content_textarea
element :wiki_message_textbox
element :save_changes_button
element :create_page_button
end
def click_edit
click_on 'Edit'
def set_title(title)
fill_element :wiki_title_textbox, title
end
def set_content(content)
fill_element :wiki_content_textarea, content
end
def set_message(message)
fill_element :wiki_message_textbox, message
end
def click_save_changes
click_element :save_changes_button
end
def click_create_page
click_element :create_page_button
end
end
end
......
# frozen_string_literal: true
module QA
module Page
module Project
module Wiki
class New < Page::Base
include Component::LazyLoader
view 'app/views/projects/wikis/_form.html.haml' do
element :wiki_title_textbox
element :wiki_content_textarea
element :wiki_message_textbox
element :save_changes_button
element :create_page_button
end
view 'app/views/shared/empty_states/_wikis.html.haml' do
element :create_first_page_link
end
view 'app/views/shared/empty_states/_wikis_layout.html.haml' do
element :svg_content
end
def click_create_your_first_page_button
# The svg takes a fraction of a second to load after which the
# "Create your first page" button shifts up a bit. This can cause
# webdriver to miss the hit so we wait for the svg to load before
# clicking the button.
within_element(:svg_content) do
has_element? :js_lazy_loaded
end
click_element :create_first_page_link
end
def set_title(title)
fill_element :wiki_title_textbox, title
end
def set_content(content)
fill_element :wiki_content_textarea, content
end
def set_message(message)
fill_element :wiki_message_textbox, message
end
def save_changes
click_element :save_changes_button
end
def create_new_page
click_element :create_page_button
end
end
end
end
end
end
......@@ -5,23 +5,70 @@ module QA
module Project
module Wiki
class Show < Page::Base
include Page::Component::LegacyClonePanel
include Component::LazyLoader
view 'app/views/projects/wikis/pages.html.haml' do
element :clone_repository_link, 'Clone repository' # rubocop:disable QA/ElementWithPattern
view 'app/views/projects/wikis/_sidebar.html.haml' do
element :clone_repository_link
end
view 'app/views/projects/wikis/show.html.haml' do
element :wiki_page_title
element :wiki_page_content
end
view 'app/views/projects/wikis/_main_links.html.haml' do
element :new_page_button
element :page_history_button
element :edit_page_button
end
view 'app/views/shared/empty_states/_wikis.html.haml' do
element :create_first_page_link
end
view 'app/views/shared/empty_states/_wikis_layout.html.haml' do
element :svg_content
end
def click_create_your_first_page
# The svg takes a fraction of a second to load after which the
# "Create your first page" button shifts up a bit. This can cause
# webdriver to miss the hit so we wait for the svg to load before
# clicking the button.
within_element(:svg_content) do
has_element? :js_lazy_loaded
end
click_element :create_first_page_link
end
def click_new_page
click_element(:new_page_button)
end
def click_page_history
click_element(:page_history_button)
end
def click_edit
click_element(:edit_page_button)
end
def click_clone_repository
click_on 'Clone repository'
click_element(:clone_repository_link)
end
def wiki_text
find_element(:wiki_page_content).text
end
def has_title?(title)
has_element?(:wiki_page_title, title)
end
def has_content?(content)
has_element?(:wiki_page_content, content)
end
end
end
end
......
......@@ -56,6 +56,8 @@ module QA
@auto_devops_enabled = false
@visibility = :public
@template_name = nil
self.name = "the_awesome_project"
end
def name=(raw_name)
......
......@@ -5,17 +5,17 @@ module QA
module Repository
class WikiPush < Repository::Push
attribute :wiki do
Wiki.fabricate! do |resource|
# We are using the project based wiki as a standard.
Wiki::ProjectPage.fabricate_via_api! do |resource|
resource.title = 'Home'
resource.content = '# My First Wiki Content'
resource.message = 'Update home'
end
end
def initialize
@file_name = 'Home.md'
@file_content = '# Welcome to My Wiki'
@commit_message = 'Updating Home Page'
@file_content = 'This line was created using git push'
@commit_message = 'Updating using git push'
@branch_name = 'master'
@new_branch = false
end
......@@ -28,9 +28,10 @@ module QA
@repository_ssh_uri ||= wiki.repository_ssh_location.uri
end
def fabricate!
super
wiki.visit!
def web_url
# TODO
# workaround
repository_http_uri.to_s.gsub(".wiki.git", "/-/wikis/#{@file_name.gsub('.md', '')}")
end
end
end
......
# frozen_string_literal: true
module QA
module Resource
class Wiki < Base
attr_accessor :title, :content, :message
attribute :project do
Project.fabricate! do |resource|
resource.name = 'project-for-wikis'
resource.description = 'project for adding wikis'
end
end
attribute :repository_http_location do
Page::Project::Wiki::Show.perform(&:click_clone_repository)
Page::Project::Wiki::GitAccess.perform do |git_access|
git_access.choose_repository_clone_http
git_access.repository_location
end
end
attribute :repository_ssh_location do
Page::Project::Wiki::Show.perform(&:click_clone_repository)
Page::Project::Wiki::GitAccess.perform do |git_access|
git_access.choose_repository_clone_ssh
git_access.repository_location
end
end
def fabricate!
project.visit!
Page::Project::Menu.perform { |menu_side| menu_side.click_wiki }
Page::Project::Wiki::New.perform do |wiki_new|
wiki_new.click_create_your_first_page_button
wiki_new.set_title(@title)
wiki_new.set_content(@content)
wiki_new.set_message(@message)
wiki_new.create_new_page
end
end
end
end
end
# frozen_string_literal: true
module QA
module Resource
module Wiki
class ProjectPage < Base
attribute :title
attribute :content
attribute :slug
attribute :format
attribute :project do
Project.fabricate_via_api! do |project|
project.name = 'wiki_testing'
project.description = 'project for testing wikis'
end
end
attribute :repository_http_location do
switching_to_wiki_url project.repository_http_location.git_uri
end
attribute :repository_ssh_location do
switching_to_wiki_url project.repository_ssh_location.git_uri
end
def initialize
@title = 'Home'
@content = 'This wiki page is created by the API'
end
def resource_web_url(resource)
super
rescue ResourceURLMissingError
# TODO
# workaround
project.web_url.concat("/-/wikis/#{slug}")
end
def api_get_path
"/projects/#{project.id}/wikis/#{slug}"
end
def api_post_path
"/projects/#{project.id}/wikis"
end
def api_post_body
{
id: project.id,
content: content,
title: title
}
end
private
def switching_to_wiki_url(url)
# TODO
# workaround
Git::Location.new(url.to_s.gsub('.git', '.wiki.git'))
end
end
end
end
end
# frozen_string_literal: true
module QA
context 'Create' do
describe 'Wiki management' do
it 'user creates, edits, clones, and pushes to the wiki' do
Flow::Login.sign_in
wiki = Resource::Wiki.fabricate_via_browser_ui! do |resource|
resource.title = 'Home'
resource.content = '# My First Wiki Content'
resource.message = 'Update home'
end
validate_content('My First Wiki Content')
Page::Project::Wiki::Edit.perform(&:click_edit)
Page::Project::Wiki::New.perform do |wiki|
wiki.set_content("My Second Wiki Content")
wiki.save_changes
end
validate_content('My Second Wiki Content')
Resource::Repository::WikiPush.fabricate! do |push|
push.wiki = wiki
push.file_name = 'Home.md'
push.file_content = '# My Third Wiki Content'
push.commit_message = 'Update Home.md'
end
Page::Project::Menu.perform(&:click_wiki)
expect(page).to have_content('My Third Wiki Content')
end
def validate_content(content)
expect(page).to have_content('Wiki was successfully updated')
expect(page).to have_content(/#{content}/)
end
end
end
end
# frozen_string_literal: true
module QA
context 'Create' do
context 'Wiki' do
describe 'testing wiki content creation inside a project' do
let(:new_wiki_title) { "just_another_wiki_page" }
let(:new_wiki_content) { "this content is changed or added" }
let(:commit_message) { "this is a new addition to the wiki" }
let(:project) { Resource::Project.fabricate_via_api! }
let(:wiki) { Resource::Wiki::ProjectPage.fabricate_via_api! }
before do
Flow::Login.sign_in
end
it 'by adding a home page to the wiki' do
project.visit!
Page::Project::Menu.perform(&:click_wiki)
Page::Project::Wiki::Show.perform(&:click_create_your_first_page)
Page::Project::Wiki::Edit.perform do |edit|
edit.set_title new_wiki_title
edit.set_content new_wiki_content
edit.set_message commit_message
end
Page::Project::Wiki::Edit.perform(&:click_create_page)
Page::Project::Wiki::Show.perform do |wiki|
expect(wiki).to have_title new_wiki_title
expect(wiki).to have_content new_wiki_content
end
end
it 'by adding a second page to the wiki' do
wiki.visit!
Page::Project::Wiki::Show.perform(&:click_new_page)
Page::Project::Wiki::Edit.perform do |edit|
edit.set_title new_wiki_title
edit.set_content new_wiki_content
edit.set_message commit_message
end
Page::Project::Wiki::Edit.perform(&:click_create_page)
Page::Project::Wiki::Show.perform do |wiki|
expect(wiki).to have_title new_wiki_title
expect(wiki).to have_content new_wiki_content
end
end
it 'by adding a home page to the wiki using git push' do
empty_wiki = Resource::Wiki::ProjectPage.new do |empty_wiki|
empty_wiki.project = project
end
Resource::Repository::WikiPush.fabricate! do |push|
push.file_name = "#{new_wiki_title}.md"
push.file_content = new_wiki_content
push.commit_message = commit_message
push.wiki = empty_wiki
push.new_branch = true
end.visit!
Page::Project::Wiki::Show.perform do |wiki|
expect(wiki).to have_title new_wiki_title
expect(wiki).to have_content new_wiki_content
end
end
it 'by adding a second page to the wiki using git push' do
Resource::Repository::WikiPush.fabricate! do |push|
push.file_name = "#{new_wiki_title}.md"
push.file_content = new_wiki_content
push.commit_message = commit_message
push.wiki = wiki
push.new_branch = false
end.visit!
Page::Project::Wiki::Show.perform do |wiki|
expect(wiki).to have_title new_wiki_title
expect(wiki).to have_content new_wiki_content
end
end
end
end
end
end
# frozen_string_literal: true
module QA
context 'Create' do
context 'Wiki' do
describe 'testing wiki content manipulation inside a project' do
let(:new_wiki_title) { "just_another_wiki_page" }
let(:new_wiki_content) { "this content is changed or added" }
let(:commit_message) { "this is a new addition to the wiki" }
let(:wiki) { Resource::Wiki::ProjectPage.fabricate_via_api! }
before do
Flow::Login.sign_in
end
it 'by manipulating content on the page' do
wiki.visit!
Page::Project::Wiki::Show.perform(&:click_edit)
Page::Project::Wiki::Edit.perform do |edit|
edit.set_title new_wiki_title
edit.set_content new_wiki_content
edit.set_message commit_message
end
Page::Project::Wiki::Edit.perform(&:click_save_changes)
Page::Project::Wiki::Show.perform do |wiki|
expect(wiki).to have_title new_wiki_title
expect(wiki).to have_content new_wiki_content
end
end
it 'by manipulating content on the page using git push' do
Resource::Repository::WikiPush.fabricate! do |push|
push.file_content = new_wiki_content
push.commit_message = commit_message
push.wiki = wiki
push.new_branch = false
end.visit!
Page::Project::Wiki::Show.perform do |wiki|
expect(wiki).to have_content new_wiki_content
end
end
end
end
end
end
......@@ -17,23 +17,23 @@ module QA
project.description = 'Geo project for wiki repo test'
end
wiki = Resource::Wiki.fabricate! do |wiki|
wiki = Resource::Wiki::ProjectPage.fabricate_via_api! do |wiki|
wiki.project = project
wiki.title = wiki_title
wiki.content = wiki_content
wiki.message = 'First commit'
end
wiki.visit!
expect(page).to have_content(wiki_content)
Resource::Repository::WikiPush.fabricate! do |push|
push = Resource::Repository::WikiPush.fabricate! do |push|
push.wiki = wiki
push.file_name = 'Home.md'
push.file_content = push_content
push.commit_message = 'Update Home.md'
end
Page::Project::Menu.perform(&:click_wiki)
push.visit!
expect(page).to have_content(push_content)
end
......@@ -57,8 +57,7 @@ module QA
Page::Project::Menu.perform(&:click_wiki)
Page::Project::Wiki::Show.perform do |show|
expect(page).to have_content(wiki_title)
expect(page).to have_content(push_content)
expect(show).to have_content(push_content)
end
end
end
......
......@@ -20,13 +20,13 @@ module QA
project.description = 'Geo test project'
end
wiki = Resource::Wiki.fabricate! do |wiki|
wiki = Resource::Wiki::ProjectPage.fabricate_via_api! do |wiki|
wiki.project = project
wiki.title = 'Geo wiki'
wiki.content = wiki_content
wiki.message = 'First wiki commit'
end
wiki.visit!
expect(wiki).to have_content(wiki_content)
# Perform a git push over HTTP directly to the primary
......@@ -90,7 +90,7 @@ module QA
expect(push.output).to match(/warning: redirecting to #{absolute_path}/)
# Validate git push worked and new content is visible
Page::Project::Menu.perform(&:click_wiki)
push.visit!
Page::Project::Wiki::Show.perform do |show|
show.wait_for_repository_replication_with(push_content_secondary)
......
......@@ -25,17 +25,17 @@ module QA
project.description = 'Geo project for wiki ssh spec'
end
wiki = Resource::Wiki.fabricate! do |wiki|
wiki = Resource::Wiki::ProjectPage.fabricate_via_api! do |wiki|
wiki.project = project
wiki.title = wiki_title
wiki.content = wiki_content
wiki.message = 'First commit'
end
wiki.visit!
validate_content(wiki_content)
# Perform a git push over SSH directly to the primary
Resource::Repository::WikiPush.fabricate! do |push|
pushed_wiki = Resource::Repository::WikiPush.fabricate! do |push|
push.ssh_key = key
push.wiki = wiki
push.file_name = 'Home.md'
......@@ -43,7 +43,7 @@ module QA
push.commit_message = 'Update Home.md'
end
Page::Project::Menu.perform(&:click_wiki)
pushed_wiki.visit!
validate_content(push_content)
end
......@@ -85,7 +85,7 @@ module QA
def validate_content(content)
Page::Project::Wiki::Show.perform do |show|
expect(show.wiki_text).to have_content(content)
expect(show).to have_content(content)
end
end
end
......
......@@ -24,13 +24,13 @@ module QA
project.description = 'Geo project for wiki ssh spec'
end
wiki = Resource::Wiki.fabricate! do |wiki|
wiki = Resource::Wiki::ProjectPage.fabricate_via_api! do |wiki|
wiki.project = project
wiki.title = wiki_title
wiki.content = wiki_content
wiki.message = 'First commit'
end
wiki.visit!
validate_content(wiki_content)
end
end
......@@ -85,11 +85,10 @@ module QA
# Remove ssh:// from the URI to ensure we can match accurately
# as ssh:// can appear depending on how GitLab is configured.
ssh_uri = wiki.repository_ssh_location.git_uri.to_s.gsub(%r{ssh://}, '')
expect(push.output).to match(%r{This request to a Geo secondary node will be forwarded to the.*Geo primary node:.*#{ssh_uri}}m)
# Validate git push worked and new content is visible
Page::Project::Menu.perform(&:click_wiki)
push.visit!
Page::Project::Wiki::Show.perform do |show|
show.wait_for_repository_replication_with(push_content)
......@@ -102,7 +101,7 @@ module QA
def validate_content(content)
Page::Project::Wiki::Show.perform do |show|
expect(show.wiki_text).to have_content(content)
expect(show).to have_content(content)
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