use of com.vaadin.flow.component.tabs.Tabs in project flow-components by vaadin.
the class SelectionEventTest method tabsAutoselectFalse_previousAndCurrentTab.
@Test
public void tabsAutoselectFalse_previousAndCurrentTab() {
AtomicReference<Tab> currentTab = new AtomicReference<>();
AtomicReference<Tab> previousTab = new AtomicReference<>();
tabs = new Tabs();
tabs.setAutoselect(false);
tabs.add(tab1, tab2);
tabs.addSelectedChangeListener(e -> {
currentTab.set(e.getSelectedTab());
previousTab.set(e.getPreviousTab());
});
tabs.setSelectedTab(tab1);
Assert.assertEquals("Current tab should be tab 1", currentTab.get(), tab1);
Assert.assertNull("Previous tab should be empty", previousTab.get());
tabs.setSelectedTab(tab2);
Assert.assertEquals("Current tab should be tab 2", currentTab.get(), tab2);
Assert.assertEquals("Previous tab should be tab 1", previousTab.get(), tab1);
}
use of com.vaadin.flow.component.tabs.Tabs in project flow-components by vaadin.
the class SelectionEventTest method init.
@Before
public void init() {
tab1 = new Tab("foo");
tab2 = new Tab("bar");
tabs = new Tabs(tab1, tab2);
addSelectedChangeListener(tabs);
eventCount = 0;
}
use of com.vaadin.flow.component.tabs.Tabs in project flow-components by vaadin.
the class SelectionEventTest method addSecondTabWithAddComponentAtIndex_selectionNotChanged.
@Test
public void addSecondTabWithAddComponentAtIndex_selectionNotChanged() {
tabs = new Tabs();
addSelectedChangeListener(tabs);
tabs.addComponentAtIndex(0, tab1);
tabs.addComponentAtIndex(0, tab2);
Assert.assertEquals("Unexpected selected index after adding the first tab.", 1, tabs.getSelectedIndex());
Assert.assertEquals("Expected the first added tab to be automatically selected.", tab1, tabs.getSelectedTab());
Assert.assertEquals("Expected no selection event after adding the second tab.", 1, eventCount);
}
use of com.vaadin.flow.component.tabs.Tabs in project flow-components by vaadin.
the class TabsTest method tabsAutoselectConstructor.
@Test
public void tabsAutoselectConstructor() {
Tabs tabs1 = new Tabs(true);
tabs1.add(new Tab("Tab"));
Assert.assertEquals(tabs1.getSelectedIndex(), 0);
Tabs tabs2 = new Tabs(false);
tabs2.add(new Tab("Tab"));
Assert.assertEquals(tabs2.getSelectedIndex(), -1);
}
use of com.vaadin.flow.component.tabs.Tabs in project flow-components by vaadin.
the class TabsTest method removeTabInTabsWithoutAutomaticSelection.
@Test
public void removeTabInTabsWithoutAutomaticSelection() {
Tab tab1 = new Tab("Tab one");
Tab tab2 = new Tab("Tab two");
Tab tab3 = new Tab("Tab three");
Tabs tabs = new Tabs(false, tab1, tab2, tab3);
tabs.setSelectedTab(tab2);
tabs.remove(tab1);
Assert.assertEquals("should not change selected tab", tabs.getSelectedTab(), tab2);
tabs.remove(tab2);
Assert.assertNull("should not select other tab if current tab removed", tabs.getSelectedTab());
}
Aggregations