From 2bfbd0cd2091192bd403c192672b7ec84cb3611f Mon Sep 17 00:00:00 2001
From: Moss <htmoss2@fa20-cs427-075.cs.illinois.edu>
Date: Tue, 1 Dec 2020 22:55:21 -0600
Subject: [PATCH] [testing] added more selenium tests in
 ViewTransactionLogsTest.java

---
 .../selenium/ViewTransactionLogsTest.java     | 162 ++++++++++++++++++
 1 file changed, 162 insertions(+)

diff --git a/iTrust/test/edu/ncsu/csc/itrust/selenium/ViewTransactionLogsTest.java b/iTrust/test/edu/ncsu/csc/itrust/selenium/ViewTransactionLogsTest.java
index 6ead2c4..d1f7f74 100644
--- a/iTrust/test/edu/ncsu/csc/itrust/selenium/ViewTransactionLogsTest.java
+++ b/iTrust/test/edu/ncsu/csc/itrust/selenium/ViewTransactionLogsTest.java
@@ -3,6 +3,7 @@ package edu.ncsu.csc.itrust.selenium;
 import java.util.concurrent.TimeUnit;
 import org.junit.*;
 import org.openqa.selenium.*;
+import org.openqa.selenium.support.ui.Select;
 import org.openqa.selenium.htmlunit.HtmlUnitDriver;
 
 public class ViewTransactionLogsTest extends iTrustSeleniumTest {
@@ -36,6 +37,167 @@ public class ViewTransactionLogsTest extends iTrustSeleniumTest {
         assertEquals("iTrust - View Transaction Logs", driver.getTitle());
     }
 
+    @Test
+    public void testAdminRegular() throws Exception {
+        driver = (HtmlUnitDriver) login("9000000001", "pw");
+        driver.setJavascriptEnabled(true);
+        assertEquals("iTrust - Admin Home", driver.getTitle());
+        driver.findElement(By.linkText("View Transaction Logs")).click();
+        assertEquals("iTrust - View Transaction Logs", driver.getTitle());
+
+        //fill form
+        driver.findElement(By.name("startDate")).clear();
+        driver.findElement(By.name("startDate")).sendKeys("05/10/2009");
+        driver.findElement(By.name("endDate")).clear();
+        driver.findElement(By.name("endDate")).sendKeys("10/10/2021");
+		Select select;
+		select = new Select (driver.findElement(By.name("mainRole")));
+		select.selectByValue("All");
+		select = new Select (driver.findElement(By.name("secondRole")));
+		select.selectByValue("All");
+		select = new Select (driver.findElement(By.name("transactionType")));
+		select.selectByValue("All");
+
+        //click button
+        driver.findElement(By.id("viewReport")).click();
+
+        //check to see if page shows info past 2009
+        assertTrue(driver.getPageSource().contains("EMERGENCY_REPORT_VIEW"));
+        assertTrue(driver.getPageSource().contains("Patient added to monitoring list"));
+        assertTrue(driver.getPageSource().contains("2011-06-24 06:54:59.0"));
+
+        //check to see pages does not show info before 2009
+        assertFalse(driver.getPageSource().contains("Identified risk factors of chronic diseases"));
+        assertFalse(driver.getPageSource().contains("2008-06-15 13:15:00.0"));
+    }
+
+    @Test
+    public void testTesterRegular() throws Exception {
+        driver = (HtmlUnitDriver) login("9999999999", "pw");
+        driver.setJavascriptEnabled(true);
+        assertEquals("iTrust - Tester Home", driver.getTitle());
+        driver.findElement(By.linkText("View Transaction Logs")).click();
+        assertEquals("iTrust - View Transaction Logs", driver.getTitle());
+
+        //fill form
+        driver.findElement(By.name("startDate")).clear();
+        driver.findElement(By.name("startDate")).sendKeys("05/10/2009");
+        driver.findElement(By.name("endDate")).clear();
+        driver.findElement(By.name("endDate")).sendKeys("10/10/2021");
+		Select select;
+		select = new Select (driver.findElement(By.name("mainRole")));
+		select.selectByValue("All");
+		select = new Select (driver.findElement(By.name("secondRole")));
+		select.selectByValue("All");
+		select = new Select (driver.findElement(By.name("transactionType")));
+		select.selectByValue("All");
+
+        //click button
+        driver.findElement(By.id("viewReport")).click();
+
+        //check to see if page shows info past 2009
+        assertTrue(driver.getPageSource().contains("EMERGENCY_REPORT_VIEW"));
+        assertTrue(driver.getPageSource().contains("Patient added to monitoring list"));
+        assertTrue(driver.getPageSource().contains("2011-06-24 06:54:59.0"));
+
+        //check to see pages does not show info before 2009
+        assertFalse(driver.getPageSource().contains("Identified risk factors of chronic diseases"));
+        assertFalse(driver.getPageSource().contains("2008-06-15 13:15:00.0"));
+    }
+
+    @Test
+    public void testAdminSelectMainRole() throws Exception {
+        driver = (HtmlUnitDriver) login("9000000001", "pw");
+        driver.setJavascriptEnabled(true);
+        assertEquals("iTrust - Admin Home", driver.getTitle());
+        driver.findElement(By.linkText("View Transaction Logs")).click();
+        assertEquals("iTrust - View Transaction Logs", driver.getTitle());
+
+        //fill form
+        driver.findElement(By.name("startDate")).clear();
+        driver.findElement(By.name("startDate")).sendKeys("05/10/2000");
+        driver.findElement(By.name("endDate")).clear();
+        driver.findElement(By.name("endDate")).sendKeys("10/10/2021");
+		Select select;
+		select = new Select (driver.findElement(By.name("mainRole")));
+		select.selectByValue("hcp");
+		select = new Select (driver.findElement(By.name("secondRole")));
+		select.selectByValue("All");
+		select = new Select (driver.findElement(By.name("transactionType")));
+		select.selectByValue("All");
+
+        //click button
+        driver.findElement(By.id("viewReport")).click();
+
+        //check to see if first five rows are only hcp
+        assertTrue(driver.findElements(By.id("resultRow")).get(0).findElement(By.id("mainTD")).getText().contains("hcp"));
+        assertTrue(driver.findElements(By.id("resultRow")).get(1).findElement(By.id("mainTD")).getText().contains("hcp"));
+        assertTrue(driver.findElements(By.id("resultRow")).get(2).findElement(By.id("mainTD")).getText().contains("hcp"));
+        assertTrue(driver.findElements(By.id("resultRow")).get(3).findElement(By.id("mainTD")).getText().contains("hcp"));
+        assertTrue(driver.findElements(By.id("resultRow")).get(4).findElement(By.id("mainTD")).getText().contains("hcp"));
+    }
+
+    @Test
+    public void testAdminSelectSecondaryRole() throws Exception {
+        driver = (HtmlUnitDriver) login("9000000001", "pw");
+        driver.setJavascriptEnabled(true);
+        assertEquals("iTrust - Admin Home", driver.getTitle());
+        driver.findElement(By.linkText("View Transaction Logs")).click();
+        assertEquals("iTrust - View Transaction Logs", driver.getTitle());
+
+        //fill form
+        driver.findElement(By.name("startDate")).clear();
+        driver.findElement(By.name("startDate")).sendKeys("05/10/2000");
+        driver.findElement(By.name("endDate")).clear();
+        driver.findElement(By.name("endDate")).sendKeys("10/10/2021");
+		Select select;
+		select = new Select (driver.findElement(By.name("mainRole")));
+		select.selectByValue("All");
+		select = new Select (driver.findElement(By.name("secondRole")));
+		select.selectByValue("patient");
+		select = new Select (driver.findElement(By.name("transactionType")));
+		select.selectByValue("All");
+
+        //click button
+        driver.findElement(By.id("viewReport")).click();
+
+        //check to see if first five rows are only patient
+        assertTrue(driver.findElements(By.id("resultRow")).get(0).findElement(By.id("secondTD")).getText().contains("patient"));
+        assertTrue(driver.findElements(By.id("resultRow")).get(1).findElement(By.id("secondTD")).getText().contains("patient"));
+        assertTrue(driver.findElements(By.id("resultRow")).get(2).findElement(By.id("secondTD")).getText().contains("patient"));
+        assertTrue(driver.findElements(By.id("resultRow")).get(3).findElement(By.id("secondTD")).getText().contains("patient"));
+        assertTrue(driver.findElements(By.id("resultRow")).get(4).findElement(By.id("secondTD")).getText().contains("patient"));
+    }
+
+    @Test
+    public void testAdminSelectType() throws Exception {
+        driver = (HtmlUnitDriver) login("9000000001", "pw");
+        driver.setJavascriptEnabled(true);
+        assertEquals("iTrust - Admin Home", driver.getTitle());
+        driver.findElement(By.linkText("View Transaction Logs")).click();
+        assertEquals("iTrust - View Transaction Logs", driver.getTitle());
+
+        //fill form
+        driver.findElement(By.name("startDate")).clear();
+        driver.findElement(By.name("startDate")).sendKeys("05/10/2000");
+        driver.findElement(By.name("endDate")).clear();
+        driver.findElement(By.name("endDate")).sendKeys("10/10/2021");
+		Select select;
+		select = new Select (driver.findElement(By.name("mainRole")));
+		select.selectByValue("All");
+		select = new Select (driver.findElement(By.name("secondRole")));
+		select.selectByValue("All");
+		select = new Select (driver.findElement(By.name("transactionType")));
+		select.selectByValue("EMERGENCY_REPORT_VIEW");
+
+        //click button
+        driver.findElement(By.id("viewReport")).click();
+
+        //check to see if first two rows are only EMERGENCY_REPORT_VIEW
+        assertTrue(driver.findElements(By.id("resultRow")).get(0).findElement(By.id("typeTD")).getText().contains("EMERGENCY_REPORT_VIEW"));
+        assertTrue(driver.findElements(By.id("resultRow")).get(1).findElement(By.id("typeTD")).getText().contains("EMERGENCY_REPORT_VIEW"));
+    }
+
     @After
     public void tearDown() throws Exception {
         driver.quit();
-- 
GitLab