use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImplTest method shouldSetUIDisplayableOnlyToCorrectFields.
@Test
public void shouldSetUIDisplayableOnlyToCorrectFields() {
// given
int fieldCount = 12;
long displayPosition = fieldCount / 4 - 1;
List<Field> fields = new ArrayList<>(fieldCount);
Map<String, Long> positions = new HashMap<>();
for (int i = 0; i < fieldCount; ++i) {
Field field = mock(Field.class);
// every 4th field will have set the uiDisplayable flag
if (i % 4 == 0) {
String fieldName = "field" + i;
doReturn(fieldName).when(field).getName();
positions.put(fieldName, displayPosition);
--displayPosition;
}
fields.add(field);
}
// when
doReturn(1L).when(entityDto).getId();
doReturn(entity).when(allEntities).retrieveById(1L);
doReturn(fields).when(entity).getFields();
entityService.addDisplayedFields(entityDto, positions);
// then
verify(allEntities).retrieveById(1L);
verify(entity).getFields();
for (int i = 0; i < fieldCount; ++i) {
Field field = fields.get(i);
// flag should be unset
if (i % 4 == 0) {
verify(field).setUIDisplayable(true);
verify(field).setUIDisplayPosition(positions.get("field" + i));
} else {
verify(field).setUIDisplayable(false);
verify(field).setUIDisplayPosition(null);
}
}
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceContextIT method shouldUpdateUserPreferencesAfterCommit.
@Test
public void shouldUpdateUserPreferencesAfterCommit() {
EntityDto entityDto = new EntityDto();
entityDto.setName("UserPrefTest");
entityDto = entityService.createEntity(entityDto);
final Long entityId = entityDto.getId();
entityService.saveDraftEntityChanges(entityId, DraftBuilder.forNewField("disp", "f1name", Long.class.getName()));
List<FieldDto> fields = entityService.getFields(entityId);
assertNotNull(fields);
assertEquals(asList("id", "creator", "owner", "modifiedBy", "creationDate", "modificationDate", "f1name"), extract(fields, on(FieldDto.class).getBasic().getName()));
entityService.commitChanges(entityId);
List<Field> draftFields = entityService.getEntityDraft(entityId).getFields();
Field field = selectFirst(draftFields, having(on(Field.class).getName(), equalTo("f1name")));
entityService.saveDraftEntityChanges(entityDto.getId(), DraftBuilder.forFieldEdit(field.getId(), "basic.name", "newName"));
userPreferencesService.selectFields(entityId, "motech");
userPreferencesService.unselectField(entityId, "motech", "id");
userPreferencesService.unselectField(entityId, "motech", "owner");
UserPreferencesDto userPreferencesDto = userPreferencesService.getUserPreferences(entityId, "motech");
assertEquals(5, userPreferencesDto.getVisibleFields().size());
assertTrue(userPreferencesDto.getVisibleFields().contains("f1name"));
assertTrue(userPreferencesDto.getVisibleFields().contains("creator"));
assertTrue(userPreferencesDto.getVisibleFields().contains("modifiedBy"));
assertTrue(userPreferencesDto.getVisibleFields().contains("creationDate"));
assertTrue(userPreferencesDto.getVisibleFields().contains("modificationDate"));
entityService.commitChanges(entityId);
userPreferencesDto = userPreferencesService.getUserPreferences(entityId, "motech");
assertEquals(5, userPreferencesDto.getVisibleFields().size());
assertTrue(userPreferencesDto.getVisibleFields().contains("newName"));
assertTrue(userPreferencesDto.getVisibleFields().contains("creator"));
assertTrue(userPreferencesDto.getVisibleFields().contains("modifiedBy"));
assertTrue(userPreferencesDto.getVisibleFields().contains("creationDate"));
assertTrue(userPreferencesDto.getVisibleFields().contains("modificationDate"));
assertEquals(2, userPreferencesDto.getUnselectedFields().size());
assertTrue(userPreferencesDto.getUnselectedFields().contains("id"));
assertTrue(userPreferencesDto.getUnselectedFields().contains("owner"));
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class SwaggerFieldConverterTest method shouldConvertComboboxes.
@Test
public void shouldConvertComboboxes() {
// not user-supplied
Property property = SwaggerFieldConverter.fieldToProperty(field(List.class));
verifySimpleProperty(property, "string", null);
Entity entity = new Entity("org.example.Something");
Field field = FieldTestHelper.fieldWithComboboxSettings(entity, "name", "disp name", List.class, true, false, asList("a", "b", "c"));
property = SwaggerFieldConverter.fieldToProperty(field);
verifyComboboxProperty(property, true);
// user-supplied
FieldTestHelper.setAllowUserSupplied(field, true);
property = SwaggerFieldConverter.fieldToProperty(field);
verifyComboboxProperty(property, false);
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class UserPreferencesServiceTest method shouldUnselectField.
@Test
public void shouldUnselectField() {
Field field1 = getField1();
when(allUserPreferences.retrieveByClassNameAndUsername(CLASS_NAME, USERNAME)).thenReturn(userPreferences);
when(entity.getField("sampleField1")).thenReturn(field1);
userPreferencesService.unselectField(15l, USERNAME, "sampleField1");
verify(userPreferences).unselectField(fieldCaptor.capture());
verify(allUserPreferences).update(userPreferences);
Field field = fieldCaptor.getValue();
assertNotNull(field);
assertEquals("sampleField1", field.getName());
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class UserPreferencesServiceTest method shouldSelectField.
@Test
public void shouldSelectField() {
when(allUserPreferences.retrieveByClassNameAndUsername(CLASS_NAME, USERNAME)).thenReturn(userPreferences);
when(entity.getField("sampleField1")).thenReturn(getField1());
userPreferencesService.selectField(15l, USERNAME, "sampleField1");
verify(userPreferences).selectField(fieldCaptor.capture());
verify(allUserPreferences).update(userPreferences);
Field field = fieldCaptor.getValue();
assertNotNull(field);
assertEquals("sampleField1", field.getName());
}
Aggregations