From 749dbc33e5280735badb6fce3d311fda0d3eab6d Mon Sep 17 00:00:00 2001
From: Brady-Malott <brady.malott@gmail.com>
Date: Mon, 13 Mar 2023 15:27:34 -0400
Subject: [PATCH] Started creating selenium tests for archiving posts

---
 tests/features/archive-post.feature        | 30 +++++++++++++
 tests/features/steps/archive-post-steps.py | 52 ++++++++++++++++++++++
 2 files changed, 82 insertions(+)
 create mode 100644 tests/features/archive-post.feature
 create mode 100644 tests/features/steps/archive-post-steps.py

diff --git a/tests/features/archive-post.feature b/tests/features/archive-post.feature
new file mode 100644
index 0000000..bd01e78
--- /dev/null
+++ b/tests/features/archive-post.feature
@@ -0,0 +1,30 @@
+Feature: Archive Posts
+  As a user,
+  I would like to archive posts
+  so i can view the post even if the original post is deleted
+
+  Scenario: Successfully archive a post
+    Given that I am on a explore page
+    When I click on the "Archive" link on a post
+    Then the link should change to "Remove from Archive"
+    And a banner shows that the post has been archived
+
+
+  Scenario: Successfully remove an archived post from the explore page
+    Given that I am on an review page
+    When I click on the "Remove from Archive" link
+    Then the link should change to "Archive"
+    And a banner shows that the post has been removed from my archives
+
+
+  Scenario: Successfully remove an archived post from the archived page
+    Given that I am on an archived page
+    When I click on the "Remove from Archive" link
+    Then the archived post should disappear
+    And a banner shows that the post has been removed from my archives
+
+
+  Scenario: View archived posts
+    Given that I am on my user profile page
+    When I click on the "View Archived Posts" link
+    Then I should be directed to a page displaying all my archived posts
diff --git a/tests/features/steps/archive-post-steps.py b/tests/features/steps/archive-post-steps.py
new file mode 100644
index 0000000..737801f
--- /dev/null
+++ b/tests/features/steps/archive-post-steps.py
@@ -0,0 +1,52 @@
+from behave import given, when, then
+from webdriver_manager.chrome import ChromeDriverManager
+from selenium import webdriver
+from selenium.webdriver.chrome.service import Service as ChromeService
+from selenium.webdriver.common.by import By
+from selenium.webdriver.chrome.options import Options
+
+
+@given("I am on the todo list page")
+def open_browser(context):
+
+    # Implementation of headless from https://stackoverflow.com/questions/46920243/how-to-configure-chromedriver-to-initiate-chrome-browser-in-headless-mode-throug
+    # Stackoverflow post desribes what is goin on with options to enable headless chrome
+
+    options = Options()
+    options.add_argument("--headless") # Runs Chrome in headless mode.
+    options.add_argument('--no-sandbox') # Bypass OS security model
+    options.add_argument('start-maximized') #to maximize viewport this should still be headless
+    options.add_argument('disable-infobars')
+    options.add_argument("--disable-extensions")
+    context.driver = webdriver.Chrome(options=options, service=ChromeService(ChromeDriverManager().install()))
+    context.driver.implicitly_wait(5)
+    context.driver.get("http://127.0.0.1:5000/")
+
+
+@when("I enter '{title}' in the title field")
+def step_impl(context, title):
+    title_field = context.driver.find_element(By.NAME, "title")
+    title_field.send_keys(title)
+
+
+@when("I enter '{estimate}' in the estimate field")
+def step_impl(context, estimate):
+    estimate_field = context.driver.find_element(By.NAME, "estimate")
+    estimate_field.send_keys(estimate)
+
+
+@when("I click the 'Add' button")
+def step_impl(context):
+    add_button = context.driver.find_element(By.XPATH, "//button[contains(text(),'Add')]")
+    add_button.click()
+    context.driver.implicitly_wait(5)
+
+
+@then("the task '{title}' with estimate '{estimate}' should be added to the todo list")
+def step_impl(context, title, estimate):
+    dump_text = context.driver.page_source
+    print(dump_text)
+    assert ("Buy groceries | 2" in dump_text) is True
+
+
+