<commit_before>package com.vaadin.tests.components.treegrid;

import java.util.Arrays;
import java.util.Collection;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized.Parameters;
import org.openqa.selenium.Keys;
import org.openqa.selenium.interactions.Actions;

import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.TreeGridElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
import com.vaadin.tests.tb3.ParameterizedTB3Runner;

@RunWith(ParameterizedTB3Runner.class)
public class TreeGridBasicFeaturesTest extends MultiBrowserTest {

    private TreeGridElement grid;

    public void setDataProvider(String dataProviderString) {
        selectMenuPath("Component", "Features", "Set data provider",
                dataProviderString);
    }

    @Parameters
    public static Collection<String> getDataProviders() {
        return Arrays.asList("LazyHierarchicalDataProvider",
                "InMemoryHierarchicalDataProvider");
    }

    @Before
    public void before() {
        openTestURL("theme=valo");
        grid = $(TreeGridElement.class).first();
    }

    @Test
    @Ignore // currently no implementation exists for toggling from the server
            // side
    public void toggle_collapse_server_side() {
        Assert.assertEquals(3, grid.getRowCount());
        assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" });

        selectMenuPath("Component", "Features", "Toggle expand", "0 | 0");
        Assert.assertEquals(6, grid.getRowCount());
        assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" });

        selectMenuPath("Component", "Features", "Toggle expand", "0 | 0");
        Assert.assertEquals(3, grid.getRowCount());
        assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" });

        // collapsing a leaf should have no effect
        selectMenuPath("Component", "Features", "Toggle expand", "1 | 0");
        Assert.assertEquals(3, grid.getRowCount());
    }

    @Test
    public void non_leaf_collapse_on_click() {
        Assert.assertEquals(3, grid.getRowCount());
        assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" });

        // Should expand "0 | 0"
        grid.getRow(0).getCell(0)
                .findElement(By.className("v-tree-grid-expander")).click();
        Assert.assertEquals(6, grid.getRowCount());
        assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" });

        // Should collapse "0 | 0"
        grid.getRow(0).getCell(0)
                .findElement(By.className("v-tree-grid-expander")).click();
        Assert.assertEquals(3, grid.getRowCount());
        assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" });
    }

    @Test
    @Ignore // FIXME: remove ignore annotation once #8758 is done
    public void keyboard_navigation() {
        grid.getRow(0).getCell(0).click();

        // Should expand "0 | 0"
        new Actions(getDriver()).keyDown(Keys.ALT).sendKeys(Keys.RIGHT)
                .keyUp(Keys.ALT).perform();
        Assert.assertEquals(6, grid.getRowCount());
        assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" });

        // Should collapse "0 | 0"
        new Actions(getDriver()).keyDown(Keys.ALT).sendKeys(Keys.LEFT)
                .keyUp(Keys.ALT).perform();
        Assert.assertEquals(3, grid.getRowCount());
        assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" });
    }

    @Test
    public void changing_hierarchy_column() {
        Assert.assertTrue(grid.getRow(0).getCell(0)
                .isElementPresent(By.className("v-tree-grid-expander")));
        Assert.assertFalse(grid.getRow(0).getCell(1)
                .isElementPresent(By.className("v-tree-grid-expander")));

        selectMenuPath("Component", "Features", "Set hierarchy column",
                "depth");

        Assert.assertFalse(grid.getRow(0).getCell(0)
                .isElementPresent(By.className("v-tree-grid-expander")));
        Assert.assertTrue(grid.getRow(0).getCell(1)
                .isElementPresent(By.className("v-tree-grid-expander")));

        selectMenuPath("Component", "Features", "Set hierarchy column",
                "string");

        Assert.assertTrue(grid.getRow(0).getCell(0)
                .isElementPresent(By.className("v-tree-grid-expander")));
        Assert.assertFalse(grid.getRow(0).getCell(1)
                .isElementPresent(By.className("v-tree-grid-expander")));
    }

    @Test
    public void expand_and_collapse_listeners() {
        selectMenuPath("Component", "State", "Expand listener");
        selectMenuPath("Component", "State", "Collapse listener");

        Assert.assertFalse(logContainsText("Item expanded: 0 | 0"));
        Assert.assertFalse(logContainsText("Item collapsed: 0 | 0"));

        grid.expandWithClick(0);

        Assert.assertTrue(logContainsText("Item expanded: 0 | 0"));
        Assert.assertFalse(logContainsText("Item collapsed: 0 | 0"));

        grid.collapseWithClick(0);

        Assert.assertTrue(logContainsText("Item expanded: 0 | 0"));
        Assert.assertTrue(logContainsText("Item collapsed: 0 | 0"));
<commit_msg>Fix TreeGridBasicFeaturesTest for IE11 (#8933)<commit_after>package com.vaadin.tests.components.treegrid;

import java.util.Arrays;
import java.util.Collection;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized.Parameters;
import org.openqa.selenium.Keys;
import org.openqa.selenium.interactions.Actions;

import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.TreeGridElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
import com.vaadin.tests.tb3.ParameterizedTB3Runner;

@RunWith(ParameterizedTB3Runner.class)
public class TreeGridBasicFeaturesTest extends MultiBrowserTest {

    private TreeGridElement grid;

    public void setDataProvider(String dataProviderString) {
        selectMenuPath("Component", "Features", "Set data provider",
                dataProviderString);
    }

    @Parameters
    public static Collection<String> getDataProviders() {
        return Arrays.asList("LazyHierarchicalDataProvider",
                "InMemoryHierarchicalDataProvider");
    }

    @Before
    public void before() {
        openTestURL("theme=valo");
        grid = $(TreeGridElement.class).first();
    }

    @Test
    @Ignore // currently no implementation exists for toggling from the server
            // side
    public void toggle_collapse_server_side() {
        Assert.assertEquals(3, grid.getRowCount());
        assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" });

        selectMenuPath("Component", "Features", "Toggle expand", "0 | 0");
        Assert.assertEquals(6, grid.getRowCount());
        assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" });

        selectMenuPath("Component", "Features", "Toggle expand", "0 | 0");
        Assert.assertEquals(3, grid.getRowCount());
        assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" });

        // collapsing a leaf should have no effect
        selectMenuPath("Component", "Features", "Toggle expand", "1 | 0");
        Assert.assertEquals(3, grid.getRowCount());
    }

    @Test
    public void non_leaf_collapse_on_click() {
        Assert.assertEquals(3, grid.getRowCount());
        assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" });

        // Should expand "0 | 0"
        grid.getRow(0).getCell(0)
                .findElement(By.className("v-tree-grid-expander")).click();
        Assert.assertEquals(6, grid.getRowCount());
        assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" });

        // Should collapse "0 | 0"
        grid.getRow(0).getCell(0)
                .findElement(By.className("v-tree-grid-expander")).click();
        Assert.assertEquals(3, grid.getRowCount());
        assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" });
    }

    @Test
    @Ignore // FIXME: remove ignore annotation once #8758 is done
    public void keyboard_navigation() {
        grid.getRow(0).getCell(0).click();

        // Should expand "0 | 0"
        new Actions(getDriver()).keyDown(Keys.ALT).sendKeys(Keys.RIGHT)
                .keyUp(Keys.ALT).perform();
        Assert.assertEquals(6, grid.getRowCount());
        assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" });

        // Should collapse "0 | 0"
        new Actions(getDriver()).keyDown(Keys.ALT).sendKeys(Keys.LEFT)
                .keyUp(Keys.ALT).perform();
        Assert.assertEquals(3, grid.getRowCount());
        assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" });
    }

    @Test
    public void changing_hierarchy_column() {
        Assert.assertTrue(grid.getRow(0).getCell(0)
                .isElementPresent(By.className("v-tree-grid-expander")));
        Assert.assertFalse(grid.getRow(0).getCell(1)
                .isElementPresent(By.className("v-tree-grid-expander")));

        selectMenuPath("Component", "Features", "Set hierarchy column",
                "depth");

        Assert.assertFalse(grid.getRow(0).getCell(0)
                .isElementPresent(By.className("v-tree-grid-expander")));
        Assert.assertTrue(grid.getRow(0).getCell(1)
                .isElementPresent(By.className("v-tree-grid-expander")));

        selectMenuPath("Component", "Features", "Set hierarchy column",
                "string");

        Assert.assertTrue(grid.getRow(0).getCell(0)
                .isElementPresent(By.className("v-tree-grid-expander")));
        Assert.assertFalse(grid.getRow(0).getCell(1)
                .isElementPresent(By.className("v-tree-grid-expander")));
    }

    @Override
    protected boolean useNativeEventsForIE() {
        //Fixes IE11 selectMenuPath troubles
        return false;
    }

    @Test
    public void expand_and_collapse_listeners() {
        selectMenuPath("Component", "State", "Expand listener");
        selectMenuPath("Component", "State", "Collapse listener");

        Assert.assertFalse(logContainsText("Item expanded: 0 | 0"));
        Assert.assertFalse(logContainsText("Item collapsed: 0 | 0"));

        grid.expandWithClick(0);

        Assert.assertTrue(logContainsText("Item expanded: 0 | 0"));
        Assert.assertFalse(logContainsText("Item collapsed: 0 | 0"));

        grid.collapseWithClick(0);

        Assert.assertTrue(logContainsText("Item expanded: 0 | 0"));
        Assert.assertTrue(logContainsText("Item collapsed: 0 | 0"));

{'fraction_non_alphanumeric': 0.14905377552932358, 'fraction_numerical': 0.02454562488289301, 'mean_word_length': 2.9045354791514266, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '21925', 'n_tokens_mistral': 3377, 'n_tokens_neox': 3175, 'n_words': 638}