commit 53b8629cf2c16dc9e9a5c7158f3ec6267555055b
Author: schenkj <schenkj@students.zcu.cz>
Date:   Tue May 3 08:34:36 2022 +0200

    Annotator redirecting
    
    testing if annotator doesnt see page content if tried to get on url they shouldnt

diff --git a/Backend/FrontendTesting/LinksTesting.cs b/Backend/FrontendTesting/LinksTesting.cs
new file mode 100644
index 0000000..05505d9
--- /dev/null
+++ b/Backend/FrontendTesting/LinksTesting.cs
@@ -0,0 +1,193 @@
+﻿using System.Linq;
+using System.Text;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using OpenQA.Selenium;
+using OpenQA.Selenium.Chrome;
+using OpenQA.Selenium.Firefox;
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Threading;
+
+
+namespace FrontendTesting
+{
+    [TestClass]
+    public class LinksTesting
+    {
+        //defining variables needed for testing
+        public string url = "http://localhost:3000/login";
+        public By usernameField = By.Id("login_username");
+        public By passwordField = By.Id("login_password");
+        public By loginButton = By.XPath("/html/body/div[1]/div/div/div[2]/main/form/div[3]/div/div/div/button");
+        public string[] usernames = { "admin", "annotator1"};
+        public string[] passwords = { "admin", "password"};
+        public By shouldBeEmpty = By.Id("__next");
+        //urls 0-4 are for admin only, url 5 is for annotator only
+        public string[] urls = { "http://localhost:3000/documents/admin", "http://localhost:3000/users", "http://localhost:3000/tags", "http://localhost:3000/classes", "http://localhost:3000/export", "http://localhost:3000/documents/annotator" };
+
+
+        /**
+         Names of tests should be self-explanatory
+        tests are separated, becouse there were problems with multiple tests runs in one method
+        tests contain thread.sleep becouse of waiting on components to load (if I find better and reasonable solution, I will change it)
+         */
+
+
+        //dummy method for constructing tests
+        public void Login_User(string username, string password, bool driverChrome)
+        {
+            IWebDriver driver;
+            if(driverChrome) driver= Drivers.cDriver;
+            else driver = Drivers.fDriver;
+            driver.Navigate().GoToUrl(url);
+            Thread.Sleep(1000);
+            driver.FindElement(usernameField).SendKeys(username);        //enter username
+            Thread.Sleep(500);
+            driver.FindElement(passwordField).SendKeys(password);          //enter password
+            Thread.Sleep(500);
+            driver.FindElement(loginButton).Click();                      //click on login
+            Thread.Sleep(1000);
+            return;
+        }
+
+
+        //                                      methods for annotator trying to get on admin pages
+        [TestMethod]
+        public void Annotator_AdminDocuments_Firefox()
+        {
+            var driver = new FirefoxDriver();
+            Login_User(usernames[1], passwords[1], false);                      //should be on /documents/annotator
+            driver.Navigate().GoToUrl(urls[0]);                                 //try to go on /documents/admin
+            Thread.Sleep(2000);
+            var div = driver.FindElement(shouldBeEmpty);                            //get element expected to be empty
+            Thread.Sleep(3000);
+            Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
+            driver.Close();
+            driver.Quit();
+        }
+        [TestMethod]
+        public void Annotator_AdminDocuments_Chrome()
+        {
+            var driver = new ChromeDriver();
+            Login_User(usernames[1], passwords[1], false);                      //should be on /documents/annotator
+            driver.Navigate().GoToUrl(urls[0]);                                 //try to go on /documents/admin
+            Thread.Sleep(2000);
+            var div = driver.FindElement(shouldBeEmpty);                            //get element expected to be empty
+            Thread.Sleep(3000);
+            Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
+            driver.Close();
+            driver.Quit();
+        }
+
+        [TestMethod]
+        public void Annotator_Users_Firefox()
+        {
+            var driver = new FirefoxDriver();
+            Login_User(usernames[1], passwords[1], false);                      //should be on /documents/annotator
+            driver.Navigate().GoToUrl(urls[1]);                                 //try to go on /documents/admin
+            Thread.Sleep(2000);
+            var div = driver.FindElement(shouldBeEmpty);                            //get element expected to be empty
+            Thread.Sleep(3000);
+            Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
+            driver.Close();
+            driver.Quit();
+        }
+        [TestMethod]
+        public void Annotator_Users_Chrome()
+        {
+            var driver = new ChromeDriver();
+            Login_User(usernames[1], passwords[1], false);                      //should be on /documents/annotator
+            driver.Navigate().GoToUrl(urls[1]);                                 //try to go on /documents/admin
+            Thread.Sleep(2000);
+            var div = driver.FindElement(shouldBeEmpty);                            //get element expected to be empty
+            Thread.Sleep(3000);
+            Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
+            driver.Close();
+            driver.Quit();
+        }
+
+        [TestMethod]
+        public void Annotator_Tags_Firefox()
+        {
+            var driver = new FirefoxDriver();
+            Login_User(usernames[1], passwords[1], false);                      //should be on /documents/annotator
+            driver.Navigate().GoToUrl(urls[2]);                                 //try to go on /documents/admin
+            Thread.Sleep(2000);
+            var div = driver.FindElement(shouldBeEmpty);                            //get element expected to be empty
+            Thread.Sleep(3000);
+            Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
+            driver.Close();
+            driver.Quit();
+        }
+        [TestMethod]
+        public void Annotator_Tags_Chrome()
+        {
+            var driver = new ChromeDriver();
+            Login_User(usernames[1], passwords[1], false);                      //should be on /documents/annotator
+            driver.Navigate().GoToUrl(urls[2]);                                 //try to go on /documents/admin
+            Thread.Sleep(2000);
+            var div = driver.FindElement(shouldBeEmpty);                            //get element expected to be empty
+            Thread.Sleep(3000);
+            Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
+            driver.Close();
+            driver.Quit();
+        }
+
+        [TestMethod]
+        public void Annotator_Classes_Firefox()
+        {
+            var driver = new FirefoxDriver();
+            Login_User(usernames[1], passwords[1], false);                      //should be on /documents/annotator
+            driver.Navigate().GoToUrl(urls[3]);                                 //try to go on /documents/admin
+            Thread.Sleep(2000);
+            var div = driver.FindElement(shouldBeEmpty);                            //get element expected to be empty
+            Thread.Sleep(3000);
+            Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
+            driver.Close();
+            driver.Quit();
+        }
+        [TestMethod]
+        public void Annotator_Classes_Chrome()
+        {
+            var driver = new ChromeDriver();
+            Login_User(usernames[1], passwords[1], false);                      //should be on /documents/annotator
+            driver.Navigate().GoToUrl(urls[3]);                                 //try to go on /documents/admin
+            Thread.Sleep(2000);
+            var div = driver.FindElement(shouldBeEmpty);                            //get element expected to be empty
+            Thread.Sleep(3000);
+            Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
+            driver.Close();
+            driver.Quit();
+        }
+
+        [TestMethod]
+        public void Annotator_Export_Firefox()
+        {
+            var driver = new FirefoxDriver();
+            Login_User(usernames[1], passwords[1], false);                      //should be on /documents/annotator
+            driver.Navigate().GoToUrl(urls[4]);                                 //try to go on /documents/admin
+            Thread.Sleep(2000);
+            var div = driver.FindElement(shouldBeEmpty);                            //get element expected to be empty
+            Thread.Sleep(3000);
+            Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
+            driver.Close();
+            driver.Quit();
+        }
+        [TestMethod]
+        public void Annotator_Export_Chrome()
+        {
+            var driver = new ChromeDriver();
+            Login_User(usernames[1], passwords[1], false);                      //should be on /documents/annotator
+            driver.Navigate().GoToUrl(urls[4]);                                 //try to go on /documents/admin
+            Thread.Sleep(2000);
+            var div = driver.FindElement(shouldBeEmpty);                            //get element expected to be empty
+            Thread.Sleep(3000);
+            Assert.AreEqual(div.Size.Height * div.Size.Width, 0, "Size of div is not 0. This user shouldnt see anything, but there is something shown");
+            driver.Close();
+            driver.Quit();
+        }
+
+    }
+}
\ No newline at end of file
diff --git a/Backend/FrontendTesting/LoginTesting.cs b/Backend/FrontendTesting/LoginTesting.cs
index 3bcd23b..cbf89a6 100644
--- a/Backend/FrontendTesting/LoginTesting.cs
+++ b/Backend/FrontendTesting/LoginTesting.cs
@@ -59,7 +59,7 @@ namespace FrontendTesting
         public void Login_Correct_Annotator_Firefox()
         {
             var driver = new FirefoxDriver();
-            driver.Navigate().GoToUrl(url);                                     //zakladni stranka
+            driver.Navigate().GoToUrl(url);                                      
             Thread.Sleep(3000);
             driver.FindElement(usernameField).SendKeys(usernames[0]);           //enter username
             driver.FindElement(passwordField).SendKeys(passwords[0]);           //enter password
@@ -74,7 +74,7 @@ namespace FrontendTesting
         public void Login_Correct_Admin_Firefox()
         {
             var driver = new FirefoxDriver();
-            driver.Navigate().GoToUrl(url);                             //zakladni stranka
+            driver.Navigate().GoToUrl(url);                              
             Thread.Sleep(3000);
             driver.FindElement(usernameField).SendKeys(usernames[2]);          //enter username
             driver.FindElement(passwordField).SendKeys(passwords[2]);          //enter password
@@ -89,7 +89,7 @@ namespace FrontendTesting
         public void Login_Correct_Annotator_Chrome()
         {
             var driver = new ChromeDriver();
-            driver.Navigate().GoToUrl(url);                             //zakladni stranka
+            driver.Navigate().GoToUrl(url);                              
             Thread.Sleep(3000);
             driver.FindElement(usernameField).SendKeys(usernames[0]);          //enter username
             driver.FindElement(passwordField).SendKeys(passwords[0]);          //enter password
@@ -104,7 +104,7 @@ namespace FrontendTesting
         public void Login_Correct_Admin_Chrome()
         {
             var driver = new ChromeDriver();
-            driver.Navigate().GoToUrl(url);                             //zakladni stranka
+            driver.Navigate().GoToUrl(url);                              
             Thread.Sleep(3000);
             driver.FindElement(usernameField).SendKeys(usernames[2]);          //enter username
             driver.FindElement(passwordField).SendKeys(passwords[2]);          //enter password
@@ -121,7 +121,7 @@ namespace FrontendTesting
         public void Login_Incorrect_Annotator_Firefox()
         {
             var driver = new FirefoxDriver();
-            driver.Navigate().GoToUrl(url);                             //zakladni stranka
+            driver.Navigate().GoToUrl(url);                             
             Thread.Sleep(3000);
             driver.FindElement(usernameField).SendKeys(usernames[0]);          //enter username
             driver.FindElement(passwordField).SendKeys("abc");          //enter password
@@ -136,7 +136,7 @@ namespace FrontendTesting
         public void Login_Incorrect_Admin_Firefox()
         {
             var driver = new FirefoxDriver();
-            driver.Navigate().GoToUrl(url);                             //zakladni stranka
+            driver.Navigate().GoToUrl(url);                              
             Thread.Sleep(3000);
             driver.FindElement(usernameField).SendKeys(usernames[2]);          //enter username
             driver.FindElement(passwordField).SendKeys("abc");          //enter password
@@ -151,7 +151,7 @@ namespace FrontendTesting
         public void Login_Incorrect_Annotator_Chrome()
         {
             var driver = new ChromeDriver();
-            driver.Navigate().GoToUrl(url);                             //zakladni stranka
+            driver.Navigate().GoToUrl(url);                              
             Thread.Sleep(3000);
             driver.FindElement(usernameField).SendKeys(usernames[0]);          //enter username
             driver.FindElement(passwordField).SendKeys("abc");          //enter password
@@ -166,7 +166,7 @@ namespace FrontendTesting
         public void Login_Incorrect_Admin_Chrome()
         {
             var driver = new ChromeDriver(); 
-            driver.Navigate().GoToUrl(url);                             //zakladni stranka
+            driver.Navigate().GoToUrl(url);                              
             Thread.Sleep(3000);
             driver.FindElement(usernameField).SendKeys(usernames[2]);          //enter username
             driver.FindElement(passwordField).SendKeys("abc");          //enter password
@@ -181,7 +181,7 @@ namespace FrontendTesting
         public void Login_EmptyUsername_Firefox()
         {
             var driver = new FirefoxDriver();
-            driver.Navigate().GoToUrl(url);                             //zakladni stranka
+            driver.Navigate().GoToUrl(url);                              
             Thread.Sleep(3000);
             driver.FindElement(usernameField).SendKeys("");          //enter username
             driver.FindElement(passwordField).SendKeys("abc");          //enter password
@@ -196,7 +196,7 @@ namespace FrontendTesting
         public void Login_EmptyUsername_Chrome()
         {
             var driver = new ChromeDriver();
-            driver.Navigate().GoToUrl(url);                             //zakladni stranka
+            driver.Navigate().GoToUrl(url);                              
             Thread.Sleep(3000);
             driver.FindElement(usernameField).SendKeys("");          //enter username
             driver.FindElement(passwordField).SendKeys("abc");          //enter password
@@ -211,7 +211,7 @@ namespace FrontendTesting
         public void Login_EmptyPassword_Firefox()
         {
             var driver = new FirefoxDriver();
-            driver.Navigate().GoToUrl(url);                             //zakladni stranka
+            driver.Navigate().GoToUrl(url);                              
             Thread.Sleep(3000);
             driver.FindElement(usernameField).SendKeys(usernames[0]);          //enter username
             driver.FindElement(passwordField).SendKeys("");          //enter password
@@ -226,7 +226,7 @@ namespace FrontendTesting
         public void Login_EmptyPassword_Chrome()
         {
             var driver = new ChromeDriver();
-            driver.Navigate().GoToUrl(url);                             //zakladni stranka
+            driver.Navigate().GoToUrl(url);                              
             Thread.Sleep(3000);
             driver.FindElement(usernameField).SendKeys(usernames[0]);          //enter username
             driver.FindElement(passwordField).SendKeys("");          //enter password
diff --git a/Backend/FrontendTesting/MainTestingClass.cs b/Backend/FrontendTesting/MainTestingClass.cs
deleted file mode 100644
index 94fa61c..0000000
--- a/Backend/FrontendTesting/MainTestingClass.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace FrontendTesting
-{
-    [TestClass]
-    public class MainTestingClass
-    {
-        [TestMethod]
-        public void RunAll()
-        {
-            
-        }
-    }
-}
\ No newline at end of file
