aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/themes/valo/ImmediateUploadTest.java
blob: d749997fa8cf95897434c9bc1c934370cc06b18d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.vaadin.tests.themes.valo;

import static com.vaadin.tests.themes.valo.ImmediateUpload.TEST_MIME_TYPE;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.io.IOException;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.vaadin.testbench.elements.UploadElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

/**
 * Test to see if upload immediate mode hides the native file input.
 *
 * @author Vaadin Ltd
 */
public class ImmediateUploadTest extends MultiBrowserTest {

    @Override
    public void setup() throws Exception {
        super.setup();
        openTestURL();
    }

    private WebElement getUploadButton(String id) {
        UploadElement normalUpload = $(UploadElement.class).id(id);

        return normalUpload.findElement(By.tagName("div"));
    }

    private WebElement getUploadFileInput(String id) {
        UploadElement normalUpload = $(UploadElement.class).id(id);

        return normalUpload.findElement(By.cssSelector("input[type='file']"));
    }

    @Test
    public void normalUploadButtonIsVisible() {
        WebElement button = getUploadButton("upload");

        assertThat(button.getCssValue("display"), is("block"));
    }

    @Test
    public void fileInputIsVisibleForNormalUpload() {
        WebElement input = getUploadFileInput("upload");

        assertThat(input.getCssValue("position"), is("static"));
    }

    @Test
    public void immediateUploadButtonIsVisible() {
        WebElement button = getUploadButton("immediateupload");

        assertThat(button.getCssValue("display"), is("block"));
    }

    @Test
    public void fileInputIsNotVisibleForImmediateUpload() {
        WebElement input = getUploadFileInput("immediateupload");

        assertThat(input.getCssValue("position"), is("absolute"));
    }

    @Test
    public void fileInputIsNotClickableForImmediateUpload() throws IOException {
        WebElement input = getUploadFileInput("immediateupload");

        // input.click() and then verifying if the upload window is opened
        // would be better but couldn't figure a way to do that. screenshots
        // don't show the upload window, not at least in firefox.
        assertThat(input.getCssValue("z-index"), is("-1"));
    }

    @Test
    public void testAcceptAttribute() {
        WebElement input = getUploadFileInput("immediateupload");
        assertThat(input.getAttribute("accept"), is(TEST_MIME_TYPE));
    }
}