Search in sources :

Example 21 with Options

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."));
    }
}
Also used : Options(com.github.jknack.handlebars.Options) IOException(java.io.IOException) Test(org.junit.Test)

Example 22 with Options

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));
}
Also used : Context(com.github.jknack.handlebars.Context) Options(com.github.jknack.handlebars.Options) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.junit.Test)

Example 23 with Options

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));
}
Also used : Context(com.github.jknack.handlebars.Context) Options(com.github.jknack.handlebars.Options) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.junit.Test)

Example 24 with Options

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));
}
Also used : Context(com.github.jknack.handlebars.Context) Options(com.github.jknack.handlebars.Options) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 25 with Options

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));
}
Also used : Context(com.github.jknack.handlebars.Context) Options(com.github.jknack.handlebars.Options) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

Options (com.github.jknack.handlebars.Options)36 Test (org.junit.Test)35 Context (com.github.jknack.handlebars.Context)8 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)5 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 IOException (java.io.IOException)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)3 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)3 Schema (io.swagger.v3.oas.models.media.Schema)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Metacard (ddf.catalog.data.Metacard)2 ThrowingRunnable (org.junit.function.ThrowingRunnable)2 UncheckedIOException (java.io.UncheckedIOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Hash (uk.nhs.digital.common.components.apispecification.handlebars.OptionsStub.Hash)1 RandomTestUtils.randomString (uk.nhs.digital.test.util.RandomTestUtils.randomString)1