use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class IsAnyTrueHelperTest method throwExceptionWhenCollectionIsNull.
@Test
public void throwExceptionWhenCollectionIsNull() {
final Boolean[] params = null;
final Options options = OptionsStub.with(params, buffer);
try {
// when
isAnyTrueHelper.apply(item, options);
fail("An exception was expected but none was thrown.");
} catch (Exception e) {
// then
assertThat("Exception in execution", e.getMessage(), containsString("At least one parameter is required but none was provided."));
}
}
use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class BorderHelperTest method returnsParentBorder_forEachIndentationLevel.
@Test
public void returnsParentBorder_forEachIndentationLevel() {
// given
final Context context = Context.newContext(new Object());
final Schema currentModel = new Schema();
final Schema parentModel = new Schema();
final Schema grandparentModel = new Schema();
final ContextModelsStack contextModelsStack = new ContextModelsStack(asList(currentModel, parentModel, grandparentModel));
final ContextModelsStack.Factory contextStackFactory = mock(ContextModelsStack.Factory.class);
given(contextStackFactory.from(context)).willReturn(contextModelsStack);
borderHelper = BorderHelper.with(contextStackFactory);
final Options options = OptionsStub.with(context);
// when
final CharSequence expectedBorders = getBorder(SchemaBorder.HORIZONTAL, 1, 1) + getBorder(SchemaBorder.SHORT_VERTICAL, 1, 1) + getBorder(SchemaBorder.VERTICAL, 2, 0);
final CharSequence actualBorders = borderHelper.apply(null, options).toString();
// then
assertThat("Helper returns HTML with one vertical border for each ancestor model, and a horizontal border", actualBorders, is(expectedBorders));
}
use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class BorderHelperTest method returnsHorizontalBorder_whenElementHasParent.
@Test
public void returnsHorizontalBorder_whenElementHasParent() {
// given
final Context context = Context.newContext(new Object());
final Schema currentModel = new Schema();
final Schema parentModel = new Schema();
final ContextModelsStack contextModelsStack = new ContextModelsStack(asList(currentModel, parentModel));
final ContextModelsStack.Factory contextStackFactory = mock(ContextModelsStack.Factory.class);
given(contextStackFactory.from(context)).willReturn(contextModelsStack);
borderHelper = BorderHelper.with(contextStackFactory);
final Options options = OptionsStub.with(context);
// when
final CharSequence expectedBorders = getBorder(SchemaBorder.HORIZONTAL, 1, 0) + getBorder(SchemaBorder.SHORT_VERTICAL, 1, 0);
final CharSequence actualBorders = borderHelper.apply(null, options).toString();
// then
assertThat("Helper returns HTML with one vertical border for each ancestor model, and a horizontal border", actualBorders, is(expectedBorders));
}
use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class BorderHelperTest method returnsChildBorder_whenElementHasChildren.
@Test
@UseDataProvider("modelsWithChildren")
public void returnsChildBorder_whenElementHasChildren(final Schema currentModel, final String expectedBorders) {
// given
final Context context = Context.newContext(new Object());
final ContextModelsStack contextModelsStack = new ContextModelsStack(asList(currentModel));
final ContextModelsStack.Factory contextStackFactory = mock(ContextModelsStack.Factory.class);
given(contextStackFactory.from(context)).willReturn(contextModelsStack);
borderHelper = BorderHelper.with(contextStackFactory);
final Options options = OptionsStub.with(context);
// when
final CharSequence actualBorders = borderHelper.apply(null, options).toString();
// then
assertThat("Helper returns HTML with a child border", actualBorders, is(expectedBorders));
}
use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class BorderHelperTest method returnsShortVerticalBorder_whenElementIsLastPropertyOfParent.
@Test
@UseDataProvider("lastChildModels")
public void returnsShortVerticalBorder_whenElementIsLastPropertyOfParent(final Schema currentModel, final Schema parentModel, final String expectedBorders) {
// given
final Context context = Context.newContext(new Object());
final ContextModelsStack contextModelsStack = new ContextModelsStack(asList(currentModel, parentModel));
final ContextModelsStack.Factory contextStackFactory = mock(ContextModelsStack.Factory.class);
given(contextStackFactory.from(context)).willReturn(contextModelsStack);
borderHelper = BorderHelper.with(contextStackFactory);
final Options options = OptionsStub.with(context);
// when
final CharSequence actualBorders = borderHelper.apply(null, options).toString();
// then
assertThat("Helper returns HTML with one short vertical border", actualBorders, is(expectedBorders));
}
Aggregations