const { Builder, By, until } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

const webdriver = process.env.CHROME_DRIVER
const service = new chrome.ServiceBuilder(webdriver);
const login = require("./helperSimulations/simulateAdminLogin");
const findLastDegreeCourseApplication = require('./helperSimulations/findDegreeCourseApplicationID');

describe("After entering DegreeCourseApplicationManagement", () => {
    let driver

    beforeAll(async () => {
        driver = new Builder().forBrowser('chrome').setChromeService(service).build();
        await login(driver)
    })

    afterAll(async () => {
        await driver.quit();
    })

    it("should be able to find and click DegreeCourse-Application-Management-Button", async () => {
        const degreeCourseApplicationManagementButton = await driver.wait(until.elementLocated(By.id("OpenDegreeCourseApplicationManagementPageButton")), 5000)
        expect(degreeCourseApplicationManagementButton).toBeDefined();
        await degreeCourseApplicationManagementButton.click();
    })

    it("should show the new Application", async () => {
        const degreeCourseApplicationManagementButton = await driver.wait(until.elementLocated(By.id("OpenDegreeCourseApplicationManagementPageButton")), 5000)
        expect(degreeCourseApplicationManagementButton).toBeDefined();
        await degreeCourseApplicationManagementButton.click();
        const id = await findLastDegreeCourseApplication(driver)
        const architectureApplication = await driver.wait(until.elementLocated(By.id("DegreeCourseApplicationItem" + id)), 5000)
        expect(architectureApplication).toBeDefined();
    })
})