Search in sources :

Example 11 with Section

use of org.kie.workbench.common.screens.library.client.settings.SettingsPresenter.Section in project kie-wb-common by kiegroup.

the class SettingsPresenterTest method testSetupSectionsWithAllErrors.

@Test
public void testSetupSectionsWithAllErrors() {
    final Section section1 = newMockedSection();
    final Section section2 = newMockedSection();
    settingsPresenter.sections = new ArrayList<>(Arrays.asList(section1, section2));
    doThrow(new RuntimeException("Test exception")).when(section1).setup(any());
    doThrow(new RuntimeException("Test exception")).when(section2).setup(any());
    settingsPresenter.setupSections(mock(ProjectScreenModel.class)).then(i -> {
        fail("Promise should've not been resolved!");
        return promises.resolve();
    });
    assertTrue(settingsPresenter.sections.isEmpty());
    verify(settingsPresenter, times(2)).setupSection(any(), any());
}
Also used : Section(org.kie.workbench.common.screens.library.client.settings.SettingsPresenter.Section) Test(org.junit.Test)

Example 12 with Section

use of org.kie.workbench.common.screens.library.client.settings.SettingsPresenter.Section in project kie-wb-common by kiegroup.

the class SettingsPresenterTest method testUpdateDirtyIndicatorExistentDirtySection.

@Test
public void testUpdateDirtyIndicatorExistentDirtySection() {
    final Section section = newMockedSection();
    doReturn(42).when(section).currentHashCode();
    settingsPresenter.sections = new ArrayList<>(Arrays.asList(section));
    settingsPresenter.originalHashCodes = new HashMap<>();
    settingsPresenter.originalHashCodes.put(section, 32);
    settingsPresenter.updateDirtyIndicator(section);
    verify(section).setDirty(true);
}
Also used : Section(org.kie.workbench.common.screens.library.client.settings.SettingsPresenter.Section) Test(org.junit.Test)

Example 13 with Section

use of org.kie.workbench.common.screens.library.client.settings.SettingsPresenter.Section in project kie-wb-common by kiegroup.

the class SettingsPresenterTest method testSaveWithFirstSectionException.

@Test
public void testSaveWithFirstSectionException() {
    final Section section1 = newMockedSection();
    final Section section2 = newMockedSection();
    final RuntimeException testException = new RuntimeException("Test exception");
    doThrow(testException).when(section1).save(any(), any());
    doReturn(promises.resolve()).when(section2).save(any(), any());
    doReturn(promises.resolve()).when(settingsPresenter).defaultErrorResolution(testException);
    settingsPresenter.sections = new ArrayList<>(Arrays.asList(section1, section2));
    settingsPresenter.save("Test comment");
    verify(section1).save(eq("Test comment"), any());
    verify(section2, never()).save(any(), any());
    verify(settingsPresenter).defaultErrorResolution(eq(testException));
    verify(settingsPresenter, never()).saveProjectScreenModel(any(), any(), any());
    verify(settingsPresenter, never()).resetDirtyIndicator(any());
    verify(settingsPresenter, never()).displaySuccessMessage();
}
Also used : Section(org.kie.workbench.common.screens.library.client.settings.SettingsPresenter.Section) Test(org.junit.Test)

Example 14 with Section

use of org.kie.workbench.common.screens.library.client.settings.SettingsPresenter.Section in project kie-wb-common by kiegroup.

the class SettingsPresenterTest method testSaveWithFirstSectionRejection.

@Test
public void testSaveWithFirstSectionRejection() {
    final Section section1 = newMockedSection();
    final Section section2 = newMockedSection();
    doReturn(promises.reject(section1)).when(section1).save(any(), any());
    doReturn(promises.resolve()).when(section2).save(any(), any());
    settingsPresenter.sections = new ArrayList<>(Arrays.asList(section1, section2));
    settingsPresenter.save("Test comment");
    verify(section1).save(eq("Test comment"), any());
    verify(section2, never()).save(any(), any());
    verify(settingsPresenter).goTo(eq(section1));
    verify(settingsPresenter, never()).saveProjectScreenModel(any(), any(), any());
    verify(settingsPresenter, never()).resetDirtyIndicator(any());
    verify(settingsPresenter, never()).displaySuccessMessage();
}
Also used : Section(org.kie.workbench.common.screens.library.client.settings.SettingsPresenter.Section) Test(org.junit.Test)

Example 15 with Section

use of org.kie.workbench.common.screens.library.client.settings.SettingsPresenter.Section in project kie-wb-common by kiegroup.

the class SettingsPresenterTest method testResetDirtyIndicator.

@Test
public void testResetDirtyIndicator() {
    final Map<Section, Integer> hashes = new HashMap<>();
    final Section section = newMockedSection();
    doReturn(42).when(section).currentHashCode();
    settingsPresenter.originalHashCodes = hashes;
    settingsPresenter.resetDirtyIndicator(section);
    assertEquals((Integer) 42, hashes.get(section));
    verify(settingsPresenter).updateDirtyIndicator(eq(section));
}
Also used : HashMap(java.util.HashMap) Section(org.kie.workbench.common.screens.library.client.settings.SettingsPresenter.Section) Test(org.junit.Test)

Aggregations

Section (org.kie.workbench.common.screens.library.client.settings.SettingsPresenter.Section)21 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)1