com.formkiq.web.FolderIntegrationTest.java Source code

Java tutorial

Introduction

Here is the source code for com.formkiq.web.FolderIntegrationTest.java

Source

/*
 * Copyright (C) 2017 FormKiQ Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.formkiq.web;

import static org.junit.Assert.assertEquals;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT;

import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * WorkflowController Edit Integration Test.
 *
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = DEFINED_PORT)
@ActiveProfiles("dev")
public class FolderIntegrationTest extends SeleniumTestBase {

    @Override
    @Before
    public void before() throws Exception {
        super.before();

        truncateTables("folders");

        login(getDefaultEmail());
        // TODO remove when new ui is complete
        getDriver().navigate().to(getDefaultHostAndPort() + "/admin/folders");
        assertEquals("FormKiQ Server - Folders", getTitle());
    }

    /**
     * testAddFolder01().
     * add folder - missing name
     *
     * @throws Exception Exception
     */
    @Test
    public void testAddFolder01() throws Exception {
        // given
        // when
        findElementBy(By.id("folder_add_button")).click();

        getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("form-modal")));

        click(By.name("_eventId_next"));

        // then
        waitUntilPageSourceText("Field required");
    }

    /**
     * testAddFolder02().
     * add folder
     *
     * @throws Exception Exception
     */
    @Test
    public void testAddFolder02() throws Exception {
        // given
        String folder = "testfolder";

        // when
        findElementBy(By.id("folder_add_button")).click();

        getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("form-modal")));

        findElementBy("input", "data-valuekey", "name").sendKeys(folder);
        WebElement el = findElementBy(By.name("_eventId_next"));
        assertEquals("Add Folder", el.getText());
        el.click();

        // then
        getWait().until(ExpectedConditions.invisibilityOfElementLocated(By.id("form-modal")));

        int i = 0;
        final int elementCount = 2;
        List<WebElement> e = findElements(By.xpath("//table[@id='results']/tbody/tr/td"));
        assertEquals(elementCount, e.size());
        assertEquals("testfolder", e.get(i++).getText());
        assertEquals("", e.get(i++).getText());

        // when
        findElementBy(By.id("tablesearch")).sendKeys("testf1");
        findElementBy(By.id("buttonsearch")).click();

        // then
        e = findElements(By.xpath("//table[@id='results']/tbody/tr"));
        assertEquals(1, e.size());
        assertEquals("No Folder(s) found", e.get(0).getText());

        // when
        findElementBy(By.id("tablesearch")).clear();
        findElementBy(By.id("tablesearch")).sendKeys("testf");
        findElementBy(By.id("buttonsearch")).click();

        // then
        e = findElements(By.xpath("//table[@id='results']/tbody/tr"));
        assertEquals(1, e.size());
        assertEquals("testfolder", e.get(0).getText());
    }
}