Skip to content

Commit

Permalink
- Further expanding playwright coverage over the KB article editing (…
Browse files Browse the repository at this point in the history
…over both Edit Article & Edit Article Metadata areas). (#5964)

- Reducing the complexity of some KB article steps.
  • Loading branch information
emilghittasv authored Apr 17, 2024
1 parent 46481d6 commit 1365233
Show file tree
Hide file tree
Showing 18 changed files with 1,093 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
AddKbMediaFlow
from playwright_tests.messages.explore_help_articles.kb_article_page_messages import (
KBArticlePageMessages)
from playwright_tests.pages.explore_help_articles.articles.kb_article_page import KBArticlePage
from playwright_tests.pages.explore_help_articles.articles.kb_article_review_revision_page import \
KBArticleReviewRevisionPage
from playwright_tests.pages.explore_help_articles.articles.kb_article_show_history_page import \
KBArticleShowHistoryPage
from playwright_tests.pages.explore_help_articles.articles.kb_edit_article_page import \
EditKBArticlePage
from playwright_tests.pages.explore_help_articles.articles.submit_kb_article_page import (
SubmitKBArticlePage)


class AddKbArticleFlow(TestUtilities, SubmitKBArticlePage, AddKbMediaFlow):
class AddKbArticleFlow(TestUtilities, SubmitKBArticlePage, AddKbMediaFlow, KBArticlePage,
KBArticleShowHistoryPage, KBArticleReviewRevisionPage, EditKBArticlePage):

def __init__(self, page: Page):
super().__init__(page)
Expand All @@ -29,7 +37,8 @@ def submit_simple_kb_article(self,
is_template=False,
expiry_date=None,
restricted_to_groups: list[str] = None,
single_group=""
single_group="",
approve_first_revision=False
) -> dict[str, Any]:
self._page.goto(KBArticlePageMessages.CREATE_NEW_KB_ARTICLE_STAGE_URL)

Expand Down Expand Up @@ -62,30 +71,38 @@ def submit_simple_kb_article(self,

if article_category is None:
if is_template:
article_category = kb_article_test_data["kb_template_category"]
super()._select_category_option_by_text(
kb_article_test_data["kb_template_category"]
article_category
)
else:
super()._select_category_option_by_text(kb_article_test_data["category_options"])
article_category = kb_article_test_data["category_options"]
super()._select_category_option_by_text(article_category)
else:
super()._select_category_option_by_text(article_category)

if not allow_translations:
super()._check_allow_translations_checkbox()

relevancy = kb_article_test_data["relevant_to_option"]
if selected_relevancy is True:
super()._click_on_a_relevant_to_option_checkbox(
kb_article_test_data["relevant_to_option"]
relevancy
)

article_topic = [
kb_article_test_data["selected_parent_topic"],
kb_article_test_data["selected_child_topic"]
]

# Adding Article topic
if selected_topics is True:
super()._click_on_a_particular_parent_topic(
kb_article_test_data["selected_parent_topic"]
article_topic[0]
)
super()._click_on_a_particular_child_topic_checkbox(
kb_article_test_data["selected_parent_topic"],
kb_article_test_data["selected_child_topic"],
article_topic[0],
article_topic[1],
)

# Interacting with Allow Discussion checkbox
Expand Down Expand Up @@ -127,6 +144,7 @@ def submit_simple_kb_article(self,
'document.getElementById("id_slug").value'
)

first_revision_id = None
if submit_article is True:
# If title and slug are empty we are not reaching the description field.
if ((article_title != '') and (article_slug != '') and (
Expand All @@ -136,19 +154,122 @@ def submit_simple_kb_article(self,
kb_article_test_data["changes_description"]
)
super()._click_on_changes_submit_button()
try:
first_revision_id = super()._get_last_revision_id()
except IndexError:
print("Chances are that the form was not submitted successfully")
else:
super()._click_on_submit_for_review_button()

article_url = super()._get_article_page_url()

if approve_first_revision:
super()._click_on_show_history_option()
self.approve_kb_revision(first_revision_id)

return {"article_title": kb_article_title,
"article_content": kb_article_test_data["article_content"],
"article_content_html": kb_article_test_data['article_content_html_rendered'],
"article_slug": slug,
"article_child_topic": kb_article_test_data["selected_child_topic"],
"article_category": article_category,
"article_relevancy": relevancy,
"article_topic": article_topic,
"article_review_description": kb_article_test_data["changes_description"],
"keyword": kb_article_test_data["keywords"],
"search_results_summary": kb_article_test_data["search_result_summary"],
"expiry_date": kb_article_test_data["expiry_date"],
"article_url": article_url
"article_url": article_url,
"first_revision_id": first_revision_id
}

def approve_kb_revision(self, revision_id: str,
revision_needs_change=False,
ready_for_l10n=False):
if (KBArticlePageMessages.KB_ARTICLE_HISTORY_URL_ENDPOINT not in
super()._get_current_page_url()):
super()._click_on_show_history_option()

super()._click_on_review_revision(
revision_id
)
super()._click_on_approve_revision_button()

if revision_needs_change:
if not super()._is_needs_change_checkbox_checked():
super()._click_on_needs_change_checkbox()
super()._add_text_to_needs_change_comment(
super().kb_revision_test_data['needs_change_message']
)

if ready_for_l10n:
super()._check_ready_for_localization_checkbox()

super()._click_accept_revision_accept_button()

def submit_new_kb_revision(self,
keywords=None,
search_result_summary=None,
content=None,
expiry_date=None,
changes_description=None,
is_admin=False,
approve_revision=False
) -> dict[str, Any]:

super()._click_on_edit_article_option()

# Only admin accounts can update article keywords.
if is_admin:
# Keywords step.
if keywords is None:
super()._fill_edit_article_keywords_field(
self.kb_article_test_data['updated_keywords']
)
else:
super()._fill_edit_article_keywords_field(keywords)

# Search Result Summary step.
if search_result_summary is None:
super()._fill_edit_article_search_result_summary_field(
self.kb_article_test_data['updated_search_result_summary']
)
else:
super()._fill_edit_article_search_result_summary_field(search_result_summary)

# Content step.
if content is None:
super()._fill_edit_article_content_field(
self.kb_article_test_data['updated_article_content']
)
else:
super()._fill_edit_article_content_field(content)

# Expiry date step.
if expiry_date is None:
super()._fill_edit_article_expiry_date(
self.kb_article_test_data['updated_expiry_date']
)
else:
super()._fill_edit_article_expiry_date(expiry_date)

# Submitting for preview steps
super()._click_submit_for_review_button()

if changes_description is None:
super()._fill_edit_article_changes_panel_comment(
self.kb_article_test_data['changes_description']
)
else:
super()._fill_edit_article_changes_panel_comment(changes_description)

super()._click_edit_article_changes_panel_submit_button()

revision_id = super()._get_last_revision_id()

if approve_revision:
self.approve_kb_revision(revision_id)

return {"revision_id": revision_id,
"changes_description": self.kb_article_test_data['changes_description']
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
from playwright_tests.core.testutilities import TestUtilities
from playwright.sync_api import Page

from playwright_tests.messages.explore_help_articles.kb_article_revision_page_messages import \
KBArticleRevision
from playwright_tests.pages.explore_help_articles.articles.kb_article_page import KBArticlePage
from playwright_tests.pages.explore_help_articles.articles.kb_edit_article_meta import (
KBArticleEditMetadata)
from playwright_tests.pages.explore_help_articles.articles.submit_kb_article_page import \
SubmitKBArticlePage


class EditArticleMetaFlow(TestUtilities, KBArticleEditMetadata):
class EditArticleMetaFlow(TestUtilities, KBArticleEditMetadata, SubmitKBArticlePage,
KBArticlePage):

def __init__(self, page: Page):
super().__init__(page)

def edit_article_metadata(self, title=None,
slug=None,
category=None,
relevancy=None,
topics=None,
obsolete=False,
discussions=True,
needs_change=False,
needs_change_comment=False,
restricted_to_groups: list[str] = None,
single_group=""):

if KBArticleRevision.KB_EDIT_METADATA not in super()._get_current_page_url():
super()._click_on_edit_article_metadata()

if restricted_to_groups is not None:
for group in restricted_to_groups:
super()._add_and_select_restrict_visibility_group_metadata(group)
Expand All @@ -25,6 +40,34 @@ def edit_article_metadata(self, title=None,
if title is not None:
super()._add_text_to_title_field(title)

if slug is not None:
super()._add_text_to_slug_field(slug)

if category is not None:
super()._select_category(category)

if relevancy is not None:
super()._check_a_particular_relevancy_option(relevancy)

if topics is not None:
super()._click_on_a_particular_parent_topic(
topics[0]
)
super()._click_on_a_particular_child_topic_checkbox(
topics[0],
topics[1],
)

if obsolete:
super()._click_on_obsolete_checkbox()

if discussions:
if not super()._is_allow_discussion_checkbox_checked():
super()._click_on_allow_discussion_on_article_checkbox()
else:
if super()._is_allow_discussion_checkbox_checked():
super()._click_on_allow_discussion_on_article_checkbox()

# If it needs change we are going to ensure that the needs change checkbox is checked.
if needs_change:
if not super()._is_needs_change_checkbox():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ class KBArticlePageMessages:
KB_ARTICLE_RELEVANCY_ERROR = "Please select at least one product."
KB_ARTICLE_TOPIC_ERROR = "Please select at least one topic."
KB_ARTICLE_RESTRICTED_BANNER = "This document is restricted."

def get_template_error(self, article_title) -> str:
return (f'Documents in the Template category must have titles that start with '
f'"Template:". (Current title is "{article_title}")')
Loading

0 comments on commit 1365233

Please sign in to comment.