Search in sources :

Example 1 with StateManagerStub

use of org.activityinfo.client.mock.StateManagerStub in project activityinfo by bedatadriven.

the class DesignTest method testSaveOnNavigateAway.

@Test
public void testSaveOnNavigateAway() {
    // Dummy Data
    SchemaDTO schema = DTOs.pear();
    // Collaborator
    MockEventBus eventBus = new MockEventBus();
    // Collaborator
    DispatcherStub service = new DispatcherStub();
    service.setResult(GetSchema.class, schema);
    service.setResult(UpdateEntity.class, new VoidResult());
    // Collaborator
    DesignPresenter.View view = createNiceMock(DesignPresenter.View.class);
    replay(view);
    // Collaborator
    UIConstants constants = createNiceMock(UIConstants.class);
    replay(constants);
    DesignPresenter designer = new DesignPresenter(eventBus, service, new StateManagerStub(), view, constants);
    designer.go(schema.getDatabaseById(1));
    // Verify that following a change to the record, a save call
    // triggers an update command
    ActivityDTO activity = (ActivityDTO) ((TreeStore) designer.getStore()).getRootItems().get(0);
    Record record = designer.getStore().getRecord(activity);
    record.set("name", "New Name");
    designer.requestToNavigateAway(new DataEntryPlace(), new NavigationCallback() {

        @Override
        public void onDecided(boolean allowed) {
        }
    });
    UpdateEntity cmd = service.getLastExecuted(UpdateEntity.class);
    Assert.assertTrue(cmd.getChanges().containsKey("name"));
    Assert.assertEquals("New Name", cmd.getChanges().get("name"));
}
Also used : VoidResult(org.activityinfo.shared.command.result.VoidResult) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) DispatcherStub(org.activityinfo.client.dispatch.DispatcherStub) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) TreeStore(com.extjs.gxt.ui.client.store.TreeStore) DataEntryPlace(org.activityinfo.client.page.entry.place.DataEntryPlace) MockEventBus(org.activityinfo.client.MockEventBus) NavigationCallback(org.activityinfo.client.page.NavigationCallback) Record(com.extjs.gxt.ui.client.store.Record) UIConstants(org.activityinfo.client.i18n.UIConstants) StateManagerStub(org.activityinfo.client.mock.StateManagerStub) Test(org.junit.Test)

Example 2 with StateManagerStub

use of org.activityinfo.client.mock.StateManagerStub in project activityinfo by bedatadriven.

the class DesignTest method testDelete.

@Test
public void testDelete() {
    // Dummy Data
    SchemaDTO schema = DTOs.pear();
    // Collaborator
    DispatcherStub service = new DispatcherStub();
    service.setResult(GetSchema.class, schema);
    service.setResult(Delete.class, new VoidResult());
    // Collaborator
    DesignPresenter.View view = createNiceMock(DesignPresenter.View.class);
    expect(view.getSelection()).andReturn(schema.getActivityById(91));
    view.confirmDeleteSelected(isA(ConfirmCallback.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            ((ConfirmCallback) getCurrentArguments()[0]).confirmed();
            return null;
        }
    });
    replay(view);
    // Collaborator
    UIConstants constants = createNiceMock(UIConstants.class);
    replay(constants);
    DesignPresenter designer = new DesignPresenter(new MockEventBus(), service, new StateManagerStub(), view, constants);
    designer.go(schema.getDatabaseById(1));
    // Verify that the proper delete command executes
    designer.onUIAction(UIActions.DELETE);
    Delete cmd = service.getLastExecuted(Delete.class);
    Assert.assertEquals("Activity", cmd.getEntityName());
    Assert.assertEquals(91, cmd.getId());
}
Also used : Delete(org.activityinfo.shared.command.Delete) ConfirmCallback(org.activityinfo.client.page.common.grid.ConfirmCallback) VoidResult(org.activityinfo.shared.command.result.VoidResult) DispatcherStub(org.activityinfo.client.dispatch.DispatcherStub) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) MockEventBus(org.activityinfo.client.MockEventBus) UIConstants(org.activityinfo.client.i18n.UIConstants) StateManagerStub(org.activityinfo.client.mock.StateManagerStub) Test(org.junit.Test)

Example 3 with StateManagerStub

use of org.activityinfo.client.mock.StateManagerStub in project activityinfo by bedatadriven.

the class DesignTest method testNewActivityComesWithFolders.

@Test
public void testNewActivityComesWithFolders() {
    // Test data
    SchemaDTO schema = DTOs.pear();
    // Collaborator : EventBus
    MockEventBus eventBus = new MockEventBus();
    // Collaborator : Command Service
    DispatcherStub service = new DispatcherStub();
    service.setResult(GetSchema.class, schema);
    service.setResult(CreateEntity.class, new CreateResult(991));
    // Collaborator : View
    MockDesignTree view = new MockDesignTree();
    // Constants
    UIConstants constants = createNiceMock(UIConstants.class);
    replay(constants);
    // Class under test
    DesignPresenter designer = new DesignPresenter(eventBus, service, new StateManagerStub(), view, constants);
    // VERIFY that when an activity is added, it appears at the end of the
    // list with two
    // sub folders
    designer.go(schema.getDatabaseById(1));
    view.newEntityProperties.put("name", "Psychosocial support");
    designer.onNew("Activity");
    List<ModelData> rootItems = designer.getTreeStore().getRootItems();
    ActivityDTO addedActivity = (ActivityDTO) rootItems.get(rootItems.size() - 1);
    Assert.assertEquals("Psychosocial support", addedActivity.getName());
    Assert.assertEquals("child nodes", 2, designer.getTreeStore().getChildCount(addedActivity));
}
Also used : ModelData(com.extjs.gxt.ui.client.data.ModelData) CreateResult(org.activityinfo.shared.command.result.CreateResult) MockEventBus(org.activityinfo.client.MockEventBus) DispatcherStub(org.activityinfo.client.dispatch.DispatcherStub) UIConstants(org.activityinfo.client.i18n.UIConstants) StateManagerStub(org.activityinfo.client.mock.StateManagerStub) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) Test(org.junit.Test)

Example 4 with StateManagerStub

use of org.activityinfo.client.mock.StateManagerStub in project activityinfo by bedatadriven.

the class DesignTest method testSave.

@Test
public void testSave() {
    // Dummy Data
    SchemaDTO schema = DTOs.pear();
    // Collaborator
    MockEventBus eventBus = new MockEventBus();
    // Collaborator
    DispatcherStub service = new DispatcherStub();
    service.setResult(GetSchema.class, schema);
    service.setResult(UpdateEntity.class, new VoidResult());
    // Collaborator
    DesignPresenter.View view = createNiceMock(DesignPresenter.View.class);
    replay(view);
    // Localisation resources
    UIConstants constants = createNiceMock(UIConstants.class);
    replay(constants);
    DesignPresenter designer = new DesignPresenter(eventBus, service, new StateManagerStub(), view, constants);
    designer.go(schema.getDatabaseById(1));
    // Verify that following a change to the record, a save call
    // triggers an update command
    ActivityDTO activity = (ActivityDTO) ((TreeStore) designer.getStore()).getRootItems().get(0);
    Record record = designer.getStore().getRecord(activity);
    record.set("name", "New Name");
    designer.onUIAction(UIActions.SAVE);
    UpdateEntity cmd = service.getLastExecuted(UpdateEntity.class);
    Assert.assertTrue(cmd.getChanges().containsKey("name"));
    Assert.assertEquals("New Name", cmd.getChanges().get("name"));
}
Also used : TreeStore(com.extjs.gxt.ui.client.store.TreeStore) VoidResult(org.activityinfo.shared.command.result.VoidResult) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) MockEventBus(org.activityinfo.client.MockEventBus) DispatcherStub(org.activityinfo.client.dispatch.DispatcherStub) Record(com.extjs.gxt.ui.client.store.Record) UIConstants(org.activityinfo.client.i18n.UIConstants) StateManagerStub(org.activityinfo.client.mock.StateManagerStub) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) Test(org.junit.Test)

Example 5 with StateManagerStub

use of org.activityinfo.client.mock.StateManagerStub in project activityinfo by bedatadriven.

the class DesignTest method testDeleteEnabled.

@Test
public void testDeleteEnabled() {
    // Dummy Data
    SchemaDTO schema = DTOs.pear();
    // Collaborator
    DispatcherStub service = new DispatcherStub();
    service.setResult(GetSchema.class, schema);
    service.setResult(Delete.class, new VoidResult());
    // Collaborator
    DesignPresenter.View view = createNiceMock(DesignPresenter.View.class);
    view.setActionEnabled(UIActions.DELETE, false);
    replay(view);
    // Collaborator
    UIConstants constants = createNiceMock(UIConstants.class);
    replay(constants);
    DesignPresenter designer = new DesignPresenter(new MockEventBus(), service, new StateManagerStub(), view, constants);
    designer.go(schema.getDatabaseById(1));
    // Verify that the delete command is initially disabled
    verify(view);
    // Verify that the delete command is enabled when an activity is
    // selected
    resetToDefault(view);
    view.setActionEnabled(UIActions.DELETE, true);
    replay(view);
    designer.onSelectionChanged(schema.getActivityById(91));
    verify(view);
    // Verify that the delete command is disabled when a folder is selected
    reset(view);
    view.setActionEnabled(UIActions.DELETE, false);
    replay(view);
    designer.onSelectionChanged(new IndicatorFolder(null));
    verify(view);
}
Also used : VoidResult(org.activityinfo.shared.command.result.VoidResult) MockEventBus(org.activityinfo.client.MockEventBus) DispatcherStub(org.activityinfo.client.dispatch.DispatcherStub) UIConstants(org.activityinfo.client.i18n.UIConstants) StateManagerStub(org.activityinfo.client.mock.StateManagerStub) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) Test(org.junit.Test)

Aggregations

MockEventBus (org.activityinfo.client.MockEventBus)5 DispatcherStub (org.activityinfo.client.dispatch.DispatcherStub)5 UIConstants (org.activityinfo.client.i18n.UIConstants)5 StateManagerStub (org.activityinfo.client.mock.StateManagerStub)5 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)5 Test (org.junit.Test)5 VoidResult (org.activityinfo.shared.command.result.VoidResult)4 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)3 Record (com.extjs.gxt.ui.client.store.Record)2 TreeStore (com.extjs.gxt.ui.client.store.TreeStore)2 UpdateEntity (org.activityinfo.shared.command.UpdateEntity)2 ModelData (com.extjs.gxt.ui.client.data.ModelData)1 NavigationCallback (org.activityinfo.client.page.NavigationCallback)1 ConfirmCallback (org.activityinfo.client.page.common.grid.ConfirmCallback)1 DataEntryPlace (org.activityinfo.client.page.entry.place.DataEntryPlace)1 Delete (org.activityinfo.shared.command.Delete)1 CreateResult (org.activityinfo.shared.command.result.CreateResult)1