Search in sources :

Example 1 with BeanFieldGroup

use of com.vaadin.v7.data.fieldgroup.BeanFieldGroup in project SORMAS-Project by hzi-braunschweig.

the class LabMessageUiHelperUnitTest method testEstablishFinalCommitButtons.

@Test
public void testEstablishFinalCommitButtons() {
    Mockito.mockConstruction(SampleCreateForm.class);
    UserReferenceDto user = new UserReferenceDto();
    CaseReferenceDto caze = new CaseReferenceDto();
    SampleDto sample = SampleDto.build(user, caze);
    SampleCreateForm createForm = new SampleCreateForm(Disease.CORONAVIRUS);
    when(createForm.getFieldGroup()).thenReturn(new BeanFieldGroup(SampleDto.class));
    CommitDiscardWrapperComponent<SampleCreateForm> sampleComponent = new CommitDiscardWrapperComponent<>(createForm, true, createForm.getFieldGroup());
    when(sampleComponent.getWrappedComponent().getValue()).thenReturn(sample);
    LabMessageUiHelper.establishFinalCommitButtons(sampleComponent);
    HorizontalLayout buttonsPanel = sampleComponent.getButtonsPanel();
    Button saveAndOpenEntryButton = (Button) buttonsPanel.getComponent(buttonsPanel.getComponentCount() - 2);
    assertThat(saveAndOpenEntryButton.getStyleName(), equalTo(sampleComponent.getCommitButton().getStyleName()));
    assertThat(saveAndOpenEntryButton.getId(), equalTo("saveAndOpenEntryButton"));
    // Both commit buttons should do the same, except each one should trigger a different navigation
    assertThat(saveAndOpenEntryButton.getListeners(Button.ClickEvent.class).size(), equalTo(sampleComponent.getCommitButton().getListeners(Button.ClickEvent.class).size()));
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) BeanFieldGroup(com.vaadin.v7.data.fieldgroup.BeanFieldGroup) Button(com.vaadin.ui.Button) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) SampleDto(de.symeda.sormas.api.sample.SampleDto) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) SampleCreateForm(de.symeda.sormas.ui.samples.SampleCreateForm) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Test(org.junit.Test)

Aggregations

Button (com.vaadin.ui.Button)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 BeanFieldGroup (com.vaadin.v7.data.fieldgroup.BeanFieldGroup)1 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)1 SampleDto (de.symeda.sormas.api.sample.SampleDto)1 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)1 SampleCreateForm (de.symeda.sormas.ui.samples.SampleCreateForm)1 CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)1 Test (org.junit.Test)1