From 675a54a49bd9f0d4e7f08fc8243b9ee8a071569b Mon Sep 17 00:00:00 2001
From: Shejanul Ayan Islam <100955969+ayan1229@users.noreply.github.com>
Date: Mon, 16 Oct 2023 11:08:55 -0400
Subject: [PATCH] Sfr 1757/automate feedback button (#448)

* SFR-1757/feedback-button

* small change on changelog.md
---
 CHANGELOG.md                                 |  1 +
 playwright/features/advSearch.feature        |  2 +-
 playwright/features/homePageElements.feature |  6 +++++-
 playwright/features/pub_yearFilter.feature   | 11 ++++++++++-
 playwright/support/mappings.ts               |  3 +++
 playwright/tests/assertions.spec.ts          | 10 ++++++++++
 6 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index fb67bc34..f23454c4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@
 - Replace Template components with TemplateAppContainer and DrbBreakout to reduce repeat components
 - Upgrade to NYPL Design System 1.7.3
 - Replace fireEvent with userEvent
+- Feedback button test PW
 
 ## [0.17.4]
 
diff --git a/playwright/features/advSearch.feature b/playwright/features/advSearch.feature
index f4aa9266..b7ab9a08 100644
--- a/playwright/features/advSearch.feature
+++ b/playwright/features/advSearch.feature
@@ -49,4 +49,4 @@ Feature: Advanced Search
         And the "governance footer link" should be displayed
         And the "rules and regulations footer link" should be displayed
         And the "about footer link" should be displayed
-        And the "language footer link" should be displayed
\ No newline at end of file
+        And the "language footer link" should be displayed
diff --git a/playwright/features/homePageElements.feature b/playwright/features/homePageElements.feature
index 4ef37866..a71bd839 100644
--- a/playwright/features/homePageElements.feature
+++ b/playwright/features/homePageElements.feature
@@ -15,4 +15,8 @@ Feature: Home Page Elements
         And the "collections heading" should be displayed
         And the "first collection card link" should be displayed
         And the "footer" should be displayed
-        And the "feedback button" should be displayed
\ No newline at end of file
+        And the "feedback button" should be displayed
+
+    Scenario: As a user I verify feedback button is displayed on homepage
+        Given I go to the "home" page
+        Then the "feedback and help button" should be displayed
\ No newline at end of file
diff --git a/playwright/features/pub_yearFilter.feature b/playwright/features/pub_yearFilter.feature
index f0e1d4fc..d6f897ab 100644
--- a/playwright/features/pub_yearFilter.feature
+++ b/playwright/features/pub_yearFilter.feature
@@ -7,4 +7,13 @@ Feature: Publication Year Filter
         And I fill in the "publication year from filter" with "1900"
         And I fill in the "publication year to filter" with "1900"
         And I click the "publication year apply button"
-        Then the "first search result edition" should be displayed
\ No newline at end of file
+        Then the "first search result edition" should be displayed
+
+    Scenario: As a user I filter by publication years and verify the search results
+        Given I go to the "home" page
+        When I fill in the "homepage search box" with "Jane Austen"
+        And I click the "search button"
+        And I fill in the "publication year from filter" with "1800"
+        And I fill in the "publication year to filter" with "1835"
+        And I click the "publication year apply button"
+        Then only published between year "1800" and "1835" should be displayed
\ No newline at end of file
diff --git a/playwright/support/mappings.ts b/playwright/support/mappings.ts
index 62d2457a..ba8ca52a 100644
--- a/playwright/support/mappings.ts
+++ b/playwright/support/mappings.ts
@@ -25,6 +25,7 @@ export const elements = {
   "advanced search link": "[href='/advanced-search']",
   "advanced search button": "#submit-button",
   "search button": "#searchbar-button-search-bar",
+  "feedback and help button": "//button[@id='open']",
   "requestable checkbox": "text=Requestable",
   "login button": "[value='Submit']",
   "first login for options button": "text=Log in for options >> nth=0",
@@ -210,6 +211,8 @@ export const inputs = {
   swimming: "swimming",
   "New York": "New York",
   "1900": "1900",
+  "1800": "1800",
+  "1835": "1835",
   petroleum: "petroleum",
   "Robot Soccer": "Robot Soccer",
   "Jane Austen": "Jane Austen",
diff --git a/playwright/tests/assertions.spec.ts b/playwright/tests/assertions.spec.ts
index 16918547..8da71945 100644
--- a/playwright/tests/assertions.spec.ts
+++ b/playwright/tests/assertions.spec.ts
@@ -20,3 +20,13 @@ Then(
     return expect(this.page.locator(element).isChecked()).toBeTruthy();
   }
 );
+
+Then(
+  /^Then only editions published between year "([^"]*)" and ""([^"]*)" should be displayed$/,
+  async function (this: CustomWorld, elementKey: keyof typeof elements) {
+    const element = elements[elementKey];
+    return expect(this.page.locator(element)).toBeVisible({
+      timeout: 50000,
+    });
+  }
+);