Search in sources :

Example 31 with Tabs

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);
}
Also used : Tab(com.vaadin.flow.component.tabs.Tab) Tabs(com.vaadin.flow.component.tabs.Tabs) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 32 with Tabs

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;
}
Also used : Tab(com.vaadin.flow.component.tabs.Tab) Tabs(com.vaadin.flow.component.tabs.Tabs) Before(org.junit.Before)

Example 33 with Tabs

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);
}
Also used : Tabs(com.vaadin.flow.component.tabs.Tabs) Test(org.junit.Test)

Example 34 with Tabs

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);
}
Also used : Tab(com.vaadin.flow.component.tabs.Tab) Tabs(com.vaadin.flow.component.tabs.Tabs) Test(org.junit.Test)

Example 35 with Tabs

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());
}
Also used : Tab(com.vaadin.flow.component.tabs.Tab) Tabs(com.vaadin.flow.component.tabs.Tabs) Test(org.junit.Test)

Aggregations

Tabs (com.vaadin.flow.component.tabs.Tabs)40 Tab (com.vaadin.flow.component.tabs.Tab)17 Test (org.junit.Test)16 Component (com.vaadin.flow.component.Component)5 Div (com.vaadin.flow.component.html.Div)3 FlexComponent (com.vaadin.flow.component.orderedlayout.FlexComponent)2 ShowComponentRequestedEvent (org.archcnl.ui.outputview.sidebar.events.ShowComponentRequestedEvent)2 HasElement (com.vaadin.flow.component.HasElement)1 Text (com.vaadin.flow.component.Text)1 H3 (com.vaadin.flow.component.html.H3)1 NativeButton (com.vaadin.flow.component.html.NativeButton)1 Icon (com.vaadin.flow.component.icon.Icon)1 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)1 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)1 TabsVariant (com.vaadin.flow.component.tabs.TabsVariant)1 Element (com.vaadin.flow.dom.Element)1 FurmsViewComponent (io.imunity.furms.ui.components.FurmsViewComponent)1 LogoutIconFactory (io.imunity.furms.ui.components.LogoutIconFactory)1 MenuComponent (io.imunity.furms.ui.components.MenuComponent)1 TabComponent (io.imunity.furms.ui.components.TabComponent)1