func (s *JsonTemplateSuite) TestLayout() {
	temp, _ := templates.NewJsonTemplate(inputBytes())

	layout := temp.Layout()
	assert.NotNil(s.T(), layout, "Layout can't be nil")
	assert.EqualValues(s.T(), "L", layout.Orientation(), "Orientation is not correct")
	assert.EqualValues(s.T(), "mm", layout.Unit(), "Unit is not correct")
	assert.EqualValues(s.T(), 50, layout.Width(), "Width is not correct")
	assert.EqualValues(s.T(), 75, layout.Height(), "Height is not correct")
}
func (s *JsonTemplateSuite) TestLoadLine() {
	template_data, _ := utils.LoadTemplate("test-pdf")
	temp, _ := templates.NewJsonTemplate(template_data)
	block_data := map[string]interface{}{"type": "line"}
	input_data := map[string]interface{}{}

	block := temp.LoadBlock(block_data, input_data)

	var rct *templates.Line
	assert.IsType(s.T(), rct, block)
}
func (s *JsonTemplateSuite) TestLoadImage() {
	template_data, _ := utils.LoadTemplate("test-pdf")
	temp, _ := templates.NewJsonTemplate(template_data)
	block_data := map[string]interface{}{"type": "image", "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1e/Wikipedia-logo-v2-es.svg/2000px-Wikipedia-logo-v2-es.svg.png"}
	input_data := map[string]interface{}{}

	block := temp.LoadBlock(block_data, input_data)

	var img *templates.Image
	assert.IsType(s.T(), img, block)
}
func (s *JsonTemplateSuite) TestLoadBlock() {
	temp, _ := templates.NewJsonTemplate(inputBytes())

	temp.LoadBlocks(userInput())

	blocks := temp.Blocks()
	assert.NotNil(s.T(), blocks[0])

	var img *templates.Image
	assert.IsType(s.T(), img, blocks[0])
}
func (s *JsonTemplateSuite) TestLoadAddPage() {
	template_data, _ := utils.LoadTemplate("test-pdf")
	temp, _ := templates.NewJsonTemplate(template_data)
	block_data := map[string]interface{}{"type": "add_page"}
	input_data := map[string]interface{}{}

	block := temp.LoadBlock(block_data, input_data)

	var pg *templates.AddPage
	assert.IsType(s.T(), pg, block)
}
Exemple #6
0
func (s *ImageBlockSuite) TestLoadOverwrite() {
	reader := bytes.NewReader([]byte{})
	img := &templates.Image{"url", 20, 20, 50, 50, "image/jpeg", reader}
	template_data, _ := utils.LoadTemplate("test-pdf")
	template, _ := templates.NewJsonTemplate(template_data)

	block_data := map[string]interface{}{}
	user_input := map[string]interface{}{"url": "new-url"}

	img.Load(template, block_data, user_input)

	assert.EqualValues(s.T(), "new-url", img.Url)
}
func (s *JsonTemplateSuite) TestBlocks() {
	temp, _ := templates.NewJsonTemplate(inputBytes())

	blocks := temp.Blocks()
	assert.Nil(s.T(), blocks)
}
func (s *JsonTemplateSuite) TestNewJsonTemplate() {
	temp, err := templates.NewJsonTemplate(inputBytes())

	assert.NotNil(s.T(), temp, "Template can't be nil")
	assert.Nil(s.T(), err, "Template not created properly")
}