﻿using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using AcademyAplication.Pages;
using OpenQA.Selenium.Support.UI;

namespace AcademyAplication
{
    [TestClass]
    public class Startup
    {
        [TestMethod]
        public void TestAcademyAplication()
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
            driver.Manage().Window.Maximize();
            driver.Url = @"http://stage.telerikacademy.com/";

            MainPage main = new MainPage(driver);
            main.LogInButton.Click();

            LoginPage login = new LoginPage(driver);
            login.UserNameTB.SendKeys("lnikod4s");
            login.PasswordTB.SendKeys("student");
            login.SubmitButton.Click();

            main.AcademyButton.Click();

            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
            main.KandButton.SendKeys("Return");
            main.KandButton.Click();

            RegistrationPage registration = new RegistrationPage(driver);
            registration.FillFormNames("Пешо", "Гошов", "Стаматов");

            string textPath = Path.GetFullPath(@"../../../eula.1028.txt");
            string imagePath = Path.GetFullPath(@"../../../y8PRWgs.jpg");

            registration.PictureInput.SendKeys(imagePath);            
            
            IJavaScriptExecutor js = driver as IJavaScriptExecutor;
            js.ExecuteScript("var dropdown = document.getElementById('WorkEducationStatusId'); var option = dropdown.children[1]; option.selected = true");
            js.ExecuteScript("var dropdown = document.getElementById('CityId'); var option = dropdown.children[1]; option.selected = true");
            js.ExecuteScript("var dropdown = document.getElementById('UniversityId'); var option = dropdown.children[1]; option.selected = true");

            registration.MaleRadio.Click();
            registration.BirthDayInput.Clear();
            registration.BirthDayInput.SendKeys("12/02/1982");
            registration.MailInput.Clear();
            registration.MailInput.SendKeys("testmail@mail.com");
            registration.PhoneInput.Clear();
            registration.PhoneInput.SendKeys("0898498756");
            registration.SchoolInput.Clear();
            registration.SchoolInput.SendKeys("Whatever school");
            registration.CVInput.Clear();
            registration.CVInput.SendKeys(textPath);
            registration.CoverLetterInput.Clear();
            registration.CoverLetterInput.SendKeys(textPath);

            registration.AcceptTermsCheck.Click();
            registration.SubmitButton.Click();
        }
    }
}