From 8a8d5d6a6a946177a8256ab40b86cd703548665d Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 26 Sep 2024 20:04:23 -0300 Subject: [PATCH 001/116] feature: configure pdf processor framework Define interfaces that the pdf generator will depend on --- pkg/processor/components/factory.go | 13 +++++++++ pkg/processor/core/core.go | 23 +++++++++++++++ pkg/processor/processor.go | 45 +++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 pkg/processor/components/factory.go create mode 100644 pkg/processor/core/core.go create mode 100644 pkg/processor/processor.go diff --git a/pkg/processor/components/factory.go b/pkg/processor/components/factory.go new file mode 100644 index 00000000..f31ae815 --- /dev/null +++ b/pkg/processor/components/factory.go @@ -0,0 +1,13 @@ +package components + +import "github.com/johnfercher/maroto/v2/pkg/processor/core" + +type FactoryComponents struct{} + +func NewFactoryComponents() *FactoryComponents { + return &FactoryComponents{} +} + +func (f *FactoryComponents) FactoryComponentTree(template interface{}, content map[string]interface{}) (core.Component, error) { + return nil, nil +} diff --git a/pkg/processor/core/core.go b/pkg/processor/core/core.go new file mode 100644 index 00000000..15684eba --- /dev/null +++ b/pkg/processor/core/core.go @@ -0,0 +1,23 @@ +package core + +type Processor interface { + RegisterTemplate(template string) error + GenerateDocument(templateId int, content string) []byte +} + +type Repository interface { + RegisterTemplate(template string) error + ReadTemplate(templateId int) (string, error) +} + +type DocumentDeserializer[T interface{}] interface { + DesserializeTemplate(template string) (T, error) + DesserializeContent(content string) (map[string]interface{}, error) +} + +type Component interface { +} + +type Provider interface { + GeneratePdf(componentTree Component) ([]byte, error) +} diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go new file mode 100644 index 00000000..9b5fedef --- /dev/null +++ b/pkg/processor/processor.go @@ -0,0 +1,45 @@ +package processor + +import ( + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/core" +) + +type processor struct { + repository core.Repository + deserializer core.DocumentDeserializer[interface{}] + factory components.FactoryComponents + provider core.Provider +} + +func NewProcessor() *processor { + return &processor{} +} + +func (p *processor) RegisterTemplate(template string) error { + return p.repository.RegisterTemplate(template) +} + +func (p *processor) GenerateDocument(templateId int, content string) ([]byte, error) { + templateJson, err := p.repository.ReadTemplate(templateId) + if err != nil { + return nil, err + } + + documentTemplate, err := p.deserializer.DesserializeTemplate(templateJson) + if err != nil { + return nil, err + } + + documentContent, err := p.deserializer.DesserializeContent(templateJson) + if err != nil { + return nil, err + } + + componentTree, err := p.factory.FactoryComponentTree(documentTemplate, documentContent) + if err != nil { + return nil, err + } + + return p.provider.GeneratePdf(componentTree) +} From 9987468c18fa3aa2a73db75835292641bb788aa6 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 26 Sep 2024 20:35:31 -0300 Subject: [PATCH 002/116] feature: implement an in-memory repository --- pkg/processor/core/core.go | 8 ++++---- pkg/processor/processor.go | 11 +++++----- pkg/processor/repository/memory_storage.go | 24 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 pkg/processor/repository/memory_storage.go diff --git a/pkg/processor/core/core.go b/pkg/processor/core/core.go index 15684eba..d6dce55d 100644 --- a/pkg/processor/core/core.go +++ b/pkg/processor/core/core.go @@ -1,13 +1,13 @@ package core type Processor interface { - RegisterTemplate(template string) error - GenerateDocument(templateId int, content string) []byte + RegisterTemplate(templateName string, template string) error + GenerateDocument(templateName string, content string) []byte } type Repository interface { - RegisterTemplate(template string) error - ReadTemplate(templateId int) (string, error) + RegisterTemplate(name string, template string) error + ReadTemplate(templateName string) (string, error) } type DocumentDeserializer[T interface{}] interface { diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index 9b5fedef..8c05a84a 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -3,6 +3,7 @@ package processor import ( "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/core" + "github.com/johnfercher/maroto/v2/pkg/processor/repository" ) type processor struct { @@ -13,15 +14,15 @@ type processor struct { } func NewProcessor() *processor { - return &processor{} + return &processor{repository: repository.NewMemoryStorage()} } -func (p *processor) RegisterTemplate(template string) error { - return p.repository.RegisterTemplate(template) +func (p *processor) RegisterTemplate(templateName string, template string) error { + return p.repository.RegisterTemplate(templateName, template) } -func (p *processor) GenerateDocument(templateId int, content string) ([]byte, error) { - templateJson, err := p.repository.ReadTemplate(templateId) +func (p *processor) GenerateDocument(templateName string, content string) ([]byte, error) { + templateJson, err := p.repository.ReadTemplate(templateName) if err != nil { return nil, err } diff --git a/pkg/processor/repository/memory_storage.go b/pkg/processor/repository/memory_storage.go new file mode 100644 index 00000000..26cf0014 --- /dev/null +++ b/pkg/processor/repository/memory_storage.go @@ -0,0 +1,24 @@ +// repository package is responsible for managing access to templates +package repository + +type memoryStorage struct { + template map[string]string +} + +func NewMemoryStorage() *memoryStorage { + return &memoryStorage{} +} + +// RegisterTemplate is responsible for register a template in memory +// - name is the model identifier and is used to access it +// - template is the template that will be stored +func (m *memoryStorage) RegisterTemplate(name string, template string) error { + m.template[name] = template + return nil +} + +// ReadTemplate is responsible for fetching the stored template +// - name is the model identifier and is used to access it +func (m *memoryStorage) ReadTemplate(templateName string) (string, error) { + return m.template[templateName], nil +} From 6946142b7ea1ae170b67b1c9b1ddd592af9dfdaa Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 26 Sep 2024 21:02:58 -0300 Subject: [PATCH 003/116] feature: Implement json deserializer --- pkg/processor/components/factory.go | 7 +++-- pkg/processor/core/core.go | 8 +++-- .../deserializer/json_desserialize.go | 31 +++++++++++++++++++ pkg/processor/mappers/content.go | 4 +++ pkg/processor/mappers/template.go | 4 +++ pkg/processor/processor.go | 2 +- 6 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 pkg/processor/deserializer/json_desserialize.go create mode 100644 pkg/processor/mappers/content.go create mode 100644 pkg/processor/mappers/template.go diff --git a/pkg/processor/components/factory.go b/pkg/processor/components/factory.go index f31ae815..e686f86e 100644 --- a/pkg/processor/components/factory.go +++ b/pkg/processor/components/factory.go @@ -1,6 +1,9 @@ package components -import "github.com/johnfercher/maroto/v2/pkg/processor/core" +import ( + "github.com/johnfercher/maroto/v2/pkg/processor/core" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" +) type FactoryComponents struct{} @@ -8,6 +11,6 @@ func NewFactoryComponents() *FactoryComponents { return &FactoryComponents{} } -func (f *FactoryComponents) FactoryComponentTree(template interface{}, content map[string]interface{}) (core.Component, error) { +func (f *FactoryComponents) FactoryComponentTree(template mappers.Template, content mappers.Content) (core.Component, error) { return nil, nil } diff --git a/pkg/processor/core/core.go b/pkg/processor/core/core.go index d6dce55d..944c9d29 100644 --- a/pkg/processor/core/core.go +++ b/pkg/processor/core/core.go @@ -1,5 +1,7 @@ package core +import "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + type Processor interface { RegisterTemplate(templateName string, template string) error GenerateDocument(templateName string, content string) []byte @@ -10,9 +12,9 @@ type Repository interface { ReadTemplate(templateName string) (string, error) } -type DocumentDeserializer[T interface{}] interface { - DesserializeTemplate(template string) (T, error) - DesserializeContent(content string) (map[string]interface{}, error) +type DocumentDeserializer interface { + DesserializeTemplate(template string) (mappers.Template, error) + DesserializeContent(content string) (mappers.Content, error) } type Component interface { diff --git a/pkg/processor/deserializer/json_desserialize.go b/pkg/processor/deserializer/json_desserialize.go new file mode 100644 index 00000000..7fe02d7c --- /dev/null +++ b/pkg/processor/deserializer/json_desserialize.go @@ -0,0 +1,31 @@ +// The deserialize package is responsible for assembling the structures used in the processor according to the receiving string. +package deserializer + +import ( + "encoding/json" + + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" +) + +type jsonDeserializer struct { +} + +func NewJsonDeserialize() *jsonDeserializer { + return &jsonDeserializer{} +} + +// DesserializeTemplate is responsible for transforming a string into a template structure +func (j *jsonDeserializer) DesserializeTemplate(templateJson string) (mappers.Template, error) { + return deserializer[mappers.Template](templateJson) +} + +// DesserializeContent is responsible for transforming a string into a content structure +func (j *jsonDeserializer) DesserializeContent(contentJson string) (mappers.Content, error) { + return deserializer[mappers.Content](contentJson) +} + +func deserializer[T interface{}](jsonDocument string) (T, error) { + var document T + err := json.Unmarshal([]byte(jsonDocument), &document) + return document, err +} diff --git a/pkg/processor/mappers/content.go b/pkg/processor/mappers/content.go new file mode 100644 index 00000000..600fdf4c --- /dev/null +++ b/pkg/processor/mappers/content.go @@ -0,0 +1,4 @@ +package mappers + +type Content struct { +} diff --git a/pkg/processor/mappers/template.go b/pkg/processor/mappers/template.go new file mode 100644 index 00000000..27537de5 --- /dev/null +++ b/pkg/processor/mappers/template.go @@ -0,0 +1,4 @@ +package mappers + +type Template struct { +} diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index 8c05a84a..fe8ddfa7 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -8,7 +8,7 @@ import ( type processor struct { repository core.Repository - deserializer core.DocumentDeserializer[interface{}] + deserializer core.DocumentDeserializer factory components.FactoryComponents provider core.Provider } From bbd2f4f8e20759ea72fe32e98d6901aa436d2560 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Fri, 27 Sep 2024 17:40:42 -0300 Subject: [PATCH 004/116] feature: Add components that will be received in the template --- pkg/processor/components/factory.go | 16 ---------------- pkg/processor/core/core.go | 10 +++++++--- .../deserializer/json_desserialize.go | 11 ++++++----- pkg/processor/mappers/builder/buider.go | 5 +++++ pkg/processor/mappers/{ => content}/content.go | 2 +- pkg/processor/mappers/factory/factory.go | 18 ++++++++++++++++++ pkg/processor/mappers/foreach/foreach.go | 10 ++++++++++ pkg/processor/mappers/pages/pages.go | 10 ++++++++++ pkg/processor/mappers/rows/rows.go | 4 ++++ pkg/processor/mappers/template.go | 4 ---- pkg/processor/mappers/template/template.go | 17 +++++++++++++++++ pkg/processor/processor.go | 4 ++-- 12 files changed, 80 insertions(+), 31 deletions(-) delete mode 100644 pkg/processor/components/factory.go create mode 100644 pkg/processor/mappers/builder/buider.go rename pkg/processor/mappers/{ => content}/content.go (60%) create mode 100644 pkg/processor/mappers/factory/factory.go create mode 100644 pkg/processor/mappers/foreach/foreach.go create mode 100644 pkg/processor/mappers/pages/pages.go create mode 100644 pkg/processor/mappers/rows/rows.go delete mode 100644 pkg/processor/mappers/template.go create mode 100644 pkg/processor/mappers/template/template.go diff --git a/pkg/processor/components/factory.go b/pkg/processor/components/factory.go deleted file mode 100644 index e686f86e..00000000 --- a/pkg/processor/components/factory.go +++ /dev/null @@ -1,16 +0,0 @@ -package components - -import ( - "github.com/johnfercher/maroto/v2/pkg/processor/core" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers" -) - -type FactoryComponents struct{} - -func NewFactoryComponents() *FactoryComponents { - return &FactoryComponents{} -} - -func (f *FactoryComponents) FactoryComponentTree(template mappers.Template, content mappers.Content) (core.Component, error) { - return nil, nil -} diff --git a/pkg/processor/core/core.go b/pkg/processor/core/core.go index 944c9d29..50bf679c 100644 --- a/pkg/processor/core/core.go +++ b/pkg/processor/core/core.go @@ -1,6 +1,10 @@ package core -import "github.com/johnfercher/maroto/v2/pkg/processor/mappers" +import ( + "html/template" + + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/content" +) type Processor interface { RegisterTemplate(templateName string, template string) error @@ -13,8 +17,8 @@ type Repository interface { } type DocumentDeserializer interface { - DesserializeTemplate(template string) (mappers.Template, error) - DesserializeContent(content string) (mappers.Content, error) + DesserializeTemplate(template string) (template.Template, error) + DesserializeContent(content string) (content.Content, error) } type Component interface { diff --git a/pkg/processor/deserializer/json_desserialize.go b/pkg/processor/deserializer/json_desserialize.go index 7fe02d7c..eadd2166 100644 --- a/pkg/processor/deserializer/json_desserialize.go +++ b/pkg/processor/deserializer/json_desserialize.go @@ -3,8 +3,9 @@ package deserializer import ( "encoding/json" + "html/template" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/content" ) type jsonDeserializer struct { @@ -15,13 +16,13 @@ func NewJsonDeserialize() *jsonDeserializer { } // DesserializeTemplate is responsible for transforming a string into a template structure -func (j *jsonDeserializer) DesserializeTemplate(templateJson string) (mappers.Template, error) { - return deserializer[mappers.Template](templateJson) +func (j *jsonDeserializer) DesserializeTemplate(templateJson string) (template.Template, error) { + return deserializer[template.Template](templateJson) } // DesserializeContent is responsible for transforming a string into a content structure -func (j *jsonDeserializer) DesserializeContent(contentJson string) (mappers.Content, error) { - return deserializer[mappers.Content](contentJson) +func (j *jsonDeserializer) DesserializeContent(contentJson string) (content.Content, error) { + return deserializer[content.Content](contentJson) } func deserializer[T interface{}](jsonDocument string) (T, error) { diff --git a/pkg/processor/mappers/builder/buider.go b/pkg/processor/mappers/builder/buider.go new file mode 100644 index 00000000..13983808 --- /dev/null +++ b/pkg/processor/mappers/builder/buider.go @@ -0,0 +1,5 @@ +package builder + +// The builder is responsible for grouping the pdf settings +type Builder struct { +} diff --git a/pkg/processor/mappers/content.go b/pkg/processor/mappers/content/content.go similarity index 60% rename from pkg/processor/mappers/content.go rename to pkg/processor/mappers/content/content.go index 600fdf4c..a2e41527 100644 --- a/pkg/processor/mappers/content.go +++ b/pkg/processor/mappers/content/content.go @@ -1,4 +1,4 @@ -package mappers +package content type Content struct { } diff --git a/pkg/processor/mappers/factory/factory.go b/pkg/processor/mappers/factory/factory.go new file mode 100644 index 00000000..6e244844 --- /dev/null +++ b/pkg/processor/mappers/factory/factory.go @@ -0,0 +1,18 @@ +package factory + +import ( + "html/template" + + "github.com/johnfercher/maroto/v2/pkg/processor/core" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/content" +) + +type FactoryComponents struct{} + +func NewFactoryComponents() *FactoryComponents { + return &FactoryComponents{} +} + +func (f *FactoryComponents) FactoryComponentTree(template template.Template, content content.Content) (core.Component, error) { + return nil, nil +} diff --git a/pkg/processor/mappers/foreach/foreach.go b/pkg/processor/mappers/foreach/foreach.go new file mode 100644 index 00000000..2d2af511 --- /dev/null +++ b/pkg/processor/mappers/foreach/foreach.go @@ -0,0 +1,10 @@ +package foreach + +// ForEach is responsible for generating a list of Pages for each group of information +type ForEach[T interface{}] struct { + // SourceKey defines the word that will be used to search the page content. + SourceKey string + + // Pages define the group of pages that should be created for each content group found + Pages []T +} diff --git a/pkg/processor/mappers/pages/pages.go b/pkg/processor/mappers/pages/pages.go new file mode 100644 index 00000000..776b3e36 --- /dev/null +++ b/pkg/processor/mappers/pages/pages.go @@ -0,0 +1,10 @@ +package pages + +import ( + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/foreach" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rows" +) + +type Page struct { + ForEach foreach.ForEach[rows.Row] +} diff --git a/pkg/processor/mappers/rows/rows.go b/pkg/processor/mappers/rows/rows.go new file mode 100644 index 00000000..9a4ec84d --- /dev/null +++ b/pkg/processor/mappers/rows/rows.go @@ -0,0 +1,4 @@ +package rows + +type Row struct { +} diff --git a/pkg/processor/mappers/template.go b/pkg/processor/mappers/template.go deleted file mode 100644 index 27537de5..00000000 --- a/pkg/processor/mappers/template.go +++ /dev/null @@ -1,4 +0,0 @@ -package mappers - -type Template struct { -} diff --git a/pkg/processor/mappers/template/template.go b/pkg/processor/mappers/template/template.go new file mode 100644 index 00000000..acec05e1 --- /dev/null +++ b/pkg/processor/mappers/template/template.go @@ -0,0 +1,17 @@ +package mappers + +import ( + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/builder" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/foreach" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pages" +) + +// Template defines the structure that should be at the top level of the template. +// It allows you to add PDF settings and add a list of pages. +type Template struct { + // The builder defines the PDF settings + Builder builder.Builder + + // ForEach defines the structure that will allow you to add a list of pages to the template + ForEach foreach.ForEach[pages.Page] +} diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index fe8ddfa7..a98c12d0 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -1,15 +1,15 @@ package processor import ( - "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/core" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/factory" "github.com/johnfercher/maroto/v2/pkg/processor/repository" ) type processor struct { repository core.Repository deserializer core.DocumentDeserializer - factory components.FactoryComponents + factory factory.FactoryComponents provider core.Provider } From 97f3ce73ee632623e4bd0b3f9fd5e978bcfbf8fe Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 29 Sep 2024 10:42:04 -0300 Subject: [PATCH 005/116] feature: Add components that will be received in the template --- pkg/processor/mappers/builder/builder.go | 4 ++++ pkg/processor/mappers/col/col.go | 16 ++++++++++++++++ .../mappers/components/barcode/bar_code.go | 8 ++++++++ pkg/processor/mappers/components/image/image.go | 5 +++++ pkg/processor/mappers/components/text/text.go | 9 +++++++++ pkg/processor/mappers/page/page.go | 8 ++++++++ pkg/processor/mappers/pdf/pdf.go | 11 +++++++++++ pkg/processor/mappers/props/barcode/bar_code.go | 5 +++++ pkg/processor/mappers/props/col/col.go | 5 +++++ pkg/processor/mappers/props/text/text.go | 5 +++++ pkg/processor/mappers/row/row.go | 8 ++++++++ 11 files changed, 84 insertions(+) create mode 100644 pkg/processor/mappers/builder/builder.go create mode 100644 pkg/processor/mappers/col/col.go create mode 100644 pkg/processor/mappers/components/barcode/bar_code.go create mode 100644 pkg/processor/mappers/components/image/image.go create mode 100644 pkg/processor/mappers/components/text/text.go create mode 100644 pkg/processor/mappers/page/page.go create mode 100644 pkg/processor/mappers/pdf/pdf.go create mode 100644 pkg/processor/mappers/props/barcode/bar_code.go create mode 100644 pkg/processor/mappers/props/col/col.go create mode 100644 pkg/processor/mappers/props/text/text.go create mode 100644 pkg/processor/mappers/row/row.go diff --git a/pkg/processor/mappers/builder/builder.go b/pkg/processor/mappers/builder/builder.go new file mode 100644 index 00000000..3db90bfb --- /dev/null +++ b/pkg/processor/mappers/builder/builder.go @@ -0,0 +1,4 @@ +package builder + +type Builder struct { +} diff --git a/pkg/processor/mappers/col/col.go b/pkg/processor/mappers/col/col.go new file mode 100644 index 00000000..cc978f73 --- /dev/null +++ b/pkg/processor/mappers/col/col.go @@ -0,0 +1,16 @@ +package col + +import ( + "image" + + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/barcode" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/text" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/props/col" +) + +type Col struct { + Props col.ColProps `json:"props"` + Text []text.Text `json:"text"` + BarCode []barcode.BarCode `json:"bar_code"` + Image []image.Image `json:"image"` +} diff --git a/pkg/processor/mappers/components/barcode/bar_code.go b/pkg/processor/mappers/components/barcode/bar_code.go new file mode 100644 index 00000000..02618f18 --- /dev/null +++ b/pkg/processor/mappers/components/barcode/bar_code.go @@ -0,0 +1,8 @@ +package barcode + +import "github.com/johnfercher/maroto/v2/pkg/processor/mappers/props/barcode" + +type BarCode struct { + Props barcode.BarCodeProps `json:"props"` + Source_key string `json:"source_key"` +} diff --git a/pkg/processor/mappers/components/image/image.go b/pkg/processor/mappers/components/image/image.go new file mode 100644 index 00000000..2971466e --- /dev/null +++ b/pkg/processor/mappers/components/image/image.go @@ -0,0 +1,5 @@ +package image + +type Image struct { + SourceKey string `json:"source_key"` +} diff --git a/pkg/processor/mappers/components/text/text.go b/pkg/processor/mappers/components/text/text.go new file mode 100644 index 00000000..e69482bc --- /dev/null +++ b/pkg/processor/mappers/components/text/text.go @@ -0,0 +1,9 @@ +package text + +import "github.com/johnfercher/maroto/v2/pkg/processor/mappers/props/text" + +type Text struct { + Props text.TextProps `json:"props"` + SourceKey string `json:"source_key"` + Value string `json:"value"` +} diff --git a/pkg/processor/mappers/page/page.go b/pkg/processor/mappers/page/page.go new file mode 100644 index 00000000..02be2352 --- /dev/null +++ b/pkg/processor/mappers/page/page.go @@ -0,0 +1,8 @@ +package page + +import "github.com/johnfercher/maroto/v2/pkg/processor/mappers/row" + +type Page struct { + Header []row.Row `json:"header"` + Rows []row.Row `json:"rows"` +} diff --git a/pkg/processor/mappers/pdf/pdf.go b/pkg/processor/mappers/pdf/pdf.go new file mode 100644 index 00000000..76295960 --- /dev/null +++ b/pkg/processor/mappers/pdf/pdf.go @@ -0,0 +1,11 @@ +package pdf + +import ( + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/builder" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/page" +) + +type Pdf struct { + Builder builder.Builder `json:"builder"` + Pages map[string]page.Page `json:"pages"` +} diff --git a/pkg/processor/mappers/props/barcode/bar_code.go b/pkg/processor/mappers/props/barcode/bar_code.go new file mode 100644 index 00000000..bd2754a1 --- /dev/null +++ b/pkg/processor/mappers/props/barcode/bar_code.go @@ -0,0 +1,5 @@ +package barcode + +type BarCodeProps struct { + Align string `json:"align"` +} diff --git a/pkg/processor/mappers/props/col/col.go b/pkg/processor/mappers/props/col/col.go new file mode 100644 index 00000000..86721351 --- /dev/null +++ b/pkg/processor/mappers/props/col/col.go @@ -0,0 +1,5 @@ +package col + +type ColProps struct { + Size int `json:"size"` +} diff --git a/pkg/processor/mappers/props/text/text.go b/pkg/processor/mappers/props/text/text.go new file mode 100644 index 00000000..99c34817 --- /dev/null +++ b/pkg/processor/mappers/props/text/text.go @@ -0,0 +1,5 @@ +package text + +type TextProps struct { + Align string `json:"align"` +} diff --git a/pkg/processor/mappers/row/row.go b/pkg/processor/mappers/row/row.go new file mode 100644 index 00000000..3fca191a --- /dev/null +++ b/pkg/processor/mappers/row/row.go @@ -0,0 +1,8 @@ +package row + +import "github.com/johnfercher/maroto/v2/pkg/processor/mappers/col" + +type Row struct { + List string `json:"list"` + Cols []col.Col `json:"cols"` +} From f8ffc58af15b75f6e5d9ab3bd4cfb58c76269509 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 29 Sep 2024 10:43:58 -0300 Subject: [PATCH 006/116] fix: update json deserializer to use new pdf struct --- pkg/processor/deserializer/json_desserialize.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/processor/deserializer/json_desserialize.go b/pkg/processor/deserializer/json_desserialize.go index eadd2166..c0689fbb 100644 --- a/pkg/processor/deserializer/json_desserialize.go +++ b/pkg/processor/deserializer/json_desserialize.go @@ -3,9 +3,9 @@ package deserializer import ( "encoding/json" - "html/template" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/content" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pdf" ) type jsonDeserializer struct { @@ -16,8 +16,8 @@ func NewJsonDeserialize() *jsonDeserializer { } // DesserializeTemplate is responsible for transforming a string into a template structure -func (j *jsonDeserializer) DesserializeTemplate(templateJson string) (template.Template, error) { - return deserializer[template.Template](templateJson) +func (j *jsonDeserializer) DesserializeTemplate(templateJson string) (pdf.Pdf, error) { + return deserializer[pdf.Pdf](templateJson) } // DesserializeContent is responsible for transforming a string into a content structure From c10f608218778b2e3de088893c7a7916d2f33cc1 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 29 Sep 2024 12:35:43 -0300 Subject: [PATCH 007/116] feat: implement content deserialization --- pkg/processor/core/core.go | 4 +--- pkg/processor/deserializer/json_desserialize.go | 7 +++---- pkg/processor/mappers/builder/buider.go | 5 ----- pkg/processor/mappers/content/content.go | 4 ---- pkg/processor/mappers/factory/factory.go | 3 +-- pkg/processor/mappers/foreach/foreach.go | 10 ---------- pkg/processor/mappers/pages/pages.go | 10 ---------- pkg/processor/mappers/rows/rows.go | 4 ---- pkg/processor/mappers/template/template.go | 17 ----------------- 9 files changed, 5 insertions(+), 59 deletions(-) delete mode 100644 pkg/processor/mappers/builder/buider.go delete mode 100644 pkg/processor/mappers/content/content.go delete mode 100644 pkg/processor/mappers/foreach/foreach.go delete mode 100644 pkg/processor/mappers/pages/pages.go delete mode 100644 pkg/processor/mappers/rows/rows.go delete mode 100644 pkg/processor/mappers/template/template.go diff --git a/pkg/processor/core/core.go b/pkg/processor/core/core.go index 50bf679c..27da26d5 100644 --- a/pkg/processor/core/core.go +++ b/pkg/processor/core/core.go @@ -2,8 +2,6 @@ package core import ( "html/template" - - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/content" ) type Processor interface { @@ -18,7 +16,7 @@ type Repository interface { type DocumentDeserializer interface { DesserializeTemplate(template string) (template.Template, error) - DesserializeContent(content string) (content.Content, error) + DesserializeContent(content string) (map[string]interface{}, error) } type Component interface { diff --git a/pkg/processor/deserializer/json_desserialize.go b/pkg/processor/deserializer/json_desserialize.go index c0689fbb..abb36d76 100644 --- a/pkg/processor/deserializer/json_desserialize.go +++ b/pkg/processor/deserializer/json_desserialize.go @@ -4,7 +4,6 @@ package deserializer import ( "encoding/json" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/content" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pdf" ) @@ -20,9 +19,9 @@ func (j *jsonDeserializer) DesserializeTemplate(templateJson string) (pdf.Pdf, e return deserializer[pdf.Pdf](templateJson) } -// DesserializeContent is responsible for transforming a string into a content structure -func (j *jsonDeserializer) DesserializeContent(contentJson string) (content.Content, error) { - return deserializer[content.Content](contentJson) +// DesserializeContent is responsible for transforming a string into a content map +func (j *jsonDeserializer) DesserializeContent(contentJson string) (map[string]interface{}, error) { + return deserializer[map[string]interface{}](contentJson) } func deserializer[T interface{}](jsonDocument string) (T, error) { diff --git a/pkg/processor/mappers/builder/buider.go b/pkg/processor/mappers/builder/buider.go deleted file mode 100644 index 13983808..00000000 --- a/pkg/processor/mappers/builder/buider.go +++ /dev/null @@ -1,5 +0,0 @@ -package builder - -// The builder is responsible for grouping the pdf settings -type Builder struct { -} diff --git a/pkg/processor/mappers/content/content.go b/pkg/processor/mappers/content/content.go deleted file mode 100644 index a2e41527..00000000 --- a/pkg/processor/mappers/content/content.go +++ /dev/null @@ -1,4 +0,0 @@ -package content - -type Content struct { -} diff --git a/pkg/processor/mappers/factory/factory.go b/pkg/processor/mappers/factory/factory.go index 6e244844..26dcad41 100644 --- a/pkg/processor/mappers/factory/factory.go +++ b/pkg/processor/mappers/factory/factory.go @@ -4,7 +4,6 @@ import ( "html/template" "github.com/johnfercher/maroto/v2/pkg/processor/core" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/content" ) type FactoryComponents struct{} @@ -13,6 +12,6 @@ func NewFactoryComponents() *FactoryComponents { return &FactoryComponents{} } -func (f *FactoryComponents) FactoryComponentTree(template template.Template, content content.Content) (core.Component, error) { +func (f *FactoryComponents) FactoryComponentTree(template template.Template, content map[string]interface{}) (core.Component, error) { return nil, nil } diff --git a/pkg/processor/mappers/foreach/foreach.go b/pkg/processor/mappers/foreach/foreach.go deleted file mode 100644 index 2d2af511..00000000 --- a/pkg/processor/mappers/foreach/foreach.go +++ /dev/null @@ -1,10 +0,0 @@ -package foreach - -// ForEach is responsible for generating a list of Pages for each group of information -type ForEach[T interface{}] struct { - // SourceKey defines the word that will be used to search the page content. - SourceKey string - - // Pages define the group of pages that should be created for each content group found - Pages []T -} diff --git a/pkg/processor/mappers/pages/pages.go b/pkg/processor/mappers/pages/pages.go deleted file mode 100644 index 776b3e36..00000000 --- a/pkg/processor/mappers/pages/pages.go +++ /dev/null @@ -1,10 +0,0 @@ -package pages - -import ( - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/foreach" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rows" -) - -type Page struct { - ForEach foreach.ForEach[rows.Row] -} diff --git a/pkg/processor/mappers/rows/rows.go b/pkg/processor/mappers/rows/rows.go deleted file mode 100644 index 9a4ec84d..00000000 --- a/pkg/processor/mappers/rows/rows.go +++ /dev/null @@ -1,4 +0,0 @@ -package rows - -type Row struct { -} diff --git a/pkg/processor/mappers/template/template.go b/pkg/processor/mappers/template/template.go deleted file mode 100644 index acec05e1..00000000 --- a/pkg/processor/mappers/template/template.go +++ /dev/null @@ -1,17 +0,0 @@ -package mappers - -import ( - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/builder" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/foreach" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pages" -) - -// Template defines the structure that should be at the top level of the template. -// It allows you to add PDF settings and add a list of pages. -type Template struct { - // The builder defines the PDF settings - Builder builder.Builder - - // ForEach defines the structure that will allow you to add a list of pages to the template - ForEach foreach.ForEach[pages.Page] -} From 9f7c16f0e460dab3baa35cb48c64d983a24aac70 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 29 Sep 2024 19:38:09 -0300 Subject: [PATCH 008/116] feature: Generate PDF components create component package add generate method in component mappers --- pkg/processor/components/barcode/bar_code.go | 15 +++++ pkg/processor/components/builder/builder.go | 8 +++ pkg/processor/components/col/col.go | 18 ++++++ pkg/processor/components/components.go | 4 ++ pkg/processor/components/image/image.go | 9 +++ pkg/processor/components/page/page.go | 15 +++++ pkg/processor/components/pdf/pdf.go | 18 ++++++ pkg/processor/components/props/bar_code.go | 5 ++ pkg/processor/components/props/col.go | 5 ++ pkg/processor/components/props/text.go | 5 ++ pkg/processor/components/row/row.go | 13 ++++ pkg/processor/components/text/text.go | 15 +++++ pkg/processor/core/core.go | 10 ++- .../deserializer/json_desserialize.go | 2 +- pkg/processor/mappers/barcode/bar_code.go | 31 ++++++++++ pkg/processor/mappers/barcode/barcode_test.go | 1 + .../{builder => buildermapper}/builder.go | 2 +- .../mappers/buildermapper/builder_test.go | 1 + pkg/processor/mappers/col/col.go | 16 ----- pkg/processor/mappers/colmapper/col.go | 62 +++++++++++++++++++ pkg/processor/mappers/colmapper/col_test.go | 1 + pkg/processor/mappers/component_mapper.go | 7 +++ .../mappers/components/barcode/bar_code.go | 8 --- pkg/processor/mappers/components/text/text.go | 9 --- pkg/processor/mappers/factory/factory.go | 17 ----- .../mappers/{components => }/image/image.go | 0 pkg/processor/mappers/image/image_test.go | 1 + pkg/processor/mappers/page/page.go | 8 --- pkg/processor/mappers/pagemapper/page.go | 42 +++++++++++++ pkg/processor/mappers/pagemapper/page_test.go | 1 + pkg/processor/mappers/pdf/pdf.go | 11 ---- pkg/processor/mappers/pdfmapper/pdf.go | 42 +++++++++++++ pkg/processor/mappers/pdfmapper/pdf_test.go | 1 + .../barcode => propsmapper}/bar_code.go | 2 +- .../mappers/{props/col => propsmapper}/col.go | 2 +- .../{props/text => propsmapper}/text.go | 2 +- pkg/processor/mappers/row/row.go | 8 --- pkg/processor/mappers/rowmapper/row.go | 59 ++++++++++++++++++ pkg/processor/mappers/rowmapper/row_test.go | 1 + pkg/processor/mappers/text/text.go | 36 +++++++++++ pkg/processor/mappers/text/text_test.go | 1 + pkg/processor/processor.go | 6 +- 42 files changed, 428 insertions(+), 92 deletions(-) create mode 100644 pkg/processor/components/barcode/bar_code.go create mode 100644 pkg/processor/components/builder/builder.go create mode 100644 pkg/processor/components/col/col.go create mode 100644 pkg/processor/components/components.go create mode 100644 pkg/processor/components/image/image.go create mode 100644 pkg/processor/components/page/page.go create mode 100644 pkg/processor/components/pdf/pdf.go create mode 100644 pkg/processor/components/props/bar_code.go create mode 100644 pkg/processor/components/props/col.go create mode 100644 pkg/processor/components/props/text.go create mode 100644 pkg/processor/components/row/row.go create mode 100644 pkg/processor/components/text/text.go create mode 100644 pkg/processor/mappers/barcode/bar_code.go create mode 100644 pkg/processor/mappers/barcode/barcode_test.go rename pkg/processor/mappers/{builder => buildermapper}/builder.go (53%) create mode 100644 pkg/processor/mappers/buildermapper/builder_test.go delete mode 100644 pkg/processor/mappers/col/col.go create mode 100644 pkg/processor/mappers/colmapper/col.go create mode 100644 pkg/processor/mappers/colmapper/col_test.go create mode 100644 pkg/processor/mappers/component_mapper.go delete mode 100644 pkg/processor/mappers/components/barcode/bar_code.go delete mode 100644 pkg/processor/mappers/components/text/text.go delete mode 100644 pkg/processor/mappers/factory/factory.go rename pkg/processor/mappers/{components => }/image/image.go (100%) create mode 100644 pkg/processor/mappers/image/image_test.go delete mode 100644 pkg/processor/mappers/page/page.go create mode 100644 pkg/processor/mappers/pagemapper/page.go create mode 100644 pkg/processor/mappers/pagemapper/page_test.go delete mode 100644 pkg/processor/mappers/pdf/pdf.go create mode 100644 pkg/processor/mappers/pdfmapper/pdf.go create mode 100644 pkg/processor/mappers/pdfmapper/pdf_test.go rename pkg/processor/mappers/{props/barcode => propsmapper}/bar_code.go (74%) rename pkg/processor/mappers/{props/col => propsmapper}/col.go (71%) rename pkg/processor/mappers/{props/text => propsmapper}/text.go (73%) delete mode 100644 pkg/processor/mappers/row/row.go create mode 100644 pkg/processor/mappers/rowmapper/row.go create mode 100644 pkg/processor/mappers/rowmapper/row_test.go create mode 100644 pkg/processor/mappers/text/text.go create mode 100644 pkg/processor/mappers/text/text_test.go diff --git a/pkg/processor/components/barcode/bar_code.go b/pkg/processor/components/barcode/bar_code.go new file mode 100644 index 00000000..92c9e0e1 --- /dev/null +++ b/pkg/processor/components/barcode/bar_code.go @@ -0,0 +1,15 @@ +package barcode + +import "github.com/johnfercher/maroto/v2/pkg/processor/components/props" + +type BarCode struct { + Props props.BarCodeProps + Code string +} + +func NewBarCode(props props.BarCodeProps, code string) *BarCode { + return &BarCode{ + Code: code, + Props: props, + } +} diff --git a/pkg/processor/components/builder/builder.go b/pkg/processor/components/builder/builder.go new file mode 100644 index 00000000..476e13e9 --- /dev/null +++ b/pkg/processor/components/builder/builder.go @@ -0,0 +1,8 @@ +package builder + +type Builder struct { +} + +func NewBuilder() *Builder { + return nil +} diff --git a/pkg/processor/components/col/col.go b/pkg/processor/components/col/col.go new file mode 100644 index 00000000..b1019cb6 --- /dev/null +++ b/pkg/processor/components/col/col.go @@ -0,0 +1,18 @@ +package col + +import ( + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/components/props" +) + +type Col struct { + Props props.ColProps + Components components.Component +} + +func NewCol(props props.ColProps, components ...components.Component) *Col { + return &Col{ + Props: props, + Components: components, + } +} diff --git a/pkg/processor/components/components.go b/pkg/processor/components/components.go new file mode 100644 index 00000000..2925b9db --- /dev/null +++ b/pkg/processor/components/components.go @@ -0,0 +1,4 @@ +package components + +type Component interface { +} diff --git a/pkg/processor/components/image/image.go b/pkg/processor/components/image/image.go new file mode 100644 index 00000000..4e87b064 --- /dev/null +++ b/pkg/processor/components/image/image.go @@ -0,0 +1,9 @@ +package image + +type Image struct { + SourceKey string +} + +func NewImage() *Image { + return &Image{} +} diff --git a/pkg/processor/components/page/page.go b/pkg/processor/components/page/page.go new file mode 100644 index 00000000..6b3f5c61 --- /dev/null +++ b/pkg/processor/components/page/page.go @@ -0,0 +1,15 @@ +package page + +import "github.com/johnfercher/maroto/v2/pkg/processor/components/row" + +type Page struct { + Header []row.Row + Rows []row.Row +} + +func NewPage(header, rows []row.Row) *Page { + return &Page{ + Header: header, + Rows: rows, + } +} diff --git a/pkg/processor/components/pdf/pdf.go b/pkg/processor/components/pdf/pdf.go new file mode 100644 index 00000000..c638f384 --- /dev/null +++ b/pkg/processor/components/pdf/pdf.go @@ -0,0 +1,18 @@ +package pdf + +import ( + "github.com/johnfercher/maroto/v2/pkg/processor/components/builder" + "github.com/johnfercher/maroto/v2/pkg/processor/components/page" +) + +type Pdf struct { + Builder *builder.Builder + Pages []*page.Page +} + +func NewPdf(builder *builder.Builder, pages ...*page.Page) *Pdf { + return &Pdf{ + Builder: builder, + Pages: pages, + } +} diff --git a/pkg/processor/components/props/bar_code.go b/pkg/processor/components/props/bar_code.go new file mode 100644 index 00000000..05a44481 --- /dev/null +++ b/pkg/processor/components/props/bar_code.go @@ -0,0 +1,5 @@ +package props + +type BarCodeProps struct { + Align string +} diff --git a/pkg/processor/components/props/col.go b/pkg/processor/components/props/col.go new file mode 100644 index 00000000..a773f6c8 --- /dev/null +++ b/pkg/processor/components/props/col.go @@ -0,0 +1,5 @@ +package props + +type ColProps struct { + Size int +} diff --git a/pkg/processor/components/props/text.go b/pkg/processor/components/props/text.go new file mode 100644 index 00000000..04109095 --- /dev/null +++ b/pkg/processor/components/props/text.go @@ -0,0 +1,5 @@ +package props + +type TextProps struct { + Align string +} diff --git a/pkg/processor/components/row/row.go b/pkg/processor/components/row/row.go new file mode 100644 index 00000000..3cf14269 --- /dev/null +++ b/pkg/processor/components/row/row.go @@ -0,0 +1,13 @@ +package row + +import "github.com/johnfercher/maroto/v2/pkg/processor/components/col" + +type Row struct { + Cols []col.Col +} + +func NewRow(cols ...col.Col) *Row { + return &Row{ + Cols: cols, + } +} diff --git a/pkg/processor/components/text/text.go b/pkg/processor/components/text/text.go new file mode 100644 index 00000000..2c1e6df3 --- /dev/null +++ b/pkg/processor/components/text/text.go @@ -0,0 +1,15 @@ +package text + +import "github.com/johnfercher/maroto/v2/pkg/processor/components/props" + +type Text struct { + Props props.TextProps + Value string +} + +func NewText(props props.TextProps, value string) *Text { + return &Text{ + Props: props, + Value: value, + } +} diff --git a/pkg/processor/core/core.go b/pkg/processor/core/core.go index 27da26d5..47f19900 100644 --- a/pkg/processor/core/core.go +++ b/pkg/processor/core/core.go @@ -1,7 +1,8 @@ package core import ( - "html/template" + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pdfmapper" ) type Processor interface { @@ -15,13 +16,10 @@ type Repository interface { } type DocumentDeserializer interface { - DesserializeTemplate(template string) (template.Template, error) + DesserializeTemplate(template string) (pdfmapper.Pdf, error) DesserializeContent(content string) (map[string]interface{}, error) } -type Component interface { -} - type Provider interface { - GeneratePdf(componentTree Component) ([]byte, error) + GeneratePdf(componentTree components.Component) ([]byte, error) } diff --git a/pkg/processor/deserializer/json_desserialize.go b/pkg/processor/deserializer/json_desserialize.go index abb36d76..3ab665e5 100644 --- a/pkg/processor/deserializer/json_desserialize.go +++ b/pkg/processor/deserializer/json_desserialize.go @@ -4,7 +4,7 @@ package deserializer import ( "encoding/json" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pdf" + pdf "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pdfmapper" ) type jsonDeserializer struct { diff --git a/pkg/processor/mappers/barcode/bar_code.go b/pkg/processor/mappers/barcode/bar_code.go new file mode 100644 index 00000000..86454d9f --- /dev/null +++ b/pkg/processor/mappers/barcode/bar_code.go @@ -0,0 +1,31 @@ +// barcode is the package responsible for mapping barcode settings +package barcode + +import ( + "fmt" + + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/components/barcode" + "github.com/johnfercher/maroto/v2/pkg/processor/components/props" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" +) + +type BarCode struct { + Props propsmapper.BarCodeProps `json:"props"` + SourceKey string `json:"source_key"` +} + +// generate is responsible for the builder barcode according to the submitted content +func (b *BarCode) Generate(content map[string]interface{}) (components.Component, error) { + value, ok := content[b.SourceKey] + if !ok { + return nil, fmt.Errorf("barcode model needs source key %s, but no content with that key was found", b.SourceKey) + } + + code, ok := value.(string) + if !ok { + return nil, fmt.Errorf("resource %s does not have a valid value for the barcode component", b.SourceKey) + } + + return barcode.NewBarCode(props.BarCodeProps{Align: b.Props.Align}, code), nil +} diff --git a/pkg/processor/mappers/barcode/barcode_test.go b/pkg/processor/mappers/barcode/barcode_test.go new file mode 100644 index 00000000..91bc1006 --- /dev/null +++ b/pkg/processor/mappers/barcode/barcode_test.go @@ -0,0 +1 @@ +package barcode_test diff --git a/pkg/processor/mappers/builder/builder.go b/pkg/processor/mappers/buildermapper/builder.go similarity index 53% rename from pkg/processor/mappers/builder/builder.go rename to pkg/processor/mappers/buildermapper/builder.go index 3db90bfb..1c4cb0b9 100644 --- a/pkg/processor/mappers/builder/builder.go +++ b/pkg/processor/mappers/buildermapper/builder.go @@ -1,4 +1,4 @@ -package builder +package buildermapper type Builder struct { } diff --git a/pkg/processor/mappers/buildermapper/builder_test.go b/pkg/processor/mappers/buildermapper/builder_test.go new file mode 100644 index 00000000..ee7eceab --- /dev/null +++ b/pkg/processor/mappers/buildermapper/builder_test.go @@ -0,0 +1 @@ +package buildermapper_test diff --git a/pkg/processor/mappers/col/col.go b/pkg/processor/mappers/col/col.go deleted file mode 100644 index cc978f73..00000000 --- a/pkg/processor/mappers/col/col.go +++ /dev/null @@ -1,16 +0,0 @@ -package col - -import ( - "image" - - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/barcode" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/text" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/props/col" -) - -type Col struct { - Props col.ColProps `json:"props"` - Text []text.Text `json:"text"` - BarCode []barcode.BarCode `json:"bar_code"` - Image []image.Image `json:"image"` -} diff --git a/pkg/processor/mappers/colmapper/col.go b/pkg/processor/mappers/colmapper/col.go new file mode 100644 index 00000000..55bc6959 --- /dev/null +++ b/pkg/processor/mappers/colmapper/col.go @@ -0,0 +1,62 @@ +// colmapper is the package responsible for mapping col settings +package colmapper + +import ( + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/components/col" + "github.com/johnfercher/maroto/v2/pkg/processor/components/props" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/barcode" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/image" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" + + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/text" +) + +type Col struct { + Props propsmapper.ColProps `json:"props"` + Text []text.Text `json:"text"` + BarCode []barcode.BarCode `json:"bar_code"` + Image []image.Image `json:"image"` +} + +// generate is responsible for the builder col according to the submitted content +func (c *Col) Generate(content map[string]interface{}) (*col.Col, error) { + components, err := c.factoryComponents(content) + if err != nil { + return nil, err + } + return col.NewCol(props.ColProps{Size: c.Props.Size}, components), nil +} + +func (c *Col) factoryComponents(content map[string]interface{}) ([]components.Component, error) { + componentsTemplate := make([]mappers.Componentmapper, 1) + + for _, text := range c.Text { + componentsTemplate = append(componentsTemplate, &text) + } + + for _, barcode := range c.BarCode { + componentsTemplate = append(componentsTemplate, &barcode) + } + + components, err := c.generateComponents(content, componentsTemplate...) + if err != nil { + return nil, err + } + + return components, nil +} + +func (c *Col) generateComponents(content map[string]interface{}, templates ...mappers.Componentmapper) ([]components.Component, error) { + components := make([]components.Component, len(templates)) + + for _, template := range templates { + component, err := template.Generate(content) + if err != nil { + return nil, err + } + components = append(components, component) + } + return components, nil +} diff --git a/pkg/processor/mappers/colmapper/col_test.go b/pkg/processor/mappers/colmapper/col_test.go new file mode 100644 index 00000000..87251be4 --- /dev/null +++ b/pkg/processor/mappers/colmapper/col_test.go @@ -0,0 +1 @@ +package colmapper_test diff --git a/pkg/processor/mappers/component_mapper.go b/pkg/processor/mappers/component_mapper.go new file mode 100644 index 00000000..61848e65 --- /dev/null +++ b/pkg/processor/mappers/component_mapper.go @@ -0,0 +1,7 @@ +package mappers + +import "github.com/johnfercher/maroto/v2/pkg/processor/components" + +type Componentmapper interface { + Generate(content map[string]interface{}) (components.Component, error) +} diff --git a/pkg/processor/mappers/components/barcode/bar_code.go b/pkg/processor/mappers/components/barcode/bar_code.go deleted file mode 100644 index 02618f18..00000000 --- a/pkg/processor/mappers/components/barcode/bar_code.go +++ /dev/null @@ -1,8 +0,0 @@ -package barcode - -import "github.com/johnfercher/maroto/v2/pkg/processor/mappers/props/barcode" - -type BarCode struct { - Props barcode.BarCodeProps `json:"props"` - Source_key string `json:"source_key"` -} diff --git a/pkg/processor/mappers/components/text/text.go b/pkg/processor/mappers/components/text/text.go deleted file mode 100644 index e69482bc..00000000 --- a/pkg/processor/mappers/components/text/text.go +++ /dev/null @@ -1,9 +0,0 @@ -package text - -import "github.com/johnfercher/maroto/v2/pkg/processor/mappers/props/text" - -type Text struct { - Props text.TextProps `json:"props"` - SourceKey string `json:"source_key"` - Value string `json:"value"` -} diff --git a/pkg/processor/mappers/factory/factory.go b/pkg/processor/mappers/factory/factory.go deleted file mode 100644 index 26dcad41..00000000 --- a/pkg/processor/mappers/factory/factory.go +++ /dev/null @@ -1,17 +0,0 @@ -package factory - -import ( - "html/template" - - "github.com/johnfercher/maroto/v2/pkg/processor/core" -) - -type FactoryComponents struct{} - -func NewFactoryComponents() *FactoryComponents { - return &FactoryComponents{} -} - -func (f *FactoryComponents) FactoryComponentTree(template template.Template, content map[string]interface{}) (core.Component, error) { - return nil, nil -} diff --git a/pkg/processor/mappers/components/image/image.go b/pkg/processor/mappers/image/image.go similarity index 100% rename from pkg/processor/mappers/components/image/image.go rename to pkg/processor/mappers/image/image.go diff --git a/pkg/processor/mappers/image/image_test.go b/pkg/processor/mappers/image/image_test.go new file mode 100644 index 00000000..aa66c334 --- /dev/null +++ b/pkg/processor/mappers/image/image_test.go @@ -0,0 +1 @@ +package image_test diff --git a/pkg/processor/mappers/page/page.go b/pkg/processor/mappers/page/page.go deleted file mode 100644 index 02be2352..00000000 --- a/pkg/processor/mappers/page/page.go +++ /dev/null @@ -1,8 +0,0 @@ -package page - -import "github.com/johnfercher/maroto/v2/pkg/processor/mappers/row" - -type Page struct { - Header []row.Row `json:"header"` - Rows []row.Row `json:"rows"` -} diff --git a/pkg/processor/mappers/pagemapper/page.go b/pkg/processor/mappers/pagemapper/page.go new file mode 100644 index 00000000..69cc598c --- /dev/null +++ b/pkg/processor/mappers/pagemapper/page.go @@ -0,0 +1,42 @@ +// pagemapper is the package responsible for mapping page settings +package pagemapper + +import ( + "github.com/johnfercher/maroto/v2/pkg/processor/components/page" + "github.com/johnfercher/maroto/v2/pkg/processor/components/row" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rowmapper" +) + +type Page struct { + Header []rowmapper.Row `json:"header"` + Rows []rowmapper.Row `json:"rows"` +} + +// generate is responsible for the builder page according to the submitted content +func (p *Page) Generate(content map[string]interface{}) (*page.Page, error) { + header, err := p.generateRows(content, p.Header) + if err != nil { + return nil, err + } + + rows, err := p.generateRows(content, p.Header) + if err != nil { + return nil, err + } + + return page.NewPage(header, rows), nil +} + +func (p *Page) generateRows(content map[string]interface{}, templates []rowmapper.Row) ([]row.Row, error) { + rows := make([]row.Row, len(content)) + + for _, headerRow := range templates { + generatedRow, err := headerRow.Generate(content) + if err != nil { + return nil, err + } + rows = append(rows, *generatedRow) + } + + return rows, nil +} diff --git a/pkg/processor/mappers/pagemapper/page_test.go b/pkg/processor/mappers/pagemapper/page_test.go new file mode 100644 index 00000000..91c984f3 --- /dev/null +++ b/pkg/processor/mappers/pagemapper/page_test.go @@ -0,0 +1 @@ +package pagemapper_test diff --git a/pkg/processor/mappers/pdf/pdf.go b/pkg/processor/mappers/pdf/pdf.go deleted file mode 100644 index 76295960..00000000 --- a/pkg/processor/mappers/pdf/pdf.go +++ /dev/null @@ -1,11 +0,0 @@ -package pdf - -import ( - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/builder" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/page" -) - -type Pdf struct { - Builder builder.Builder `json:"builder"` - Pages map[string]page.Page `json:"pages"` -} diff --git a/pkg/processor/mappers/pdfmapper/pdf.go b/pkg/processor/mappers/pdfmapper/pdf.go new file mode 100644 index 00000000..51fea379 --- /dev/null +++ b/pkg/processor/mappers/pdfmapper/pdf.go @@ -0,0 +1,42 @@ +// padmapper is the package responsible for mapping pdf settings +package pdfmapper + +import ( + "fmt" + + "github.com/johnfercher/maroto/v2/pkg/processor/components/builder" + "github.com/johnfercher/maroto/v2/pkg/processor/components/page" + "github.com/johnfercher/maroto/v2/pkg/processor/components/pdf" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/buildermapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pagemapper" +) + +type Pdf struct { + Builder buildermapper.Builder `json:"builder"` + Pages map[string]pagemapper.Page `json:"pages"` +} + +// generate is responsible for the builder pdf according to the submitted content +func (p *Pdf) Generate(content map[string]interface{}) (*pdf.Pdf, error) { + var pages []*page.Page + + for pageKey, pageContent := range content { + pageTemplate, ok := p.Pages[pageKey] + if !ok { + return nil, fmt.Errorf("key %s does not match any page template", pageKey) + } + + content, ok := pageContent.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("key %s has content that cannot be converted to a valid format", pageKey) + } + + generatedPage, err := pageTemplate.Generate(content) + if err != nil { + return nil, err + } + + pages = append(pages, generatedPage) + } + return pdf.NewPdf(builder.NewBuilder(), pages...), nil +} diff --git a/pkg/processor/mappers/pdfmapper/pdf_test.go b/pkg/processor/mappers/pdfmapper/pdf_test.go new file mode 100644 index 00000000..dc28ec76 --- /dev/null +++ b/pkg/processor/mappers/pdfmapper/pdf_test.go @@ -0,0 +1 @@ +package pdfmapper_test diff --git a/pkg/processor/mappers/props/barcode/bar_code.go b/pkg/processor/mappers/propsmapper/bar_code.go similarity index 74% rename from pkg/processor/mappers/props/barcode/bar_code.go rename to pkg/processor/mappers/propsmapper/bar_code.go index bd2754a1..26b7aab9 100644 --- a/pkg/processor/mappers/props/barcode/bar_code.go +++ b/pkg/processor/mappers/propsmapper/bar_code.go @@ -1,4 +1,4 @@ -package barcode +package propsmapper type BarCodeProps struct { Align string `json:"align"` diff --git a/pkg/processor/mappers/props/col/col.go b/pkg/processor/mappers/propsmapper/col.go similarity index 71% rename from pkg/processor/mappers/props/col/col.go rename to pkg/processor/mappers/propsmapper/col.go index 86721351..0f54681b 100644 --- a/pkg/processor/mappers/props/col/col.go +++ b/pkg/processor/mappers/propsmapper/col.go @@ -1,4 +1,4 @@ -package col +package propsmapper type ColProps struct { Size int `json:"size"` diff --git a/pkg/processor/mappers/props/text/text.go b/pkg/processor/mappers/propsmapper/text.go similarity index 73% rename from pkg/processor/mappers/props/text/text.go rename to pkg/processor/mappers/propsmapper/text.go index 99c34817..8cc553e6 100644 --- a/pkg/processor/mappers/props/text/text.go +++ b/pkg/processor/mappers/propsmapper/text.go @@ -1,4 +1,4 @@ -package text +package propsmapper type TextProps struct { Align string `json:"align"` diff --git a/pkg/processor/mappers/row/row.go b/pkg/processor/mappers/row/row.go deleted file mode 100644 index 3fca191a..00000000 --- a/pkg/processor/mappers/row/row.go +++ /dev/null @@ -1,8 +0,0 @@ -package row - -import "github.com/johnfercher/maroto/v2/pkg/processor/mappers/col" - -type Row struct { - List string `json:"list"` - Cols []col.Col `json:"cols"` -} diff --git a/pkg/processor/mappers/rowmapper/row.go b/pkg/processor/mappers/rowmapper/row.go new file mode 100644 index 00000000..f88596d2 --- /dev/null +++ b/pkg/processor/mappers/rowmapper/row.go @@ -0,0 +1,59 @@ +// rowmapper is the package responsible for mapping row settings +package rowmapper + +import ( + "fmt" + + "github.com/johnfercher/maroto/v2/pkg/processor/components/col" + "github.com/johnfercher/maroto/v2/pkg/processor/components/row" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/colmapper" +) + +type Row struct { + List string `json:"list"` + Cols []colmapper.Col `json:"cols"` +} + +// generate is responsible for the builder row according to the submitted content +func (r *Row) Generate(content map[string]interface{}) (*row.Row, error) { + if len(r.List) > 0 { + listContent, err := r.getListContent(r.List, content) + if err != nil { + return nil, err + } + content = listContent + } + + cols, err := r.generateCols(content) + if err != nil { + return nil, err + } + return row.NewRow(cols...), nil +} + +func (r *Row) getListContent(listKey string, content map[string]interface{}) (map[string]interface{}, error) { + contentList, ok := content[listKey] + if !ok { + return nil, fmt.Errorf("the model needed a list with key %s, but that key was not found in the content", r.List) + } + + contentMap, ok := contentList.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("the model needed a list with key %s, but that key was not found in the content", r.List) + } + + return contentMap, nil +} + +func (r *Row) generateCols(content map[string]interface{}) ([]col.Col, error) { + generatedCols := make([]col.Col, len(r.Cols)) + + for _, col := range r.Cols { + generatedCol, err := col.Generate(content) + if err != nil { + return nil, err + } + generatedCols = append(generatedCols, *generatedCol) + } + return generatedCols, nil +} diff --git a/pkg/processor/mappers/rowmapper/row_test.go b/pkg/processor/mappers/rowmapper/row_test.go new file mode 100644 index 00000000..fedb3077 --- /dev/null +++ b/pkg/processor/mappers/rowmapper/row_test.go @@ -0,0 +1 @@ +package rowmapper_test diff --git a/pkg/processor/mappers/text/text.go b/pkg/processor/mappers/text/text.go new file mode 100644 index 00000000..0dafdbc2 --- /dev/null +++ b/pkg/processor/mappers/text/text.go @@ -0,0 +1,36 @@ +// text is the package responsible for mapping text settings +package text + +import ( + "fmt" + + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/components/props" + "github.com/johnfercher/maroto/v2/pkg/processor/components/text" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" +) + +type Text struct { + Props propsmapper.TextProps `json:"props"` + SourceKey string `json:"source_key"` + DefaultValue string `json:"value"` +} + +// generate is responsible for the builder text according to the submitted content +func (t *Text) Generate(content map[string]interface{}) (components.Component, error) { + if t.DefaultValue != "" { + return text.NewText(props.TextProps{Align: t.Props.Align}, t.DefaultValue), nil + } + + value, ok := content[t.SourceKey] + if !ok { + return nil, fmt.Errorf("text model needs source key %s, but no content with that key was found", t.SourceKey) + } + + textValue, ok := value.(string) + if !ok { + return nil, fmt.Errorf("resource %s does not have a valid value for the text component", t.SourceKey) + } + + return text.NewText(props.TextProps{Align: t.Props.Align}, textValue), nil +} diff --git a/pkg/processor/mappers/text/text_test.go b/pkg/processor/mappers/text/text_test.go new file mode 100644 index 00000000..e4ece32f --- /dev/null +++ b/pkg/processor/mappers/text/text_test.go @@ -0,0 +1 @@ +package text_test diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index a98c12d0..c38cc941 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -2,14 +2,12 @@ package processor import ( "github.com/johnfercher/maroto/v2/pkg/processor/core" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/factory" "github.com/johnfercher/maroto/v2/pkg/processor/repository" ) type processor struct { repository core.Repository deserializer core.DocumentDeserializer - factory factory.FactoryComponents provider core.Provider } @@ -37,10 +35,10 @@ func (p *processor) GenerateDocument(templateName string, content string) ([]byt return nil, err } - componentTree, err := p.factory.FactoryComponentTree(documentTemplate, documentContent) + pdfComponent, err := documentTemplate.Generate(documentContent) if err != nil { return nil, err } - return p.provider.GeneratePdf(componentTree) + return p.provider.GeneratePdf(pdfComponent) } From 9ae04f9f86344cbae69abc56a1f2085ed7f1c530 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 3 Oct 2024 22:28:41 -0300 Subject: [PATCH 009/116] feature: set provider to generate pdf --- pkg/processor/components/barcode/bar_code.go | 10 ++- pkg/processor/components/col/col.go | 13 +++- pkg/processor/components/components.go | 6 ++ pkg/processor/components/page/page.go | 21 ++++-- pkg/processor/components/pdf/pdf.go | 9 +++ pkg/processor/components/row/row.go | 15 ++++- pkg/processor/components/text/text.go | 10 ++- pkg/processor/core/core.go | 5 -- pkg/processor/mappers/colmapper/col.go | 15 +++-- pkg/processor/mappers/pagemapper/page.go | 10 +-- pkg/processor/mappers/pdfmapper/pdf.go | 4 +- pkg/processor/mappers/rowmapper/row.go | 16 +++-- pkg/processor/processor.go | 10 +-- pkg/processor/provider/Maroto.go | 70 ++++++++++++++++++++ pkg/processor/provider/provider.go | 19 ++++++ pkg/processor/repository/memory_storage.go | 4 +- 16 files changed, 200 insertions(+), 37 deletions(-) create mode 100644 pkg/processor/provider/Maroto.go create mode 100644 pkg/processor/provider/provider.go diff --git a/pkg/processor/components/barcode/bar_code.go b/pkg/processor/components/barcode/bar_code.go index 92c9e0e1..e62f9a0b 100644 --- a/pkg/processor/components/barcode/bar_code.go +++ b/pkg/processor/components/barcode/bar_code.go @@ -1,6 +1,10 @@ package barcode -import "github.com/johnfercher/maroto/v2/pkg/processor/components/props" +import ( + "github.com/johnfercher/maroto/v2/pkg/core" + "github.com/johnfercher/maroto/v2/pkg/processor/components/props" + "github.com/johnfercher/maroto/v2/pkg/processor/provider" +) type BarCode struct { Props props.BarCodeProps @@ -13,3 +17,7 @@ func NewBarCode(props props.BarCodeProps, code string) *BarCode { Props: props, } } + +func (b *BarCode) Generate(provider provider.Provider) core.Component { + return provider.CreateBarCode(b.Code, b.Props) +} diff --git a/pkg/processor/components/col/col.go b/pkg/processor/components/col/col.go index b1019cb6..f7944b43 100644 --- a/pkg/processor/components/col/col.go +++ b/pkg/processor/components/col/col.go @@ -1,13 +1,15 @@ package col import ( + "github.com/johnfercher/maroto/v2/pkg/core" "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/components/props" + "github.com/johnfercher/maroto/v2/pkg/processor/provider" ) type Col struct { Props props.ColProps - Components components.Component + Components []components.Component } func NewCol(props props.ColProps, components ...components.Component) *Col { @@ -16,3 +18,12 @@ func NewCol(props props.ColProps, components ...components.Component) *Col { Components: components, } } + +func (c *Col) Generate(provider provider.Provider) core.Col { + components := make([]core.Component, len(c.Components)) + + for i, component := range c.Components { + components[i] = component.Generate(provider) + } + return provider.CreateCol(c.Props.Size, components...) +} diff --git a/pkg/processor/components/components.go b/pkg/processor/components/components.go index 2925b9db..1095b0f5 100644 --- a/pkg/processor/components/components.go +++ b/pkg/processor/components/components.go @@ -1,4 +1,10 @@ package components +import ( + "github.com/johnfercher/maroto/v2/pkg/core" + "github.com/johnfercher/maroto/v2/pkg/processor/provider" +) + type Component interface { + Generate(provider provider.Provider) core.Component } diff --git a/pkg/processor/components/page/page.go b/pkg/processor/components/page/page.go index 6b3f5c61..93e02e37 100644 --- a/pkg/processor/components/page/page.go +++ b/pkg/processor/components/page/page.go @@ -1,15 +1,26 @@ package page -import "github.com/johnfercher/maroto/v2/pkg/processor/components/row" +import ( + "github.com/johnfercher/maroto/v2/pkg/core" + "github.com/johnfercher/maroto/v2/pkg/processor/components/row" + "github.com/johnfercher/maroto/v2/pkg/processor/provider" +) type Page struct { - Header []row.Row - Rows []row.Row + Rows []row.Row } func NewPage(header, rows []row.Row) *Page { return &Page{ - Header: header, - Rows: rows, + Rows: rows, } } + +func (p *Page) Generate(provider provider.Provider) { + rows := make([]core.Row, len(p.Rows)) + + for i, row := range p.Rows { + rows[i] = row.Generate(provider) + } + provider.CreatePage(rows...) +} diff --git a/pkg/processor/components/pdf/pdf.go b/pkg/processor/components/pdf/pdf.go index c638f384..281d60a7 100644 --- a/pkg/processor/components/pdf/pdf.go +++ b/pkg/processor/components/pdf/pdf.go @@ -3,6 +3,7 @@ package pdf import ( "github.com/johnfercher/maroto/v2/pkg/processor/components/builder" "github.com/johnfercher/maroto/v2/pkg/processor/components/page" + "github.com/johnfercher/maroto/v2/pkg/processor/provider" ) type Pdf struct { @@ -16,3 +17,11 @@ func NewPdf(builder *builder.Builder, pages ...*page.Page) *Pdf { Pages: pages, } } + +func (p *Pdf) Generate(provider provider.Provider) provider.Provider { + for _, page := range p.Pages { + page.Generate(provider) + } + + return provider +} diff --git a/pkg/processor/components/row/row.go b/pkg/processor/components/row/row.go index 3cf14269..22e3e371 100644 --- a/pkg/processor/components/row/row.go +++ b/pkg/processor/components/row/row.go @@ -1,6 +1,10 @@ package row -import "github.com/johnfercher/maroto/v2/pkg/processor/components/col" +import ( + "github.com/johnfercher/maroto/v2/pkg/core" + "github.com/johnfercher/maroto/v2/pkg/processor/components/col" + "github.com/johnfercher/maroto/v2/pkg/processor/provider" +) type Row struct { Cols []col.Col @@ -11,3 +15,12 @@ func NewRow(cols ...col.Col) *Row { Cols: cols, } } + +func (r *Row) Generate(provider provider.Provider) core.Row { + cols := make([]core.Col, len(r.Cols)) + + for i, col := range r.Cols { + cols[i] = col.Generate(provider) + } + return provider.CreateRow(cols...) +} diff --git a/pkg/processor/components/text/text.go b/pkg/processor/components/text/text.go index 2c1e6df3..fabe50ba 100644 --- a/pkg/processor/components/text/text.go +++ b/pkg/processor/components/text/text.go @@ -1,6 +1,10 @@ package text -import "github.com/johnfercher/maroto/v2/pkg/processor/components/props" +import ( + "github.com/johnfercher/maroto/v2/pkg/core" + "github.com/johnfercher/maroto/v2/pkg/processor/components/props" + "github.com/johnfercher/maroto/v2/pkg/processor/provider" +) type Text struct { Props props.TextProps @@ -13,3 +17,7 @@ func NewText(props props.TextProps, value string) *Text { Value: value, } } + +func (t *Text) Generate(provider provider.Provider) core.Component { + return provider.CreateText(t.Value, t.Props) +} diff --git a/pkg/processor/core/core.go b/pkg/processor/core/core.go index 47f19900..49da405c 100644 --- a/pkg/processor/core/core.go +++ b/pkg/processor/core/core.go @@ -1,7 +1,6 @@ package core import ( - "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pdfmapper" ) @@ -19,7 +18,3 @@ type DocumentDeserializer interface { DesserializeTemplate(template string) (pdfmapper.Pdf, error) DesserializeContent(content string) (map[string]interface{}, error) } - -type Provider interface { - GeneratePdf(componentTree components.Component) ([]byte, error) -} diff --git a/pkg/processor/mappers/colmapper/col.go b/pkg/processor/mappers/colmapper/col.go index 55bc6959..b3298240 100644 --- a/pkg/processor/mappers/colmapper/col.go +++ b/pkg/processor/mappers/colmapper/col.go @@ -26,14 +26,14 @@ func (c *Col) Generate(content map[string]interface{}) (*col.Col, error) { if err != nil { return nil, err } - return col.NewCol(props.ColProps{Size: c.Props.Size}, components), nil + return col.NewCol(props.ColProps{Size: c.Props.Size}, components...), nil } func (c *Col) factoryComponents(content map[string]interface{}) ([]components.Component, error) { - componentsTemplate := make([]mappers.Componentmapper, 1) + componentsTemplate := make([]mappers.Componentmapper, 0) - for _, text := range c.Text { - componentsTemplate = append(componentsTemplate, &text) + for _, t := range c.Text { + componentsTemplate = append(componentsTemplate, &text.Text{Props: t.Props, SourceKey: t.SourceKey, DefaultValue: t.DefaultValue}) } for _, barcode := range c.BarCode { @@ -51,12 +51,15 @@ func (c *Col) factoryComponents(content map[string]interface{}) ([]components.Co func (c *Col) generateComponents(content map[string]interface{}, templates ...mappers.Componentmapper) ([]components.Component, error) { components := make([]components.Component, len(templates)) - for _, template := range templates { + if len(templates) == 0 { + return components, nil + } + for i, template := range templates { component, err := template.Generate(content) if err != nil { return nil, err } - components = append(components, component) + components[i] = component } return components, nil } diff --git a/pkg/processor/mappers/pagemapper/page.go b/pkg/processor/mappers/pagemapper/page.go index 69cc598c..db692c34 100644 --- a/pkg/processor/mappers/pagemapper/page.go +++ b/pkg/processor/mappers/pagemapper/page.go @@ -19,7 +19,7 @@ func (p *Page) Generate(content map[string]interface{}) (*page.Page, error) { return nil, err } - rows, err := p.generateRows(content, p.Header) + rows, err := p.generateRows(content, p.Rows) if err != nil { return nil, err } @@ -28,14 +28,14 @@ func (p *Page) Generate(content map[string]interface{}) (*page.Page, error) { } func (p *Page) generateRows(content map[string]interface{}, templates []rowmapper.Row) ([]row.Row, error) { - rows := make([]row.Row, len(content)) + rows := make([]row.Row, len(templates)) - for _, headerRow := range templates { - generatedRow, err := headerRow.Generate(content) + for i, template := range templates { + generatedRow, err := template.Generate(content) if err != nil { return nil, err } - rows = append(rows, *generatedRow) + rows[i] = *generatedRow } return rows, nil diff --git a/pkg/processor/mappers/pdfmapper/pdf.go b/pkg/processor/mappers/pdfmapper/pdf.go index 51fea379..1c65ed29 100644 --- a/pkg/processor/mappers/pdfmapper/pdf.go +++ b/pkg/processor/mappers/pdfmapper/pdf.go @@ -23,12 +23,12 @@ func (p *Pdf) Generate(content map[string]interface{}) (*pdf.Pdf, error) { for pageKey, pageContent := range content { pageTemplate, ok := p.Pages[pageKey] if !ok { - return nil, fmt.Errorf("key %s does not match any page template", pageKey) + return nil, fmt.Errorf("the document content references a page template with key \"%s\", but no page with that key was found in the current template", pageKey) } content, ok := pageContent.(map[string]interface{}) if !ok { - return nil, fmt.Errorf("key %s has content that cannot be converted to a valid format", pageKey) + return nil, fmt.Errorf("key \"%s\" references a content that cannot be converted to a valid format, ensure that this content can be converted to a map[string]interface{}", pageKey) } generatedPage, err := pageTemplate.Generate(content) diff --git a/pkg/processor/mappers/rowmapper/row.go b/pkg/processor/mappers/rowmapper/row.go index f88596d2..9ee3716c 100644 --- a/pkg/processor/mappers/rowmapper/row.go +++ b/pkg/processor/mappers/rowmapper/row.go @@ -37,23 +37,29 @@ func (r *Row) getListContent(listKey string, content map[string]interface{}) (ma return nil, fmt.Errorf("the model needed a list with key %s, but that key was not found in the content", r.List) } - contentMap, ok := contentList.(map[string]interface{}) + contentMap, ok := contentList.([]interface{}) if !ok { - return nil, fmt.Errorf("the model needed a list with key %s, but that key was not found in the content", r.List) + return nil, fmt.Errorf("key \"%s\" references a content that cannot be converted to a valid format, ensure that this content can be converted to a map[string]interface{}", r.List) + } + + b := contentMap[0] + c, ok := b.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("key \"%s\" references a content that cannot be converted to a valid format, ensure that this content can be converted to a map[string]interface{}", r.List) } - return contentMap, nil + return c, nil } func (r *Row) generateCols(content map[string]interface{}) ([]col.Col, error) { generatedCols := make([]col.Col, len(r.Cols)) - for _, col := range r.Cols { + for i, col := range r.Cols { generatedCol, err := col.Generate(content) if err != nil { return nil, err } - generatedCols = append(generatedCols, *generatedCol) + generatedCols[i] = *generatedCol } return generatedCols, nil } diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index c38cc941..1148a8f1 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -2,17 +2,19 @@ package processor import ( "github.com/johnfercher/maroto/v2/pkg/processor/core" + "github.com/johnfercher/maroto/v2/pkg/processor/deserializer" + "github.com/johnfercher/maroto/v2/pkg/processor/provider" "github.com/johnfercher/maroto/v2/pkg/processor/repository" ) type processor struct { repository core.Repository deserializer core.DocumentDeserializer - provider core.Provider + provider provider.Provider } func NewProcessor() *processor { - return &processor{repository: repository.NewMemoryStorage()} + return &processor{repository: repository.NewMemoryStorage(), deserializer: deserializer.NewJsonDeserialize(), provider: provider.NewMaroto()} } func (p *processor) RegisterTemplate(templateName string, template string) error { @@ -30,7 +32,7 @@ func (p *processor) GenerateDocument(templateName string, content string) ([]byt return nil, err } - documentContent, err := p.deserializer.DesserializeContent(templateJson) + documentContent, err := p.deserializer.DesserializeContent(content) if err != nil { return nil, err } @@ -40,5 +42,5 @@ func (p *processor) GenerateDocument(templateName string, content string) ([]byt return nil, err } - return p.provider.GeneratePdf(pdfComponent) + return pdfComponent.Generate(p.provider).GeneratePdf() } diff --git a/pkg/processor/provider/Maroto.go b/pkg/processor/provider/Maroto.go new file mode 100644 index 00000000..53e051a7 --- /dev/null +++ b/pkg/processor/provider/Maroto.go @@ -0,0 +1,70 @@ +package provider + +import ( + "github.com/johnfercher/maroto/v2" + "github.com/johnfercher/maroto/v2/pkg/components/code" + "github.com/johnfercher/maroto/v2/pkg/components/col" + "github.com/johnfercher/maroto/v2/pkg/components/page" + "github.com/johnfercher/maroto/v2/pkg/components/row" + marototext "github.com/johnfercher/maroto/v2/pkg/components/text" + marotoprops "github.com/johnfercher/maroto/v2/pkg/props" + + "github.com/johnfercher/maroto/v2/pkg/consts/align" + "github.com/johnfercher/maroto/v2/pkg/core" + "github.com/johnfercher/maroto/v2/pkg/processor/components/builder" + "github.com/johnfercher/maroto/v2/pkg/processor/components/props" +) + +type Maroto struct { + maroto *core.Maroto +} + +func NewMaroto() *Maroto { + m := maroto.New() + return &Maroto{maroto: &m} +} + +func (m *Maroto) GeneratePdf() ([]byte, error) { + doc, err := (*m.maroto).Generate() + if err != nil { + return nil, err + } + doc.Save("docs/assets/pdf/backgroundv2.pdf") + return doc.GetBytes(), nil +} + +func (m *Maroto) ConfigureBuilder(builder builder.Builder) Provider { + return nil +} + +func (m *Maroto) RegisterHeader(rows ...core.Row) Provider { + (*m.maroto).RegisterHeader(rows...) + return m +} + +func (m *Maroto) RegisterFooter(rows ...core.Row) Provider { + (*m.maroto).RegisterFooter(rows...) + return m +} + +func (m *Maroto) CreatePage(components ...core.Row) core.Page { + newPage := page.New().Add(components...) + (*m.maroto).AddPages(newPage) + return newPage +} + +func (m *Maroto) CreateRow(cols ...core.Col) core.Row { + return row.New().Add(cols...) +} + +func (m *Maroto) CreateCol(size int, components ...core.Component) core.Col { + return col.New(size).Add(components...) +} + +func (m *Maroto) CreateText(value string, props props.TextProps) core.Component { + return marototext.New(value, marotoprops.Text{Align: align.Type(props.Align)}) +} + +func (m *Maroto) CreateBarCode(codeValue string, props props.BarCodeProps) core.Component { + return code.NewBar(codeValue) +} diff --git a/pkg/processor/provider/provider.go b/pkg/processor/provider/provider.go new file mode 100644 index 00000000..30ef0286 --- /dev/null +++ b/pkg/processor/provider/provider.go @@ -0,0 +1,19 @@ +package provider + +import ( + "github.com/johnfercher/maroto/v2/pkg/core" + "github.com/johnfercher/maroto/v2/pkg/processor/components/builder" + "github.com/johnfercher/maroto/v2/pkg/processor/components/props" +) + +type Provider interface { + GeneratePdf() ([]byte, error) + ConfigureBuilder(builder builder.Builder) Provider + RegisterHeader(rows ...core.Row) Provider + RegisterFooter(rows ...core.Row) Provider + CreatePage(components ...core.Row) core.Page + CreateRow(components ...core.Col) core.Row + CreateCol(size int, components ...core.Component) core.Col + CreateText(value string, props props.TextProps) core.Component + CreateBarCode(value string, props props.BarCodeProps) core.Component +} diff --git a/pkg/processor/repository/memory_storage.go b/pkg/processor/repository/memory_storage.go index 26cf0014..b0d0058d 100644 --- a/pkg/processor/repository/memory_storage.go +++ b/pkg/processor/repository/memory_storage.go @@ -6,7 +6,9 @@ type memoryStorage struct { } func NewMemoryStorage() *memoryStorage { - return &memoryStorage{} + return &memoryStorage{ + template: make(map[string]string), + } } // RegisterTemplate is responsible for register a template in memory From 93a6e4381e4af5cd1c81a4088bae6674d4f77a60 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 6 Oct 2024 11:40:05 -0300 Subject: [PATCH 010/116] refactory: allow the definition of a list of templates refactor document to allow defining page lists --- pkg/processor/core/core.go | 9 +- .../deserializer/json_desserialize.go | 19 +-- pkg/processor/mappers/barcode/bar_code.go | 31 ---- pkg/processor/mappers/barcode/barcode_test.go | 1 - .../mappers/buildermapper/builder.go | 17 +++ .../mappers/buildermapper/builder_test.go | 1 - pkg/processor/mappers/colmapper/col.go | 65 -------- pkg/processor/mappers/colmapper/col_test.go | 1 - .../mappers/documentmapper/document.go | 144 ++++++++++++++++++ .../mappers/documentmapper/document_test.go | 1 + pkg/processor/mappers/image/image.go | 5 - pkg/processor/mappers/image/image_test.go | 1 - pkg/processor/mappers/listmapper/list.go | 20 +++ pkg/processor/mappers/listmapper/list_test.go | 1 + pkg/processor/mappers/pagemapper/page.go | 36 +---- pkg/processor/mappers/pdfmapper/pdf.go | 42 ----- pkg/processor/mappers/pdfmapper/pdf_test.go | 1 - pkg/processor/mappers/propsmapper/bar_code.go | 5 - pkg/processor/mappers/propsmapper/col.go | 5 - pkg/processor/mappers/propsmapper/color.go | 13 ++ .../mappers/propsmapper/customfont.go | 8 + .../mappers/propsmapper/dimensions.go | 7 + pkg/processor/mappers/propsmapper/font.go | 13 ++ pkg/processor/mappers/propsmapper/margins.go | 9 ++ pkg/processor/mappers/propsmapper/metadata.go | 19 +++ .../mappers/propsmapper/pagenumber.go | 17 +++ .../mappers/propsmapper/protection.go | 8 + pkg/processor/mappers/propsmapper/text.go | 5 - pkg/processor/mappers/rowmapper/row.go | 61 +------- pkg/processor/mappers/text/text.go | 36 ----- pkg/processor/mappers/text/text_test.go | 1 - pkg/processor/processor.go | 26 ++-- 32 files changed, 306 insertions(+), 322 deletions(-) delete mode 100644 pkg/processor/mappers/barcode/bar_code.go delete mode 100644 pkg/processor/mappers/barcode/barcode_test.go delete mode 100644 pkg/processor/mappers/buildermapper/builder_test.go delete mode 100644 pkg/processor/mappers/colmapper/col.go delete mode 100644 pkg/processor/mappers/colmapper/col_test.go create mode 100644 pkg/processor/mappers/documentmapper/document.go create mode 100644 pkg/processor/mappers/documentmapper/document_test.go delete mode 100644 pkg/processor/mappers/image/image.go delete mode 100644 pkg/processor/mappers/image/image_test.go create mode 100644 pkg/processor/mappers/listmapper/list.go create mode 100644 pkg/processor/mappers/listmapper/list_test.go delete mode 100644 pkg/processor/mappers/pdfmapper/pdf.go delete mode 100644 pkg/processor/mappers/pdfmapper/pdf_test.go delete mode 100644 pkg/processor/mappers/propsmapper/bar_code.go delete mode 100644 pkg/processor/mappers/propsmapper/col.go create mode 100644 pkg/processor/mappers/propsmapper/color.go create mode 100644 pkg/processor/mappers/propsmapper/customfont.go create mode 100644 pkg/processor/mappers/propsmapper/dimensions.go create mode 100644 pkg/processor/mappers/propsmapper/font.go create mode 100644 pkg/processor/mappers/propsmapper/margins.go create mode 100644 pkg/processor/mappers/propsmapper/metadata.go create mode 100644 pkg/processor/mappers/propsmapper/pagenumber.go create mode 100644 pkg/processor/mappers/propsmapper/protection.go delete mode 100644 pkg/processor/mappers/propsmapper/text.go delete mode 100644 pkg/processor/mappers/text/text.go delete mode 100644 pkg/processor/mappers/text/text_test.go diff --git a/pkg/processor/core/core.go b/pkg/processor/core/core.go index 49da405c..c9f81fc1 100644 --- a/pkg/processor/core/core.go +++ b/pkg/processor/core/core.go @@ -1,9 +1,5 @@ package core -import ( - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pdfmapper" -) - type Processor interface { RegisterTemplate(templateName string, template string) error GenerateDocument(templateName string, content string) []byte @@ -14,7 +10,6 @@ type Repository interface { ReadTemplate(templateName string) (string, error) } -type DocumentDeserializer interface { - DesserializeTemplate(template string) (pdfmapper.Pdf, error) - DesserializeContent(content string) (map[string]interface{}, error) +type Deserializer interface { + Deserialize(document string) (map[string]interface{}, error) } diff --git a/pkg/processor/deserializer/json_desserialize.go b/pkg/processor/deserializer/json_desserialize.go index 3ab665e5..5e91c1de 100644 --- a/pkg/processor/deserializer/json_desserialize.go +++ b/pkg/processor/deserializer/json_desserialize.go @@ -3,8 +3,6 @@ package deserializer import ( "encoding/json" - - pdf "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pdfmapper" ) type jsonDeserializer struct { @@ -14,18 +12,9 @@ func NewJsonDeserialize() *jsonDeserializer { return &jsonDeserializer{} } -// DesserializeTemplate is responsible for transforming a string into a template structure -func (j *jsonDeserializer) DesserializeTemplate(templateJson string) (pdf.Pdf, error) { - return deserializer[pdf.Pdf](templateJson) -} - -// DesserializeContent is responsible for transforming a string into a content map -func (j *jsonDeserializer) DesserializeContent(contentJson string) (map[string]interface{}, error) { - return deserializer[map[string]interface{}](contentJson) -} - -func deserializer[T interface{}](jsonDocument string) (T, error) { - var document T - err := json.Unmarshal([]byte(jsonDocument), &document) +func (j *jsonDeserializer) Deserialize(documentJson string) (map[string]interface{}, error) { + var document map[string]interface{} + err := json.Unmarshal([]byte(documentJson), &document) return document, err + } diff --git a/pkg/processor/mappers/barcode/bar_code.go b/pkg/processor/mappers/barcode/bar_code.go deleted file mode 100644 index 86454d9f..00000000 --- a/pkg/processor/mappers/barcode/bar_code.go +++ /dev/null @@ -1,31 +0,0 @@ -// barcode is the package responsible for mapping barcode settings -package barcode - -import ( - "fmt" - - "github.com/johnfercher/maroto/v2/pkg/processor/components" - "github.com/johnfercher/maroto/v2/pkg/processor/components/barcode" - "github.com/johnfercher/maroto/v2/pkg/processor/components/props" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" -) - -type BarCode struct { - Props propsmapper.BarCodeProps `json:"props"` - SourceKey string `json:"source_key"` -} - -// generate is responsible for the builder barcode according to the submitted content -func (b *BarCode) Generate(content map[string]interface{}) (components.Component, error) { - value, ok := content[b.SourceKey] - if !ok { - return nil, fmt.Errorf("barcode model needs source key %s, but no content with that key was found", b.SourceKey) - } - - code, ok := value.(string) - if !ok { - return nil, fmt.Errorf("resource %s does not have a valid value for the barcode component", b.SourceKey) - } - - return barcode.NewBarCode(props.BarCodeProps{Align: b.Props.Align}, code), nil -} diff --git a/pkg/processor/mappers/barcode/barcode_test.go b/pkg/processor/mappers/barcode/barcode_test.go deleted file mode 100644 index 91bc1006..00000000 --- a/pkg/processor/mappers/barcode/barcode_test.go +++ /dev/null @@ -1 +0,0 @@ -package barcode_test diff --git a/pkg/processor/mappers/buildermapper/builder.go b/pkg/processor/mappers/buildermapper/builder.go index 1c4cb0b9..34c0fa34 100644 --- a/pkg/processor/mappers/buildermapper/builder.go +++ b/pkg/processor/mappers/buildermapper/builder.go @@ -1,4 +1,21 @@ package buildermapper +import "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" + type Builder struct { + Dimensions propsmapper.Dimensions `json:"dimensions"` + Margins propsmapper.Margins `json:"margins"` + ChunkWorkers int `json:"chunk_workers"` + Debug bool `json:"debug"` + MaxGridSize int `json:"max_grid_size"` + DefaultFont propsmapper.Font `json:"default_font"` + CustomFonts []propsmapper.CustomFont `json:"custom_fonts"` + PageNumber propsmapper.PageNumber `json:"page_number"` + Protection propsmapper.Protection `json:"protection"` + Compression bool `json:"compression"` + PageSize string `json:"page_size"` + Orientation string `json:"orientation"` + Metadata propsmapper.Metadata `json:"metadata"` + DisableAutoPageBreak bool `json:"disable_auto_page_break"` + GenerationMode string `json:"generation_mode"` } diff --git a/pkg/processor/mappers/buildermapper/builder_test.go b/pkg/processor/mappers/buildermapper/builder_test.go deleted file mode 100644 index ee7eceab..00000000 --- a/pkg/processor/mappers/buildermapper/builder_test.go +++ /dev/null @@ -1 +0,0 @@ -package buildermapper_test diff --git a/pkg/processor/mappers/colmapper/col.go b/pkg/processor/mappers/colmapper/col.go deleted file mode 100644 index b3298240..00000000 --- a/pkg/processor/mappers/colmapper/col.go +++ /dev/null @@ -1,65 +0,0 @@ -// colmapper is the package responsible for mapping col settings -package colmapper - -import ( - "github.com/johnfercher/maroto/v2/pkg/processor/components" - "github.com/johnfercher/maroto/v2/pkg/processor/components/col" - "github.com/johnfercher/maroto/v2/pkg/processor/components/props" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/barcode" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/image" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" - - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/text" -) - -type Col struct { - Props propsmapper.ColProps `json:"props"` - Text []text.Text `json:"text"` - BarCode []barcode.BarCode `json:"bar_code"` - Image []image.Image `json:"image"` -} - -// generate is responsible for the builder col according to the submitted content -func (c *Col) Generate(content map[string]interface{}) (*col.Col, error) { - components, err := c.factoryComponents(content) - if err != nil { - return nil, err - } - return col.NewCol(props.ColProps{Size: c.Props.Size}, components...), nil -} - -func (c *Col) factoryComponents(content map[string]interface{}) ([]components.Component, error) { - componentsTemplate := make([]mappers.Componentmapper, 0) - - for _, t := range c.Text { - componentsTemplate = append(componentsTemplate, &text.Text{Props: t.Props, SourceKey: t.SourceKey, DefaultValue: t.DefaultValue}) - } - - for _, barcode := range c.BarCode { - componentsTemplate = append(componentsTemplate, &barcode) - } - - components, err := c.generateComponents(content, componentsTemplate...) - if err != nil { - return nil, err - } - - return components, nil -} - -func (c *Col) generateComponents(content map[string]interface{}, templates ...mappers.Componentmapper) ([]components.Component, error) { - components := make([]components.Component, len(templates)) - - if len(templates) == 0 { - return components, nil - } - for i, template := range templates { - component, err := template.Generate(content) - if err != nil { - return nil, err - } - components[i] = component - } - return components, nil -} diff --git a/pkg/processor/mappers/colmapper/col_test.go b/pkg/processor/mappers/colmapper/col_test.go deleted file mode 100644 index 87251be4..00000000 --- a/pkg/processor/mappers/colmapper/col_test.go +++ /dev/null @@ -1 +0,0 @@ -package colmapper_test diff --git a/pkg/processor/mappers/documentmapper/document.go b/pkg/processor/mappers/documentmapper/document.go new file mode 100644 index 00000000..94b064a6 --- /dev/null +++ b/pkg/processor/mappers/documentmapper/document.go @@ -0,0 +1,144 @@ +// documentmapper is the package responsible for mapping pdf settings +package documentmapper + +import ( + "fmt" + + "github.com/johnfercher/maroto/v2/pkg/processor/components/pdf" + "github.com/johnfercher/maroto/v2/pkg/processor2/core" + "github.com/johnfercher/maroto/v2/pkg/processor2/mappers" + "github.com/johnfercher/maroto/v2/pkg/processor2/mappers/buildermapper" + "github.com/johnfercher/maroto/v2/pkg/processor2/mappers/listmapper" + "github.com/johnfercher/maroto/v2/pkg/processor2/mappers/pagemapper" + "github.com/johnfercher/maroto/v2/pkg/processor2/mappers/rowmapper" +) + +type Document struct { + Builder buildermapper.Builder + Header []mappers.Componentmapper + Footer []mappers.Componentmapper + pages []mappers.Componentmapper +} + +// NewPdf is responsible for creating the pdf template +func NewPdf(document string, deserializer core.Deserializer) (*Document, error) { + newPdf := Document{} + template, err := deserializer.Deserialize(document) + if err != nil { + return nil, err + } + + err = newPdf.addComponentsToPdf(template) + if err != nil { + return nil, err + } + + return &newPdf, nil +} + +// addComponentsToPdf is responsible for adding all the components that are part of the template to the PDF. +// This is the method where the components that are part of the PDF are created. +func (p *Document) addComponentsToPdf(templates map[string]interface{}) error { + fieldMappers := p.getFieldMappers() + + for field, template := range templates { + mapper, ok := fieldMappers[field] + if !ok { + return fmt.Errorf("the field %s present in the template cannot be mapped to any valid component", field) + } + err := mapper(template) + if err != nil { + return err + } + } + return nil +} + +// getFieldMappers is responsible for defining which methods are responsible for assembling which components. +// To do this, the component name is linked to a function in a Map. +func (p *Document) getFieldMappers() map[string]func(interface{}) error { + return map[string]func(interface{}) error{ + "builder": p.setBuilder, + "header": p.setHeader, + "footer": p.setFooter, + "pages": p.setPages, + } +} + +// setBuilder is responsible for factories builder information +func (p *Document) setBuilder(builderDoc interface{}) error { + builder, ok := builderDoc.(buildermapper.Builder) + if !ok { + return fmt.Errorf("builder settings could not be deserialized") + } + p.Builder = builder + return nil +} + +// setHeader is responsible for factory the header +func (p *Document) setHeader(rowsDoc interface{}) error { + rowsTemplate, ok := rowsDoc.([]interface{}) + if !ok { + return fmt.Errorf("header cannot be deserialized, ensure header has an array of rows") + } + + for _, rowTemplate := range rowsTemplate { + row, err := rowmapper.NewRow(rowTemplate) + if err != nil { + return err + } + p.Header = append(p.Header, row) + } + + return nil +} + +// setFooter is responsible for factory the footer +func (p *Document) setFooter(rowsDoc interface{}) error { + rowsTemplate, ok := rowsDoc.([]interface{}) + if !ok { + return fmt.Errorf("header cannot be deserialized, ensure header has an array of rows") + } + + for _, rowTemplate := range rowsTemplate { + row, err := rowmapper.NewRow(rowTemplate) + if err != nil { + return err + } + p.Header = append(p.Footer, row) + } + + return nil +} + +// setPages is responsible for factory the pages. +// pages can be a list of pages or just one page +func (p *Document) setPages(rowsDoc interface{}) error { + templatePage, ok := rowsDoc.(map[string]interface{}) + if !ok { + return fmt.Errorf("ensure pages can be converted to map[string] interface{}") + } + + for templateName, pageTemplate := range templatePage { + var page mappers.Componentmapper + var err error + + if templateName == "list" { + page, err = listmapper.NewList[*pagemapper.Page](pageTemplate) + } else { + page, err = pagemapper.NewPage(pageTemplate) + } + + if err != nil { + return err + } + p.pages = append(p.pages, page) + } + + return nil +} + +// generate is responsible for the builder pdf according to the submitted content +func (p *Document) Generate(content map[string]interface{}) (*pdf.Pdf, error) { + return nil, nil +} diff --git a/pkg/processor/mappers/documentmapper/document_test.go b/pkg/processor/mappers/documentmapper/document_test.go new file mode 100644 index 00000000..a537fe1f --- /dev/null +++ b/pkg/processor/mappers/documentmapper/document_test.go @@ -0,0 +1 @@ +package documentmapper diff --git a/pkg/processor/mappers/image/image.go b/pkg/processor/mappers/image/image.go deleted file mode 100644 index 2971466e..00000000 --- a/pkg/processor/mappers/image/image.go +++ /dev/null @@ -1,5 +0,0 @@ -package image - -type Image struct { - SourceKey string `json:"source_key"` -} diff --git a/pkg/processor/mappers/image/image_test.go b/pkg/processor/mappers/image/image_test.go deleted file mode 100644 index aa66c334..00000000 --- a/pkg/processor/mappers/image/image_test.go +++ /dev/null @@ -1 +0,0 @@ -package image_test diff --git a/pkg/processor/mappers/listmapper/list.go b/pkg/processor/mappers/listmapper/list.go new file mode 100644 index 00000000..cf620f28 --- /dev/null +++ b/pkg/processor/mappers/listmapper/list.go @@ -0,0 +1,20 @@ +// listmapper is the package responsible for mapping row settings +package listmapper + +import ( + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" +) + +type List[T mappers.Componentmapper] struct { + sourceKey string + templates T +} + +func NewList[T mappers.Componentmapper](document interface{}) (*List[T], error) { + return nil, nil +} + +func (r *List[T]) Generate(content map[string]interface{}) (components.Component, error) { + return nil, nil +} diff --git a/pkg/processor/mappers/listmapper/list_test.go b/pkg/processor/mappers/listmapper/list_test.go new file mode 100644 index 00000000..83325aff --- /dev/null +++ b/pkg/processor/mappers/listmapper/list_test.go @@ -0,0 +1 @@ +package listmapper diff --git a/pkg/processor/mappers/pagemapper/page.go b/pkg/processor/mappers/pagemapper/page.go index db692c34..8da86de4 100644 --- a/pkg/processor/mappers/pagemapper/page.go +++ b/pkg/processor/mappers/pagemapper/page.go @@ -2,41 +2,17 @@ package pagemapper import ( - "github.com/johnfercher/maroto/v2/pkg/processor/components/page" - "github.com/johnfercher/maroto/v2/pkg/processor/components/row" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rowmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/components" ) type Page struct { - Header []rowmapper.Row `json:"header"` - Rows []rowmapper.Row `json:"rows"` + Teste string } -// generate is responsible for the builder page according to the submitted content -func (p *Page) Generate(content map[string]interface{}) (*page.Page, error) { - header, err := p.generateRows(content, p.Header) - if err != nil { - return nil, err - } - - rows, err := p.generateRows(content, p.Rows) - if err != nil { - return nil, err - } - - return page.NewPage(header, rows), nil +func NewPage(page interface{}) (*Page, error) { + return nil, nil } -func (p *Page) generateRows(content map[string]interface{}, templates []rowmapper.Row) ([]row.Row, error) { - rows := make([]row.Row, len(templates)) - - for i, template := range templates { - generatedRow, err := template.Generate(content) - if err != nil { - return nil, err - } - rows[i] = *generatedRow - } - - return rows, nil +func (r *Page) Generate(content map[string]interface{}) (components.Component, error) { + return nil, nil } diff --git a/pkg/processor/mappers/pdfmapper/pdf.go b/pkg/processor/mappers/pdfmapper/pdf.go deleted file mode 100644 index 1c65ed29..00000000 --- a/pkg/processor/mappers/pdfmapper/pdf.go +++ /dev/null @@ -1,42 +0,0 @@ -// padmapper is the package responsible for mapping pdf settings -package pdfmapper - -import ( - "fmt" - - "github.com/johnfercher/maroto/v2/pkg/processor/components/builder" - "github.com/johnfercher/maroto/v2/pkg/processor/components/page" - "github.com/johnfercher/maroto/v2/pkg/processor/components/pdf" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/buildermapper" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pagemapper" -) - -type Pdf struct { - Builder buildermapper.Builder `json:"builder"` - Pages map[string]pagemapper.Page `json:"pages"` -} - -// generate is responsible for the builder pdf according to the submitted content -func (p *Pdf) Generate(content map[string]interface{}) (*pdf.Pdf, error) { - var pages []*page.Page - - for pageKey, pageContent := range content { - pageTemplate, ok := p.Pages[pageKey] - if !ok { - return nil, fmt.Errorf("the document content references a page template with key \"%s\", but no page with that key was found in the current template", pageKey) - } - - content, ok := pageContent.(map[string]interface{}) - if !ok { - return nil, fmt.Errorf("key \"%s\" references a content that cannot be converted to a valid format, ensure that this content can be converted to a map[string]interface{}", pageKey) - } - - generatedPage, err := pageTemplate.Generate(content) - if err != nil { - return nil, err - } - - pages = append(pages, generatedPage) - } - return pdf.NewPdf(builder.NewBuilder(), pages...), nil -} diff --git a/pkg/processor/mappers/pdfmapper/pdf_test.go b/pkg/processor/mappers/pdfmapper/pdf_test.go deleted file mode 100644 index dc28ec76..00000000 --- a/pkg/processor/mappers/pdfmapper/pdf_test.go +++ /dev/null @@ -1 +0,0 @@ -package pdfmapper_test diff --git a/pkg/processor/mappers/propsmapper/bar_code.go b/pkg/processor/mappers/propsmapper/bar_code.go deleted file mode 100644 index 26b7aab9..00000000 --- a/pkg/processor/mappers/propsmapper/bar_code.go +++ /dev/null @@ -1,5 +0,0 @@ -package propsmapper - -type BarCodeProps struct { - Align string `json:"align"` -} diff --git a/pkg/processor/mappers/propsmapper/col.go b/pkg/processor/mappers/propsmapper/col.go deleted file mode 100644 index 0f54681b..00000000 --- a/pkg/processor/mappers/propsmapper/col.go +++ /dev/null @@ -1,5 +0,0 @@ -package propsmapper - -type ColProps struct { - Size int `json:"size"` -} diff --git a/pkg/processor/mappers/propsmapper/color.go b/pkg/processor/mappers/propsmapper/color.go new file mode 100644 index 00000000..71d3adce --- /dev/null +++ b/pkg/processor/mappers/propsmapper/color.go @@ -0,0 +1,13 @@ +package propsmapper + +// Color represents a color in the RGB (Red, Green, Blue) space, +// is possible mix values, when all values are 0 the result color is black +// when all values are 255 the result color is white. +type Color struct { + // Red is the amount of red + Red int + // Green is the amount of red + Green int + // Blue is the amount of red + Blue int +} diff --git a/pkg/processor/mappers/propsmapper/customfont.go b/pkg/processor/mappers/propsmapper/customfont.go new file mode 100644 index 00000000..ea117971 --- /dev/null +++ b/pkg/processor/mappers/propsmapper/customfont.go @@ -0,0 +1,8 @@ +package propsmapper + +type CustomFont struct { + Family string + Style string + File string + Bytes []byte +} diff --git a/pkg/processor/mappers/propsmapper/dimensions.go b/pkg/processor/mappers/propsmapper/dimensions.go new file mode 100644 index 00000000..941790d8 --- /dev/null +++ b/pkg/processor/mappers/propsmapper/dimensions.go @@ -0,0 +1,7 @@ +package propsmapper + +// Dimensions is the representation of a width and height. +type Dimensions struct { + Width float64 `json:"width"` + Height float64 `json:"height"` +} diff --git a/pkg/processor/mappers/propsmapper/font.go b/pkg/processor/mappers/propsmapper/font.go new file mode 100644 index 00000000..0b8dff80 --- /dev/null +++ b/pkg/processor/mappers/propsmapper/font.go @@ -0,0 +1,13 @@ +package propsmapper + +// Font represents properties from a text. +type Font struct { + // Family of the text, ex: constf.Arial, helvetica and etc. + Family string + // Style of the text, ex: constf.Normal, bold and etc. + Style string + // Size of the text. + Size float64 + // Color define the font color. + Color *Color +} diff --git a/pkg/processor/mappers/propsmapper/margins.go b/pkg/processor/mappers/propsmapper/margins.go new file mode 100644 index 00000000..0627aee8 --- /dev/null +++ b/pkg/processor/mappers/propsmapper/margins.go @@ -0,0 +1,9 @@ +package propsmapper + +// Margins is the representation of a margin. +type Margins struct { + Left float64 `json:"left"` + Right float64 `json:"right"` + Top float64 `json:"top"` + Bottom float64 `json:"bottom"` +} diff --git a/pkg/processor/mappers/propsmapper/metadata.go b/pkg/processor/mappers/propsmapper/metadata.go new file mode 100644 index 00000000..cd41eb28 --- /dev/null +++ b/pkg/processor/mappers/propsmapper/metadata.go @@ -0,0 +1,19 @@ +package propsmapper + +import "time" + +// Metadata is the representation of a PDF metadata. +type Metadata struct { + Author *Utf8Text + Creator *Utf8Text + Subject *Utf8Text + Title *Utf8Text + CreationDate *time.Time + KeywordsStr *Utf8Text +} + +// Utf8Text is the representation of a text with a flag to indicate if it's UTF8. +type Utf8Text struct { + Text string + UTF8 bool +} diff --git a/pkg/processor/mappers/propsmapper/pagenumber.go b/pkg/processor/mappers/propsmapper/pagenumber.go new file mode 100644 index 00000000..803475ec --- /dev/null +++ b/pkg/processor/mappers/propsmapper/pagenumber.go @@ -0,0 +1,17 @@ +package propsmapper + +// PageNumber have attributes of page number +type PageNumber struct { + // Pattern is the string pattern which will be used to apply the page count component. + Pattern string + // Place defines where the page count component will be placed. + Place string + // Family defines which font family will be applied to page count. + Family string + // Style defines which font style will be applied to page count. + Style string + // Size defines which font size will be applied to page count. + Size float64 + // Color defines which will be applied to page count. + Color *Color +} diff --git a/pkg/processor/mappers/propsmapper/protection.go b/pkg/processor/mappers/propsmapper/protection.go new file mode 100644 index 00000000..e026adda --- /dev/null +++ b/pkg/processor/mappers/propsmapper/protection.go @@ -0,0 +1,8 @@ +package propsmapper + +// Protection is the representation of a pdf protection. +type Protection struct { + Type byte + UserPassword string + OwnerPassword string +} diff --git a/pkg/processor/mappers/propsmapper/text.go b/pkg/processor/mappers/propsmapper/text.go deleted file mode 100644 index 8cc553e6..00000000 --- a/pkg/processor/mappers/propsmapper/text.go +++ /dev/null @@ -1,5 +0,0 @@ -package propsmapper - -type TextProps struct { - Align string `json:"align"` -} diff --git a/pkg/processor/mappers/rowmapper/row.go b/pkg/processor/mappers/rowmapper/row.go index 9ee3716c..e0239274 100644 --- a/pkg/processor/mappers/rowmapper/row.go +++ b/pkg/processor/mappers/rowmapper/row.go @@ -1,65 +1,16 @@ // rowmapper is the package responsible for mapping row settings package rowmapper -import ( - "fmt" - - "github.com/johnfercher/maroto/v2/pkg/processor/components/col" - "github.com/johnfercher/maroto/v2/pkg/processor/components/row" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/colmapper" -) +import "github.com/johnfercher/maroto/v2/pkg/processor/components" type Row struct { - List string `json:"list"` - Cols []colmapper.Col `json:"cols"` -} - -// generate is responsible for the builder row according to the submitted content -func (r *Row) Generate(content map[string]interface{}) (*row.Row, error) { - if len(r.List) > 0 { - listContent, err := r.getListContent(r.List, content) - if err != nil { - return nil, err - } - content = listContent - } - - cols, err := r.generateCols(content) - if err != nil { - return nil, err - } - return row.NewRow(cols...), nil + Test string } -func (r *Row) getListContent(listKey string, content map[string]interface{}) (map[string]interface{}, error) { - contentList, ok := content[listKey] - if !ok { - return nil, fmt.Errorf("the model needed a list with key %s, but that key was not found in the content", r.List) - } - - contentMap, ok := contentList.([]interface{}) - if !ok { - return nil, fmt.Errorf("key \"%s\" references a content that cannot be converted to a valid format, ensure that this content can be converted to a map[string]interface{}", r.List) - } - - b := contentMap[0] - c, ok := b.(map[string]interface{}) - if !ok { - return nil, fmt.Errorf("key \"%s\" references a content that cannot be converted to a valid format, ensure that this content can be converted to a map[string]interface{}", r.List) - } - - return c, nil +func NewRow(document interface{}) (*Row, error) { + return &Row{Test: "a"}, nil } -func (r *Row) generateCols(content map[string]interface{}) ([]col.Col, error) { - generatedCols := make([]col.Col, len(r.Cols)) - - for i, col := range r.Cols { - generatedCol, err := col.Generate(content) - if err != nil { - return nil, err - } - generatedCols[i] = *generatedCol - } - return generatedCols, nil +func (r *Row) Generate(content map[string]interface{}) (components.Component, error) { + return nil, nil } diff --git a/pkg/processor/mappers/text/text.go b/pkg/processor/mappers/text/text.go deleted file mode 100644 index 0dafdbc2..00000000 --- a/pkg/processor/mappers/text/text.go +++ /dev/null @@ -1,36 +0,0 @@ -// text is the package responsible for mapping text settings -package text - -import ( - "fmt" - - "github.com/johnfercher/maroto/v2/pkg/processor/components" - "github.com/johnfercher/maroto/v2/pkg/processor/components/props" - "github.com/johnfercher/maroto/v2/pkg/processor/components/text" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" -) - -type Text struct { - Props propsmapper.TextProps `json:"props"` - SourceKey string `json:"source_key"` - DefaultValue string `json:"value"` -} - -// generate is responsible for the builder text according to the submitted content -func (t *Text) Generate(content map[string]interface{}) (components.Component, error) { - if t.DefaultValue != "" { - return text.NewText(props.TextProps{Align: t.Props.Align}, t.DefaultValue), nil - } - - value, ok := content[t.SourceKey] - if !ok { - return nil, fmt.Errorf("text model needs source key %s, but no content with that key was found", t.SourceKey) - } - - textValue, ok := value.(string) - if !ok { - return nil, fmt.Errorf("resource %s does not have a valid value for the text component", t.SourceKey) - } - - return text.NewText(props.TextProps{Align: t.Props.Align}, textValue), nil -} diff --git a/pkg/processor/mappers/text/text_test.go b/pkg/processor/mappers/text/text_test.go deleted file mode 100644 index e4ece32f..00000000 --- a/pkg/processor/mappers/text/text_test.go +++ /dev/null @@ -1 +0,0 @@ -package text_test diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index 1148a8f1..40730e28 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -1,20 +1,20 @@ package processor import ( + "fmt" + "github.com/johnfercher/maroto/v2/pkg/processor/core" "github.com/johnfercher/maroto/v2/pkg/processor/deserializer" - "github.com/johnfercher/maroto/v2/pkg/processor/provider" "github.com/johnfercher/maroto/v2/pkg/processor/repository" ) type processor struct { repository core.Repository - deserializer core.DocumentDeserializer - provider provider.Provider + deserializer core.Deserializer } func NewProcessor() *processor { - return &processor{repository: repository.NewMemoryStorage(), deserializer: deserializer.NewJsonDeserialize(), provider: provider.NewMaroto()} + return &processor{repository: repository.NewMemoryStorage(), deserializer: deserializer.NewJsonDeserialize()} } func (p *processor) RegisterTemplate(templateName string, template string) error { @@ -27,20 +27,16 @@ func (p *processor) GenerateDocument(templateName string, content string) ([]byt return nil, err } - documentTemplate, err := p.deserializer.DesserializeTemplate(templateJson) - if err != nil { - return nil, err - } - - documentContent, err := p.deserializer.DesserializeContent(content) + documentTemplate, err := p.deserializer.Deserialize(templateJson) if err != nil { return nil, err } + fmt.Println(documentTemplate) - pdfComponent, err := documentTemplate.Generate(documentContent) - if err != nil { - return nil, err - } + // documentContent, err := p.deserializer.DesserializeContent(content) + // if err != nil { + // return nil, err + // } - return pdfComponent.Generate(p.provider).GeneratePdf() + return nil, nil } From 7d77c89403a2d3ecdecc7ccd37be00ac733ddce5 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 9 Oct 2024 14:38:36 -0300 Subject: [PATCH 011/116] test: validate Builder deserialization --- .../mappers/buildermapper/bulder_test.go | 101 +++++++++++++++ .../mappers/propsmapper/color_test.go | 1 + .../mappers/propsmapper/customfont_test.go | 1 + .../mappers/propsmapper/dimensions_test.go | 1 + .../mappers/propsmapper/font_test.go | 1 + .../mappers/propsmapper/margins_test.go | 1 + .../mappers/propsmapper/metadata_test.go | 1 + .../mappers/propsmapper/pagenumber_test.go | 1 + .../mappers/propsmapper/protection_test.go | 1 + pkg/processor/test/File.go | 118 ++++++++++++++++++ pkg/processor/test/config.go | 12 ++ test/maroto/processor/all_builder_pros.json | 43 +++++++ .../processor/without_all_builder_props.json | 5 + .../processor/without_builder_props.json | 3 + 14 files changed, 290 insertions(+) create mode 100644 pkg/processor/mappers/buildermapper/bulder_test.go create mode 100644 pkg/processor/mappers/propsmapper/color_test.go create mode 100644 pkg/processor/mappers/propsmapper/customfont_test.go create mode 100644 pkg/processor/mappers/propsmapper/dimensions_test.go create mode 100644 pkg/processor/mappers/propsmapper/font_test.go create mode 100644 pkg/processor/mappers/propsmapper/margins_test.go create mode 100644 pkg/processor/mappers/propsmapper/metadata_test.go create mode 100644 pkg/processor/mappers/propsmapper/pagenumber_test.go create mode 100644 pkg/processor/mappers/propsmapper/protection_test.go create mode 100644 pkg/processor/test/File.go create mode 100644 pkg/processor/test/config.go create mode 100644 test/maroto/processor/all_builder_pros.json create mode 100644 test/maroto/processor/without_all_builder_props.json create mode 100644 test/maroto/processor/without_builder_props.json diff --git a/pkg/processor/mappers/buildermapper/bulder_test.go b/pkg/processor/mappers/buildermapper/bulder_test.go new file mode 100644 index 00000000..b341af10 --- /dev/null +++ b/pkg/processor/mappers/buildermapper/bulder_test.go @@ -0,0 +1,101 @@ +package buildermapper + +import ( + "encoding/json" + "testing" + "time" + + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/test" + "github.com/stretchr/testify/assert" +) + +func DefaultBuilderMap() *Builder { + time, _ := time.Parse("2006-01-02 15:04:05", "2024-10-09 14:30:00") + return &Builder{ + Dimensions: &propsmapper.Dimensions{ + Width: 10.0, + Height: 10.0, + }, + Margins: &propsmapper.Margins{ + Left: 10.0, + Right: 10.0, + Top: 10.0, + Bottom: 10.0, + }, + ChunkWorkers: 10, + Debug: true, + MaxGridSize: 10, + DefaultFont: &propsmapper.Font{ + Family: "Arial", + Style: "bold", + Size: 10, + Color: &propsmapper.Color{ + Red: 10, + Green: 100, + Blue: 150, + }, + }, + Protection: &propsmapper.Protection{ + Type: 4, + UserPassword: "senha123", + OwnerPassword: "senha123", + }, + Compression: true, + PageSize: "T", + Orientation: "portrait", + Metadata: &propsmapper.Metadata{ + Author: &propsmapper.Utf8Text{Text: "user_test", UTF8: true}, + Creator: &propsmapper.Utf8Text{Text: "user_test", UTF8: true}, + Subject: &propsmapper.Utf8Text{Text: "test", UTF8: true}, + Title: &propsmapper.Utf8Text{Text: "report", UTF8: true}, + CreationDate: &time, + KeywordsStr: &propsmapper.Utf8Text{Text: "test", UTF8: true}, + }, + DisableAutoPageBreak: true, + GenerationMode: "concurrent", + } +} + +func TestNewBuilder(t *testing.T) { + t.Run("when all builder properties are sent, it should generate the builder with all props", func(t *testing.T) { + builderMap := DefaultBuilderMap() + file, _ := test.NewFileReader().LoadFile("processor/all_builder_pros.json") + + var builderInterface interface{} + json.Unmarshal(file, &builderInterface) + + generateBuilder, err := NewBuilder(builderInterface) + assert.Nil(t, err) + assert.Equal(t, *builderMap, *generateBuilder) + }) + + t.Run("when props is not sent, it should use deafault props", func(t *testing.T) { + file, _ := test.NewFileReader().LoadFile("processor/without_all_builder_props.json") + const defaultDimensions = -1.0 + + var builderInterface interface{} + json.Unmarshal(file, &builderInterface) + + generateBuilder, err := NewBuilder(builderInterface) + assert.Nil(t, err) + assert.Equal(t, defaultDimensions, generateBuilder.Dimensions.Width) + }) + + t.Run("when no builder props is sent, no error is returned", func(t *testing.T) { + file, _ := test.NewFileReader().LoadFile("processor/without_builder_props.json") + + var builderInterface interface{} + json.Unmarshal(file, &builderInterface) + + _, err := NewBuilder(builderInterface) + assert.Nil(t, err) + }) + + t.Run("when an invalid Builder is sent, it should return an error", func(t *testing.T) { + var builderInterface interface{} = 1 + + _, err := NewBuilder(builderInterface) + assert.NotNil(t, err) + }) +} diff --git a/pkg/processor/mappers/propsmapper/color_test.go b/pkg/processor/mappers/propsmapper/color_test.go new file mode 100644 index 00000000..9426b76e --- /dev/null +++ b/pkg/processor/mappers/propsmapper/color_test.go @@ -0,0 +1 @@ +package propsmapper_test diff --git a/pkg/processor/mappers/propsmapper/customfont_test.go b/pkg/processor/mappers/propsmapper/customfont_test.go new file mode 100644 index 00000000..131847e4 --- /dev/null +++ b/pkg/processor/mappers/propsmapper/customfont_test.go @@ -0,0 +1 @@ +package propsmapper diff --git a/pkg/processor/mappers/propsmapper/dimensions_test.go b/pkg/processor/mappers/propsmapper/dimensions_test.go new file mode 100644 index 00000000..9426b76e --- /dev/null +++ b/pkg/processor/mappers/propsmapper/dimensions_test.go @@ -0,0 +1 @@ +package propsmapper_test diff --git a/pkg/processor/mappers/propsmapper/font_test.go b/pkg/processor/mappers/propsmapper/font_test.go new file mode 100644 index 00000000..9426b76e --- /dev/null +++ b/pkg/processor/mappers/propsmapper/font_test.go @@ -0,0 +1 @@ +package propsmapper_test diff --git a/pkg/processor/mappers/propsmapper/margins_test.go b/pkg/processor/mappers/propsmapper/margins_test.go new file mode 100644 index 00000000..9426b76e --- /dev/null +++ b/pkg/processor/mappers/propsmapper/margins_test.go @@ -0,0 +1 @@ +package propsmapper_test diff --git a/pkg/processor/mappers/propsmapper/metadata_test.go b/pkg/processor/mappers/propsmapper/metadata_test.go new file mode 100644 index 00000000..9426b76e --- /dev/null +++ b/pkg/processor/mappers/propsmapper/metadata_test.go @@ -0,0 +1 @@ +package propsmapper_test diff --git a/pkg/processor/mappers/propsmapper/pagenumber_test.go b/pkg/processor/mappers/propsmapper/pagenumber_test.go new file mode 100644 index 00000000..9426b76e --- /dev/null +++ b/pkg/processor/mappers/propsmapper/pagenumber_test.go @@ -0,0 +1 @@ +package propsmapper_test diff --git a/pkg/processor/mappers/propsmapper/protection_test.go b/pkg/processor/mappers/propsmapper/protection_test.go new file mode 100644 index 00000000..9426b76e --- /dev/null +++ b/pkg/processor/mappers/propsmapper/protection_test.go @@ -0,0 +1 @@ +package propsmapper_test diff --git a/pkg/processor/test/File.go b/pkg/processor/test/File.go new file mode 100644 index 00000000..1c63e795 --- /dev/null +++ b/pkg/processor/test/File.go @@ -0,0 +1,118 @@ +package test + +import ( + "errors" + "os" + "strings" + + "gopkg.in/yaml.v3" +) + +var ( + marotoFile = ".maroto.yml" + goModFile = "go.mod" + fileSingleton *File = nil +) + +type File struct { + config *Config +} + +func NewFileReader() *File { + if fileSingleton == nil { + path, err := getMarotoConfigFilePath() + if err != nil { + return nil + } + + cfg, err := loadMarotoConfigFile(path) + if err != nil { + return nil + } + + cfg.AbsolutePath = path + fileSingleton = &File{config: cfg} + } + + return fileSingleton +} + +func (f File) LoadFile(file string) ([]byte, error) { + fileContent, err := os.ReadFile(f.config.getAbsoluteFilePath(file)) + if err != nil { + return nil, err + } + return fileContent, err +} + +func getMarotoConfigFilePath() (string, error) { + path, _ := os.Getwd() + path += "/" + + return getMarotoConfigFilePathRecursive(path) +} + +func getMarotoConfigFilePathRecursive(path string) (string, error) { + hasMaroto, err := hasFileInPath(marotoFile, path) + if err != nil { + return "", err + } + + if hasMaroto { + return path, nil + } + + hasGoMod, err := hasFileInPath(goModFile, path) + if err != nil { + return "", err + } + + if hasGoMod { + return "", errors.New("found go.mod but not .maroto.yml") + } + + parentPath := getParentDir(path) + return getMarotoConfigFilePathRecursive(parentPath) +} + +func hasFileInPath(file string, path string) (bool, error) { + entries, err := os.ReadDir(path) + if err != nil { + return false, err + } + + for _, entry := range entries { + if entry.Name() == file { + return true, nil + } + } + + return false, nil +} + +func getParentDir(path string) string { + dirs := strings.Split(path, "/") + dirs = dirs[:len(dirs)-2] + + var newPath string + for _, dir := range dirs { + newPath += dir + "/" + } + + return newPath +} + +func loadMarotoConfigFile(path string) (*Config, error) { + bytes, err := os.ReadFile(path + "/" + marotoFile) + if err != nil { + return nil, err + } + + cfg := &Config{} + err = yaml.Unmarshal(bytes, cfg) + if err != nil { + return nil, err + } + + return cfg, nil +} diff --git a/pkg/processor/test/config.go b/pkg/processor/test/config.go new file mode 100644 index 00000000..63f335dc --- /dev/null +++ b/pkg/processor/test/config.go @@ -0,0 +1,12 @@ +// Package test implements unit test feature. +package test + +// Config is the representation of a test config. +type Config struct { + AbsolutePath string + TestPath string `yaml:"test_path"` +} + +func (c *Config) getAbsoluteFilePath(file string) string { + return c.AbsolutePath + c.TestPath + file +} diff --git a/test/maroto/processor/all_builder_pros.json b/test/maroto/processor/all_builder_pros.json new file mode 100644 index 00000000..a282c876 --- /dev/null +++ b/test/maroto/processor/all_builder_pros.json @@ -0,0 +1,43 @@ +{ + "dimensions": { + "width": 10.0, + "height": 10.0 + }, + "margins": { + "left": 10, + "right": 10, + "top": 10, + "bottom": 10 + }, + "chunk_workers": 10, + "debug": true, + "max_grid_size": 10, + "default_font": { + "family": "Arial", + "style": "bold", + "size": 10, + "color": { + "red": 10, + "green": 100, + "blue": 150 + } + }, + "protection": { + "type": "Print", + "user_password": "senha123", + "owner_password": "senha123" + }, + "compression": true, + "page_size": "T", + "orientation": "portrait", + "metadata": { + "author": {"text": "user_test", "utf8": true}, + "creator": {"text": "user_test", "utf8": true}, + "subject": {"text": "test", "utf8": true}, + "title": {"text": "report", "utf8": true}, + "creation_date": "2024-10-09 14:30:00", + "keywords_str": {"text": "test", "utf8": true} + }, + "disable_auto_page_break": true, + "generation_mode": "concurrent" +} \ No newline at end of file diff --git a/test/maroto/processor/without_all_builder_props.json b/test/maroto/processor/without_all_builder_props.json new file mode 100644 index 00000000..ca025525 --- /dev/null +++ b/test/maroto/processor/without_all_builder_props.json @@ -0,0 +1,5 @@ +{ + "dimensions": { + + } +} \ No newline at end of file diff --git a/test/maroto/processor/without_builder_props.json b/test/maroto/processor/without_builder_props.json new file mode 100644 index 00000000..c1860fa3 --- /dev/null +++ b/test/maroto/processor/without_builder_props.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file From 079b38e903a200499dfc5b54453f85324b4f2190 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 9 Oct 2024 14:39:33 -0300 Subject: [PATCH 012/116] feat: Add build props deserialization --- .../mappers/buildermapper/builder.go | 68 ++++++++++++++----- pkg/processor/mappers/propsmapper/color.go | 15 ++++ .../mappers/propsmapper/convert_fields.go | 19 ++++++ .../mappers/propsmapper/customfont.go | 24 +++++-- .../mappers/propsmapper/dimensions.go | 18 ++++- pkg/processor/mappers/propsmapper/font.go | 30 ++++++++ pkg/processor/mappers/propsmapper/margins.go | 24 +++++-- pkg/processor/mappers/propsmapper/metadata.go | 36 +++++++++- .../mappers/propsmapper/pagenumber.go | 28 ++++++-- .../mappers/propsmapper/protection.go | 30 ++++++++ 10 files changed, 260 insertions(+), 32 deletions(-) create mode 100644 pkg/processor/mappers/propsmapper/convert_fields.go diff --git a/pkg/processor/mappers/buildermapper/builder.go b/pkg/processor/mappers/buildermapper/builder.go index 34c0fa34..317447b4 100644 --- a/pkg/processor/mappers/buildermapper/builder.go +++ b/pkg/processor/mappers/buildermapper/builder.go @@ -1,21 +1,57 @@ package buildermapper -import "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" +import ( + "fmt" + + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" +) type Builder struct { - Dimensions propsmapper.Dimensions `json:"dimensions"` - Margins propsmapper.Margins `json:"margins"` - ChunkWorkers int `json:"chunk_workers"` - Debug bool `json:"debug"` - MaxGridSize int `json:"max_grid_size"` - DefaultFont propsmapper.Font `json:"default_font"` - CustomFonts []propsmapper.CustomFont `json:"custom_fonts"` - PageNumber propsmapper.PageNumber `json:"page_number"` - Protection propsmapper.Protection `json:"protection"` - Compression bool `json:"compression"` - PageSize string `json:"page_size"` - Orientation string `json:"orientation"` - Metadata propsmapper.Metadata `json:"metadata"` - DisableAutoPageBreak bool `json:"disable_auto_page_break"` - GenerationMode string `json:"generation_mode"` + Dimensions *propsmapper.Dimensions + Margins *propsmapper.Margins + ChunkWorkers int + Debug bool + MaxGridSize int + DefaultFont *propsmapper.Font + CustomFonts []*propsmapper.CustomFont + PageNumber *propsmapper.PageNumber + Protection *propsmapper.Protection + Compression bool + PageSize string + Orientation string + Metadata *propsmapper.Metadata + DisableAutoPageBreak bool + GenerationMode string +} + +// NewBuilder is responsible for creating Builder properties. If an invalid property is provided, a default value will be assigned. +func NewBuilder(builder interface{}) (*Builder, error) { + builderMap, ok := builder.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("builder settings could not be deserialized") + } + + return &Builder{ + Dimensions: propsmapper.NewDimensions(builderMap["dimensions"]), + Margins: propsmapper.NewMargins(builderMap["margins"]), + ChunkWorkers: int(factoryField(builderMap["chunk_workers"], -1.0)), + Debug: factoryField(builderMap["debug"], false), + MaxGridSize: int(factoryField(builderMap["max_grid_size"], -1.0)), + DefaultFont: propsmapper.NewFont(builderMap["default_font"]), + Protection: propsmapper.NewProtection(builderMap["protection"]), + Compression: factoryField(builderMap["compression"], false), + PageSize: factoryField(builderMap["page_size"], ""), + Orientation: factoryField(builderMap["orientation"], ""), + Metadata: propsmapper.NewMetadata(builderMap["metadata"]), + DisableAutoPageBreak: factoryField(builderMap["disable_auto_page_break"], false), + GenerationMode: factoryField(builderMap["generation_mode"], ""), + }, nil +} + +func factoryField[T any](val interface{}, defaultValue T) T { + result, ok := val.(T) + if !ok { + return defaultValue + } + return result } diff --git a/pkg/processor/mappers/propsmapper/color.go b/pkg/processor/mappers/propsmapper/color.go index 71d3adce..4df58a86 100644 --- a/pkg/processor/mappers/propsmapper/color.go +++ b/pkg/processor/mappers/propsmapper/color.go @@ -11,3 +11,18 @@ type Color struct { // Blue is the amount of red Blue int } + +// NewColor is responsible for creating the color, if the font fields cannot be +// converted, an invalid value is set. +func NewColor(color interface{}) *Color { + colorMap, ok := color.(map[string]interface{}) + if !ok { + return nil + } + + return &Color{ + Red: int(*convertFields(colorMap["red"], 0.0)), + Green: int(*convertFields(colorMap["green"], 0.0)), + Blue: int(*convertFields(colorMap["blue"], 0.0)), + } +} diff --git a/pkg/processor/mappers/propsmapper/convert_fields.go b/pkg/processor/mappers/propsmapper/convert_fields.go new file mode 100644 index 00000000..6385f49e --- /dev/null +++ b/pkg/processor/mappers/propsmapper/convert_fields.go @@ -0,0 +1,19 @@ +package propsmapper + +import "time" + +func convertFields[T any](val interface{}, defaultValue T) *T { + result, ok := val.(T) + if !ok { + return &defaultValue + } + return &result +} + +func factoryTime(date, layout string, defaultTime time.Time) *time.Time { + newTime, err := time.Parse(layout, date) + if err != nil { + return &defaultTime + } + return &newTime +} diff --git a/pkg/processor/mappers/propsmapper/customfont.go b/pkg/processor/mappers/propsmapper/customfont.go index ea117971..6649054f 100644 --- a/pkg/processor/mappers/propsmapper/customfont.go +++ b/pkg/processor/mappers/propsmapper/customfont.go @@ -1,8 +1,24 @@ package propsmapper type CustomFont struct { - Family string - Style string - File string - Bytes []byte + Family *string + Style *string + File *string + Bytes []*byte +} + +// NewCustomFont is responsible for creating the CustomFont, if the CustomFont fields cannot be +// converted, an invalid value is set. +func NewCustomFont(font interface{}) *CustomFont { + fontMap, ok := font.(map[string]interface{}) + if !ok { + return nil + } + + return &CustomFont{ + Family: convertFields(fontMap["family"], ""), + Style: convertFields(fontMap["style"], ""), + File: convertFields(fontMap["file"], ""), + // Bytes: NewColor(fontMap["bytes"]), + } } diff --git a/pkg/processor/mappers/propsmapper/dimensions.go b/pkg/processor/mappers/propsmapper/dimensions.go index 941790d8..33c52b54 100644 --- a/pkg/processor/mappers/propsmapper/dimensions.go +++ b/pkg/processor/mappers/propsmapper/dimensions.go @@ -2,6 +2,20 @@ package propsmapper // Dimensions is the representation of a width and height. type Dimensions struct { - Width float64 `json:"width"` - Height float64 `json:"height"` + Width float64 + Height float64 +} + +// NewDimensions is responsible for creating the dimensions, if the font fields cannot be +// converted, an invalid value is set. +func NewDimensions(dimensions interface{}) *Dimensions { + dimensionsMap, ok := dimensions.(map[string]interface{}) + if !ok { + return nil + } + + return &Dimensions{ + Width: *convertFields(dimensionsMap["width"], -1.0), + Height: *convertFields(dimensionsMap["height"], -1.0), + } } diff --git a/pkg/processor/mappers/propsmapper/font.go b/pkg/processor/mappers/propsmapper/font.go index 0b8dff80..4fe0dceb 100644 --- a/pkg/processor/mappers/propsmapper/font.go +++ b/pkg/processor/mappers/propsmapper/font.go @@ -11,3 +11,33 @@ type Font struct { // Color define the font color. Color *Color } + +// NewFont is responsible for creating the fonts, if the font fields cannot be +// converted, an invalid value is set. +func NewFont(font interface{}) *Font { + fontMap, ok := font.(map[string]interface{}) + if !ok { + return nil + } + + return &Font{ + Family: *convertFields(fontMap["family"], ""), + Style: *convertFields(fontMap["style"], ""), + Size: *convertFields(fontMap["size"], 0.0), + Color: NewColor(fontMap["color"]), + } +} + +func NewListFont(fontsSource interface{}) []*Font { + listOfFonts, ok := fontsSource.([]interface{}) + if !ok { + return nil + } + fonts := make([]*Font, len(listOfFonts)) + + for i, font := range listOfFonts { + fonts[i] = NewFont(font) + } + + return fonts +} diff --git a/pkg/processor/mappers/propsmapper/margins.go b/pkg/processor/mappers/propsmapper/margins.go index 0627aee8..43786ba0 100644 --- a/pkg/processor/mappers/propsmapper/margins.go +++ b/pkg/processor/mappers/propsmapper/margins.go @@ -2,8 +2,24 @@ package propsmapper // Margins is the representation of a margin. type Margins struct { - Left float64 `json:"left"` - Right float64 `json:"right"` - Top float64 `json:"top"` - Bottom float64 `json:"bottom"` + Left float64 + Right float64 + Top float64 + Bottom float64 +} + +// NewMargins is responsible for creating the margins, if the font fields cannot be +// converted, an invalid value is set. +func NewMargins(margins interface{}) *Margins { + marginsMap, ok := margins.(map[string]interface{}) + if !ok { + return nil + } + + return &Margins{ + Left: *convertFields(marginsMap["left"], -1.0), + Right: *convertFields(marginsMap["right"], -1.0), + Top: *convertFields(marginsMap["top"], -1.0), + Bottom: *convertFields(marginsMap["bottom"], -1.0), + } } diff --git a/pkg/processor/mappers/propsmapper/metadata.go b/pkg/processor/mappers/propsmapper/metadata.go index cd41eb28..941cfa1c 100644 --- a/pkg/processor/mappers/propsmapper/metadata.go +++ b/pkg/processor/mappers/propsmapper/metadata.go @@ -1,6 +1,8 @@ package propsmapper -import "time" +import ( + "time" +) // Metadata is the representation of a PDF metadata. type Metadata struct { @@ -17,3 +19,35 @@ type Utf8Text struct { Text string UTF8 bool } + +// NewUtf8Text is responsible for creating the Utf8Text, if the Utf8Text fields cannot be +// converted, an invalid value is set. +func NewUtf8Text(utf8Text interface{}) *Utf8Text { + utf8TextMap, ok := utf8Text.(map[string]interface{}) + if !ok { + return nil + } + + return &Utf8Text{ + Text: *convertFields(utf8TextMap["text"], ""), + UTF8: *convertFields(utf8TextMap["utf8"], true), + } +} + +// NewMetadata is responsible for creating the metadata, if the metadata fields cannot be +// converted, an invalid value is set. +func NewMetadata(metadata interface{}) *Metadata { + metadataMap, ok := metadata.(map[string]interface{}) + if !ok { + return nil + } + + return &Metadata{ + Author: NewUtf8Text(metadataMap["author"]), + Creator: NewUtf8Text(metadataMap["creator"]), + Subject: NewUtf8Text(metadataMap["subject"]), + Title: NewUtf8Text(metadataMap["title"]), + CreationDate: factoryTime(*convertFields(metadataMap["creation_date"], ""), "2006-01-02 15:04:05", time.Now()), + KeywordsStr: NewUtf8Text(metadataMap["keywords_str"]), + } +} diff --git a/pkg/processor/mappers/propsmapper/pagenumber.go b/pkg/processor/mappers/propsmapper/pagenumber.go index 803475ec..b34dbb55 100644 --- a/pkg/processor/mappers/propsmapper/pagenumber.go +++ b/pkg/processor/mappers/propsmapper/pagenumber.go @@ -3,15 +3,33 @@ package propsmapper // PageNumber have attributes of page number type PageNumber struct { // Pattern is the string pattern which will be used to apply the page count component. - Pattern string + Pattern *string // Place defines where the page count component will be placed. - Place string + Place *string // Family defines which font family will be applied to page count. - Family string + Family *string // Style defines which font style will be applied to page count. - Style string + Style *string // Size defines which font size will be applied to page count. - Size float64 + Size *float64 // Color defines which will be applied to page count. Color *Color } + +// NewPageNumber is responsible for creating the pageNumber, if the pageNumber fields cannot be +// converted, an invalid value is set. +func NewPageNumber(pageNumber interface{}) *PageNumber { + pageNumberMap, ok := pageNumber.(map[string]interface{}) + if !ok { + return nil + } + + return &PageNumber{ + Pattern: convertFields(pageNumberMap["pattern"], ""), + Place: convertFields(pageNumberMap["place"], ""), + Family: convertFields(pageNumberMap["family"], ""), + Style: convertFields(pageNumberMap["style"], ""), + Size: convertFields(pageNumberMap["size"], 0.0), + Color: NewColor(pageNumberMap["color"]), + } +} diff --git a/pkg/processor/mappers/propsmapper/protection.go b/pkg/processor/mappers/propsmapper/protection.go index e026adda..339538f9 100644 --- a/pkg/processor/mappers/propsmapper/protection.go +++ b/pkg/processor/mappers/propsmapper/protection.go @@ -6,3 +6,33 @@ type Protection struct { UserPassword string OwnerPassword string } + +// NewPageNumber is responsible for creating the pageNumber, if the pageNumber fields cannot be +// converted, an invalid value is set. +func NewProtection(protection interface{}) *Protection { + protectionMap, ok := protection.(map[string]interface{}) + if !ok { + return nil + } + + return &Protection{ + Type: factoryTypeProtection(*convertFields(protectionMap["type"], "None")), + UserPassword: *convertFields(protectionMap["user_password"], ""), + OwnerPassword: *convertFields(protectionMap["owner_password"], ""), + } +} + +func factoryTypeProtection(typeProtection string) byte { + switch typeProtection { + case "Print": + return 4 + case "Modify": + return 8 + case "Copy": + return 16 + case "AnnotForms": + return 32 + } + + return 0 +} From ed17cdba85e33c74957459fe228f564b96301839 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 9 Oct 2024 14:52:56 -0300 Subject: [PATCH 013/116] fix: generate valid build structure --- .../mappers/documentmapper/document.go | 35 ++++++++++--------- pkg/processor/mappers/rowmapper/row.go | 2 +- pkg/processor/processor.go | 11 ++---- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/pkg/processor/mappers/documentmapper/document.go b/pkg/processor/mappers/documentmapper/document.go index 94b064a6..0347ff99 100644 --- a/pkg/processor/mappers/documentmapper/document.go +++ b/pkg/processor/mappers/documentmapper/document.go @@ -5,12 +5,12 @@ import ( "fmt" "github.com/johnfercher/maroto/v2/pkg/processor/components/pdf" - "github.com/johnfercher/maroto/v2/pkg/processor2/core" - "github.com/johnfercher/maroto/v2/pkg/processor2/mappers" - "github.com/johnfercher/maroto/v2/pkg/processor2/mappers/buildermapper" - "github.com/johnfercher/maroto/v2/pkg/processor2/mappers/listmapper" - "github.com/johnfercher/maroto/v2/pkg/processor2/mappers/pagemapper" - "github.com/johnfercher/maroto/v2/pkg/processor2/mappers/rowmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/core" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/buildermapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/listmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pagemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rowmapper" ) type Document struct { @@ -67,23 +67,24 @@ func (p *Document) getFieldMappers() map[string]func(interface{}) error { // setBuilder is responsible for factories builder information func (p *Document) setBuilder(builderDoc interface{}) error { - builder, ok := builderDoc.(buildermapper.Builder) - if !ok { - return fmt.Errorf("builder settings could not be deserialized") + builder, err := buildermapper.NewBuilder(builderDoc) + if err != nil { + return err } - p.Builder = builder + + p.Builder = *builder return nil } // setHeader is responsible for factory the header func (p *Document) setHeader(rowsDoc interface{}) error { - rowsTemplate, ok := rowsDoc.([]interface{}) + rowsTemplate, ok := rowsDoc.(map[string]interface{}) if !ok { return fmt.Errorf("header cannot be deserialized, ensure header has an array of rows") } - for _, rowTemplate := range rowsTemplate { - row, err := rowmapper.NewRow(rowTemplate) + for templateKey, rowTemplate := range rowsTemplate { + row, err := rowmapper.NewRow(rowTemplate, templateKey) if err != nil { return err } @@ -95,13 +96,13 @@ func (p *Document) setHeader(rowsDoc interface{}) error { // setFooter is responsible for factory the footer func (p *Document) setFooter(rowsDoc interface{}) error { - rowsTemplate, ok := rowsDoc.([]interface{}) + rowsTemplate, ok := rowsDoc.(map[string]interface{}) if !ok { - return fmt.Errorf("header cannot be deserialized, ensure header has an array of rows") + return fmt.Errorf("footer cannot be deserialized, ensure footer has an array of rows") } - for _, rowTemplate := range rowsTemplate { - row, err := rowmapper.NewRow(rowTemplate) + for templateKey, rowTemplate := range rowsTemplate { + row, err := rowmapper.NewRow(rowTemplate, templateKey) if err != nil { return err } diff --git a/pkg/processor/mappers/rowmapper/row.go b/pkg/processor/mappers/rowmapper/row.go index e0239274..98d3e7e9 100644 --- a/pkg/processor/mappers/rowmapper/row.go +++ b/pkg/processor/mappers/rowmapper/row.go @@ -7,7 +7,7 @@ type Row struct { Test string } -func NewRow(document interface{}) (*Row, error) { +func NewRow(document interface{}, sourceKey string) (*Row, error) { return &Row{Test: "a"}, nil } diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index 40730e28..2911b4fe 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -1,10 +1,9 @@ package processor import ( - "fmt" - "github.com/johnfercher/maroto/v2/pkg/processor/core" "github.com/johnfercher/maroto/v2/pkg/processor/deserializer" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/documentmapper" "github.com/johnfercher/maroto/v2/pkg/processor/repository" ) @@ -27,16 +26,10 @@ func (p *processor) GenerateDocument(templateName string, content string) ([]byt return nil, err } - documentTemplate, err := p.deserializer.Deserialize(templateJson) + document, err := documentmapper.NewPdf(templateJson, p.deserializer) if err != nil { return nil, err } - fmt.Println(documentTemplate) - - // documentContent, err := p.deserializer.DesserializeContent(content) - // if err != nil { - // return nil, err - // } return nil, nil } From 817e9cbe598bf17cb6a8e492625a815efd24f2f5 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 10 Oct 2024 14:36:25 -0300 Subject: [PATCH 014/116] feat: provide an abstract factory to create mapper components create a factory that wrapper the creation of components to facilitate the creation of unit tests --- pkg/processor/components/builder/builder.go | 3 +- .../deserializer/json_desserialize.go | 4 +-- .../abstractfactory/abstractfactory.go | 30 +++++++++++++++++++ pkg/processor/mappers/component_mapper.go | 8 +++++ pkg/processor/processor.go | 6 +++- 5 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 pkg/processor/mappers/abstractfactory/abstractfactory.go diff --git a/pkg/processor/components/builder/builder.go b/pkg/processor/components/builder/builder.go index 476e13e9..7870c7c0 100644 --- a/pkg/processor/components/builder/builder.go +++ b/pkg/processor/components/builder/builder.go @@ -1,7 +1,6 @@ package builder -type Builder struct { -} +type Builder struct{} func NewBuilder() *Builder { return nil diff --git a/pkg/processor/deserializer/json_desserialize.go b/pkg/processor/deserializer/json_desserialize.go index 5e91c1de..27daeeac 100644 --- a/pkg/processor/deserializer/json_desserialize.go +++ b/pkg/processor/deserializer/json_desserialize.go @@ -5,8 +5,7 @@ import ( "encoding/json" ) -type jsonDeserializer struct { -} +type jsonDeserializer struct{} func NewJsonDeserialize() *jsonDeserializer { return &jsonDeserializer{} @@ -16,5 +15,4 @@ func (j *jsonDeserializer) Deserialize(documentJson string) (map[string]interfac var document map[string]interface{} err := json.Unmarshal([]byte(documentJson), &document) return document, err - } diff --git a/pkg/processor/mappers/abstractfactory/abstractfactory.go b/pkg/processor/mappers/abstractfactory/abstractfactory.go new file mode 100644 index 00000000..aa84d873 --- /dev/null +++ b/pkg/processor/mappers/abstractfactory/abstractfactory.go @@ -0,0 +1,30 @@ +package abstractfactory + +import ( + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/listmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pagemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rowmapper" +) + +// abstractFactoryMaps is responsible for providing a factory for all mapper components +type abstractFactoryMaps struct{} + +func NewAbstractFactoryMaps() *abstractFactoryMaps { + return &abstractFactoryMaps{} +} + +// NewRow is responsible for wrapper the creation of a row +func (f *abstractFactoryMaps) NewRow(document interface{}, sourceKey string) (mappers.Componentmapper, error) { + return rowmapper.NewRow(document, sourceKey) +} + +// NewPage is responsible for wrapper the creation of a page +func (f *abstractFactoryMaps) NewPage(document interface{}, sourceKey string) (mappers.Componentmapper, error) { + return pagemapper.NewPage(document, sourceKey) +} + +// NewList is responsible for wrapper the creation of a list +func (f *abstractFactoryMaps) NewList(document interface{}, sourceKey string, generate mappers.GenerateComponent) (mappers.Componentmapper, error) { + return listmapper.NewList(document, sourceKey, generate) +} diff --git a/pkg/processor/mappers/component_mapper.go b/pkg/processor/mappers/component_mapper.go index 61848e65..aabbaa0e 100644 --- a/pkg/processor/mappers/component_mapper.go +++ b/pkg/processor/mappers/component_mapper.go @@ -2,6 +2,14 @@ package mappers import "github.com/johnfercher/maroto/v2/pkg/processor/components" +type GenerateComponent func(document interface{}, sourceKey string) (Componentmapper, error) + type Componentmapper interface { Generate(content map[string]interface{}) (components.Component, error) } + +type AbstractFactoryMaps interface { + NewRow(document interface{}, sourceKey string) (Componentmapper, error) + NewPage(document interface{}, sourceKey string) (Componentmapper, error) + NewList(document interface{}, sourceKey string, generate GenerateComponent) (Componentmapper, error) +} diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index 2911b4fe..a21a464b 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -1,8 +1,11 @@ package processor import ( + "fmt" + "github.com/johnfercher/maroto/v2/pkg/processor/core" "github.com/johnfercher/maroto/v2/pkg/processor/deserializer" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/abstractfactory" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/documentmapper" "github.com/johnfercher/maroto/v2/pkg/processor/repository" ) @@ -26,10 +29,11 @@ func (p *processor) GenerateDocument(templateName string, content string) ([]byt return nil, err } - document, err := documentmapper.NewPdf(templateJson, p.deserializer) + document, err := documentmapper.NewPdf(templateJson, p.deserializer, abstractfactory.NewAbstractFactoryMaps()) if err != nil { return nil, err } + fmt.Print(document) return nil, nil } From ca8ec923cfe16356552ddf39a4e0eb57b8f79f26 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 10 Oct 2024 14:46:09 -0300 Subject: [PATCH 015/116] test: validate document creation --- internal/fixture/processorfixture.go | 23 + mocks/AbstractFactoryMaps.go | 214 +++++ mocks/Componentmapper.go | 95 ++ mocks/Deserializer.go | 91 ++ mocks/GenerateComponent.go | 95 ++ mocks/Processor.go | 129 +++ mocks/Provider.go | 853 ++++++------------ .../mappers/documentmapper/document_test.go | 145 +++ 8 files changed, 1058 insertions(+), 587 deletions(-) create mode 100644 internal/fixture/processorfixture.go create mode 100644 mocks/AbstractFactoryMaps.go create mode 100644 mocks/Componentmapper.go create mode 100644 mocks/Deserializer.go create mode 100644 mocks/GenerateComponent.go create mode 100644 mocks/Processor.go diff --git a/internal/fixture/processorfixture.go b/internal/fixture/processorfixture.go new file mode 100644 index 00000000..7586c27b --- /dev/null +++ b/internal/fixture/processorfixture.go @@ -0,0 +1,23 @@ +package fixture + +import ( + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/listmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pagemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rowmapper" +) + +func MapperRow() *rowmapper.Row { + return &rowmapper.Row{ + Test: "1", + } +} + +func MapperPage() *pagemapper.Page { + return &pagemapper.Page{ + Teste: "1", + } +} + +func MapperList() *listmapper.List { + return &listmapper.List{} +} diff --git a/mocks/AbstractFactoryMaps.go b/mocks/AbstractFactoryMaps.go new file mode 100644 index 00000000..afeec53f --- /dev/null +++ b/mocks/AbstractFactoryMaps.go @@ -0,0 +1,214 @@ +// Code generated by mockery v2.42.0. DO NOT EDIT. + +package mocks + +import ( + mappers "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + mock "github.com/stretchr/testify/mock" +) + +// AbstractFactoryMaps is an autogenerated mock type for the AbstractFactoryMaps type +type AbstractFactoryMaps struct { + mock.Mock +} + +type AbstractFactoryMaps_Expecter struct { + mock *mock.Mock +} + +func (_m *AbstractFactoryMaps) EXPECT() *AbstractFactoryMaps_Expecter { + return &AbstractFactoryMaps_Expecter{mock: &_m.Mock} +} + +// NewList provides a mock function with given fields: document, sourceKey, generate +func (_m *AbstractFactoryMaps) NewList(document interface{}, sourceKey string, generate mappers.GenerateComponent) (mappers.Componentmapper, error) { + ret := _m.Called(document, sourceKey, generate) + + if len(ret) == 0 { + panic("no return value specified for NewList") + } + + var r0 mappers.Componentmapper + var r1 error + if rf, ok := ret.Get(0).(func(interface{}, string, mappers.GenerateComponent) (mappers.Componentmapper, error)); ok { + return rf(document, sourceKey, generate) + } + if rf, ok := ret.Get(0).(func(interface{}, string, mappers.GenerateComponent) mappers.Componentmapper); ok { + r0 = rf(document, sourceKey, generate) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mappers.Componentmapper) + } + } + + if rf, ok := ret.Get(1).(func(interface{}, string, mappers.GenerateComponent) error); ok { + r1 = rf(document, sourceKey, generate) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AbstractFactoryMaps_NewList_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewList' +type AbstractFactoryMaps_NewList_Call struct { + *mock.Call +} + +// NewList is a helper method to define mock.On call +// - document interface{} +// - sourceKey string +// - generate mappers.GenerateComponent +func (_e *AbstractFactoryMaps_Expecter) NewList(document interface{}, sourceKey interface{}, generate interface{}) *AbstractFactoryMaps_NewList_Call { + return &AbstractFactoryMaps_NewList_Call{Call: _e.mock.On("NewList", document, sourceKey, generate)} +} + +func (_c *AbstractFactoryMaps_NewList_Call) Run(run func(document interface{}, sourceKey string, generate mappers.GenerateComponent)) *AbstractFactoryMaps_NewList_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{}), args[1].(string), args[2].(mappers.GenerateComponent)) + }) + return _c +} + +func (_c *AbstractFactoryMaps_NewList_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewList_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AbstractFactoryMaps_NewList_Call) RunAndReturn(run func(interface{}, string, mappers.GenerateComponent) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewList_Call { + _c.Call.Return(run) + return _c +} + +// NewPage provides a mock function with given fields: document, sourceKey +func (_m *AbstractFactoryMaps) NewPage(document interface{}, sourceKey string) (mappers.Componentmapper, error) { + ret := _m.Called(document, sourceKey) + + if len(ret) == 0 { + panic("no return value specified for NewPage") + } + + var r0 mappers.Componentmapper + var r1 error + if rf, ok := ret.Get(0).(func(interface{}, string) (mappers.Componentmapper, error)); ok { + return rf(document, sourceKey) + } + if rf, ok := ret.Get(0).(func(interface{}, string) mappers.Componentmapper); ok { + r0 = rf(document, sourceKey) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mappers.Componentmapper) + } + } + + if rf, ok := ret.Get(1).(func(interface{}, string) error); ok { + r1 = rf(document, sourceKey) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AbstractFactoryMaps_NewPage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewPage' +type AbstractFactoryMaps_NewPage_Call struct { + *mock.Call +} + +// NewPage is a helper method to define mock.On call +// - document interface{} +// - sourceKey string +func (_e *AbstractFactoryMaps_Expecter) NewPage(document interface{}, sourceKey interface{}) *AbstractFactoryMaps_NewPage_Call { + return &AbstractFactoryMaps_NewPage_Call{Call: _e.mock.On("NewPage", document, sourceKey)} +} + +func (_c *AbstractFactoryMaps_NewPage_Call) Run(run func(document interface{}, sourceKey string)) *AbstractFactoryMaps_NewPage_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{}), args[1].(string)) + }) + return _c +} + +func (_c *AbstractFactoryMaps_NewPage_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewPage_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AbstractFactoryMaps_NewPage_Call) RunAndReturn(run func(interface{}, string) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewPage_Call { + _c.Call.Return(run) + return _c +} + +// NewRow provides a mock function with given fields: document, sourceKey +func (_m *AbstractFactoryMaps) NewRow(document interface{}, sourceKey string) (mappers.Componentmapper, error) { + ret := _m.Called(document, sourceKey) + + if len(ret) == 0 { + panic("no return value specified for NewRow") + } + + var r0 mappers.Componentmapper + var r1 error + if rf, ok := ret.Get(0).(func(interface{}, string) (mappers.Componentmapper, error)); ok { + return rf(document, sourceKey) + } + if rf, ok := ret.Get(0).(func(interface{}, string) mappers.Componentmapper); ok { + r0 = rf(document, sourceKey) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mappers.Componentmapper) + } + } + + if rf, ok := ret.Get(1).(func(interface{}, string) error); ok { + r1 = rf(document, sourceKey) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AbstractFactoryMaps_NewRow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewRow' +type AbstractFactoryMaps_NewRow_Call struct { + *mock.Call +} + +// NewRow is a helper method to define mock.On call +// - document interface{} +// - sourceKey string +func (_e *AbstractFactoryMaps_Expecter) NewRow(document interface{}, sourceKey interface{}) *AbstractFactoryMaps_NewRow_Call { + return &AbstractFactoryMaps_NewRow_Call{Call: _e.mock.On("NewRow", document, sourceKey)} +} + +func (_c *AbstractFactoryMaps_NewRow_Call) Run(run func(document interface{}, sourceKey string)) *AbstractFactoryMaps_NewRow_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{}), args[1].(string)) + }) + return _c +} + +func (_c *AbstractFactoryMaps_NewRow_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewRow_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AbstractFactoryMaps_NewRow_Call) RunAndReturn(run func(interface{}, string) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewRow_Call { + _c.Call.Return(run) + return _c +} + +// NewAbstractFactoryMaps creates a new instance of AbstractFactoryMaps. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewAbstractFactoryMaps(t interface { + mock.TestingT + Cleanup(func()) +}, +) *AbstractFactoryMaps { + mock := &AbstractFactoryMaps{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/Componentmapper.go b/mocks/Componentmapper.go new file mode 100644 index 00000000..e668fe34 --- /dev/null +++ b/mocks/Componentmapper.go @@ -0,0 +1,95 @@ +// Code generated by mockery v2.42.0. DO NOT EDIT. + +package mocks + +import ( + components "github.com/johnfercher/maroto/v2/pkg/processor/components" + + mock "github.com/stretchr/testify/mock" +) + +// Componentmapper is an autogenerated mock type for the Componentmapper type +type Componentmapper struct { + mock.Mock +} + +type Componentmapper_Expecter struct { + mock *mock.Mock +} + +func (_m *Componentmapper) EXPECT() *Componentmapper_Expecter { + return &Componentmapper_Expecter{mock: &_m.Mock} +} + +// Generate provides a mock function with given fields: content +func (_m *Componentmapper) Generate(content map[string]interface{}) (components.Component, error) { + ret := _m.Called(content) + + if len(ret) == 0 { + panic("no return value specified for Generate") + } + + var r0 components.Component + var r1 error + if rf, ok := ret.Get(0).(func(map[string]interface{}) (components.Component, error)); ok { + return rf(content) + } + if rf, ok := ret.Get(0).(func(map[string]interface{}) components.Component); ok { + r0 = rf(content) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(components.Component) + } + } + + if rf, ok := ret.Get(1).(func(map[string]interface{}) error); ok { + r1 = rf(content) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Componentmapper_Generate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Generate' +type Componentmapper_Generate_Call struct { + *mock.Call +} + +// Generate is a helper method to define mock.On call +// - content map[string]interface{} +func (_e *Componentmapper_Expecter) Generate(content interface{}) *Componentmapper_Generate_Call { + return &Componentmapper_Generate_Call{Call: _e.mock.On("Generate", content)} +} + +func (_c *Componentmapper_Generate_Call) Run(run func(content map[string]interface{})) *Componentmapper_Generate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(map[string]interface{})) + }) + return _c +} + +func (_c *Componentmapper_Generate_Call) Return(_a0 components.Component, _a1 error) *Componentmapper_Generate_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Componentmapper_Generate_Call) RunAndReturn(run func(map[string]interface{}) (components.Component, error)) *Componentmapper_Generate_Call { + _c.Call.Return(run) + return _c +} + +// NewComponentmapper creates a new instance of Componentmapper. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewComponentmapper(t interface { + mock.TestingT + Cleanup(func()) +}, +) *Componentmapper { + mock := &Componentmapper{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/Deserializer.go b/mocks/Deserializer.go new file mode 100644 index 00000000..b5dcd4c4 --- /dev/null +++ b/mocks/Deserializer.go @@ -0,0 +1,91 @@ +// Code generated by mockery v2.42.0. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// Deserializer is an autogenerated mock type for the Deserializer type +type Deserializer struct { + mock.Mock +} + +type Deserializer_Expecter struct { + mock *mock.Mock +} + +func (_m *Deserializer) EXPECT() *Deserializer_Expecter { + return &Deserializer_Expecter{mock: &_m.Mock} +} + +// Deserialize provides a mock function with given fields: document +func (_m *Deserializer) Deserialize(document string) (map[string]interface{}, error) { + ret := _m.Called(document) + + if len(ret) == 0 { + panic("no return value specified for Deserialize") + } + + var r0 map[string]interface{} + var r1 error + if rf, ok := ret.Get(0).(func(string) (map[string]interface{}, error)); ok { + return rf(document) + } + if rf, ok := ret.Get(0).(func(string) map[string]interface{}); ok { + r0 = rf(document) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[string]interface{}) + } + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(document) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Deserializer_Deserialize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Deserialize' +type Deserializer_Deserialize_Call struct { + *mock.Call +} + +// Deserialize is a helper method to define mock.On call +// - document string +func (_e *Deserializer_Expecter) Deserialize(document interface{}) *Deserializer_Deserialize_Call { + return &Deserializer_Deserialize_Call{Call: _e.mock.On("Deserialize", document)} +} + +func (_c *Deserializer_Deserialize_Call) Run(run func(document string)) *Deserializer_Deserialize_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Deserializer_Deserialize_Call) Return(_a0 map[string]interface{}, _a1 error) *Deserializer_Deserialize_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Deserializer_Deserialize_Call) RunAndReturn(run func(string) (map[string]interface{}, error)) *Deserializer_Deserialize_Call { + _c.Call.Return(run) + return _c +} + +// NewDeserializer creates a new instance of Deserializer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewDeserializer(t interface { + mock.TestingT + Cleanup(func()) +}, +) *Deserializer { + mock := &Deserializer{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/GenerateComponent.go b/mocks/GenerateComponent.go new file mode 100644 index 00000000..932c0278 --- /dev/null +++ b/mocks/GenerateComponent.go @@ -0,0 +1,95 @@ +// Code generated by mockery v2.42.0. DO NOT EDIT. + +package mocks + +import ( + mappers "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + mock "github.com/stretchr/testify/mock" +) + +// GenerateComponent is an autogenerated mock type for the GenerateComponent type +type GenerateComponent struct { + mock.Mock +} + +type GenerateComponent_Expecter struct { + mock *mock.Mock +} + +func (_m *GenerateComponent) EXPECT() *GenerateComponent_Expecter { + return &GenerateComponent_Expecter{mock: &_m.Mock} +} + +// Execute provides a mock function with given fields: document, sourceKey +func (_m *GenerateComponent) Execute(document interface{}, sourceKey string) (mappers.Componentmapper, error) { + ret := _m.Called(document, sourceKey) + + if len(ret) == 0 { + panic("no return value specified for Execute") + } + + var r0 mappers.Componentmapper + var r1 error + if rf, ok := ret.Get(0).(func(interface{}, string) (mappers.Componentmapper, error)); ok { + return rf(document, sourceKey) + } + if rf, ok := ret.Get(0).(func(interface{}, string) mappers.Componentmapper); ok { + r0 = rf(document, sourceKey) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mappers.Componentmapper) + } + } + + if rf, ok := ret.Get(1).(func(interface{}, string) error); ok { + r1 = rf(document, sourceKey) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GenerateComponent_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' +type GenerateComponent_Execute_Call struct { + *mock.Call +} + +// Execute is a helper method to define mock.On call +// - document interface{} +// - sourceKey string +func (_e *GenerateComponent_Expecter) Execute(document interface{}, sourceKey interface{}) *GenerateComponent_Execute_Call { + return &GenerateComponent_Execute_Call{Call: _e.mock.On("Execute", document, sourceKey)} +} + +func (_c *GenerateComponent_Execute_Call) Run(run func(document interface{}, sourceKey string)) *GenerateComponent_Execute_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{}), args[1].(string)) + }) + return _c +} + +func (_c *GenerateComponent_Execute_Call) Return(_a0 mappers.Componentmapper, _a1 error) *GenerateComponent_Execute_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *GenerateComponent_Execute_Call) RunAndReturn(run func(interface{}, string) (mappers.Componentmapper, error)) *GenerateComponent_Execute_Call { + _c.Call.Return(run) + return _c +} + +// NewGenerateComponent creates a new instance of GenerateComponent. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewGenerateComponent(t interface { + mock.TestingT + Cleanup(func()) +}, +) *GenerateComponent { + mock := &GenerateComponent{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/Processor.go b/mocks/Processor.go new file mode 100644 index 00000000..c8d28d27 --- /dev/null +++ b/mocks/Processor.go @@ -0,0 +1,129 @@ +// Code generated by mockery v2.42.0. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// Processor is an autogenerated mock type for the Processor type +type Processor struct { + mock.Mock +} + +type Processor_Expecter struct { + mock *mock.Mock +} + +func (_m *Processor) EXPECT() *Processor_Expecter { + return &Processor_Expecter{mock: &_m.Mock} +} + +// GenerateDocument provides a mock function with given fields: templateName, content +func (_m *Processor) GenerateDocument(templateName string, content string) []byte { + ret := _m.Called(templateName, content) + + if len(ret) == 0 { + panic("no return value specified for GenerateDocument") + } + + var r0 []byte + if rf, ok := ret.Get(0).(func(string, string) []byte); ok { + r0 = rf(templateName, content) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + return r0 +} + +// Processor_GenerateDocument_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GenerateDocument' +type Processor_GenerateDocument_Call struct { + *mock.Call +} + +// GenerateDocument is a helper method to define mock.On call +// - templateName string +// - content string +func (_e *Processor_Expecter) GenerateDocument(templateName interface{}, content interface{}) *Processor_GenerateDocument_Call { + return &Processor_GenerateDocument_Call{Call: _e.mock.On("GenerateDocument", templateName, content)} +} + +func (_c *Processor_GenerateDocument_Call) Run(run func(templateName string, content string)) *Processor_GenerateDocument_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(string)) + }) + return _c +} + +func (_c *Processor_GenerateDocument_Call) Return(_a0 []byte) *Processor_GenerateDocument_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Processor_GenerateDocument_Call) RunAndReturn(run func(string, string) []byte) *Processor_GenerateDocument_Call { + _c.Call.Return(run) + return _c +} + +// RegisterTemplate provides a mock function with given fields: templateName, template +func (_m *Processor) RegisterTemplate(templateName string, template string) error { + ret := _m.Called(templateName, template) + + if len(ret) == 0 { + panic("no return value specified for RegisterTemplate") + } + + var r0 error + if rf, ok := ret.Get(0).(func(string, string) error); ok { + r0 = rf(templateName, template) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// Processor_RegisterTemplate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterTemplate' +type Processor_RegisterTemplate_Call struct { + *mock.Call +} + +// RegisterTemplate is a helper method to define mock.On call +// - templateName string +// - template string +func (_e *Processor_Expecter) RegisterTemplate(templateName interface{}, template interface{}) *Processor_RegisterTemplate_Call { + return &Processor_RegisterTemplate_Call{Call: _e.mock.On("RegisterTemplate", templateName, template)} +} + +func (_c *Processor_RegisterTemplate_Call) Run(run func(templateName string, template string)) *Processor_RegisterTemplate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(string)) + }) + return _c +} + +func (_c *Processor_RegisterTemplate_Call) Return(_a0 error) *Processor_RegisterTemplate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Processor_RegisterTemplate_Call) RunAndReturn(run func(string, string) error) *Processor_RegisterTemplate_Call { + _c.Call.Return(run) + return _c +} + +// NewProcessor creates a new instance of Processor. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewProcessor(t interface { + mock.TestingT + Cleanup(func()) +}, +) *Processor { + mock := &Processor{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/Provider.go b/mocks/Provider.go index dd7b2bf4..7b016909 100644 --- a/mocks/Provider.go +++ b/mocks/Provider.go @@ -3,12 +3,14 @@ package mocks import ( - extension "github.com/johnfercher/maroto/v2/pkg/consts/extension" - entity "github.com/johnfercher/maroto/v2/pkg/core/entity" + core "github.com/johnfercher/maroto/v2/pkg/core" + builder "github.com/johnfercher/maroto/v2/pkg/processor/components/builder" mock "github.com/stretchr/testify/mock" - props "github.com/johnfercher/maroto/v2/pkg/props" + props "github.com/johnfercher/maroto/v2/pkg/processor/components/props" + + provider "github.com/johnfercher/maroto/v2/pkg/processor/provider" ) // Provider is an autogenerated mock type for the Provider type @@ -24,611 +26,360 @@ func (_m *Provider) EXPECT() *Provider_Expecter { return &Provider_Expecter{mock: &_m.Mock} } -// AddBackgroundImageFromBytes provides a mock function with given fields: bytes, cell, prop, _a3 -func (_m *Provider) AddBackgroundImageFromBytes(bytes []byte, cell *entity.Cell, prop *props.Rect, _a3 extension.Type) { - _m.Called(bytes, cell, prop, _a3) -} - -// Provider_AddBackgroundImageFromBytes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddBackgroundImageFromBytes' -type Provider_AddBackgroundImageFromBytes_Call struct { - *mock.Call -} - -// AddBackgroundImageFromBytes is a helper method to define mock.On call -// - bytes []byte -// - cell *entity.Cell -// - prop *props.Rect -// - _a3 extension.Type -func (_e *Provider_Expecter) AddBackgroundImageFromBytes(bytes interface{}, cell interface{}, prop interface{}, _a3 interface{}) *Provider_AddBackgroundImageFromBytes_Call { - return &Provider_AddBackgroundImageFromBytes_Call{Call: _e.mock.On("AddBackgroundImageFromBytes", bytes, cell, prop, _a3)} -} - -func (_c *Provider_AddBackgroundImageFromBytes_Call) Run(run func(bytes []byte, cell *entity.Cell, prop *props.Rect, _a3 extension.Type)) *Provider_AddBackgroundImageFromBytes_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].([]byte), args[1].(*entity.Cell), args[2].(*props.Rect), args[3].(extension.Type)) - }) - return _c -} +// ConfigureBuilder provides a mock function with given fields: _a0 +func (_m *Provider) ConfigureBuilder(_a0 builder.Builder) provider.Provider { + ret := _m.Called(_a0) -func (_c *Provider_AddBackgroundImageFromBytes_Call) Return() *Provider_AddBackgroundImageFromBytes_Call { - _c.Call.Return() - return _c -} + if len(ret) == 0 { + panic("no return value specified for ConfigureBuilder") + } -func (_c *Provider_AddBackgroundImageFromBytes_Call) RunAndReturn(run func([]byte, *entity.Cell, *props.Rect, extension.Type)) *Provider_AddBackgroundImageFromBytes_Call { - _c.Call.Return(run) - return _c -} + var r0 provider.Provider + if rf, ok := ret.Get(0).(func(builder.Builder) provider.Provider); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(provider.Provider) + } + } -// AddBarCode provides a mock function with given fields: code, cell, prop -func (_m *Provider) AddBarCode(code string, cell *entity.Cell, prop *props.Barcode) { - _m.Called(code, cell, prop) + return r0 } -// Provider_AddBarCode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddBarCode' -type Provider_AddBarCode_Call struct { +// Provider_ConfigureBuilder_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ConfigureBuilder' +type Provider_ConfigureBuilder_Call struct { *mock.Call } -// AddBarCode is a helper method to define mock.On call -// - code string -// - cell *entity.Cell -// - prop *props.Barcode -func (_e *Provider_Expecter) AddBarCode(code interface{}, cell interface{}, prop interface{}) *Provider_AddBarCode_Call { - return &Provider_AddBarCode_Call{Call: _e.mock.On("AddBarCode", code, cell, prop)} +// ConfigureBuilder is a helper method to define mock.On call +// - _a0 builder.Builder +func (_e *Provider_Expecter) ConfigureBuilder(_a0 interface{}) *Provider_ConfigureBuilder_Call { + return &Provider_ConfigureBuilder_Call{Call: _e.mock.On("ConfigureBuilder", _a0)} } -func (_c *Provider_AddBarCode_Call) Run(run func(code string, cell *entity.Cell, prop *props.Barcode)) *Provider_AddBarCode_Call { +func (_c *Provider_ConfigureBuilder_Call) Run(run func(_a0 builder.Builder)) *Provider_ConfigureBuilder_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(*entity.Cell), args[2].(*props.Barcode)) + run(args[0].(builder.Builder)) }) return _c } -func (_c *Provider_AddBarCode_Call) Return() *Provider_AddBarCode_Call { - _c.Call.Return() +func (_c *Provider_ConfigureBuilder_Call) Return(_a0 provider.Provider) *Provider_ConfigureBuilder_Call { + _c.Call.Return(_a0) return _c } -func (_c *Provider_AddBarCode_Call) RunAndReturn(run func(string, *entity.Cell, *props.Barcode)) *Provider_AddBarCode_Call { +func (_c *Provider_ConfigureBuilder_Call) RunAndReturn(run func(builder.Builder) provider.Provider) *Provider_ConfigureBuilder_Call { _c.Call.Return(run) return _c } -// AddImageFromBytes provides a mock function with given fields: bytes, cell, prop, _a3 -func (_m *Provider) AddImageFromBytes(bytes []byte, cell *entity.Cell, prop *props.Rect, _a3 extension.Type) { - _m.Called(bytes, cell, prop, _a3) -} +// CreateBarCode provides a mock function with given fields: value, _a1 +func (_m *Provider) CreateBarCode(value string, _a1 props.BarCodeProps) core.Component { + ret := _m.Called(value, _a1) -// Provider_AddImageFromBytes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddImageFromBytes' -type Provider_AddImageFromBytes_Call struct { - *mock.Call -} - -// AddImageFromBytes is a helper method to define mock.On call -// - bytes []byte -// - cell *entity.Cell -// - prop *props.Rect -// - _a3 extension.Type -func (_e *Provider_Expecter) AddImageFromBytes(bytes interface{}, cell interface{}, prop interface{}, _a3 interface{}) *Provider_AddImageFromBytes_Call { - return &Provider_AddImageFromBytes_Call{Call: _e.mock.On("AddImageFromBytes", bytes, cell, prop, _a3)} -} - -func (_c *Provider_AddImageFromBytes_Call) Run(run func(bytes []byte, cell *entity.Cell, prop *props.Rect, _a3 extension.Type)) *Provider_AddImageFromBytes_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].([]byte), args[1].(*entity.Cell), args[2].(*props.Rect), args[3].(extension.Type)) - }) - return _c -} - -func (_c *Provider_AddImageFromBytes_Call) Return() *Provider_AddImageFromBytes_Call { - _c.Call.Return() - return _c -} + if len(ret) == 0 { + panic("no return value specified for CreateBarCode") + } -func (_c *Provider_AddImageFromBytes_Call) RunAndReturn(run func([]byte, *entity.Cell, *props.Rect, extension.Type)) *Provider_AddImageFromBytes_Call { - _c.Call.Return(run) - return _c -} + var r0 core.Component + if rf, ok := ret.Get(0).(func(string, props.BarCodeProps) core.Component); ok { + r0 = rf(value, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(core.Component) + } + } -// AddImageFromFile provides a mock function with given fields: value, cell, prop -func (_m *Provider) AddImageFromFile(value string, cell *entity.Cell, prop *props.Rect) { - _m.Called(value, cell, prop) + return r0 } -// Provider_AddImageFromFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddImageFromFile' -type Provider_AddImageFromFile_Call struct { +// Provider_CreateBarCode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateBarCode' +type Provider_CreateBarCode_Call struct { *mock.Call } -// AddImageFromFile is a helper method to define mock.On call +// CreateBarCode is a helper method to define mock.On call // - value string -// - cell *entity.Cell -// - prop *props.Rect -func (_e *Provider_Expecter) AddImageFromFile(value interface{}, cell interface{}, prop interface{}) *Provider_AddImageFromFile_Call { - return &Provider_AddImageFromFile_Call{Call: _e.mock.On("AddImageFromFile", value, cell, prop)} -} - -func (_c *Provider_AddImageFromFile_Call) Run(run func(value string, cell *entity.Cell, prop *props.Rect)) *Provider_AddImageFromFile_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(*entity.Cell), args[2].(*props.Rect)) - }) - return _c -} - -func (_c *Provider_AddImageFromFile_Call) Return() *Provider_AddImageFromFile_Call { - _c.Call.Return() - return _c -} - -func (_c *Provider_AddImageFromFile_Call) RunAndReturn(run func(string, *entity.Cell, *props.Rect)) *Provider_AddImageFromFile_Call { - _c.Call.Return(run) - return _c -} - -// AddLine provides a mock function with given fields: cell, prop -func (_m *Provider) AddLine(cell *entity.Cell, prop *props.Line) { - _m.Called(cell, prop) -} - -// Provider_AddLine_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddLine' -type Provider_AddLine_Call struct { - *mock.Call -} - -// AddLine is a helper method to define mock.On call -// - cell *entity.Cell -// - prop *props.Line -func (_e *Provider_Expecter) AddLine(cell interface{}, prop interface{}) *Provider_AddLine_Call { - return &Provider_AddLine_Call{Call: _e.mock.On("AddLine", cell, prop)} -} - -func (_c *Provider_AddLine_Call) Run(run func(cell *entity.Cell, prop *props.Line)) *Provider_AddLine_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*entity.Cell), args[1].(*props.Line)) - }) - return _c -} - -func (_c *Provider_AddLine_Call) Return() *Provider_AddLine_Call { - _c.Call.Return() - return _c -} - -func (_c *Provider_AddLine_Call) RunAndReturn(run func(*entity.Cell, *props.Line)) *Provider_AddLine_Call { - _c.Call.Return(run) - return _c -} - -// AddMatrixCode provides a mock function with given fields: code, cell, prop -func (_m *Provider) AddMatrixCode(code string, cell *entity.Cell, prop *props.Rect) { - _m.Called(code, cell, prop) -} - -// Provider_AddMatrixCode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddMatrixCode' -type Provider_AddMatrixCode_Call struct { - *mock.Call +// - _a1 props.BarCodeProps +func (_e *Provider_Expecter) CreateBarCode(value interface{}, _a1 interface{}) *Provider_CreateBarCode_Call { + return &Provider_CreateBarCode_Call{Call: _e.mock.On("CreateBarCode", value, _a1)} } -// AddMatrixCode is a helper method to define mock.On call -// - code string -// - cell *entity.Cell -// - prop *props.Rect -func (_e *Provider_Expecter) AddMatrixCode(code interface{}, cell interface{}, prop interface{}) *Provider_AddMatrixCode_Call { - return &Provider_AddMatrixCode_Call{Call: _e.mock.On("AddMatrixCode", code, cell, prop)} -} - -func (_c *Provider_AddMatrixCode_Call) Run(run func(code string, cell *entity.Cell, prop *props.Rect)) *Provider_AddMatrixCode_Call { +func (_c *Provider_CreateBarCode_Call) Run(run func(value string, _a1 props.BarCodeProps)) *Provider_CreateBarCode_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(*entity.Cell), args[2].(*props.Rect)) + run(args[0].(string), args[1].(props.BarCodeProps)) }) return _c } -func (_c *Provider_AddMatrixCode_Call) Return() *Provider_AddMatrixCode_Call { - _c.Call.Return() - return _c -} - -func (_c *Provider_AddMatrixCode_Call) RunAndReturn(run func(string, *entity.Cell, *props.Rect)) *Provider_AddMatrixCode_Call { - _c.Call.Return(run) - return _c -} - -// AddQrCode provides a mock function with given fields: code, cell, rect -func (_m *Provider) AddQrCode(code string, cell *entity.Cell, rect *props.Rect) { - _m.Called(code, cell, rect) -} - -// Provider_AddQrCode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddQrCode' -type Provider_AddQrCode_Call struct { - *mock.Call -} - -// AddQrCode is a helper method to define mock.On call -// - code string -// - cell *entity.Cell -// - rect *props.Rect -func (_e *Provider_Expecter) AddQrCode(code interface{}, cell interface{}, rect interface{}) *Provider_AddQrCode_Call { - return &Provider_AddQrCode_Call{Call: _e.mock.On("AddQrCode", code, cell, rect)} -} - -func (_c *Provider_AddQrCode_Call) Run(run func(code string, cell *entity.Cell, rect *props.Rect)) *Provider_AddQrCode_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(*entity.Cell), args[2].(*props.Rect)) - }) - return _c -} - -func (_c *Provider_AddQrCode_Call) Return() *Provider_AddQrCode_Call { - _c.Call.Return() - return _c -} - -func (_c *Provider_AddQrCode_Call) RunAndReturn(run func(string, *entity.Cell, *props.Rect)) *Provider_AddQrCode_Call { - _c.Call.Return(run) - return _c -} - -// AddText provides a mock function with given fields: text, cell, prop -func (_m *Provider) AddText(text string, cell *entity.Cell, prop *props.Text) { - _m.Called(text, cell, prop) -} - -// Provider_AddText_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddText' -type Provider_AddText_Call struct { - *mock.Call -} - -// AddText is a helper method to define mock.On call -// - text string -// - cell *entity.Cell -// - prop *props.Text -func (_e *Provider_Expecter) AddText(text interface{}, cell interface{}, prop interface{}) *Provider_AddText_Call { - return &Provider_AddText_Call{Call: _e.mock.On("AddText", text, cell, prop)} -} - -func (_c *Provider_AddText_Call) Run(run func(text string, cell *entity.Cell, prop *props.Text)) *Provider_AddText_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(*entity.Cell), args[2].(*props.Text)) - }) - return _c -} - -func (_c *Provider_AddText_Call) Return() *Provider_AddText_Call { - _c.Call.Return() - return _c -} - -func (_c *Provider_AddText_Call) RunAndReturn(run func(string, *entity.Cell, *props.Text)) *Provider_AddText_Call { - _c.Call.Return(run) - return _c -} - -// CreateCol provides a mock function with given fields: width, height, config, prop -func (_m *Provider) CreateCol(width float64, height float64, config *entity.Config, prop *props.Cell) { - _m.Called(width, height, config, prop) -} - -// Provider_CreateCol_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateCol' -type Provider_CreateCol_Call struct { - *mock.Call -} - -// CreateCol is a helper method to define mock.On call -// - width float64 -// - height float64 -// - config *entity.Config -// - prop *props.Cell -func (_e *Provider_Expecter) CreateCol(width interface{}, height interface{}, config interface{}, prop interface{}) *Provider_CreateCol_Call { - return &Provider_CreateCol_Call{Call: _e.mock.On("CreateCol", width, height, config, prop)} -} - -func (_c *Provider_CreateCol_Call) Run(run func(width float64, height float64, config *entity.Config, prop *props.Cell)) *Provider_CreateCol_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64), args[1].(float64), args[2].(*entity.Config), args[3].(*props.Cell)) - }) - return _c -} - -func (_c *Provider_CreateCol_Call) Return() *Provider_CreateCol_Call { - _c.Call.Return() - return _c -} - -func (_c *Provider_CreateCol_Call) RunAndReturn(run func(float64, float64, *entity.Config, *props.Cell)) *Provider_CreateCol_Call { - _c.Call.Return(run) - return _c -} - -// CreateRow provides a mock function with given fields: height -func (_m *Provider) CreateRow(height float64) { - _m.Called(height) -} - -// Provider_CreateRow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRow' -type Provider_CreateRow_Call struct { - *mock.Call -} - -// CreateRow is a helper method to define mock.On call -// - height float64 -func (_e *Provider_Expecter) CreateRow(height interface{}) *Provider_CreateRow_Call { - return &Provider_CreateRow_Call{Call: _e.mock.On("CreateRow", height)} -} - -func (_c *Provider_CreateRow_Call) Run(run func(height float64)) *Provider_CreateRow_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) - }) - return _c -} - -func (_c *Provider_CreateRow_Call) Return() *Provider_CreateRow_Call { - _c.Call.Return() +func (_c *Provider_CreateBarCode_Call) Return(_a0 core.Component) *Provider_CreateBarCode_Call { + _c.Call.Return(_a0) return _c } -func (_c *Provider_CreateRow_Call) RunAndReturn(run func(float64)) *Provider_CreateRow_Call { +func (_c *Provider_CreateBarCode_Call) RunAndReturn(run func(string, props.BarCodeProps) core.Component) *Provider_CreateBarCode_Call { _c.Call.Return(run) return _c } -// GenerateBytes provides a mock function with given fields: -func (_m *Provider) GenerateBytes() ([]byte, error) { - ret := _m.Called() +// CreateCol provides a mock function with given fields: size, components +func (_m *Provider) CreateCol(size int, components ...core.Component) core.Col { + _va := make([]interface{}, len(components)) + for _i := range components { + _va[_i] = components[_i] + } + var _ca []interface{} + _ca = append(_ca, size) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) if len(ret) == 0 { - panic("no return value specified for GenerateBytes") + panic("no return value specified for CreateCol") } - var r0 []byte - var r1 error - if rf, ok := ret.Get(0).(func() ([]byte, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() []byte); ok { - r0 = rf() + var r0 core.Col + if rf, ok := ret.Get(0).(func(int, ...core.Component) core.Col); ok { + r0 = rf(size, components...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]byte) + r0 = ret.Get(0).(core.Col) } } - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 + return r0 } -// Provider_GenerateBytes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GenerateBytes' -type Provider_GenerateBytes_Call struct { +// Provider_CreateCol_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateCol' +type Provider_CreateCol_Call struct { *mock.Call } -// GenerateBytes is a helper method to define mock.On call -func (_e *Provider_Expecter) GenerateBytes() *Provider_GenerateBytes_Call { - return &Provider_GenerateBytes_Call{Call: _e.mock.On("GenerateBytes")} +// CreateCol is a helper method to define mock.On call +// - size int +// - components ...core.Component +func (_e *Provider_Expecter) CreateCol(size interface{}, components ...interface{}) *Provider_CreateCol_Call { + return &Provider_CreateCol_Call{Call: _e.mock.On("CreateCol", + append([]interface{}{size}, components...)...)} } -func (_c *Provider_GenerateBytes_Call) Run(run func()) *Provider_GenerateBytes_Call { +func (_c *Provider_CreateCol_Call) Run(run func(size int, components ...core.Component)) *Provider_CreateCol_Call { _c.Call.Run(func(args mock.Arguments) { - run() + variadicArgs := make([]core.Component, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(core.Component) + } + } + run(args[0].(int), variadicArgs...) }) return _c } -func (_c *Provider_GenerateBytes_Call) Return(_a0 []byte, _a1 error) *Provider_GenerateBytes_Call { - _c.Call.Return(_a0, _a1) +func (_c *Provider_CreateCol_Call) Return(_a0 core.Col) *Provider_CreateCol_Call { + _c.Call.Return(_a0) return _c } -func (_c *Provider_GenerateBytes_Call) RunAndReturn(run func() ([]byte, error)) *Provider_GenerateBytes_Call { +func (_c *Provider_CreateCol_Call) RunAndReturn(run func(int, ...core.Component) core.Col) *Provider_CreateCol_Call { _c.Call.Return(run) return _c } -// GetDimensionsByImage provides a mock function with given fields: file -func (_m *Provider) GetDimensionsByImage(file string) (*entity.Dimensions, error) { - ret := _m.Called(file) +// CreatePage provides a mock function with given fields: components +func (_m *Provider) CreatePage(components ...core.Row) core.Page { + _va := make([]interface{}, len(components)) + for _i := range components { + _va[_i] = components[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) if len(ret) == 0 { - panic("no return value specified for GetDimensionsByImage") + panic("no return value specified for CreatePage") } - var r0 *entity.Dimensions - var r1 error - if rf, ok := ret.Get(0).(func(string) (*entity.Dimensions, error)); ok { - return rf(file) - } - if rf, ok := ret.Get(0).(func(string) *entity.Dimensions); ok { - r0 = rf(file) + var r0 core.Page + if rf, ok := ret.Get(0).(func(...core.Row) core.Page); ok { + r0 = rf(components...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*entity.Dimensions) + r0 = ret.Get(0).(core.Page) } } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(file) - } else { - r1 = ret.Error(1) - } - - return r0, r1 + return r0 } -// Provider_GetDimensionsByImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDimensionsByImage' -type Provider_GetDimensionsByImage_Call struct { +// Provider_CreatePage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreatePage' +type Provider_CreatePage_Call struct { *mock.Call } -// GetDimensionsByImage is a helper method to define mock.On call -// - file string -func (_e *Provider_Expecter) GetDimensionsByImage(file interface{}) *Provider_GetDimensionsByImage_Call { - return &Provider_GetDimensionsByImage_Call{Call: _e.mock.On("GetDimensionsByImage", file)} +// CreatePage is a helper method to define mock.On call +// - components ...core.Row +func (_e *Provider_Expecter) CreatePage(components ...interface{}) *Provider_CreatePage_Call { + return &Provider_CreatePage_Call{Call: _e.mock.On("CreatePage", + append([]interface{}{}, components...)...)} } -func (_c *Provider_GetDimensionsByImage_Call) Run(run func(file string)) *Provider_GetDimensionsByImage_Call { +func (_c *Provider_CreatePage_Call) Run(run func(components ...core.Row)) *Provider_CreatePage_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) + variadicArgs := make([]core.Row, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(core.Row) + } + } + run(variadicArgs...) }) return _c } -func (_c *Provider_GetDimensionsByImage_Call) Return(_a0 *entity.Dimensions, _a1 error) *Provider_GetDimensionsByImage_Call { - _c.Call.Return(_a0, _a1) +func (_c *Provider_CreatePage_Call) Return(_a0 core.Page) *Provider_CreatePage_Call { + _c.Call.Return(_a0) return _c } -func (_c *Provider_GetDimensionsByImage_Call) RunAndReturn(run func(string) (*entity.Dimensions, error)) *Provider_GetDimensionsByImage_Call { +func (_c *Provider_CreatePage_Call) RunAndReturn(run func(...core.Row) core.Page) *Provider_CreatePage_Call { _c.Call.Return(run) return _c } -// GetDimensionsByImageByte provides a mock function with given fields: bytes, _a1 -func (_m *Provider) GetDimensionsByImageByte(bytes []byte, _a1 extension.Type) (*entity.Dimensions, error) { - ret := _m.Called(bytes, _a1) +// CreateRow provides a mock function with given fields: components +func (_m *Provider) CreateRow(components ...core.Col) core.Row { + _va := make([]interface{}, len(components)) + for _i := range components { + _va[_i] = components[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) if len(ret) == 0 { - panic("no return value specified for GetDimensionsByImageByte") + panic("no return value specified for CreateRow") } - var r0 *entity.Dimensions - var r1 error - if rf, ok := ret.Get(0).(func([]byte, extension.Type) (*entity.Dimensions, error)); ok { - return rf(bytes, _a1) - } - if rf, ok := ret.Get(0).(func([]byte, extension.Type) *entity.Dimensions); ok { - r0 = rf(bytes, _a1) + var r0 core.Row + if rf, ok := ret.Get(0).(func(...core.Col) core.Row); ok { + r0 = rf(components...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*entity.Dimensions) + r0 = ret.Get(0).(core.Row) } } - if rf, ok := ret.Get(1).(func([]byte, extension.Type) error); ok { - r1 = rf(bytes, _a1) - } else { - r1 = ret.Error(1) - } - - return r0, r1 + return r0 } -// Provider_GetDimensionsByImageByte_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDimensionsByImageByte' -type Provider_GetDimensionsByImageByte_Call struct { +// Provider_CreateRow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRow' +type Provider_CreateRow_Call struct { *mock.Call } -// GetDimensionsByImageByte is a helper method to define mock.On call -// - bytes []byte -// - _a1 extension.Type -func (_e *Provider_Expecter) GetDimensionsByImageByte(bytes interface{}, _a1 interface{}) *Provider_GetDimensionsByImageByte_Call { - return &Provider_GetDimensionsByImageByte_Call{Call: _e.mock.On("GetDimensionsByImageByte", bytes, _a1)} +// CreateRow is a helper method to define mock.On call +// - components ...core.Col +func (_e *Provider_Expecter) CreateRow(components ...interface{}) *Provider_CreateRow_Call { + return &Provider_CreateRow_Call{Call: _e.mock.On("CreateRow", + append([]interface{}{}, components...)...)} } -func (_c *Provider_GetDimensionsByImageByte_Call) Run(run func(bytes []byte, _a1 extension.Type)) *Provider_GetDimensionsByImageByte_Call { +func (_c *Provider_CreateRow_Call) Run(run func(components ...core.Col)) *Provider_CreateRow_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].([]byte), args[1].(extension.Type)) + variadicArgs := make([]core.Col, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(core.Col) + } + } + run(variadicArgs...) }) return _c } -func (_c *Provider_GetDimensionsByImageByte_Call) Return(_a0 *entity.Dimensions, _a1 error) *Provider_GetDimensionsByImageByte_Call { - _c.Call.Return(_a0, _a1) +func (_c *Provider_CreateRow_Call) Return(_a0 core.Row) *Provider_CreateRow_Call { + _c.Call.Return(_a0) return _c } -func (_c *Provider_GetDimensionsByImageByte_Call) RunAndReturn(run func([]byte, extension.Type) (*entity.Dimensions, error)) *Provider_GetDimensionsByImageByte_Call { +func (_c *Provider_CreateRow_Call) RunAndReturn(run func(...core.Col) core.Row) *Provider_CreateRow_Call { _c.Call.Return(run) return _c } -// GetDimensionsByMatrixCode provides a mock function with given fields: code -func (_m *Provider) GetDimensionsByMatrixCode(code string) (*entity.Dimensions, error) { - ret := _m.Called(code) +// CreateText provides a mock function with given fields: value, _a1 +func (_m *Provider) CreateText(value string, _a1 props.TextProps) core.Component { + ret := _m.Called(value, _a1) if len(ret) == 0 { - panic("no return value specified for GetDimensionsByMatrixCode") + panic("no return value specified for CreateText") } - var r0 *entity.Dimensions - var r1 error - if rf, ok := ret.Get(0).(func(string) (*entity.Dimensions, error)); ok { - return rf(code) - } - if rf, ok := ret.Get(0).(func(string) *entity.Dimensions); ok { - r0 = rf(code) + var r0 core.Component + if rf, ok := ret.Get(0).(func(string, props.TextProps) core.Component); ok { + r0 = rf(value, _a1) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*entity.Dimensions) + r0 = ret.Get(0).(core.Component) } } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(code) - } else { - r1 = ret.Error(1) - } - - return r0, r1 + return r0 } -// Provider_GetDimensionsByMatrixCode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDimensionsByMatrixCode' -type Provider_GetDimensionsByMatrixCode_Call struct { +// Provider_CreateText_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateText' +type Provider_CreateText_Call struct { *mock.Call } -// GetDimensionsByMatrixCode is a helper method to define mock.On call -// - code string -func (_e *Provider_Expecter) GetDimensionsByMatrixCode(code interface{}) *Provider_GetDimensionsByMatrixCode_Call { - return &Provider_GetDimensionsByMatrixCode_Call{Call: _e.mock.On("GetDimensionsByMatrixCode", code)} +// CreateText is a helper method to define mock.On call +// - value string +// - _a1 props.TextProps +func (_e *Provider_Expecter) CreateText(value interface{}, _a1 interface{}) *Provider_CreateText_Call { + return &Provider_CreateText_Call{Call: _e.mock.On("CreateText", value, _a1)} } -func (_c *Provider_GetDimensionsByMatrixCode_Call) Run(run func(code string)) *Provider_GetDimensionsByMatrixCode_Call { +func (_c *Provider_CreateText_Call) Run(run func(value string, _a1 props.TextProps)) *Provider_CreateText_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) + run(args[0].(string), args[1].(props.TextProps)) }) return _c } -func (_c *Provider_GetDimensionsByMatrixCode_Call) Return(_a0 *entity.Dimensions, _a1 error) *Provider_GetDimensionsByMatrixCode_Call { - _c.Call.Return(_a0, _a1) +func (_c *Provider_CreateText_Call) Return(_a0 core.Component) *Provider_CreateText_Call { + _c.Call.Return(_a0) return _c } -func (_c *Provider_GetDimensionsByMatrixCode_Call) RunAndReturn(run func(string) (*entity.Dimensions, error)) *Provider_GetDimensionsByMatrixCode_Call { +func (_c *Provider_CreateText_Call) RunAndReturn(run func(string, props.TextProps) core.Component) *Provider_CreateText_Call { _c.Call.Return(run) return _c } -// GetDimensionsByQrCode provides a mock function with given fields: code -func (_m *Provider) GetDimensionsByQrCode(code string) (*entity.Dimensions, error) { - ret := _m.Called(code) +// GeneratePdf provides a mock function with given fields: +func (_m *Provider) GeneratePdf() ([]byte, error) { + ret := _m.Called() if len(ret) == 0 { - panic("no return value specified for GetDimensionsByQrCode") + panic("no return value specified for GeneratePdf") } - var r0 *entity.Dimensions + var r0 []byte var r1 error - if rf, ok := ret.Get(0).(func(string) (*entity.Dimensions, error)); ok { - return rf(code) + if rf, ok := ret.Get(0).(func() ([]byte, error)); ok { + return rf() } - if rf, ok := ret.Get(0).(func(string) *entity.Dimensions); ok { - r0 = rf(code) + if rf, ok := ret.Get(0).(func() []byte); ok { + r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*entity.Dimensions) + r0 = ret.Get(0).([]byte) } } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(code) + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() } else { r1 = ret.Error(1) } @@ -636,223 +387,151 @@ func (_m *Provider) GetDimensionsByQrCode(code string) (*entity.Dimensions, erro return r0, r1 } -// Provider_GetDimensionsByQrCode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDimensionsByQrCode' -type Provider_GetDimensionsByQrCode_Call struct { +// Provider_GeneratePdf_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GeneratePdf' +type Provider_GeneratePdf_Call struct { *mock.Call } -// GetDimensionsByQrCode is a helper method to define mock.On call -// - code string -func (_e *Provider_Expecter) GetDimensionsByQrCode(code interface{}) *Provider_GetDimensionsByQrCode_Call { - return &Provider_GetDimensionsByQrCode_Call{Call: _e.mock.On("GetDimensionsByQrCode", code)} +// GeneratePdf is a helper method to define mock.On call +func (_e *Provider_Expecter) GeneratePdf() *Provider_GeneratePdf_Call { + return &Provider_GeneratePdf_Call{Call: _e.mock.On("GeneratePdf")} } -func (_c *Provider_GetDimensionsByQrCode_Call) Run(run func(code string)) *Provider_GetDimensionsByQrCode_Call { +func (_c *Provider_GeneratePdf_Call) Run(run func()) *Provider_GeneratePdf_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) + run() }) return _c } -func (_c *Provider_GetDimensionsByQrCode_Call) Return(_a0 *entity.Dimensions, _a1 error) *Provider_GetDimensionsByQrCode_Call { +func (_c *Provider_GeneratePdf_Call) Return(_a0 []byte, _a1 error) *Provider_GeneratePdf_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *Provider_GetDimensionsByQrCode_Call) RunAndReturn(run func(string) (*entity.Dimensions, error)) *Provider_GetDimensionsByQrCode_Call { +func (_c *Provider_GeneratePdf_Call) RunAndReturn(run func() ([]byte, error)) *Provider_GeneratePdf_Call { _c.Call.Return(run) return _c } -// GetFontHeight provides a mock function with given fields: prop -func (_m *Provider) GetFontHeight(prop *props.Font) float64 { - ret := _m.Called(prop) +// RegisterFooter provides a mock function with given fields: rows +func (_m *Provider) RegisterFooter(rows ...core.Row) provider.Provider { + _va := make([]interface{}, len(rows)) + for _i := range rows { + _va[_i] = rows[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) if len(ret) == 0 { - panic("no return value specified for GetFontHeight") + panic("no return value specified for RegisterFooter") } - var r0 float64 - if rf, ok := ret.Get(0).(func(*props.Font) float64); ok { - r0 = rf(prop) + var r0 provider.Provider + if rf, ok := ret.Get(0).(func(...core.Row) provider.Provider); ok { + r0 = rf(rows...) } else { - r0 = ret.Get(0).(float64) + if ret.Get(0) != nil { + r0 = ret.Get(0).(provider.Provider) + } } return r0 } -// Provider_GetFontHeight_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetFontHeight' -type Provider_GetFontHeight_Call struct { +// Provider_RegisterFooter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterFooter' +type Provider_RegisterFooter_Call struct { *mock.Call } -// GetFontHeight is a helper method to define mock.On call -// - prop *props.Font -func (_e *Provider_Expecter) GetFontHeight(prop interface{}) *Provider_GetFontHeight_Call { - return &Provider_GetFontHeight_Call{Call: _e.mock.On("GetFontHeight", prop)} +// RegisterFooter is a helper method to define mock.On call +// - rows ...core.Row +func (_e *Provider_Expecter) RegisterFooter(rows ...interface{}) *Provider_RegisterFooter_Call { + return &Provider_RegisterFooter_Call{Call: _e.mock.On("RegisterFooter", + append([]interface{}{}, rows...)...)} } -func (_c *Provider_GetFontHeight_Call) Run(run func(prop *props.Font)) *Provider_GetFontHeight_Call { +func (_c *Provider_RegisterFooter_Call) Run(run func(rows ...core.Row)) *Provider_RegisterFooter_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*props.Font)) + variadicArgs := make([]core.Row, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(core.Row) + } + } + run(variadicArgs...) }) return _c } -func (_c *Provider_GetFontHeight_Call) Return(_a0 float64) *Provider_GetFontHeight_Call { +func (_c *Provider_RegisterFooter_Call) Return(_a0 provider.Provider) *Provider_RegisterFooter_Call { _c.Call.Return(_a0) return _c } -func (_c *Provider_GetFontHeight_Call) RunAndReturn(run func(*props.Font) float64) *Provider_GetFontHeight_Call { +func (_c *Provider_RegisterFooter_Call) RunAndReturn(run func(...core.Row) provider.Provider) *Provider_RegisterFooter_Call { _c.Call.Return(run) return _c } -// GetLinesQuantity provides a mock function with given fields: text, textProp, colWidth -func (_m *Provider) GetLinesQuantity(text string, textProp *props.Text, colWidth float64) int { - ret := _m.Called(text, textProp, colWidth) +// RegisterHeader provides a mock function with given fields: rows +func (_m *Provider) RegisterHeader(rows ...core.Row) provider.Provider { + _va := make([]interface{}, len(rows)) + for _i := range rows { + _va[_i] = rows[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) if len(ret) == 0 { - panic("no return value specified for GetLinesQuantity") + panic("no return value specified for RegisterHeader") } - var r0 int - if rf, ok := ret.Get(0).(func(string, *props.Text, float64) int); ok { - r0 = rf(text, textProp, colWidth) + var r0 provider.Provider + if rf, ok := ret.Get(0).(func(...core.Row) provider.Provider); ok { + r0 = rf(rows...) } else { - r0 = ret.Get(0).(int) + if ret.Get(0) != nil { + r0 = ret.Get(0).(provider.Provider) + } } return r0 } -// Provider_GetLinesQuantity_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLinesQuantity' -type Provider_GetLinesQuantity_Call struct { +// Provider_RegisterHeader_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterHeader' +type Provider_RegisterHeader_Call struct { *mock.Call } -// GetLinesQuantity is a helper method to define mock.On call -// - text string -// - textProp *props.Text -// - colWidth float64 -func (_e *Provider_Expecter) GetLinesQuantity(text interface{}, textProp interface{}, colWidth interface{}) *Provider_GetLinesQuantity_Call { - return &Provider_GetLinesQuantity_Call{Call: _e.mock.On("GetLinesQuantity", text, textProp, colWidth)} +// RegisterHeader is a helper method to define mock.On call +// - rows ...core.Row +func (_e *Provider_Expecter) RegisterHeader(rows ...interface{}) *Provider_RegisterHeader_Call { + return &Provider_RegisterHeader_Call{Call: _e.mock.On("RegisterHeader", + append([]interface{}{}, rows...)...)} } -func (_c *Provider_GetLinesQuantity_Call) Run(run func(text string, textProp *props.Text, colWidth float64)) *Provider_GetLinesQuantity_Call { +func (_c *Provider_RegisterHeader_Call) Run(run func(rows ...core.Row)) *Provider_RegisterHeader_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(*props.Text), args[2].(float64)) + variadicArgs := make([]core.Row, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(core.Row) + } + } + run(variadicArgs...) }) return _c } -func (_c *Provider_GetLinesQuantity_Call) Return(_a0 int) *Provider_GetLinesQuantity_Call { +func (_c *Provider_RegisterHeader_Call) Return(_a0 provider.Provider) *Provider_RegisterHeader_Call { _c.Call.Return(_a0) return _c } -func (_c *Provider_GetLinesQuantity_Call) RunAndReturn(run func(string, *props.Text, float64) int) *Provider_GetLinesQuantity_Call { - _c.Call.Return(run) - return _c -} - -// SetCompression provides a mock function with given fields: compression -func (_m *Provider) SetCompression(compression bool) { - _m.Called(compression) -} - -// Provider_SetCompression_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetCompression' -type Provider_SetCompression_Call struct { - *mock.Call -} - -// SetCompression is a helper method to define mock.On call -// - compression bool -func (_e *Provider_Expecter) SetCompression(compression interface{}) *Provider_SetCompression_Call { - return &Provider_SetCompression_Call{Call: _e.mock.On("SetCompression", compression)} -} - -func (_c *Provider_SetCompression_Call) Run(run func(compression bool)) *Provider_SetCompression_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(bool)) - }) - return _c -} - -func (_c *Provider_SetCompression_Call) Return() *Provider_SetCompression_Call { - _c.Call.Return() - return _c -} - -func (_c *Provider_SetCompression_Call) RunAndReturn(run func(bool)) *Provider_SetCompression_Call { - _c.Call.Return(run) - return _c -} - -// SetMetadata provides a mock function with given fields: metadata -func (_m *Provider) SetMetadata(metadata *entity.Metadata) { - _m.Called(metadata) -} - -// Provider_SetMetadata_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetMetadata' -type Provider_SetMetadata_Call struct { - *mock.Call -} - -// SetMetadata is a helper method to define mock.On call -// - metadata *entity.Metadata -func (_e *Provider_Expecter) SetMetadata(metadata interface{}) *Provider_SetMetadata_Call { - return &Provider_SetMetadata_Call{Call: _e.mock.On("SetMetadata", metadata)} -} - -func (_c *Provider_SetMetadata_Call) Run(run func(metadata *entity.Metadata)) *Provider_SetMetadata_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*entity.Metadata)) - }) - return _c -} - -func (_c *Provider_SetMetadata_Call) Return() *Provider_SetMetadata_Call { - _c.Call.Return() - return _c -} - -func (_c *Provider_SetMetadata_Call) RunAndReturn(run func(*entity.Metadata)) *Provider_SetMetadata_Call { - _c.Call.Return(run) - return _c -} - -// SetProtection provides a mock function with given fields: protection -func (_m *Provider) SetProtection(protection *entity.Protection) { - _m.Called(protection) -} - -// Provider_SetProtection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetProtection' -type Provider_SetProtection_Call struct { - *mock.Call -} - -// SetProtection is a helper method to define mock.On call -// - protection *entity.Protection -func (_e *Provider_Expecter) SetProtection(protection interface{}) *Provider_SetProtection_Call { - return &Provider_SetProtection_Call{Call: _e.mock.On("SetProtection", protection)} -} - -func (_c *Provider_SetProtection_Call) Run(run func(protection *entity.Protection)) *Provider_SetProtection_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*entity.Protection)) - }) - return _c -} - -func (_c *Provider_SetProtection_Call) Return() *Provider_SetProtection_Call { - _c.Call.Return() - return _c -} - -func (_c *Provider_SetProtection_Call) RunAndReturn(run func(*entity.Protection)) *Provider_SetProtection_Call { +func (_c *Provider_RegisterHeader_Call) RunAndReturn(run func(...core.Row) provider.Provider) *Provider_RegisterHeader_Call { _c.Call.Return(run) return _c } diff --git a/pkg/processor/mappers/documentmapper/document_test.go b/pkg/processor/mappers/documentmapper/document_test.go index a537fe1f..018c6d08 100644 --- a/pkg/processor/mappers/documentmapper/document_test.go +++ b/pkg/processor/mappers/documentmapper/document_test.go @@ -1 +1,146 @@ package documentmapper + +import ( + "testing" + + "github.com/johnfercher/maroto/v2/internal/fixture" + "github.com/johnfercher/maroto/v2/mocks" + "github.com/johnfercher/maroto/v2/pkg/processor/deserializer" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/listmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pagemapper" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +func TestNewPdf(t *testing.T) { + t.Run("When an invalid field is submitted, should return an error", func(t *testing.T) { + invalidDocument := `{"invalid": 123}` + factory := mocks.NewAbstractFactoryMaps(t) + + doc, err := NewPdf(invalidDocument, deserializer.NewJsonDeserialize(), factory) + + assert.Nil(t, doc) + assert.NotNil(t, err) + }) + + t.Run("when builder is sent, should set builder", func(t *testing.T) { + builderDocument := ` + { + "builder": {"chunk_workers": 10} + } + ` + factory := mocks.NewAbstractFactoryMaps(t) + + doc, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + + assert.Nil(t, err) + assert.Equal(t, doc.Builder.ChunkWorkers, 10) + }) + + t.Run("when an invalid builder is passed, should return an error", func(t *testing.T) { + builderDocument := `{"builder": 10}` + factory := mocks.NewAbstractFactoryMaps(t) + + doc, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + + assert.NotNil(t, err) + assert.Nil(t, doc) + }) + + t.Run("When a 2-rows header is sent, should set the header", func(t *testing.T) { + builderDocument := ` + {"header": { + "row_template_1": {}, + "row_template_2": {} + }} + ` + validRow := fixture.MapperRow() + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewRow", mock.Anything, mock.Anything).Return(validRow, nil) + + doc, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + + assert.Nil(t, err) + assert.Equal(t, 2, len(doc.Header)) + }) + + t.Run("when an invalid header is passed, should return an error", func(t *testing.T) { + builderDocument := `{"header": 1}` + factory := mocks.NewAbstractFactoryMaps(t) + + _, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + + assert.NotNil(t, err) + }) + + t.Run("When a 2-rows footer is sent, should set the footer", func(t *testing.T) { + builderDocument := ` + {"footer": { + "row_template_1": {}, + "row_template_2": {} + }} + ` + validRow := fixture.MapperRow() + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewRow", mock.Anything, mock.Anything).Return(validRow, nil) + + doc, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + + assert.Nil(t, err) + assert.Equal(t, 2, len(doc.Footer)) + }) + + t.Run("when an invalid footer is passed, should return an error", func(t *testing.T) { + builderDocument := `{"footer": 1}` + factory := mocks.NewAbstractFactoryMaps(t) + + _, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + + assert.NotNil(t, err) + }) + + t.Run("when 2 pages are sent, it should add 2 pages to the document", func(t *testing.T) { + builderDocument := ` + {"pages": { + "page_template_1":{}, + "page_template_2":{} + }} + ` + validPage := fixture.MapperPage() + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewPage", mock.Anything, "page_template_1").Return(validPage, nil) + factory.On("NewPage", mock.Anything, "page_template_2").Return(validPage, nil) + + doc, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + + assert.Nil(t, err) + assert.Equal(t, len(doc.pages), 2) + assert.IsType(t, &pagemapper.Page{}, doc.pages[0]) + }) + + t.Run("when 1 list is sent, it should add 1 list to the document", func(t *testing.T) { + builderDocument := ` + {"pages": { + "list_template_1":{} + }} + ` + validPage := fixture.MapperList() + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewList", mock.Anything, "list_template_1", mock.Anything).Return(validPage, nil) + + doc, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + + assert.Nil(t, err) + assert.Equal(t, len(doc.pages), 1) + assert.IsType(t, &listmapper.List{}, doc.pages[0]) + }) + + t.Run("when an invalid page is sent, it should return an error", func(t *testing.T) { + builderDocument := `{"pages": 1}` + factory := mocks.NewAbstractFactoryMaps(t) + + _, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + + assert.NotNil(t, err) + }) +} From ee2e56ddad5c0a09f467477d14981d47279b3e5b Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 10 Oct 2024 14:47:08 -0300 Subject: [PATCH 016/116] fix: fix error in document creation fix page list creation use abstract factory to create components --- .../mappers/documentmapper/document.go | 23 +++++++++---------- pkg/processor/mappers/listmapper/list.go | 10 ++++---- pkg/processor/mappers/pagemapper/page.go | 2 +- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/pkg/processor/mappers/documentmapper/document.go b/pkg/processor/mappers/documentmapper/document.go index 0347ff99..971162ee 100644 --- a/pkg/processor/mappers/documentmapper/document.go +++ b/pkg/processor/mappers/documentmapper/document.go @@ -3,17 +3,16 @@ package documentmapper import ( "fmt" + "strings" "github.com/johnfercher/maroto/v2/pkg/processor/components/pdf" "github.com/johnfercher/maroto/v2/pkg/processor/core" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/buildermapper" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/listmapper" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pagemapper" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rowmapper" ) type Document struct { + factory mappers.AbstractFactoryMaps Builder buildermapper.Builder Header []mappers.Componentmapper Footer []mappers.Componentmapper @@ -21,8 +20,8 @@ type Document struct { } // NewPdf is responsible for creating the pdf template -func NewPdf(document string, deserializer core.Deserializer) (*Document, error) { - newPdf := Document{} +func NewPdf(document string, deserializer core.Deserializer, factory mappers.AbstractFactoryMaps) (*Document, error) { + newPdf := Document{factory: factory} template, err := deserializer.Deserialize(document) if err != nil { return nil, err @@ -84,7 +83,7 @@ func (p *Document) setHeader(rowsDoc interface{}) error { } for templateKey, rowTemplate := range rowsTemplate { - row, err := rowmapper.NewRow(rowTemplate, templateKey) + row, err := p.factory.NewRow(rowTemplate, templateKey) if err != nil { return err } @@ -102,11 +101,11 @@ func (p *Document) setFooter(rowsDoc interface{}) error { } for templateKey, rowTemplate := range rowsTemplate { - row, err := rowmapper.NewRow(rowTemplate, templateKey) + row, err := p.factory.NewRow(rowTemplate, templateKey) if err != nil { return err } - p.Header = append(p.Footer, row) + p.Footer = append(p.Footer, row) } return nil @@ -120,14 +119,14 @@ func (p *Document) setPages(rowsDoc interface{}) error { return fmt.Errorf("ensure pages can be converted to map[string] interface{}") } - for templateName, pageTemplate := range templatePage { + for templateName, template := range templatePage { var page mappers.Componentmapper var err error - if templateName == "list" { - page, err = listmapper.NewList[*pagemapper.Page](pageTemplate) + if strings.HasPrefix(templateName, "list") { + page, err = p.factory.NewList(template, templateName, p.factory.NewPage) } else { - page, err = pagemapper.NewPage(pageTemplate) + page, err = p.factory.NewPage(template, templateName) } if err != nil { diff --git a/pkg/processor/mappers/listmapper/list.go b/pkg/processor/mappers/listmapper/list.go index cf620f28..014d502b 100644 --- a/pkg/processor/mappers/listmapper/list.go +++ b/pkg/processor/mappers/listmapper/list.go @@ -6,15 +6,15 @@ import ( "github.com/johnfercher/maroto/v2/pkg/processor/mappers" ) -type List[T mappers.Componentmapper] struct { +type List struct { sourceKey string - templates T + templates mappers.Componentmapper } -func NewList[T mappers.Componentmapper](document interface{}) (*List[T], error) { - return nil, nil +func NewList(document interface{}, sourceKey string, generate mappers.GenerateComponent) (*List, error) { + return &List{}, nil } -func (r *List[T]) Generate(content map[string]interface{}) (components.Component, error) { +func (r *List) Generate(content map[string]interface{}) (components.Component, error) { return nil, nil } diff --git a/pkg/processor/mappers/pagemapper/page.go b/pkg/processor/mappers/pagemapper/page.go index 8da86de4..efb96513 100644 --- a/pkg/processor/mappers/pagemapper/page.go +++ b/pkg/processor/mappers/pagemapper/page.go @@ -9,7 +9,7 @@ type Page struct { Teste string } -func NewPage(page interface{}) (*Page, error) { +func NewPage(page interface{}, sourceKey string) (*Page, error) { return nil, nil } From 17038fd08917b2ba0ce33f7b1d55e2ab3a97ccb1 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Fri, 11 Oct 2024 12:22:13 -0300 Subject: [PATCH 017/116] test: fix bug in mock creation Rename interfaces to non-names not used by Maroto --- mocks/Builder.go | 1263 ++++++++++++++++- mocks/Componentmapper.go | 14 +- mocks/PdfComponent.go | 86 ++ mocks/ProcessorProvider.go | 552 +++++++ mocks/Provider.go | 853 +++++++---- mocks/Repository.go | 159 +-- pkg/processor/components/barcode/bar_code.go | 4 +- pkg/processor/components/col/col.go | 8 +- pkg/processor/components/components.go | 6 +- pkg/processor/components/page/page.go | 4 +- pkg/processor/components/pdf/pdf.go | 4 +- pkg/processor/components/row/row.go | 4 +- pkg/processor/components/text/text.go | 4 +- pkg/processor/mappers/component_mapper.go | 2 +- pkg/processor/mappers/listmapper/list.go | 2 +- pkg/processor/mappers/pagemapper/page.go | 2 +- pkg/processor/mappers/rowmapper/row.go | 2 +- .../{provider => processorprovider}/Maroto.go | 8 +- .../provider.go | 10 +- 19 files changed, 2557 insertions(+), 430 deletions(-) create mode 100644 mocks/PdfComponent.go create mode 100644 mocks/ProcessorProvider.go rename pkg/processor/{provider => processorprovider}/Maroto.go (87%) rename pkg/processor/{provider => processorprovider}/provider.go (69%) diff --git a/mocks/Builder.go b/mocks/Builder.go index 883f7968..2cbe240a 100644 --- a/mocks/Builder.go +++ b/mocks/Builder.go @@ -3,12 +3,22 @@ package mocks import ( - cache "github.com/johnfercher/maroto/v2/internal/cache" + config "github.com/johnfercher/maroto/v2/pkg/config" entity "github.com/johnfercher/maroto/v2/pkg/core/entity" - gofpdf "github.com/johnfercher/maroto/v2/internal/providers/gofpdf" + extension "github.com/johnfercher/maroto/v2/pkg/consts/extension" mock "github.com/stretchr/testify/mock" + + orientation "github.com/johnfercher/maroto/v2/pkg/consts/orientation" + + pagesize "github.com/johnfercher/maroto/v2/pkg/consts/pagesize" + + props "github.com/johnfercher/maroto/v2/pkg/props" + + protection "github.com/johnfercher/maroto/v2/pkg/consts/protection" + + time "time" ) // Builder is an autogenerated mock type for the Builder type @@ -24,20 +34,20 @@ func (_m *Builder) EXPECT() *Builder_Expecter { return &Builder_Expecter{mock: &_m.Mock} } -// Build provides a mock function with given fields: cfg, _a1 -func (_m *Builder) Build(cfg *entity.Config, _a1 cache.Cache) *gofpdf.Dependencies { - ret := _m.Called(cfg, _a1) +// Build provides a mock function with given fields: +func (_m *Builder) Build() *entity.Config { + ret := _m.Called() if len(ret) == 0 { panic("no return value specified for Build") } - var r0 *gofpdf.Dependencies - if rf, ok := ret.Get(0).(func(*entity.Config, cache.Cache) *gofpdf.Dependencies); ok { - r0 = rf(cfg, _a1) + var r0 *entity.Config + if rf, ok := ret.Get(0).(func() *entity.Config); ok { + r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*gofpdf.Dependencies) + r0 = ret.Get(0).(*entity.Config) } } @@ -50,25 +60,1244 @@ type Builder_Build_Call struct { } // Build is a helper method to define mock.On call -// - cfg *entity.Config -// - _a1 cache.Cache -func (_e *Builder_Expecter) Build(cfg interface{}, _a1 interface{}) *Builder_Build_Call { - return &Builder_Build_Call{Call: _e.mock.On("Build", cfg, _a1)} +func (_e *Builder_Expecter) Build() *Builder_Build_Call { + return &Builder_Build_Call{Call: _e.mock.On("Build")} +} + +func (_c *Builder_Build_Call) Run(run func()) *Builder_Build_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Builder_Build_Call) Return(_a0 *entity.Config) *Builder_Build_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_Build_Call) RunAndReturn(run func() *entity.Config) *Builder_Build_Call { + _c.Call.Return(run) + return _c +} + +// WithAuthor provides a mock function with given fields: author, isUTF8 +func (_m *Builder) WithAuthor(author string, isUTF8 bool) config.Builder { + ret := _m.Called(author, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithAuthor") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(author, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithAuthor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithAuthor' +type Builder_WithAuthor_Call struct { + *mock.Call +} + +// WithAuthor is a helper method to define mock.On call +// - author string +// - isUTF8 bool +func (_e *Builder_Expecter) WithAuthor(author interface{}, isUTF8 interface{}) *Builder_WithAuthor_Call { + return &Builder_WithAuthor_Call{Call: _e.mock.On("WithAuthor", author, isUTF8)} +} + +func (_c *Builder_WithAuthor_Call) Run(run func(author string, isUTF8 bool)) *Builder_WithAuthor_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithAuthor_Call) Return(_a0 config.Builder) *Builder_WithAuthor_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithAuthor_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithAuthor_Call { + _c.Call.Return(run) + return _c +} + +// WithBackgroundImage provides a mock function with given fields: _a0, _a1 +func (_m *Builder) WithBackgroundImage(_a0 []byte, _a1 extension.Type) config.Builder { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for WithBackgroundImage") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func([]byte, extension.Type) config.Builder); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithBackgroundImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBackgroundImage' +type Builder_WithBackgroundImage_Call struct { + *mock.Call +} + +// WithBackgroundImage is a helper method to define mock.On call +// - _a0 []byte +// - _a1 extension.Type +func (_e *Builder_Expecter) WithBackgroundImage(_a0 interface{}, _a1 interface{}) *Builder_WithBackgroundImage_Call { + return &Builder_WithBackgroundImage_Call{Call: _e.mock.On("WithBackgroundImage", _a0, _a1)} +} + +func (_c *Builder_WithBackgroundImage_Call) Run(run func(_a0 []byte, _a1 extension.Type)) *Builder_WithBackgroundImage_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]byte), args[1].(extension.Type)) + }) + return _c +} + +func (_c *Builder_WithBackgroundImage_Call) Return(_a0 config.Builder) *Builder_WithBackgroundImage_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithBackgroundImage_Call) RunAndReturn(run func([]byte, extension.Type) config.Builder) *Builder_WithBackgroundImage_Call { + _c.Call.Return(run) + return _c +} + +// WithBottomMargin provides a mock function with given fields: bottom +func (_m *Builder) WithBottomMargin(bottom float64) config.Builder { + ret := _m.Called(bottom) + + if len(ret) == 0 { + panic("no return value specified for WithBottomMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(bottom) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithBottomMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBottomMargin' +type Builder_WithBottomMargin_Call struct { + *mock.Call +} + +// WithBottomMargin is a helper method to define mock.On call +// - bottom float64 +func (_e *Builder_Expecter) WithBottomMargin(bottom interface{}) *Builder_WithBottomMargin_Call { + return &Builder_WithBottomMargin_Call{Call: _e.mock.On("WithBottomMargin", bottom)} +} + +func (_c *Builder_WithBottomMargin_Call) Run(run func(bottom float64)) *Builder_WithBottomMargin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Builder_WithBottomMargin_Call) Return(_a0 config.Builder) *Builder_WithBottomMargin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithBottomMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithBottomMargin_Call { + _c.Call.Return(run) + return _c +} + +// WithCompression provides a mock function with given fields: compression +func (_m *Builder) WithCompression(compression bool) config.Builder { + ret := _m.Called(compression) + + if len(ret) == 0 { + panic("no return value specified for WithCompression") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { + r0 = rf(compression) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCompression_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCompression' +type Builder_WithCompression_Call struct { + *mock.Call +} + +// WithCompression is a helper method to define mock.On call +// - compression bool +func (_e *Builder_Expecter) WithCompression(compression interface{}) *Builder_WithCompression_Call { + return &Builder_WithCompression_Call{Call: _e.mock.On("WithCompression", compression)} +} + +func (_c *Builder_WithCompression_Call) Run(run func(compression bool)) *Builder_WithCompression_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Builder_WithCompression_Call) Return(_a0 config.Builder) *Builder_WithCompression_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCompression_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithCompression_Call { + _c.Call.Return(run) + return _c +} + +// WithConcurrentMode provides a mock function with given fields: chunkWorkers +func (_m *Builder) WithConcurrentMode(chunkWorkers int) config.Builder { + ret := _m.Called(chunkWorkers) + + if len(ret) == 0 { + panic("no return value specified for WithConcurrentMode") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(int) config.Builder); ok { + r0 = rf(chunkWorkers) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithConcurrentMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithConcurrentMode' +type Builder_WithConcurrentMode_Call struct { + *mock.Call +} + +// WithConcurrentMode is a helper method to define mock.On call +// - chunkWorkers int +func (_e *Builder_Expecter) WithConcurrentMode(chunkWorkers interface{}) *Builder_WithConcurrentMode_Call { + return &Builder_WithConcurrentMode_Call{Call: _e.mock.On("WithConcurrentMode", chunkWorkers)} +} + +func (_c *Builder_WithConcurrentMode_Call) Run(run func(chunkWorkers int)) *Builder_WithConcurrentMode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Builder_WithConcurrentMode_Call) Return(_a0 config.Builder) *Builder_WithConcurrentMode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithConcurrentMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithConcurrentMode_Call { + _c.Call.Return(run) + return _c +} + +// WithCreationDate provides a mock function with given fields: _a0 +func (_m *Builder) WithCreationDate(_a0 time.Time) config.Builder { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for WithCreationDate") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(time.Time) config.Builder); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCreationDate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreationDate' +type Builder_WithCreationDate_Call struct { + *mock.Call +} + +// WithCreationDate is a helper method to define mock.On call +// - _a0 time.Time +func (_e *Builder_Expecter) WithCreationDate(_a0 interface{}) *Builder_WithCreationDate_Call { + return &Builder_WithCreationDate_Call{Call: _e.mock.On("WithCreationDate", _a0)} +} + +func (_c *Builder_WithCreationDate_Call) Run(run func(_a0 time.Time)) *Builder_WithCreationDate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(time.Time)) + }) + return _c +} + +func (_c *Builder_WithCreationDate_Call) Return(_a0 config.Builder) *Builder_WithCreationDate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCreationDate_Call) RunAndReturn(run func(time.Time) config.Builder) *Builder_WithCreationDate_Call { + _c.Call.Return(run) + return _c +} + +// WithCreator provides a mock function with given fields: creator, isUTF8 +func (_m *Builder) WithCreator(creator string, isUTF8 bool) config.Builder { + ret := _m.Called(creator, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithCreator") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(creator, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCreator_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreator' +type Builder_WithCreator_Call struct { + *mock.Call +} + +// WithCreator is a helper method to define mock.On call +// - creator string +// - isUTF8 bool +func (_e *Builder_Expecter) WithCreator(creator interface{}, isUTF8 interface{}) *Builder_WithCreator_Call { + return &Builder_WithCreator_Call{Call: _e.mock.On("WithCreator", creator, isUTF8)} +} + +func (_c *Builder_WithCreator_Call) Run(run func(creator string, isUTF8 bool)) *Builder_WithCreator_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithCreator_Call) Return(_a0 config.Builder) *Builder_WithCreator_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCreator_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithCreator_Call { + _c.Call.Return(run) + return _c +} + +// WithCustomFonts provides a mock function with given fields: _a0 +func (_m *Builder) WithCustomFonts(_a0 []*entity.CustomFont) config.Builder { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for WithCustomFonts") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func([]*entity.CustomFont) config.Builder); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCustomFonts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCustomFonts' +type Builder_WithCustomFonts_Call struct { + *mock.Call +} + +// WithCustomFonts is a helper method to define mock.On call +// - _a0 []*entity.CustomFont +func (_e *Builder_Expecter) WithCustomFonts(_a0 interface{}) *Builder_WithCustomFonts_Call { + return &Builder_WithCustomFonts_Call{Call: _e.mock.On("WithCustomFonts", _a0)} +} + +func (_c *Builder_WithCustomFonts_Call) Run(run func(_a0 []*entity.CustomFont)) *Builder_WithCustomFonts_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]*entity.CustomFont)) + }) + return _c +} + +func (_c *Builder_WithCustomFonts_Call) Return(_a0 config.Builder) *Builder_WithCustomFonts_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCustomFonts_Call) RunAndReturn(run func([]*entity.CustomFont) config.Builder) *Builder_WithCustomFonts_Call { + _c.Call.Return(run) + return _c +} + +// WithDebug provides a mock function with given fields: on +func (_m *Builder) WithDebug(on bool) config.Builder { + ret := _m.Called(on) + + if len(ret) == 0 { + panic("no return value specified for WithDebug") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { + r0 = rf(on) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDebug_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDebug' +type Builder_WithDebug_Call struct { + *mock.Call +} + +// WithDebug is a helper method to define mock.On call +// - on bool +func (_e *Builder_Expecter) WithDebug(on interface{}) *Builder_WithDebug_Call { + return &Builder_WithDebug_Call{Call: _e.mock.On("WithDebug", on)} +} + +func (_c *Builder_WithDebug_Call) Run(run func(on bool)) *Builder_WithDebug_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Builder_WithDebug_Call) Return(_a0 config.Builder) *Builder_WithDebug_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDebug_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDebug_Call { + _c.Call.Return(run) + return _c +} + +// WithDefaultFont provides a mock function with given fields: font +func (_m *Builder) WithDefaultFont(font *props.Font) config.Builder { + ret := _m.Called(font) + + if len(ret) == 0 { + panic("no return value specified for WithDefaultFont") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(*props.Font) config.Builder); ok { + r0 = rf(font) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDefaultFont_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDefaultFont' +type Builder_WithDefaultFont_Call struct { + *mock.Call +} + +// WithDefaultFont is a helper method to define mock.On call +// - font *props.Font +func (_e *Builder_Expecter) WithDefaultFont(font interface{}) *Builder_WithDefaultFont_Call { + return &Builder_WithDefaultFont_Call{Call: _e.mock.On("WithDefaultFont", font)} +} + +func (_c *Builder_WithDefaultFont_Call) Run(run func(font *props.Font)) *Builder_WithDefaultFont_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*props.Font)) + }) + return _c +} + +func (_c *Builder_WithDefaultFont_Call) Return(_a0 config.Builder) *Builder_WithDefaultFont_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDefaultFont_Call) RunAndReturn(run func(*props.Font) config.Builder) *Builder_WithDefaultFont_Call { + _c.Call.Return(run) + return _c +} + +// WithDimensions provides a mock function with given fields: width, height +func (_m *Builder) WithDimensions(width float64, height float64) config.Builder { + ret := _m.Called(width, height) + + if len(ret) == 0 { + panic("no return value specified for WithDimensions") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64, float64) config.Builder); ok { + r0 = rf(width, height) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDimensions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDimensions' +type Builder_WithDimensions_Call struct { + *mock.Call +} + +// WithDimensions is a helper method to define mock.On call +// - width float64 +// - height float64 +func (_e *Builder_Expecter) WithDimensions(width interface{}, height interface{}) *Builder_WithDimensions_Call { + return &Builder_WithDimensions_Call{Call: _e.mock.On("WithDimensions", width, height)} +} + +func (_c *Builder_WithDimensions_Call) Run(run func(width float64, height float64)) *Builder_WithDimensions_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64), args[1].(float64)) + }) + return _c +} + +func (_c *Builder_WithDimensions_Call) Return(_a0 config.Builder) *Builder_WithDimensions_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDimensions_Call) RunAndReturn(run func(float64, float64) config.Builder) *Builder_WithDimensions_Call { + _c.Call.Return(run) + return _c +} + +// WithDisableAutoPageBreak provides a mock function with given fields: disabled +func (_m *Builder) WithDisableAutoPageBreak(disabled bool) config.Builder { + ret := _m.Called(disabled) + + if len(ret) == 0 { + panic("no return value specified for WithDisableAutoPageBreak") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { + r0 = rf(disabled) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDisableAutoPageBreak_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDisableAutoPageBreak' +type Builder_WithDisableAutoPageBreak_Call struct { + *mock.Call +} + +// WithDisableAutoPageBreak is a helper method to define mock.On call +// - disabled bool +func (_e *Builder_Expecter) WithDisableAutoPageBreak(disabled interface{}) *Builder_WithDisableAutoPageBreak_Call { + return &Builder_WithDisableAutoPageBreak_Call{Call: _e.mock.On("WithDisableAutoPageBreak", disabled)} +} + +func (_c *Builder_WithDisableAutoPageBreak_Call) Run(run func(disabled bool)) *Builder_WithDisableAutoPageBreak_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Builder_WithDisableAutoPageBreak_Call) Return(_a0 config.Builder) *Builder_WithDisableAutoPageBreak_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDisableAutoPageBreak_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDisableAutoPageBreak_Call { + _c.Call.Return(run) + return _c +} + +// WithKeywords provides a mock function with given fields: keywordsStr, isUTF8 +func (_m *Builder) WithKeywords(keywordsStr string, isUTF8 bool) config.Builder { + ret := _m.Called(keywordsStr, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithKeywords") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(keywordsStr, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithKeywords_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithKeywords' +type Builder_WithKeywords_Call struct { + *mock.Call +} + +// WithKeywords is a helper method to define mock.On call +// - keywordsStr string +// - isUTF8 bool +func (_e *Builder_Expecter) WithKeywords(keywordsStr interface{}, isUTF8 interface{}) *Builder_WithKeywords_Call { + return &Builder_WithKeywords_Call{Call: _e.mock.On("WithKeywords", keywordsStr, isUTF8)} +} + +func (_c *Builder_WithKeywords_Call) Run(run func(keywordsStr string, isUTF8 bool)) *Builder_WithKeywords_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithKeywords_Call) Return(_a0 config.Builder) *Builder_WithKeywords_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithKeywords_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithKeywords_Call { + _c.Call.Return(run) + return _c +} + +// WithLeftMargin provides a mock function with given fields: left +func (_m *Builder) WithLeftMargin(left float64) config.Builder { + ret := _m.Called(left) + + if len(ret) == 0 { + panic("no return value specified for WithLeftMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(left) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithLeftMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithLeftMargin' +type Builder_WithLeftMargin_Call struct { + *mock.Call +} + +// WithLeftMargin is a helper method to define mock.On call +// - left float64 +func (_e *Builder_Expecter) WithLeftMargin(left interface{}) *Builder_WithLeftMargin_Call { + return &Builder_WithLeftMargin_Call{Call: _e.mock.On("WithLeftMargin", left)} +} + +func (_c *Builder_WithLeftMargin_Call) Run(run func(left float64)) *Builder_WithLeftMargin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Builder_WithLeftMargin_Call) Return(_a0 config.Builder) *Builder_WithLeftMargin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithLeftMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithLeftMargin_Call { + _c.Call.Return(run) + return _c +} + +// WithMaxGridSize provides a mock function with given fields: maxGridSize +func (_m *Builder) WithMaxGridSize(maxGridSize int) config.Builder { + ret := _m.Called(maxGridSize) + + if len(ret) == 0 { + panic("no return value specified for WithMaxGridSize") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(int) config.Builder); ok { + r0 = rf(maxGridSize) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithMaxGridSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithMaxGridSize' +type Builder_WithMaxGridSize_Call struct { + *mock.Call +} + +// WithMaxGridSize is a helper method to define mock.On call +// - maxGridSize int +func (_e *Builder_Expecter) WithMaxGridSize(maxGridSize interface{}) *Builder_WithMaxGridSize_Call { + return &Builder_WithMaxGridSize_Call{Call: _e.mock.On("WithMaxGridSize", maxGridSize)} +} + +func (_c *Builder_WithMaxGridSize_Call) Run(run func(maxGridSize int)) *Builder_WithMaxGridSize_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Builder_WithMaxGridSize_Call) Return(_a0 config.Builder) *Builder_WithMaxGridSize_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithMaxGridSize_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithMaxGridSize_Call { + _c.Call.Return(run) + return _c +} + +// WithOrientation provides a mock function with given fields: _a0 +func (_m *Builder) WithOrientation(_a0 orientation.Type) config.Builder { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for WithOrientation") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(orientation.Type) config.Builder); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithOrientation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithOrientation' +type Builder_WithOrientation_Call struct { + *mock.Call +} + +// WithOrientation is a helper method to define mock.On call +// - _a0 orientation.Type +func (_e *Builder_Expecter) WithOrientation(_a0 interface{}) *Builder_WithOrientation_Call { + return &Builder_WithOrientation_Call{Call: _e.mock.On("WithOrientation", _a0)} +} + +func (_c *Builder_WithOrientation_Call) Run(run func(_a0 orientation.Type)) *Builder_WithOrientation_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(orientation.Type)) + }) + return _c +} + +func (_c *Builder_WithOrientation_Call) Return(_a0 config.Builder) *Builder_WithOrientation_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithOrientation_Call) RunAndReturn(run func(orientation.Type) config.Builder) *Builder_WithOrientation_Call { + _c.Call.Return(run) + return _c +} + +// WithPageNumber provides a mock function with given fields: pageNumber +func (_m *Builder) WithPageNumber(pageNumber ...props.PageNumber) config.Builder { + _va := make([]interface{}, len(pageNumber)) + for _i := range pageNumber { + _va[_i] = pageNumber[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for WithPageNumber") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(...props.PageNumber) config.Builder); ok { + r0 = rf(pageNumber...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithPageNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageNumber' +type Builder_WithPageNumber_Call struct { + *mock.Call +} + +// WithPageNumber is a helper method to define mock.On call +// - pageNumber ...props.PageNumber +func (_e *Builder_Expecter) WithPageNumber(pageNumber ...interface{}) *Builder_WithPageNumber_Call { + return &Builder_WithPageNumber_Call{Call: _e.mock.On("WithPageNumber", + append([]interface{}{}, pageNumber...)...)} +} + +func (_c *Builder_WithPageNumber_Call) Run(run func(pageNumber ...props.PageNumber)) *Builder_WithPageNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]props.PageNumber, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(props.PageNumber) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *Builder_WithPageNumber_Call) Return(_a0 config.Builder) *Builder_WithPageNumber_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithPageNumber_Call) RunAndReturn(run func(...props.PageNumber) config.Builder) *Builder_WithPageNumber_Call { + _c.Call.Return(run) + return _c +} + +// WithPageSize provides a mock function with given fields: size +func (_m *Builder) WithPageSize(size pagesize.Type) config.Builder { + ret := _m.Called(size) + + if len(ret) == 0 { + panic("no return value specified for WithPageSize") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(pagesize.Type) config.Builder); ok { + r0 = rf(size) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithPageSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageSize' +type Builder_WithPageSize_Call struct { + *mock.Call +} + +// WithPageSize is a helper method to define mock.On call +// - size pagesize.Type +func (_e *Builder_Expecter) WithPageSize(size interface{}) *Builder_WithPageSize_Call { + return &Builder_WithPageSize_Call{Call: _e.mock.On("WithPageSize", size)} +} + +func (_c *Builder_WithPageSize_Call) Run(run func(size pagesize.Type)) *Builder_WithPageSize_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(pagesize.Type)) + }) + return _c +} + +func (_c *Builder_WithPageSize_Call) Return(_a0 config.Builder) *Builder_WithPageSize_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithPageSize_Call) RunAndReturn(run func(pagesize.Type) config.Builder) *Builder_WithPageSize_Call { + _c.Call.Return(run) + return _c +} + +// WithProtection provides a mock function with given fields: protectionType, userPassword, ownerPassword +func (_m *Builder) WithProtection(protectionType protection.Type, userPassword string, ownerPassword string) config.Builder { + ret := _m.Called(protectionType, userPassword, ownerPassword) + + if len(ret) == 0 { + panic("no return value specified for WithProtection") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(protection.Type, string, string) config.Builder); ok { + r0 = rf(protectionType, userPassword, ownerPassword) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithProtection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithProtection' +type Builder_WithProtection_Call struct { + *mock.Call +} + +// WithProtection is a helper method to define mock.On call +// - protectionType protection.Type +// - userPassword string +// - ownerPassword string +func (_e *Builder_Expecter) WithProtection(protectionType interface{}, userPassword interface{}, ownerPassword interface{}) *Builder_WithProtection_Call { + return &Builder_WithProtection_Call{Call: _e.mock.On("WithProtection", protectionType, userPassword, ownerPassword)} +} + +func (_c *Builder_WithProtection_Call) Run(run func(protectionType protection.Type, userPassword string, ownerPassword string)) *Builder_WithProtection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(protection.Type), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *Builder_WithProtection_Call) Return(_a0 config.Builder) *Builder_WithProtection_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithProtection_Call) RunAndReturn(run func(protection.Type, string, string) config.Builder) *Builder_WithProtection_Call { + _c.Call.Return(run) + return _c +} + +// WithRightMargin provides a mock function with given fields: right +func (_m *Builder) WithRightMargin(right float64) config.Builder { + ret := _m.Called(right) + + if len(ret) == 0 { + panic("no return value specified for WithRightMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(right) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithRightMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithRightMargin' +type Builder_WithRightMargin_Call struct { + *mock.Call +} + +// WithRightMargin is a helper method to define mock.On call +// - right float64 +func (_e *Builder_Expecter) WithRightMargin(right interface{}) *Builder_WithRightMargin_Call { + return &Builder_WithRightMargin_Call{Call: _e.mock.On("WithRightMargin", right)} +} + +func (_c *Builder_WithRightMargin_Call) Run(run func(right float64)) *Builder_WithRightMargin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Builder_WithRightMargin_Call) Return(_a0 config.Builder) *Builder_WithRightMargin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithRightMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithRightMargin_Call { + _c.Call.Return(run) + return _c +} + +// WithSequentialLowMemoryMode provides a mock function with given fields: chunkWorkers +func (_m *Builder) WithSequentialLowMemoryMode(chunkWorkers int) config.Builder { + ret := _m.Called(chunkWorkers) + + if len(ret) == 0 { + panic("no return value specified for WithSequentialLowMemoryMode") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(int) config.Builder); ok { + r0 = rf(chunkWorkers) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithSequentialLowMemoryMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialLowMemoryMode' +type Builder_WithSequentialLowMemoryMode_Call struct { + *mock.Call +} + +// WithSequentialLowMemoryMode is a helper method to define mock.On call +// - chunkWorkers int +func (_e *Builder_Expecter) WithSequentialLowMemoryMode(chunkWorkers interface{}) *Builder_WithSequentialLowMemoryMode_Call { + return &Builder_WithSequentialLowMemoryMode_Call{Call: _e.mock.On("WithSequentialLowMemoryMode", chunkWorkers)} +} + +func (_c *Builder_WithSequentialLowMemoryMode_Call) Run(run func(chunkWorkers int)) *Builder_WithSequentialLowMemoryMode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Builder_WithSequentialLowMemoryMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialLowMemoryMode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithSequentialLowMemoryMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithSequentialLowMemoryMode_Call { + _c.Call.Return(run) + return _c +} + +// WithSequentialMode provides a mock function with given fields: +func (_m *Builder) WithSequentialMode() config.Builder { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for WithSequentialMode") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func() config.Builder); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithSequentialMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialMode' +type Builder_WithSequentialMode_Call struct { + *mock.Call +} + +// WithSequentialMode is a helper method to define mock.On call +func (_e *Builder_Expecter) WithSequentialMode() *Builder_WithSequentialMode_Call { + return &Builder_WithSequentialMode_Call{Call: _e.mock.On("WithSequentialMode")} +} + +func (_c *Builder_WithSequentialMode_Call) Run(run func()) *Builder_WithSequentialMode_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Builder_WithSequentialMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialMode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithSequentialMode_Call) RunAndReturn(run func() config.Builder) *Builder_WithSequentialMode_Call { + _c.Call.Return(run) + return _c +} + +// WithSubject provides a mock function with given fields: subject, isUTF8 +func (_m *Builder) WithSubject(subject string, isUTF8 bool) config.Builder { + ret := _m.Called(subject, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithSubject") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(subject, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithSubject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSubject' +type Builder_WithSubject_Call struct { + *mock.Call +} + +// WithSubject is a helper method to define mock.On call +// - subject string +// - isUTF8 bool +func (_e *Builder_Expecter) WithSubject(subject interface{}, isUTF8 interface{}) *Builder_WithSubject_Call { + return &Builder_WithSubject_Call{Call: _e.mock.On("WithSubject", subject, isUTF8)} +} + +func (_c *Builder_WithSubject_Call) Run(run func(subject string, isUTF8 bool)) *Builder_WithSubject_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithSubject_Call) Return(_a0 config.Builder) *Builder_WithSubject_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithSubject_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithSubject_Call { + _c.Call.Return(run) + return _c +} + +// WithTitle provides a mock function with given fields: title, isUTF8 +func (_m *Builder) WithTitle(title string, isUTF8 bool) config.Builder { + ret := _m.Called(title, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithTitle") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(title, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithTitle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTitle' +type Builder_WithTitle_Call struct { + *mock.Call +} + +// WithTitle is a helper method to define mock.On call +// - title string +// - isUTF8 bool +func (_e *Builder_Expecter) WithTitle(title interface{}, isUTF8 interface{}) *Builder_WithTitle_Call { + return &Builder_WithTitle_Call{Call: _e.mock.On("WithTitle", title, isUTF8)} +} + +func (_c *Builder_WithTitle_Call) Run(run func(title string, isUTF8 bool)) *Builder_WithTitle_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithTitle_Call) Return(_a0 config.Builder) *Builder_WithTitle_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithTitle_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithTitle_Call { + _c.Call.Return(run) + return _c +} + +// WithTopMargin provides a mock function with given fields: top +func (_m *Builder) WithTopMargin(top float64) config.Builder { + ret := _m.Called(top) + + if len(ret) == 0 { + panic("no return value specified for WithTopMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(top) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithTopMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTopMargin' +type Builder_WithTopMargin_Call struct { + *mock.Call +} + +// WithTopMargin is a helper method to define mock.On call +// - top float64 +func (_e *Builder_Expecter) WithTopMargin(top interface{}) *Builder_WithTopMargin_Call { + return &Builder_WithTopMargin_Call{Call: _e.mock.On("WithTopMargin", top)} } -func (_c *Builder_Build_Call) Run(run func(cfg *entity.Config, _a1 cache.Cache)) *Builder_Build_Call { +func (_c *Builder_WithTopMargin_Call) Run(run func(top float64)) *Builder_WithTopMargin_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*entity.Config), args[1].(cache.Cache)) + run(args[0].(float64)) }) return _c } -func (_c *Builder_Build_Call) Return(_a0 *gofpdf.Dependencies) *Builder_Build_Call { +func (_c *Builder_WithTopMargin_Call) Return(_a0 config.Builder) *Builder_WithTopMargin_Call { _c.Call.Return(_a0) return _c } -func (_c *Builder_Build_Call) RunAndReturn(run func(*entity.Config, cache.Cache) *gofpdf.Dependencies) *Builder_Build_Call { +func (_c *Builder_WithTopMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithTopMargin_Call { _c.Call.Return(run) return _c } diff --git a/mocks/Componentmapper.go b/mocks/Componentmapper.go index e668fe34..3da8c065 100644 --- a/mocks/Componentmapper.go +++ b/mocks/Componentmapper.go @@ -22,23 +22,23 @@ func (_m *Componentmapper) EXPECT() *Componentmapper_Expecter { } // Generate provides a mock function with given fields: content -func (_m *Componentmapper) Generate(content map[string]interface{}) (components.Component, error) { +func (_m *Componentmapper) Generate(content map[string]interface{}) (components.PdfComponent, error) { ret := _m.Called(content) if len(ret) == 0 { panic("no return value specified for Generate") } - var r0 components.Component + var r0 components.PdfComponent var r1 error - if rf, ok := ret.Get(0).(func(map[string]interface{}) (components.Component, error)); ok { + if rf, ok := ret.Get(0).(func(map[string]interface{}) (components.PdfComponent, error)); ok { return rf(content) } - if rf, ok := ret.Get(0).(func(map[string]interface{}) components.Component); ok { + if rf, ok := ret.Get(0).(func(map[string]interface{}) components.PdfComponent); ok { r0 = rf(content) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(components.Component) + r0 = ret.Get(0).(components.PdfComponent) } } @@ -69,12 +69,12 @@ func (_c *Componentmapper_Generate_Call) Run(run func(content map[string]interfa return _c } -func (_c *Componentmapper_Generate_Call) Return(_a0 components.Component, _a1 error) *Componentmapper_Generate_Call { +func (_c *Componentmapper_Generate_Call) Return(_a0 components.PdfComponent, _a1 error) *Componentmapper_Generate_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *Componentmapper_Generate_Call) RunAndReturn(run func(map[string]interface{}) (components.Component, error)) *Componentmapper_Generate_Call { +func (_c *Componentmapper_Generate_Call) RunAndReturn(run func(map[string]interface{}) (components.PdfComponent, error)) *Componentmapper_Generate_Call { _c.Call.Return(run) return _c } diff --git a/mocks/PdfComponent.go b/mocks/PdfComponent.go new file mode 100644 index 00000000..73fffc01 --- /dev/null +++ b/mocks/PdfComponent.go @@ -0,0 +1,86 @@ +// Code generated by mockery v2.42.0. DO NOT EDIT. + +package mocks + +import ( + core "github.com/johnfercher/maroto/v2/pkg/core" + mock "github.com/stretchr/testify/mock" + + processorprovider "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" +) + +// PdfComponent is an autogenerated mock type for the PdfComponent type +type PdfComponent struct { + mock.Mock +} + +type PdfComponent_Expecter struct { + mock *mock.Mock +} + +func (_m *PdfComponent) EXPECT() *PdfComponent_Expecter { + return &PdfComponent_Expecter{mock: &_m.Mock} +} + +// Generate provides a mock function with given fields: provider +func (_m *PdfComponent) Generate(provider processorprovider.ProcessorProvider) core.Component { + ret := _m.Called(provider) + + if len(ret) == 0 { + panic("no return value specified for Generate") + } + + var r0 core.Component + if rf, ok := ret.Get(0).(func(processorprovider.ProcessorProvider) core.Component); ok { + r0 = rf(provider) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(core.Component) + } + } + + return r0 +} + +// PdfComponent_Generate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Generate' +type PdfComponent_Generate_Call struct { + *mock.Call +} + +// Generate is a helper method to define mock.On call +// - provider processorprovider.ProcessorProvider +func (_e *PdfComponent_Expecter) Generate(provider interface{}) *PdfComponent_Generate_Call { + return &PdfComponent_Generate_Call{Call: _e.mock.On("Generate", provider)} +} + +func (_c *PdfComponent_Generate_Call) Run(run func(provider processorprovider.ProcessorProvider)) *PdfComponent_Generate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(processorprovider.ProcessorProvider)) + }) + return _c +} + +func (_c *PdfComponent_Generate_Call) Return(_a0 core.Component) *PdfComponent_Generate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PdfComponent_Generate_Call) RunAndReturn(run func(processorprovider.ProcessorProvider) core.Component) *PdfComponent_Generate_Call { + _c.Call.Return(run) + return _c +} + +// NewPdfComponent creates a new instance of PdfComponent. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewPdfComponent(t interface { + mock.TestingT + Cleanup(func()) +}, +) *PdfComponent { + mock := &PdfComponent{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/ProcessorProvider.go b/mocks/ProcessorProvider.go new file mode 100644 index 00000000..a570981d --- /dev/null +++ b/mocks/ProcessorProvider.go @@ -0,0 +1,552 @@ +// Code generated by mockery v2.42.0. DO NOT EDIT. + +package mocks + +import ( + core "github.com/johnfercher/maroto/v2/pkg/core" + builder "github.com/johnfercher/maroto/v2/pkg/processor/components/builder" + + mock "github.com/stretchr/testify/mock" + + processorprovider "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" + + props "github.com/johnfercher/maroto/v2/pkg/processor/components/props" +) + +// ProcessorProvider is an autogenerated mock type for the ProcessorProvider type +type ProcessorProvider struct { + mock.Mock +} + +type ProcessorProvider_Expecter struct { + mock *mock.Mock +} + +func (_m *ProcessorProvider) EXPECT() *ProcessorProvider_Expecter { + return &ProcessorProvider_Expecter{mock: &_m.Mock} +} + +// ConfigureBuilder provides a mock function with given fields: _a0 +func (_m *ProcessorProvider) ConfigureBuilder(_a0 builder.Builder) processorprovider.ProcessorProvider { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for ConfigureBuilder") + } + + var r0 processorprovider.ProcessorProvider + if rf, ok := ret.Get(0).(func(builder.Builder) processorprovider.ProcessorProvider); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(processorprovider.ProcessorProvider) + } + } + + return r0 +} + +// ProcessorProvider_ConfigureBuilder_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ConfigureBuilder' +type ProcessorProvider_ConfigureBuilder_Call struct { + *mock.Call +} + +// ConfigureBuilder is a helper method to define mock.On call +// - _a0 builder.Builder +func (_e *ProcessorProvider_Expecter) ConfigureBuilder(_a0 interface{}) *ProcessorProvider_ConfigureBuilder_Call { + return &ProcessorProvider_ConfigureBuilder_Call{Call: _e.mock.On("ConfigureBuilder", _a0)} +} + +func (_c *ProcessorProvider_ConfigureBuilder_Call) Run(run func(_a0 builder.Builder)) *ProcessorProvider_ConfigureBuilder_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(builder.Builder)) + }) + return _c +} + +func (_c *ProcessorProvider_ConfigureBuilder_Call) Return(_a0 processorprovider.ProcessorProvider) *ProcessorProvider_ConfigureBuilder_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorProvider_ConfigureBuilder_Call) RunAndReturn(run func(builder.Builder) processorprovider.ProcessorProvider) *ProcessorProvider_ConfigureBuilder_Call { + _c.Call.Return(run) + return _c +} + +// CreateBarCode provides a mock function with given fields: value, _a1 +func (_m *ProcessorProvider) CreateBarCode(value string, _a1 props.BarCodeProps) core.Component { + ret := _m.Called(value, _a1) + + if len(ret) == 0 { + panic("no return value specified for CreateBarCode") + } + + var r0 core.Component + if rf, ok := ret.Get(0).(func(string, props.BarCodeProps) core.Component); ok { + r0 = rf(value, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(core.Component) + } + } + + return r0 +} + +// ProcessorProvider_CreateBarCode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateBarCode' +type ProcessorProvider_CreateBarCode_Call struct { + *mock.Call +} + +// CreateBarCode is a helper method to define mock.On call +// - value string +// - _a1 props.BarCodeProps +func (_e *ProcessorProvider_Expecter) CreateBarCode(value interface{}, _a1 interface{}) *ProcessorProvider_CreateBarCode_Call { + return &ProcessorProvider_CreateBarCode_Call{Call: _e.mock.On("CreateBarCode", value, _a1)} +} + +func (_c *ProcessorProvider_CreateBarCode_Call) Run(run func(value string, _a1 props.BarCodeProps)) *ProcessorProvider_CreateBarCode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(props.BarCodeProps)) + }) + return _c +} + +func (_c *ProcessorProvider_CreateBarCode_Call) Return(_a0 core.Component) *ProcessorProvider_CreateBarCode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorProvider_CreateBarCode_Call) RunAndReturn(run func(string, props.BarCodeProps) core.Component) *ProcessorProvider_CreateBarCode_Call { + _c.Call.Return(run) + return _c +} + +// CreateCol provides a mock function with given fields: size, components +func (_m *ProcessorProvider) CreateCol(size int, components ...core.Component) core.Col { + _va := make([]interface{}, len(components)) + for _i := range components { + _va[_i] = components[_i] + } + var _ca []interface{} + _ca = append(_ca, size) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for CreateCol") + } + + var r0 core.Col + if rf, ok := ret.Get(0).(func(int, ...core.Component) core.Col); ok { + r0 = rf(size, components...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(core.Col) + } + } + + return r0 +} + +// ProcessorProvider_CreateCol_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateCol' +type ProcessorProvider_CreateCol_Call struct { + *mock.Call +} + +// CreateCol is a helper method to define mock.On call +// - size int +// - components ...core.Component +func (_e *ProcessorProvider_Expecter) CreateCol(size interface{}, components ...interface{}) *ProcessorProvider_CreateCol_Call { + return &ProcessorProvider_CreateCol_Call{Call: _e.mock.On("CreateCol", + append([]interface{}{size}, components...)...)} +} + +func (_c *ProcessorProvider_CreateCol_Call) Run(run func(size int, components ...core.Component)) *ProcessorProvider_CreateCol_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]core.Component, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(core.Component) + } + } + run(args[0].(int), variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_CreateCol_Call) Return(_a0 core.Col) *ProcessorProvider_CreateCol_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorProvider_CreateCol_Call) RunAndReturn(run func(int, ...core.Component) core.Col) *ProcessorProvider_CreateCol_Call { + _c.Call.Return(run) + return _c +} + +// CreatePage provides a mock function with given fields: components +func (_m *ProcessorProvider) CreatePage(components ...core.Row) core.Page { + _va := make([]interface{}, len(components)) + for _i := range components { + _va[_i] = components[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for CreatePage") + } + + var r0 core.Page + if rf, ok := ret.Get(0).(func(...core.Row) core.Page); ok { + r0 = rf(components...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(core.Page) + } + } + + return r0 +} + +// ProcessorProvider_CreatePage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreatePage' +type ProcessorProvider_CreatePage_Call struct { + *mock.Call +} + +// CreatePage is a helper method to define mock.On call +// - components ...core.Row +func (_e *ProcessorProvider_Expecter) CreatePage(components ...interface{}) *ProcessorProvider_CreatePage_Call { + return &ProcessorProvider_CreatePage_Call{Call: _e.mock.On("CreatePage", + append([]interface{}{}, components...)...)} +} + +func (_c *ProcessorProvider_CreatePage_Call) Run(run func(components ...core.Row)) *ProcessorProvider_CreatePage_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]core.Row, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(core.Row) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_CreatePage_Call) Return(_a0 core.Page) *ProcessorProvider_CreatePage_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorProvider_CreatePage_Call) RunAndReturn(run func(...core.Row) core.Page) *ProcessorProvider_CreatePage_Call { + _c.Call.Return(run) + return _c +} + +// CreateRow provides a mock function with given fields: components +func (_m *ProcessorProvider) CreateRow(components ...core.Col) core.Row { + _va := make([]interface{}, len(components)) + for _i := range components { + _va[_i] = components[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for CreateRow") + } + + var r0 core.Row + if rf, ok := ret.Get(0).(func(...core.Col) core.Row); ok { + r0 = rf(components...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(core.Row) + } + } + + return r0 +} + +// ProcessorProvider_CreateRow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRow' +type ProcessorProvider_CreateRow_Call struct { + *mock.Call +} + +// CreateRow is a helper method to define mock.On call +// - components ...core.Col +func (_e *ProcessorProvider_Expecter) CreateRow(components ...interface{}) *ProcessorProvider_CreateRow_Call { + return &ProcessorProvider_CreateRow_Call{Call: _e.mock.On("CreateRow", + append([]interface{}{}, components...)...)} +} + +func (_c *ProcessorProvider_CreateRow_Call) Run(run func(components ...core.Col)) *ProcessorProvider_CreateRow_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]core.Col, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(core.Col) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_CreateRow_Call) Return(_a0 core.Row) *ProcessorProvider_CreateRow_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorProvider_CreateRow_Call) RunAndReturn(run func(...core.Col) core.Row) *ProcessorProvider_CreateRow_Call { + _c.Call.Return(run) + return _c +} + +// CreateText provides a mock function with given fields: value, _a1 +func (_m *ProcessorProvider) CreateText(value string, _a1 props.TextProps) core.Component { + ret := _m.Called(value, _a1) + + if len(ret) == 0 { + panic("no return value specified for CreateText") + } + + var r0 core.Component + if rf, ok := ret.Get(0).(func(string, props.TextProps) core.Component); ok { + r0 = rf(value, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(core.Component) + } + } + + return r0 +} + +// ProcessorProvider_CreateText_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateText' +type ProcessorProvider_CreateText_Call struct { + *mock.Call +} + +// CreateText is a helper method to define mock.On call +// - value string +// - _a1 props.TextProps +func (_e *ProcessorProvider_Expecter) CreateText(value interface{}, _a1 interface{}) *ProcessorProvider_CreateText_Call { + return &ProcessorProvider_CreateText_Call{Call: _e.mock.On("CreateText", value, _a1)} +} + +func (_c *ProcessorProvider_CreateText_Call) Run(run func(value string, _a1 props.TextProps)) *ProcessorProvider_CreateText_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(props.TextProps)) + }) + return _c +} + +func (_c *ProcessorProvider_CreateText_Call) Return(_a0 core.Component) *ProcessorProvider_CreateText_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorProvider_CreateText_Call) RunAndReturn(run func(string, props.TextProps) core.Component) *ProcessorProvider_CreateText_Call { + _c.Call.Return(run) + return _c +} + +// GeneratePdf provides a mock function with given fields: +func (_m *ProcessorProvider) GeneratePdf() ([]byte, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GeneratePdf") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func() ([]byte, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []byte); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProcessorProvider_GeneratePdf_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GeneratePdf' +type ProcessorProvider_GeneratePdf_Call struct { + *mock.Call +} + +// GeneratePdf is a helper method to define mock.On call +func (_e *ProcessorProvider_Expecter) GeneratePdf() *ProcessorProvider_GeneratePdf_Call { + return &ProcessorProvider_GeneratePdf_Call{Call: _e.mock.On("GeneratePdf")} +} + +func (_c *ProcessorProvider_GeneratePdf_Call) Run(run func()) *ProcessorProvider_GeneratePdf_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ProcessorProvider_GeneratePdf_Call) Return(_a0 []byte, _a1 error) *ProcessorProvider_GeneratePdf_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ProcessorProvider_GeneratePdf_Call) RunAndReturn(run func() ([]byte, error)) *ProcessorProvider_GeneratePdf_Call { + _c.Call.Return(run) + return _c +} + +// RegisterFooter provides a mock function with given fields: rows +func (_m *ProcessorProvider) RegisterFooter(rows ...core.Row) processorprovider.ProcessorProvider { + _va := make([]interface{}, len(rows)) + for _i := range rows { + _va[_i] = rows[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for RegisterFooter") + } + + var r0 processorprovider.ProcessorProvider + if rf, ok := ret.Get(0).(func(...core.Row) processorprovider.ProcessorProvider); ok { + r0 = rf(rows...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(processorprovider.ProcessorProvider) + } + } + + return r0 +} + +// ProcessorProvider_RegisterFooter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterFooter' +type ProcessorProvider_RegisterFooter_Call struct { + *mock.Call +} + +// RegisterFooter is a helper method to define mock.On call +// - rows ...core.Row +func (_e *ProcessorProvider_Expecter) RegisterFooter(rows ...interface{}) *ProcessorProvider_RegisterFooter_Call { + return &ProcessorProvider_RegisterFooter_Call{Call: _e.mock.On("RegisterFooter", + append([]interface{}{}, rows...)...)} +} + +func (_c *ProcessorProvider_RegisterFooter_Call) Run(run func(rows ...core.Row)) *ProcessorProvider_RegisterFooter_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]core.Row, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(core.Row) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_RegisterFooter_Call) Return(_a0 processorprovider.ProcessorProvider) *ProcessorProvider_RegisterFooter_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorProvider_RegisterFooter_Call) RunAndReturn(run func(...core.Row) processorprovider.ProcessorProvider) *ProcessorProvider_RegisterFooter_Call { + _c.Call.Return(run) + return _c +} + +// RegisterHeader provides a mock function with given fields: rows +func (_m *ProcessorProvider) RegisterHeader(rows ...core.Row) processorprovider.ProcessorProvider { + _va := make([]interface{}, len(rows)) + for _i := range rows { + _va[_i] = rows[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for RegisterHeader") + } + + var r0 processorprovider.ProcessorProvider + if rf, ok := ret.Get(0).(func(...core.Row) processorprovider.ProcessorProvider); ok { + r0 = rf(rows...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(processorprovider.ProcessorProvider) + } + } + + return r0 +} + +// ProcessorProvider_RegisterHeader_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterHeader' +type ProcessorProvider_RegisterHeader_Call struct { + *mock.Call +} + +// RegisterHeader is a helper method to define mock.On call +// - rows ...core.Row +func (_e *ProcessorProvider_Expecter) RegisterHeader(rows ...interface{}) *ProcessorProvider_RegisterHeader_Call { + return &ProcessorProvider_RegisterHeader_Call{Call: _e.mock.On("RegisterHeader", + append([]interface{}{}, rows...)...)} +} + +func (_c *ProcessorProvider_RegisterHeader_Call) Run(run func(rows ...core.Row)) *ProcessorProvider_RegisterHeader_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]core.Row, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(core.Row) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_RegisterHeader_Call) Return(_a0 processorprovider.ProcessorProvider) *ProcessorProvider_RegisterHeader_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorProvider_RegisterHeader_Call) RunAndReturn(run func(...core.Row) processorprovider.ProcessorProvider) *ProcessorProvider_RegisterHeader_Call { + _c.Call.Return(run) + return _c +} + +// NewProcessorProvider creates a new instance of ProcessorProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewProcessorProvider(t interface { + mock.TestingT + Cleanup(func()) +}, +) *ProcessorProvider { + mock := &ProcessorProvider{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/Provider.go b/mocks/Provider.go index 7b016909..dd7b2bf4 100644 --- a/mocks/Provider.go +++ b/mocks/Provider.go @@ -3,14 +3,12 @@ package mocks import ( - core "github.com/johnfercher/maroto/v2/pkg/core" - builder "github.com/johnfercher/maroto/v2/pkg/processor/components/builder" + extension "github.com/johnfercher/maroto/v2/pkg/consts/extension" + entity "github.com/johnfercher/maroto/v2/pkg/core/entity" mock "github.com/stretchr/testify/mock" - props "github.com/johnfercher/maroto/v2/pkg/processor/components/props" - - provider "github.com/johnfercher/maroto/v2/pkg/processor/provider" + props "github.com/johnfercher/maroto/v2/pkg/props" ) // Provider is an autogenerated mock type for the Provider type @@ -26,360 +24,611 @@ func (_m *Provider) EXPECT() *Provider_Expecter { return &Provider_Expecter{mock: &_m.Mock} } -// ConfigureBuilder provides a mock function with given fields: _a0 -func (_m *Provider) ConfigureBuilder(_a0 builder.Builder) provider.Provider { - ret := _m.Called(_a0) +// AddBackgroundImageFromBytes provides a mock function with given fields: bytes, cell, prop, _a3 +func (_m *Provider) AddBackgroundImageFromBytes(bytes []byte, cell *entity.Cell, prop *props.Rect, _a3 extension.Type) { + _m.Called(bytes, cell, prop, _a3) +} - if len(ret) == 0 { - panic("no return value specified for ConfigureBuilder") - } +// Provider_AddBackgroundImageFromBytes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddBackgroundImageFromBytes' +type Provider_AddBackgroundImageFromBytes_Call struct { + *mock.Call +} - var r0 provider.Provider - if rf, ok := ret.Get(0).(func(builder.Builder) provider.Provider); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(provider.Provider) - } - } +// AddBackgroundImageFromBytes is a helper method to define mock.On call +// - bytes []byte +// - cell *entity.Cell +// - prop *props.Rect +// - _a3 extension.Type +func (_e *Provider_Expecter) AddBackgroundImageFromBytes(bytes interface{}, cell interface{}, prop interface{}, _a3 interface{}) *Provider_AddBackgroundImageFromBytes_Call { + return &Provider_AddBackgroundImageFromBytes_Call{Call: _e.mock.On("AddBackgroundImageFromBytes", bytes, cell, prop, _a3)} +} - return r0 +func (_c *Provider_AddBackgroundImageFromBytes_Call) Run(run func(bytes []byte, cell *entity.Cell, prop *props.Rect, _a3 extension.Type)) *Provider_AddBackgroundImageFromBytes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]byte), args[1].(*entity.Cell), args[2].(*props.Rect), args[3].(extension.Type)) + }) + return _c } -// Provider_ConfigureBuilder_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ConfigureBuilder' -type Provider_ConfigureBuilder_Call struct { +func (_c *Provider_AddBackgroundImageFromBytes_Call) Return() *Provider_AddBackgroundImageFromBytes_Call { + _c.Call.Return() + return _c +} + +func (_c *Provider_AddBackgroundImageFromBytes_Call) RunAndReturn(run func([]byte, *entity.Cell, *props.Rect, extension.Type)) *Provider_AddBackgroundImageFromBytes_Call { + _c.Call.Return(run) + return _c +} + +// AddBarCode provides a mock function with given fields: code, cell, prop +func (_m *Provider) AddBarCode(code string, cell *entity.Cell, prop *props.Barcode) { + _m.Called(code, cell, prop) +} + +// Provider_AddBarCode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddBarCode' +type Provider_AddBarCode_Call struct { *mock.Call } -// ConfigureBuilder is a helper method to define mock.On call -// - _a0 builder.Builder -func (_e *Provider_Expecter) ConfigureBuilder(_a0 interface{}) *Provider_ConfigureBuilder_Call { - return &Provider_ConfigureBuilder_Call{Call: _e.mock.On("ConfigureBuilder", _a0)} +// AddBarCode is a helper method to define mock.On call +// - code string +// - cell *entity.Cell +// - prop *props.Barcode +func (_e *Provider_Expecter) AddBarCode(code interface{}, cell interface{}, prop interface{}) *Provider_AddBarCode_Call { + return &Provider_AddBarCode_Call{Call: _e.mock.On("AddBarCode", code, cell, prop)} } -func (_c *Provider_ConfigureBuilder_Call) Run(run func(_a0 builder.Builder)) *Provider_ConfigureBuilder_Call { +func (_c *Provider_AddBarCode_Call) Run(run func(code string, cell *entity.Cell, prop *props.Barcode)) *Provider_AddBarCode_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(builder.Builder)) + run(args[0].(string), args[1].(*entity.Cell), args[2].(*props.Barcode)) }) return _c } -func (_c *Provider_ConfigureBuilder_Call) Return(_a0 provider.Provider) *Provider_ConfigureBuilder_Call { - _c.Call.Return(_a0) +func (_c *Provider_AddBarCode_Call) Return() *Provider_AddBarCode_Call { + _c.Call.Return() return _c } -func (_c *Provider_ConfigureBuilder_Call) RunAndReturn(run func(builder.Builder) provider.Provider) *Provider_ConfigureBuilder_Call { +func (_c *Provider_AddBarCode_Call) RunAndReturn(run func(string, *entity.Cell, *props.Barcode)) *Provider_AddBarCode_Call { _c.Call.Return(run) return _c } -// CreateBarCode provides a mock function with given fields: value, _a1 -func (_m *Provider) CreateBarCode(value string, _a1 props.BarCodeProps) core.Component { - ret := _m.Called(value, _a1) +// AddImageFromBytes provides a mock function with given fields: bytes, cell, prop, _a3 +func (_m *Provider) AddImageFromBytes(bytes []byte, cell *entity.Cell, prop *props.Rect, _a3 extension.Type) { + _m.Called(bytes, cell, prop, _a3) +} - if len(ret) == 0 { - panic("no return value specified for CreateBarCode") - } +// Provider_AddImageFromBytes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddImageFromBytes' +type Provider_AddImageFromBytes_Call struct { + *mock.Call +} - var r0 core.Component - if rf, ok := ret.Get(0).(func(string, props.BarCodeProps) core.Component); ok { - r0 = rf(value, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(core.Component) - } - } +// AddImageFromBytes is a helper method to define mock.On call +// - bytes []byte +// - cell *entity.Cell +// - prop *props.Rect +// - _a3 extension.Type +func (_e *Provider_Expecter) AddImageFromBytes(bytes interface{}, cell interface{}, prop interface{}, _a3 interface{}) *Provider_AddImageFromBytes_Call { + return &Provider_AddImageFromBytes_Call{Call: _e.mock.On("AddImageFromBytes", bytes, cell, prop, _a3)} +} - return r0 +func (_c *Provider_AddImageFromBytes_Call) Run(run func(bytes []byte, cell *entity.Cell, prop *props.Rect, _a3 extension.Type)) *Provider_AddImageFromBytes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]byte), args[1].(*entity.Cell), args[2].(*props.Rect), args[3].(extension.Type)) + }) + return _c } -// Provider_CreateBarCode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateBarCode' -type Provider_CreateBarCode_Call struct { +func (_c *Provider_AddImageFromBytes_Call) Return() *Provider_AddImageFromBytes_Call { + _c.Call.Return() + return _c +} + +func (_c *Provider_AddImageFromBytes_Call) RunAndReturn(run func([]byte, *entity.Cell, *props.Rect, extension.Type)) *Provider_AddImageFromBytes_Call { + _c.Call.Return(run) + return _c +} + +// AddImageFromFile provides a mock function with given fields: value, cell, prop +func (_m *Provider) AddImageFromFile(value string, cell *entity.Cell, prop *props.Rect) { + _m.Called(value, cell, prop) +} + +// Provider_AddImageFromFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddImageFromFile' +type Provider_AddImageFromFile_Call struct { *mock.Call } -// CreateBarCode is a helper method to define mock.On call +// AddImageFromFile is a helper method to define mock.On call // - value string -// - _a1 props.BarCodeProps -func (_e *Provider_Expecter) CreateBarCode(value interface{}, _a1 interface{}) *Provider_CreateBarCode_Call { - return &Provider_CreateBarCode_Call{Call: _e.mock.On("CreateBarCode", value, _a1)} +// - cell *entity.Cell +// - prop *props.Rect +func (_e *Provider_Expecter) AddImageFromFile(value interface{}, cell interface{}, prop interface{}) *Provider_AddImageFromFile_Call { + return &Provider_AddImageFromFile_Call{Call: _e.mock.On("AddImageFromFile", value, cell, prop)} } -func (_c *Provider_CreateBarCode_Call) Run(run func(value string, _a1 props.BarCodeProps)) *Provider_CreateBarCode_Call { +func (_c *Provider_AddImageFromFile_Call) Run(run func(value string, cell *entity.Cell, prop *props.Rect)) *Provider_AddImageFromFile_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(props.BarCodeProps)) + run(args[0].(string), args[1].(*entity.Cell), args[2].(*props.Rect)) }) return _c } -func (_c *Provider_CreateBarCode_Call) Return(_a0 core.Component) *Provider_CreateBarCode_Call { - _c.Call.Return(_a0) +func (_c *Provider_AddImageFromFile_Call) Return() *Provider_AddImageFromFile_Call { + _c.Call.Return() return _c } -func (_c *Provider_CreateBarCode_Call) RunAndReturn(run func(string, props.BarCodeProps) core.Component) *Provider_CreateBarCode_Call { +func (_c *Provider_AddImageFromFile_Call) RunAndReturn(run func(string, *entity.Cell, *props.Rect)) *Provider_AddImageFromFile_Call { _c.Call.Return(run) return _c } -// CreateCol provides a mock function with given fields: size, components -func (_m *Provider) CreateCol(size int, components ...core.Component) core.Col { - _va := make([]interface{}, len(components)) - for _i := range components { - _va[_i] = components[_i] - } - var _ca []interface{} - _ca = append(_ca, size) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) +// AddLine provides a mock function with given fields: cell, prop +func (_m *Provider) AddLine(cell *entity.Cell, prop *props.Line) { + _m.Called(cell, prop) +} + +// Provider_AddLine_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddLine' +type Provider_AddLine_Call struct { + *mock.Call +} + +// AddLine is a helper method to define mock.On call +// - cell *entity.Cell +// - prop *props.Line +func (_e *Provider_Expecter) AddLine(cell interface{}, prop interface{}) *Provider_AddLine_Call { + return &Provider_AddLine_Call{Call: _e.mock.On("AddLine", cell, prop)} +} + +func (_c *Provider_AddLine_Call) Run(run func(cell *entity.Cell, prop *props.Line)) *Provider_AddLine_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*entity.Cell), args[1].(*props.Line)) + }) + return _c +} + +func (_c *Provider_AddLine_Call) Return() *Provider_AddLine_Call { + _c.Call.Return() + return _c +} + +func (_c *Provider_AddLine_Call) RunAndReturn(run func(*entity.Cell, *props.Line)) *Provider_AddLine_Call { + _c.Call.Return(run) + return _c +} + +// AddMatrixCode provides a mock function with given fields: code, cell, prop +func (_m *Provider) AddMatrixCode(code string, cell *entity.Cell, prop *props.Rect) { + _m.Called(code, cell, prop) +} + +// Provider_AddMatrixCode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddMatrixCode' +type Provider_AddMatrixCode_Call struct { + *mock.Call +} + +// AddMatrixCode is a helper method to define mock.On call +// - code string +// - cell *entity.Cell +// - prop *props.Rect +func (_e *Provider_Expecter) AddMatrixCode(code interface{}, cell interface{}, prop interface{}) *Provider_AddMatrixCode_Call { + return &Provider_AddMatrixCode_Call{Call: _e.mock.On("AddMatrixCode", code, cell, prop)} +} + +func (_c *Provider_AddMatrixCode_Call) Run(run func(code string, cell *entity.Cell, prop *props.Rect)) *Provider_AddMatrixCode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(*entity.Cell), args[2].(*props.Rect)) + }) + return _c +} + +func (_c *Provider_AddMatrixCode_Call) Return() *Provider_AddMatrixCode_Call { + _c.Call.Return() + return _c +} + +func (_c *Provider_AddMatrixCode_Call) RunAndReturn(run func(string, *entity.Cell, *props.Rect)) *Provider_AddMatrixCode_Call { + _c.Call.Return(run) + return _c +} + +// AddQrCode provides a mock function with given fields: code, cell, rect +func (_m *Provider) AddQrCode(code string, cell *entity.Cell, rect *props.Rect) { + _m.Called(code, cell, rect) +} + +// Provider_AddQrCode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddQrCode' +type Provider_AddQrCode_Call struct { + *mock.Call +} + +// AddQrCode is a helper method to define mock.On call +// - code string +// - cell *entity.Cell +// - rect *props.Rect +func (_e *Provider_Expecter) AddQrCode(code interface{}, cell interface{}, rect interface{}) *Provider_AddQrCode_Call { + return &Provider_AddQrCode_Call{Call: _e.mock.On("AddQrCode", code, cell, rect)} +} + +func (_c *Provider_AddQrCode_Call) Run(run func(code string, cell *entity.Cell, rect *props.Rect)) *Provider_AddQrCode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(*entity.Cell), args[2].(*props.Rect)) + }) + return _c +} + +func (_c *Provider_AddQrCode_Call) Return() *Provider_AddQrCode_Call { + _c.Call.Return() + return _c +} + +func (_c *Provider_AddQrCode_Call) RunAndReturn(run func(string, *entity.Cell, *props.Rect)) *Provider_AddQrCode_Call { + _c.Call.Return(run) + return _c +} + +// AddText provides a mock function with given fields: text, cell, prop +func (_m *Provider) AddText(text string, cell *entity.Cell, prop *props.Text) { + _m.Called(text, cell, prop) +} + +// Provider_AddText_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddText' +type Provider_AddText_Call struct { + *mock.Call +} + +// AddText is a helper method to define mock.On call +// - text string +// - cell *entity.Cell +// - prop *props.Text +func (_e *Provider_Expecter) AddText(text interface{}, cell interface{}, prop interface{}) *Provider_AddText_Call { + return &Provider_AddText_Call{Call: _e.mock.On("AddText", text, cell, prop)} +} + +func (_c *Provider_AddText_Call) Run(run func(text string, cell *entity.Cell, prop *props.Text)) *Provider_AddText_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(*entity.Cell), args[2].(*props.Text)) + }) + return _c +} + +func (_c *Provider_AddText_Call) Return() *Provider_AddText_Call { + _c.Call.Return() + return _c +} + +func (_c *Provider_AddText_Call) RunAndReturn(run func(string, *entity.Cell, *props.Text)) *Provider_AddText_Call { + _c.Call.Return(run) + return _c +} + +// CreateCol provides a mock function with given fields: width, height, config, prop +func (_m *Provider) CreateCol(width float64, height float64, config *entity.Config, prop *props.Cell) { + _m.Called(width, height, config, prop) +} + +// Provider_CreateCol_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateCol' +type Provider_CreateCol_Call struct { + *mock.Call +} + +// CreateCol is a helper method to define mock.On call +// - width float64 +// - height float64 +// - config *entity.Config +// - prop *props.Cell +func (_e *Provider_Expecter) CreateCol(width interface{}, height interface{}, config interface{}, prop interface{}) *Provider_CreateCol_Call { + return &Provider_CreateCol_Call{Call: _e.mock.On("CreateCol", width, height, config, prop)} +} + +func (_c *Provider_CreateCol_Call) Run(run func(width float64, height float64, config *entity.Config, prop *props.Cell)) *Provider_CreateCol_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64), args[1].(float64), args[2].(*entity.Config), args[3].(*props.Cell)) + }) + return _c +} + +func (_c *Provider_CreateCol_Call) Return() *Provider_CreateCol_Call { + _c.Call.Return() + return _c +} + +func (_c *Provider_CreateCol_Call) RunAndReturn(run func(float64, float64, *entity.Config, *props.Cell)) *Provider_CreateCol_Call { + _c.Call.Return(run) + return _c +} + +// CreateRow provides a mock function with given fields: height +func (_m *Provider) CreateRow(height float64) { + _m.Called(height) +} + +// Provider_CreateRow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRow' +type Provider_CreateRow_Call struct { + *mock.Call +} + +// CreateRow is a helper method to define mock.On call +// - height float64 +func (_e *Provider_Expecter) CreateRow(height interface{}) *Provider_CreateRow_Call { + return &Provider_CreateRow_Call{Call: _e.mock.On("CreateRow", height)} +} + +func (_c *Provider_CreateRow_Call) Run(run func(height float64)) *Provider_CreateRow_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Provider_CreateRow_Call) Return() *Provider_CreateRow_Call { + _c.Call.Return() + return _c +} + +func (_c *Provider_CreateRow_Call) RunAndReturn(run func(float64)) *Provider_CreateRow_Call { + _c.Call.Return(run) + return _c +} + +// GenerateBytes provides a mock function with given fields: +func (_m *Provider) GenerateBytes() ([]byte, error) { + ret := _m.Called() if len(ret) == 0 { - panic("no return value specified for CreateCol") + panic("no return value specified for GenerateBytes") } - var r0 core.Col - if rf, ok := ret.Get(0).(func(int, ...core.Component) core.Col); ok { - r0 = rf(size, components...) + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func() ([]byte, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []byte); ok { + r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(core.Col) + r0 = ret.Get(0).([]byte) } } - return r0 + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 } -// Provider_CreateCol_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateCol' -type Provider_CreateCol_Call struct { +// Provider_GenerateBytes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GenerateBytes' +type Provider_GenerateBytes_Call struct { *mock.Call } -// CreateCol is a helper method to define mock.On call -// - size int -// - components ...core.Component -func (_e *Provider_Expecter) CreateCol(size interface{}, components ...interface{}) *Provider_CreateCol_Call { - return &Provider_CreateCol_Call{Call: _e.mock.On("CreateCol", - append([]interface{}{size}, components...)...)} +// GenerateBytes is a helper method to define mock.On call +func (_e *Provider_Expecter) GenerateBytes() *Provider_GenerateBytes_Call { + return &Provider_GenerateBytes_Call{Call: _e.mock.On("GenerateBytes")} } -func (_c *Provider_CreateCol_Call) Run(run func(size int, components ...core.Component)) *Provider_CreateCol_Call { +func (_c *Provider_GenerateBytes_Call) Run(run func()) *Provider_GenerateBytes_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]core.Component, len(args)-1) - for i, a := range args[1:] { - if a != nil { - variadicArgs[i] = a.(core.Component) - } - } - run(args[0].(int), variadicArgs...) + run() }) return _c } -func (_c *Provider_CreateCol_Call) Return(_a0 core.Col) *Provider_CreateCol_Call { - _c.Call.Return(_a0) +func (_c *Provider_GenerateBytes_Call) Return(_a0 []byte, _a1 error) *Provider_GenerateBytes_Call { + _c.Call.Return(_a0, _a1) return _c } -func (_c *Provider_CreateCol_Call) RunAndReturn(run func(int, ...core.Component) core.Col) *Provider_CreateCol_Call { +func (_c *Provider_GenerateBytes_Call) RunAndReturn(run func() ([]byte, error)) *Provider_GenerateBytes_Call { _c.Call.Return(run) return _c } -// CreatePage provides a mock function with given fields: components -func (_m *Provider) CreatePage(components ...core.Row) core.Page { - _va := make([]interface{}, len(components)) - for _i := range components { - _va[_i] = components[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) +// GetDimensionsByImage provides a mock function with given fields: file +func (_m *Provider) GetDimensionsByImage(file string) (*entity.Dimensions, error) { + ret := _m.Called(file) if len(ret) == 0 { - panic("no return value specified for CreatePage") + panic("no return value specified for GetDimensionsByImage") } - var r0 core.Page - if rf, ok := ret.Get(0).(func(...core.Row) core.Page); ok { - r0 = rf(components...) + var r0 *entity.Dimensions + var r1 error + if rf, ok := ret.Get(0).(func(string) (*entity.Dimensions, error)); ok { + return rf(file) + } + if rf, ok := ret.Get(0).(func(string) *entity.Dimensions); ok { + r0 = rf(file) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(core.Page) + r0 = ret.Get(0).(*entity.Dimensions) } } - return r0 + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(file) + } else { + r1 = ret.Error(1) + } + + return r0, r1 } -// Provider_CreatePage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreatePage' -type Provider_CreatePage_Call struct { +// Provider_GetDimensionsByImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDimensionsByImage' +type Provider_GetDimensionsByImage_Call struct { *mock.Call } -// CreatePage is a helper method to define mock.On call -// - components ...core.Row -func (_e *Provider_Expecter) CreatePage(components ...interface{}) *Provider_CreatePage_Call { - return &Provider_CreatePage_Call{Call: _e.mock.On("CreatePage", - append([]interface{}{}, components...)...)} +// GetDimensionsByImage is a helper method to define mock.On call +// - file string +func (_e *Provider_Expecter) GetDimensionsByImage(file interface{}) *Provider_GetDimensionsByImage_Call { + return &Provider_GetDimensionsByImage_Call{Call: _e.mock.On("GetDimensionsByImage", file)} } -func (_c *Provider_CreatePage_Call) Run(run func(components ...core.Row)) *Provider_CreatePage_Call { +func (_c *Provider_GetDimensionsByImage_Call) Run(run func(file string)) *Provider_GetDimensionsByImage_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]core.Row, len(args)-0) - for i, a := range args[0:] { - if a != nil { - variadicArgs[i] = a.(core.Row) - } - } - run(variadicArgs...) + run(args[0].(string)) }) return _c } -func (_c *Provider_CreatePage_Call) Return(_a0 core.Page) *Provider_CreatePage_Call { - _c.Call.Return(_a0) +func (_c *Provider_GetDimensionsByImage_Call) Return(_a0 *entity.Dimensions, _a1 error) *Provider_GetDimensionsByImage_Call { + _c.Call.Return(_a0, _a1) return _c } -func (_c *Provider_CreatePage_Call) RunAndReturn(run func(...core.Row) core.Page) *Provider_CreatePage_Call { +func (_c *Provider_GetDimensionsByImage_Call) RunAndReturn(run func(string) (*entity.Dimensions, error)) *Provider_GetDimensionsByImage_Call { _c.Call.Return(run) return _c } -// CreateRow provides a mock function with given fields: components -func (_m *Provider) CreateRow(components ...core.Col) core.Row { - _va := make([]interface{}, len(components)) - for _i := range components { - _va[_i] = components[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) +// GetDimensionsByImageByte provides a mock function with given fields: bytes, _a1 +func (_m *Provider) GetDimensionsByImageByte(bytes []byte, _a1 extension.Type) (*entity.Dimensions, error) { + ret := _m.Called(bytes, _a1) if len(ret) == 0 { - panic("no return value specified for CreateRow") + panic("no return value specified for GetDimensionsByImageByte") } - var r0 core.Row - if rf, ok := ret.Get(0).(func(...core.Col) core.Row); ok { - r0 = rf(components...) + var r0 *entity.Dimensions + var r1 error + if rf, ok := ret.Get(0).(func([]byte, extension.Type) (*entity.Dimensions, error)); ok { + return rf(bytes, _a1) + } + if rf, ok := ret.Get(0).(func([]byte, extension.Type) *entity.Dimensions); ok { + r0 = rf(bytes, _a1) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(core.Row) + r0 = ret.Get(0).(*entity.Dimensions) } } - return r0 + if rf, ok := ret.Get(1).(func([]byte, extension.Type) error); ok { + r1 = rf(bytes, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 } -// Provider_CreateRow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRow' -type Provider_CreateRow_Call struct { +// Provider_GetDimensionsByImageByte_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDimensionsByImageByte' +type Provider_GetDimensionsByImageByte_Call struct { *mock.Call } -// CreateRow is a helper method to define mock.On call -// - components ...core.Col -func (_e *Provider_Expecter) CreateRow(components ...interface{}) *Provider_CreateRow_Call { - return &Provider_CreateRow_Call{Call: _e.mock.On("CreateRow", - append([]interface{}{}, components...)...)} +// GetDimensionsByImageByte is a helper method to define mock.On call +// - bytes []byte +// - _a1 extension.Type +func (_e *Provider_Expecter) GetDimensionsByImageByte(bytes interface{}, _a1 interface{}) *Provider_GetDimensionsByImageByte_Call { + return &Provider_GetDimensionsByImageByte_Call{Call: _e.mock.On("GetDimensionsByImageByte", bytes, _a1)} } -func (_c *Provider_CreateRow_Call) Run(run func(components ...core.Col)) *Provider_CreateRow_Call { +func (_c *Provider_GetDimensionsByImageByte_Call) Run(run func(bytes []byte, _a1 extension.Type)) *Provider_GetDimensionsByImageByte_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]core.Col, len(args)-0) - for i, a := range args[0:] { - if a != nil { - variadicArgs[i] = a.(core.Col) - } - } - run(variadicArgs...) + run(args[0].([]byte), args[1].(extension.Type)) }) return _c } -func (_c *Provider_CreateRow_Call) Return(_a0 core.Row) *Provider_CreateRow_Call { - _c.Call.Return(_a0) +func (_c *Provider_GetDimensionsByImageByte_Call) Return(_a0 *entity.Dimensions, _a1 error) *Provider_GetDimensionsByImageByte_Call { + _c.Call.Return(_a0, _a1) return _c } -func (_c *Provider_CreateRow_Call) RunAndReturn(run func(...core.Col) core.Row) *Provider_CreateRow_Call { +func (_c *Provider_GetDimensionsByImageByte_Call) RunAndReturn(run func([]byte, extension.Type) (*entity.Dimensions, error)) *Provider_GetDimensionsByImageByte_Call { _c.Call.Return(run) return _c } -// CreateText provides a mock function with given fields: value, _a1 -func (_m *Provider) CreateText(value string, _a1 props.TextProps) core.Component { - ret := _m.Called(value, _a1) +// GetDimensionsByMatrixCode provides a mock function with given fields: code +func (_m *Provider) GetDimensionsByMatrixCode(code string) (*entity.Dimensions, error) { + ret := _m.Called(code) if len(ret) == 0 { - panic("no return value specified for CreateText") + panic("no return value specified for GetDimensionsByMatrixCode") } - var r0 core.Component - if rf, ok := ret.Get(0).(func(string, props.TextProps) core.Component); ok { - r0 = rf(value, _a1) + var r0 *entity.Dimensions + var r1 error + if rf, ok := ret.Get(0).(func(string) (*entity.Dimensions, error)); ok { + return rf(code) + } + if rf, ok := ret.Get(0).(func(string) *entity.Dimensions); ok { + r0 = rf(code) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(core.Component) + r0 = ret.Get(0).(*entity.Dimensions) } } - return r0 + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(code) + } else { + r1 = ret.Error(1) + } + + return r0, r1 } -// Provider_CreateText_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateText' -type Provider_CreateText_Call struct { +// Provider_GetDimensionsByMatrixCode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDimensionsByMatrixCode' +type Provider_GetDimensionsByMatrixCode_Call struct { *mock.Call } -// CreateText is a helper method to define mock.On call -// - value string -// - _a1 props.TextProps -func (_e *Provider_Expecter) CreateText(value interface{}, _a1 interface{}) *Provider_CreateText_Call { - return &Provider_CreateText_Call{Call: _e.mock.On("CreateText", value, _a1)} +// GetDimensionsByMatrixCode is a helper method to define mock.On call +// - code string +func (_e *Provider_Expecter) GetDimensionsByMatrixCode(code interface{}) *Provider_GetDimensionsByMatrixCode_Call { + return &Provider_GetDimensionsByMatrixCode_Call{Call: _e.mock.On("GetDimensionsByMatrixCode", code)} } -func (_c *Provider_CreateText_Call) Run(run func(value string, _a1 props.TextProps)) *Provider_CreateText_Call { +func (_c *Provider_GetDimensionsByMatrixCode_Call) Run(run func(code string)) *Provider_GetDimensionsByMatrixCode_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(props.TextProps)) + run(args[0].(string)) }) return _c } -func (_c *Provider_CreateText_Call) Return(_a0 core.Component) *Provider_CreateText_Call { - _c.Call.Return(_a0) +func (_c *Provider_GetDimensionsByMatrixCode_Call) Return(_a0 *entity.Dimensions, _a1 error) *Provider_GetDimensionsByMatrixCode_Call { + _c.Call.Return(_a0, _a1) return _c } -func (_c *Provider_CreateText_Call) RunAndReturn(run func(string, props.TextProps) core.Component) *Provider_CreateText_Call { +func (_c *Provider_GetDimensionsByMatrixCode_Call) RunAndReturn(run func(string) (*entity.Dimensions, error)) *Provider_GetDimensionsByMatrixCode_Call { _c.Call.Return(run) return _c } -// GeneratePdf provides a mock function with given fields: -func (_m *Provider) GeneratePdf() ([]byte, error) { - ret := _m.Called() +// GetDimensionsByQrCode provides a mock function with given fields: code +func (_m *Provider) GetDimensionsByQrCode(code string) (*entity.Dimensions, error) { + ret := _m.Called(code) if len(ret) == 0 { - panic("no return value specified for GeneratePdf") + panic("no return value specified for GetDimensionsByQrCode") } - var r0 []byte + var r0 *entity.Dimensions var r1 error - if rf, ok := ret.Get(0).(func() ([]byte, error)); ok { - return rf() + if rf, ok := ret.Get(0).(func(string) (*entity.Dimensions, error)); ok { + return rf(code) } - if rf, ok := ret.Get(0).(func() []byte); ok { - r0 = rf() + if rf, ok := ret.Get(0).(func(string) *entity.Dimensions); ok { + r0 = rf(code) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]byte) + r0 = ret.Get(0).(*entity.Dimensions) } } - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(code) } else { r1 = ret.Error(1) } @@ -387,151 +636,223 @@ func (_m *Provider) GeneratePdf() ([]byte, error) { return r0, r1 } -// Provider_GeneratePdf_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GeneratePdf' -type Provider_GeneratePdf_Call struct { +// Provider_GetDimensionsByQrCode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDimensionsByQrCode' +type Provider_GetDimensionsByQrCode_Call struct { *mock.Call } -// GeneratePdf is a helper method to define mock.On call -func (_e *Provider_Expecter) GeneratePdf() *Provider_GeneratePdf_Call { - return &Provider_GeneratePdf_Call{Call: _e.mock.On("GeneratePdf")} +// GetDimensionsByQrCode is a helper method to define mock.On call +// - code string +func (_e *Provider_Expecter) GetDimensionsByQrCode(code interface{}) *Provider_GetDimensionsByQrCode_Call { + return &Provider_GetDimensionsByQrCode_Call{Call: _e.mock.On("GetDimensionsByQrCode", code)} } -func (_c *Provider_GeneratePdf_Call) Run(run func()) *Provider_GeneratePdf_Call { +func (_c *Provider_GetDimensionsByQrCode_Call) Run(run func(code string)) *Provider_GetDimensionsByQrCode_Call { _c.Call.Run(func(args mock.Arguments) { - run() + run(args[0].(string)) }) return _c } -func (_c *Provider_GeneratePdf_Call) Return(_a0 []byte, _a1 error) *Provider_GeneratePdf_Call { +func (_c *Provider_GetDimensionsByQrCode_Call) Return(_a0 *entity.Dimensions, _a1 error) *Provider_GetDimensionsByQrCode_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *Provider_GeneratePdf_Call) RunAndReturn(run func() ([]byte, error)) *Provider_GeneratePdf_Call { +func (_c *Provider_GetDimensionsByQrCode_Call) RunAndReturn(run func(string) (*entity.Dimensions, error)) *Provider_GetDimensionsByQrCode_Call { _c.Call.Return(run) return _c } -// RegisterFooter provides a mock function with given fields: rows -func (_m *Provider) RegisterFooter(rows ...core.Row) provider.Provider { - _va := make([]interface{}, len(rows)) - for _i := range rows { - _va[_i] = rows[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) +// GetFontHeight provides a mock function with given fields: prop +func (_m *Provider) GetFontHeight(prop *props.Font) float64 { + ret := _m.Called(prop) if len(ret) == 0 { - panic("no return value specified for RegisterFooter") + panic("no return value specified for GetFontHeight") } - var r0 provider.Provider - if rf, ok := ret.Get(0).(func(...core.Row) provider.Provider); ok { - r0 = rf(rows...) + var r0 float64 + if rf, ok := ret.Get(0).(func(*props.Font) float64); ok { + r0 = rf(prop) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(provider.Provider) - } + r0 = ret.Get(0).(float64) } return r0 } -// Provider_RegisterFooter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterFooter' -type Provider_RegisterFooter_Call struct { +// Provider_GetFontHeight_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetFontHeight' +type Provider_GetFontHeight_Call struct { *mock.Call } -// RegisterFooter is a helper method to define mock.On call -// - rows ...core.Row -func (_e *Provider_Expecter) RegisterFooter(rows ...interface{}) *Provider_RegisterFooter_Call { - return &Provider_RegisterFooter_Call{Call: _e.mock.On("RegisterFooter", - append([]interface{}{}, rows...)...)} +// GetFontHeight is a helper method to define mock.On call +// - prop *props.Font +func (_e *Provider_Expecter) GetFontHeight(prop interface{}) *Provider_GetFontHeight_Call { + return &Provider_GetFontHeight_Call{Call: _e.mock.On("GetFontHeight", prop)} } -func (_c *Provider_RegisterFooter_Call) Run(run func(rows ...core.Row)) *Provider_RegisterFooter_Call { +func (_c *Provider_GetFontHeight_Call) Run(run func(prop *props.Font)) *Provider_GetFontHeight_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]core.Row, len(args)-0) - for i, a := range args[0:] { - if a != nil { - variadicArgs[i] = a.(core.Row) - } - } - run(variadicArgs...) + run(args[0].(*props.Font)) }) return _c } -func (_c *Provider_RegisterFooter_Call) Return(_a0 provider.Provider) *Provider_RegisterFooter_Call { +func (_c *Provider_GetFontHeight_Call) Return(_a0 float64) *Provider_GetFontHeight_Call { _c.Call.Return(_a0) return _c } -func (_c *Provider_RegisterFooter_Call) RunAndReturn(run func(...core.Row) provider.Provider) *Provider_RegisterFooter_Call { +func (_c *Provider_GetFontHeight_Call) RunAndReturn(run func(*props.Font) float64) *Provider_GetFontHeight_Call { _c.Call.Return(run) return _c } -// RegisterHeader provides a mock function with given fields: rows -func (_m *Provider) RegisterHeader(rows ...core.Row) provider.Provider { - _va := make([]interface{}, len(rows)) - for _i := range rows { - _va[_i] = rows[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) +// GetLinesQuantity provides a mock function with given fields: text, textProp, colWidth +func (_m *Provider) GetLinesQuantity(text string, textProp *props.Text, colWidth float64) int { + ret := _m.Called(text, textProp, colWidth) if len(ret) == 0 { - panic("no return value specified for RegisterHeader") + panic("no return value specified for GetLinesQuantity") } - var r0 provider.Provider - if rf, ok := ret.Get(0).(func(...core.Row) provider.Provider); ok { - r0 = rf(rows...) + var r0 int + if rf, ok := ret.Get(0).(func(string, *props.Text, float64) int); ok { + r0 = rf(text, textProp, colWidth) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(provider.Provider) - } + r0 = ret.Get(0).(int) } return r0 } -// Provider_RegisterHeader_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterHeader' -type Provider_RegisterHeader_Call struct { +// Provider_GetLinesQuantity_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLinesQuantity' +type Provider_GetLinesQuantity_Call struct { *mock.Call } -// RegisterHeader is a helper method to define mock.On call -// - rows ...core.Row -func (_e *Provider_Expecter) RegisterHeader(rows ...interface{}) *Provider_RegisterHeader_Call { - return &Provider_RegisterHeader_Call{Call: _e.mock.On("RegisterHeader", - append([]interface{}{}, rows...)...)} +// GetLinesQuantity is a helper method to define mock.On call +// - text string +// - textProp *props.Text +// - colWidth float64 +func (_e *Provider_Expecter) GetLinesQuantity(text interface{}, textProp interface{}, colWidth interface{}) *Provider_GetLinesQuantity_Call { + return &Provider_GetLinesQuantity_Call{Call: _e.mock.On("GetLinesQuantity", text, textProp, colWidth)} } -func (_c *Provider_RegisterHeader_Call) Run(run func(rows ...core.Row)) *Provider_RegisterHeader_Call { +func (_c *Provider_GetLinesQuantity_Call) Run(run func(text string, textProp *props.Text, colWidth float64)) *Provider_GetLinesQuantity_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]core.Row, len(args)-0) - for i, a := range args[0:] { - if a != nil { - variadicArgs[i] = a.(core.Row) - } - } - run(variadicArgs...) + run(args[0].(string), args[1].(*props.Text), args[2].(float64)) }) return _c } -func (_c *Provider_RegisterHeader_Call) Return(_a0 provider.Provider) *Provider_RegisterHeader_Call { +func (_c *Provider_GetLinesQuantity_Call) Return(_a0 int) *Provider_GetLinesQuantity_Call { _c.Call.Return(_a0) return _c } -func (_c *Provider_RegisterHeader_Call) RunAndReturn(run func(...core.Row) provider.Provider) *Provider_RegisterHeader_Call { +func (_c *Provider_GetLinesQuantity_Call) RunAndReturn(run func(string, *props.Text, float64) int) *Provider_GetLinesQuantity_Call { + _c.Call.Return(run) + return _c +} + +// SetCompression provides a mock function with given fields: compression +func (_m *Provider) SetCompression(compression bool) { + _m.Called(compression) +} + +// Provider_SetCompression_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetCompression' +type Provider_SetCompression_Call struct { + *mock.Call +} + +// SetCompression is a helper method to define mock.On call +// - compression bool +func (_e *Provider_Expecter) SetCompression(compression interface{}) *Provider_SetCompression_Call { + return &Provider_SetCompression_Call{Call: _e.mock.On("SetCompression", compression)} +} + +func (_c *Provider_SetCompression_Call) Run(run func(compression bool)) *Provider_SetCompression_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Provider_SetCompression_Call) Return() *Provider_SetCompression_Call { + _c.Call.Return() + return _c +} + +func (_c *Provider_SetCompression_Call) RunAndReturn(run func(bool)) *Provider_SetCompression_Call { + _c.Call.Return(run) + return _c +} + +// SetMetadata provides a mock function with given fields: metadata +func (_m *Provider) SetMetadata(metadata *entity.Metadata) { + _m.Called(metadata) +} + +// Provider_SetMetadata_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetMetadata' +type Provider_SetMetadata_Call struct { + *mock.Call +} + +// SetMetadata is a helper method to define mock.On call +// - metadata *entity.Metadata +func (_e *Provider_Expecter) SetMetadata(metadata interface{}) *Provider_SetMetadata_Call { + return &Provider_SetMetadata_Call{Call: _e.mock.On("SetMetadata", metadata)} +} + +func (_c *Provider_SetMetadata_Call) Run(run func(metadata *entity.Metadata)) *Provider_SetMetadata_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*entity.Metadata)) + }) + return _c +} + +func (_c *Provider_SetMetadata_Call) Return() *Provider_SetMetadata_Call { + _c.Call.Return() + return _c +} + +func (_c *Provider_SetMetadata_Call) RunAndReturn(run func(*entity.Metadata)) *Provider_SetMetadata_Call { + _c.Call.Return(run) + return _c +} + +// SetProtection provides a mock function with given fields: protection +func (_m *Provider) SetProtection(protection *entity.Protection) { + _m.Called(protection) +} + +// Provider_SetProtection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetProtection' +type Provider_SetProtection_Call struct { + *mock.Call +} + +// SetProtection is a helper method to define mock.On call +// - protection *entity.Protection +func (_e *Provider_Expecter) SetProtection(protection interface{}) *Provider_SetProtection_Call { + return &Provider_SetProtection_Call{Call: _e.mock.On("SetProtection", protection)} +} + +func (_c *Provider_SetProtection_Call) Run(run func(protection *entity.Protection)) *Provider_SetProtection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*entity.Protection)) + }) + return _c +} + +func (_c *Provider_SetProtection_Call) Return() *Provider_SetProtection_Call { + _c.Call.Return() + return _c +} + +func (_c *Provider_SetProtection_Call) RunAndReturn(run func(*entity.Protection)) *Provider_SetProtection_Call { _c.Call.Return(run) return _c } diff --git a/mocks/Repository.go b/mocks/Repository.go index 3977c94e..dd241eb4 100644 --- a/mocks/Repository.go +++ b/mocks/Repository.go @@ -2,14 +2,7 @@ package mocks -import ( - fontstyle "github.com/johnfercher/maroto/v2/pkg/consts/fontstyle" - entity "github.com/johnfercher/maroto/v2/pkg/core/entity" - - mock "github.com/stretchr/testify/mock" - - repository "github.com/johnfercher/maroto/v2/pkg/repository" -) +import mock "github.com/stretchr/testify/mock" // Repository is an autogenerated mock type for the Repository type type Repository struct { @@ -24,159 +17,105 @@ func (_m *Repository) EXPECT() *Repository_Expecter { return &Repository_Expecter{mock: &_m.Mock} } -// AddUTF8Font provides a mock function with given fields: family, style, file -func (_m *Repository) AddUTF8Font(family string, style fontstyle.Type, file string) repository.Repository { - ret := _m.Called(family, style, file) +// ReadTemplate provides a mock function with given fields: templateName +func (_m *Repository) ReadTemplate(templateName string) (string, error) { + ret := _m.Called(templateName) if len(ret) == 0 { - panic("no return value specified for AddUTF8Font") + panic("no return value specified for ReadTemplate") } - var r0 repository.Repository - if rf, ok := ret.Get(0).(func(string, fontstyle.Type, string) repository.Repository); ok { - r0 = rf(family, style, file) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(repository.Repository) - } + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(string) (string, error)); ok { + return rf(templateName) } - - return r0 -} - -// Repository_AddUTF8Font_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddUTF8Font' -type Repository_AddUTF8Font_Call struct { - *mock.Call -} - -// AddUTF8Font is a helper method to define mock.On call -// - family string -// - style fontstyle.Type -// - file string -func (_e *Repository_Expecter) AddUTF8Font(family interface{}, style interface{}, file interface{}) *Repository_AddUTF8Font_Call { - return &Repository_AddUTF8Font_Call{Call: _e.mock.On("AddUTF8Font", family, style, file)} -} - -func (_c *Repository_AddUTF8Font_Call) Run(run func(family string, style fontstyle.Type, file string)) *Repository_AddUTF8Font_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(fontstyle.Type), args[2].(string)) - }) - return _c -} - -func (_c *Repository_AddUTF8Font_Call) Return(_a0 repository.Repository) *Repository_AddUTF8Font_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Repository_AddUTF8Font_Call) RunAndReturn(run func(string, fontstyle.Type, string) repository.Repository) *Repository_AddUTF8Font_Call { - _c.Call.Return(run) - return _c -} - -// AddUTF8FontFromBytes provides a mock function with given fields: family, style, bytes -func (_m *Repository) AddUTF8FontFromBytes(family string, style fontstyle.Type, bytes []byte) repository.Repository { - ret := _m.Called(family, style, bytes) - - if len(ret) == 0 { - panic("no return value specified for AddUTF8FontFromBytes") + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(templateName) + } else { + r0 = ret.Get(0).(string) } - var r0 repository.Repository - if rf, ok := ret.Get(0).(func(string, fontstyle.Type, []byte) repository.Repository); ok { - r0 = rf(family, style, bytes) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(templateName) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(repository.Repository) - } + r1 = ret.Error(1) } - return r0 + return r0, r1 } -// Repository_AddUTF8FontFromBytes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddUTF8FontFromBytes' -type Repository_AddUTF8FontFromBytes_Call struct { +// Repository_ReadTemplate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReadTemplate' +type Repository_ReadTemplate_Call struct { *mock.Call } -// AddUTF8FontFromBytes is a helper method to define mock.On call -// - family string -// - style fontstyle.Type -// - bytes []byte -func (_e *Repository_Expecter) AddUTF8FontFromBytes(family interface{}, style interface{}, bytes interface{}) *Repository_AddUTF8FontFromBytes_Call { - return &Repository_AddUTF8FontFromBytes_Call{Call: _e.mock.On("AddUTF8FontFromBytes", family, style, bytes)} +// ReadTemplate is a helper method to define mock.On call +// - templateName string +func (_e *Repository_Expecter) ReadTemplate(templateName interface{}) *Repository_ReadTemplate_Call { + return &Repository_ReadTemplate_Call{Call: _e.mock.On("ReadTemplate", templateName)} } -func (_c *Repository_AddUTF8FontFromBytes_Call) Run(run func(family string, style fontstyle.Type, bytes []byte)) *Repository_AddUTF8FontFromBytes_Call { +func (_c *Repository_ReadTemplate_Call) Run(run func(templateName string)) *Repository_ReadTemplate_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(fontstyle.Type), args[2].([]byte)) + run(args[0].(string)) }) return _c } -func (_c *Repository_AddUTF8FontFromBytes_Call) Return(_a0 repository.Repository) *Repository_AddUTF8FontFromBytes_Call { - _c.Call.Return(_a0) +func (_c *Repository_ReadTemplate_Call) Return(_a0 string, _a1 error) *Repository_ReadTemplate_Call { + _c.Call.Return(_a0, _a1) return _c } -func (_c *Repository_AddUTF8FontFromBytes_Call) RunAndReturn(run func(string, fontstyle.Type, []byte) repository.Repository) *Repository_AddUTF8FontFromBytes_Call { +func (_c *Repository_ReadTemplate_Call) RunAndReturn(run func(string) (string, error)) *Repository_ReadTemplate_Call { _c.Call.Return(run) return _c } -// Load provides a mock function with given fields: -func (_m *Repository) Load() ([]*entity.CustomFont, error) { - ret := _m.Called() +// RegisterTemplate provides a mock function with given fields: name, template +func (_m *Repository) RegisterTemplate(name string, template string) error { + ret := _m.Called(name, template) if len(ret) == 0 { - panic("no return value specified for Load") + panic("no return value specified for RegisterTemplate") } - var r0 []*entity.CustomFont - var r1 error - if rf, ok := ret.Get(0).(func() ([]*entity.CustomFont, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() []*entity.CustomFont); ok { - r0 = rf() + var r0 error + if rf, ok := ret.Get(0).(func(string, string) error); ok { + r0 = rf(name, template) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*entity.CustomFont) - } + r0 = ret.Error(0) } - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 + return r0 } -// Repository_Load_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Load' -type Repository_Load_Call struct { +// Repository_RegisterTemplate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterTemplate' +type Repository_RegisterTemplate_Call struct { *mock.Call } -// Load is a helper method to define mock.On call -func (_e *Repository_Expecter) Load() *Repository_Load_Call { - return &Repository_Load_Call{Call: _e.mock.On("Load")} +// RegisterTemplate is a helper method to define mock.On call +// - name string +// - template string +func (_e *Repository_Expecter) RegisterTemplate(name interface{}, template interface{}) *Repository_RegisterTemplate_Call { + return &Repository_RegisterTemplate_Call{Call: _e.mock.On("RegisterTemplate", name, template)} } -func (_c *Repository_Load_Call) Run(run func()) *Repository_Load_Call { +func (_c *Repository_RegisterTemplate_Call) Run(run func(name string, template string)) *Repository_RegisterTemplate_Call { _c.Call.Run(func(args mock.Arguments) { - run() + run(args[0].(string), args[1].(string)) }) return _c } -func (_c *Repository_Load_Call) Return(_a0 []*entity.CustomFont, _a1 error) *Repository_Load_Call { - _c.Call.Return(_a0, _a1) +func (_c *Repository_RegisterTemplate_Call) Return(_a0 error) *Repository_RegisterTemplate_Call { + _c.Call.Return(_a0) return _c } -func (_c *Repository_Load_Call) RunAndReturn(run func() ([]*entity.CustomFont, error)) *Repository_Load_Call { +func (_c *Repository_RegisterTemplate_Call) RunAndReturn(run func(string, string) error) *Repository_RegisterTemplate_Call { _c.Call.Return(run) return _c } diff --git a/pkg/processor/components/barcode/bar_code.go b/pkg/processor/components/barcode/bar_code.go index e62f9a0b..18074155 100644 --- a/pkg/processor/components/barcode/bar_code.go +++ b/pkg/processor/components/barcode/bar_code.go @@ -3,7 +3,7 @@ package barcode import ( "github.com/johnfercher/maroto/v2/pkg/core" "github.com/johnfercher/maroto/v2/pkg/processor/components/props" - "github.com/johnfercher/maroto/v2/pkg/processor/provider" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type BarCode struct { @@ -18,6 +18,6 @@ func NewBarCode(props props.BarCodeProps, code string) *BarCode { } } -func (b *BarCode) Generate(provider provider.Provider) core.Component { +func (b *BarCode) Generate(provider processorprovider.ProcessorProvider) core.Component { return provider.CreateBarCode(b.Code, b.Props) } diff --git a/pkg/processor/components/col/col.go b/pkg/processor/components/col/col.go index f7944b43..b0677795 100644 --- a/pkg/processor/components/col/col.go +++ b/pkg/processor/components/col/col.go @@ -4,22 +4,22 @@ import ( "github.com/johnfercher/maroto/v2/pkg/core" "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/components/props" - "github.com/johnfercher/maroto/v2/pkg/processor/provider" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Col struct { Props props.ColProps - Components []components.Component + Components []components.PdfComponent } -func NewCol(props props.ColProps, components ...components.Component) *Col { +func NewCol(props props.ColProps, components ...components.PdfComponent) *Col { return &Col{ Props: props, Components: components, } } -func (c *Col) Generate(provider provider.Provider) core.Col { +func (c *Col) Generate(provider processorprovider.ProcessorProvider) core.Col { components := make([]core.Component, len(c.Components)) for i, component := range c.Components { diff --git a/pkg/processor/components/components.go b/pkg/processor/components/components.go index 1095b0f5..aac7332d 100644 --- a/pkg/processor/components/components.go +++ b/pkg/processor/components/components.go @@ -2,9 +2,9 @@ package components import ( "github.com/johnfercher/maroto/v2/pkg/core" - "github.com/johnfercher/maroto/v2/pkg/processor/provider" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) -type Component interface { - Generate(provider provider.Provider) core.Component +type PdfComponent interface { + Generate(provider processorprovider.ProcessorProvider) core.Component } diff --git a/pkg/processor/components/page/page.go b/pkg/processor/components/page/page.go index 93e02e37..e435670d 100644 --- a/pkg/processor/components/page/page.go +++ b/pkg/processor/components/page/page.go @@ -3,7 +3,7 @@ package page import ( "github.com/johnfercher/maroto/v2/pkg/core" "github.com/johnfercher/maroto/v2/pkg/processor/components/row" - "github.com/johnfercher/maroto/v2/pkg/processor/provider" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Page struct { @@ -16,7 +16,7 @@ func NewPage(header, rows []row.Row) *Page { } } -func (p *Page) Generate(provider provider.Provider) { +func (p *Page) Generate(provider processorprovider.ProcessorProvider) { rows := make([]core.Row, len(p.Rows)) for i, row := range p.Rows { diff --git a/pkg/processor/components/pdf/pdf.go b/pkg/processor/components/pdf/pdf.go index 281d60a7..e503f9f4 100644 --- a/pkg/processor/components/pdf/pdf.go +++ b/pkg/processor/components/pdf/pdf.go @@ -3,7 +3,7 @@ package pdf import ( "github.com/johnfercher/maroto/v2/pkg/processor/components/builder" "github.com/johnfercher/maroto/v2/pkg/processor/components/page" - "github.com/johnfercher/maroto/v2/pkg/processor/provider" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Pdf struct { @@ -18,7 +18,7 @@ func NewPdf(builder *builder.Builder, pages ...*page.Page) *Pdf { } } -func (p *Pdf) Generate(provider provider.Provider) provider.Provider { +func (p *Pdf) Generate(provider processorprovider.ProcessorProvider) processorprovider.ProcessorProvider { for _, page := range p.Pages { page.Generate(provider) } diff --git a/pkg/processor/components/row/row.go b/pkg/processor/components/row/row.go index 22e3e371..6389803f 100644 --- a/pkg/processor/components/row/row.go +++ b/pkg/processor/components/row/row.go @@ -3,7 +3,7 @@ package row import ( "github.com/johnfercher/maroto/v2/pkg/core" "github.com/johnfercher/maroto/v2/pkg/processor/components/col" - "github.com/johnfercher/maroto/v2/pkg/processor/provider" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Row struct { @@ -16,7 +16,7 @@ func NewRow(cols ...col.Col) *Row { } } -func (r *Row) Generate(provider provider.Provider) core.Row { +func (r *Row) Generate(provider processorprovider.ProcessorProvider) core.Row { cols := make([]core.Col, len(r.Cols)) for i, col := range r.Cols { diff --git a/pkg/processor/components/text/text.go b/pkg/processor/components/text/text.go index fabe50ba..46bc133b 100644 --- a/pkg/processor/components/text/text.go +++ b/pkg/processor/components/text/text.go @@ -3,7 +3,7 @@ package text import ( "github.com/johnfercher/maroto/v2/pkg/core" "github.com/johnfercher/maroto/v2/pkg/processor/components/props" - "github.com/johnfercher/maroto/v2/pkg/processor/provider" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Text struct { @@ -18,6 +18,6 @@ func NewText(props props.TextProps, value string) *Text { } } -func (t *Text) Generate(provider provider.Provider) core.Component { +func (t *Text) Generate(provider processorprovider.ProcessorProvider) core.Component { return provider.CreateText(t.Value, t.Props) } diff --git a/pkg/processor/mappers/component_mapper.go b/pkg/processor/mappers/component_mapper.go index aabbaa0e..4e894860 100644 --- a/pkg/processor/mappers/component_mapper.go +++ b/pkg/processor/mappers/component_mapper.go @@ -5,7 +5,7 @@ import "github.com/johnfercher/maroto/v2/pkg/processor/components" type GenerateComponent func(document interface{}, sourceKey string) (Componentmapper, error) type Componentmapper interface { - Generate(content map[string]interface{}) (components.Component, error) + Generate(content map[string]interface{}) (components.PdfComponent, error) } type AbstractFactoryMaps interface { diff --git a/pkg/processor/mappers/listmapper/list.go b/pkg/processor/mappers/listmapper/list.go index 014d502b..320a7abe 100644 --- a/pkg/processor/mappers/listmapper/list.go +++ b/pkg/processor/mappers/listmapper/list.go @@ -15,6 +15,6 @@ func NewList(document interface{}, sourceKey string, generate mappers.GenerateCo return &List{}, nil } -func (r *List) Generate(content map[string]interface{}) (components.Component, error) { +func (r *List) Generate(content map[string]interface{}) (components.PdfComponent, error) { return nil, nil } diff --git a/pkg/processor/mappers/pagemapper/page.go b/pkg/processor/mappers/pagemapper/page.go index efb96513..12ab1e1a 100644 --- a/pkg/processor/mappers/pagemapper/page.go +++ b/pkg/processor/mappers/pagemapper/page.go @@ -13,6 +13,6 @@ func NewPage(page interface{}, sourceKey string) (*Page, error) { return nil, nil } -func (r *Page) Generate(content map[string]interface{}) (components.Component, error) { +func (r *Page) Generate(content map[string]interface{}) (components.PdfComponent, error) { return nil, nil } diff --git a/pkg/processor/mappers/rowmapper/row.go b/pkg/processor/mappers/rowmapper/row.go index 98d3e7e9..19d1365e 100644 --- a/pkg/processor/mappers/rowmapper/row.go +++ b/pkg/processor/mappers/rowmapper/row.go @@ -11,6 +11,6 @@ func NewRow(document interface{}, sourceKey string) (*Row, error) { return &Row{Test: "a"}, nil } -func (r *Row) Generate(content map[string]interface{}) (components.Component, error) { +func (r *Row) Generate(content map[string]interface{}) (components.PdfComponent, error) { return nil, nil } diff --git a/pkg/processor/provider/Maroto.go b/pkg/processor/processorprovider/Maroto.go similarity index 87% rename from pkg/processor/provider/Maroto.go rename to pkg/processor/processorprovider/Maroto.go index 53e051a7..b4b2d039 100644 --- a/pkg/processor/provider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -1,4 +1,4 @@ -package provider +package processorprovider import ( "github.com/johnfercher/maroto/v2" @@ -33,16 +33,16 @@ func (m *Maroto) GeneratePdf() ([]byte, error) { return doc.GetBytes(), nil } -func (m *Maroto) ConfigureBuilder(builder builder.Builder) Provider { +func (m *Maroto) ConfigureBuilder(builder builder.Builder) ProcessorProvider { return nil } -func (m *Maroto) RegisterHeader(rows ...core.Row) Provider { +func (m *Maroto) RegisterHeader(rows ...core.Row) ProcessorProvider { (*m.maroto).RegisterHeader(rows...) return m } -func (m *Maroto) RegisterFooter(rows ...core.Row) Provider { +func (m *Maroto) RegisterFooter(rows ...core.Row) ProcessorProvider { (*m.maroto).RegisterFooter(rows...) return m } diff --git a/pkg/processor/provider/provider.go b/pkg/processor/processorprovider/provider.go similarity index 69% rename from pkg/processor/provider/provider.go rename to pkg/processor/processorprovider/provider.go index 30ef0286..4e1aec05 100644 --- a/pkg/processor/provider/provider.go +++ b/pkg/processor/processorprovider/provider.go @@ -1,4 +1,4 @@ -package provider +package processorprovider import ( "github.com/johnfercher/maroto/v2/pkg/core" @@ -6,11 +6,11 @@ import ( "github.com/johnfercher/maroto/v2/pkg/processor/components/props" ) -type Provider interface { +type ProcessorProvider interface { GeneratePdf() ([]byte, error) - ConfigureBuilder(builder builder.Builder) Provider - RegisterHeader(rows ...core.Row) Provider - RegisterFooter(rows ...core.Row) Provider + ConfigureBuilder(builder builder.Builder) ProcessorProvider + RegisterHeader(rows ...core.Row) ProcessorProvider + RegisterFooter(rows ...core.Row) ProcessorProvider CreatePage(components ...core.Row) core.Page CreateRow(components ...core.Col) core.Row CreateCol(size int, components ...core.Component) core.Col From d3882f4d559947e6697c0a26aa2081692a55297c Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Fri, 11 Oct 2024 13:57:14 -0300 Subject: [PATCH 018/116] test: validate page mapper creation --- internal/fixture/processorfixture.go | 4 +- pkg/processor/mappers/pagemapper/page_test.go | 58 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/internal/fixture/processorfixture.go b/internal/fixture/processorfixture.go index 7586c27b..39b33b16 100644 --- a/internal/fixture/processorfixture.go +++ b/internal/fixture/processorfixture.go @@ -1,6 +1,7 @@ package fixture import ( + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/listmapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pagemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rowmapper" @@ -14,7 +15,8 @@ func MapperRow() *rowmapper.Row { func MapperPage() *pagemapper.Page { return &pagemapper.Page{ - Teste: "1", + SourceKey: "template_page_1", + Rows: make([]mappers.Componentmapper, 0), } } diff --git a/pkg/processor/mappers/pagemapper/page_test.go b/pkg/processor/mappers/pagemapper/page_test.go index 91c984f3..c6db7cde 100644 --- a/pkg/processor/mappers/pagemapper/page_test.go +++ b/pkg/processor/mappers/pagemapper/page_test.go @@ -1 +1,59 @@ package pagemapper_test + +import ( + "testing" + + "github.com/johnfercher/maroto/v2/internal/fixture" + "github.com/johnfercher/maroto/v2/mocks" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/listmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pagemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rowmapper" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +func TestNewPage(t *testing.T) { + t.Run("When an invalid field is submitted, should return an error", func(t *testing.T) { + var invalidInterface interface{} = 1 + factory := mocks.NewAbstractFactoryMaps(t) + + doc, err := pagemapper.NewPage(invalidInterface, "test", factory) + + assert.Nil(t, doc) + assert.NotNil(t, err) + }) + + t.Run("When 2 rows are sent, should set the 2 rows", func(t *testing.T) { + templateRows := map[string]interface{}{ + "row_template_1": nil, + "row_template_2": nil, + } + + validRow := fixture.MapperRow() + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewRow", mock.Anything, "row_template_1").Return(validRow, nil) + factory.On("NewRow", mock.Anything, "row_template_2").Return(validRow, nil) + + doc, err := pagemapper.NewPage(templateRows, "test", factory) + + assert.Nil(t, err) + assert.Equal(t, 2, len(doc.Rows)) + assert.IsType(t, &rowmapper.Row{}, doc.Rows[0]) + }) + + t.Run("when 1 list is sent, it should add 1 list to the document", func(t *testing.T) { + templateRows := map[string]interface{}{ + "list_rows_1": nil, + } + + validPage := fixture.MapperList() + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewList", mock.Anything, "list_rows_1", mock.Anything).Return(validPage, nil) + + doc, err := pagemapper.NewPage(templateRows, "test", factory) + + assert.Nil(t, err) + assert.Equal(t, len(doc.Rows), 1) + assert.IsType(t, &listmapper.List{}, doc.Rows[0]) + }) +} From 5250a379fb05a157a5125716d0fc0a4a3cf14104 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Fri, 11 Oct 2024 13:59:52 -0300 Subject: [PATCH 019/116] feat: Configure mapper page creation --- .../abstractfactory/abstractfactory.go | 2 +- .../mappers/documentmapper/document.go | 4 +- pkg/processor/mappers/pagemapper/page.go | 47 +++++++++++++++++-- pkg/processor/processorprovider/Maroto.go | 5 +- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/pkg/processor/mappers/abstractfactory/abstractfactory.go b/pkg/processor/mappers/abstractfactory/abstractfactory.go index aa84d873..5da7bd9e 100644 --- a/pkg/processor/mappers/abstractfactory/abstractfactory.go +++ b/pkg/processor/mappers/abstractfactory/abstractfactory.go @@ -21,7 +21,7 @@ func (f *abstractFactoryMaps) NewRow(document interface{}, sourceKey string) (ma // NewPage is responsible for wrapper the creation of a page func (f *abstractFactoryMaps) NewPage(document interface{}, sourceKey string) (mappers.Componentmapper, error) { - return pagemapper.NewPage(document, sourceKey) + return pagemapper.NewPage(document, sourceKey, f) } // NewList is responsible for wrapper the creation of a list diff --git a/pkg/processor/mappers/documentmapper/document.go b/pkg/processor/mappers/documentmapper/document.go index 971162ee..89ac16db 100644 --- a/pkg/processor/mappers/documentmapper/document.go +++ b/pkg/processor/mappers/documentmapper/document.go @@ -113,8 +113,8 @@ func (p *Document) setFooter(rowsDoc interface{}) error { // setPages is responsible for factory the pages. // pages can be a list of pages or just one page -func (p *Document) setPages(rowsDoc interface{}) error { - templatePage, ok := rowsDoc.(map[string]interface{}) +func (p *Document) setPages(pagesDoc interface{}) error { + templatePage, ok := pagesDoc.(map[string]interface{}) if !ok { return fmt.Errorf("ensure pages can be converted to map[string] interface{}") } diff --git a/pkg/processor/mappers/pagemapper/page.go b/pkg/processor/mappers/pagemapper/page.go index 12ab1e1a..d1e03ec0 100644 --- a/pkg/processor/mappers/pagemapper/page.go +++ b/pkg/processor/mappers/pagemapper/page.go @@ -2,15 +2,56 @@ package pagemapper import ( + "fmt" + "strings" + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" ) type Page struct { - Teste string + SourceKey string + Rows []mappers.Componentmapper + factory mappers.AbstractFactoryMaps } -func NewPage(page interface{}, sourceKey string) (*Page, error) { - return nil, nil +func NewPage(rows interface{}, sourceKey string, factory mappers.AbstractFactoryMaps) (*Page, error) { + newPage := &Page{ + SourceKey: sourceKey, + factory: factory, + } + if err := newPage.setRows(rows); err != nil { + return nil, err + } + + return newPage, nil +} + +// setPages is responsible for factory the pages. +// pages can be a list of pages or just one page +func (p *Page) setRows(rowsDoc interface{}) error { + templateRows, ok := rowsDoc.(map[string]interface{}) + if !ok { + return fmt.Errorf("ensure rows can be converted to map[string] interface{}") + } + + for templateName, template := range templateRows { + var rows mappers.Componentmapper + var err error + + if strings.HasPrefix(templateName, "list") { + rows, err = p.factory.NewList(template, templateName, p.factory.NewRow) + } else { + rows, err = p.factory.NewRow(template, templateName) + } + + if err != nil { + return err + } + p.Rows = append(p.Rows, rows) + } + + return nil } func (r *Page) Generate(content map[string]interface{}) (components.PdfComponent, error) { diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index b4b2d039..341aea8d 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -1,7 +1,6 @@ package processorprovider import ( - "github.com/johnfercher/maroto/v2" "github.com/johnfercher/maroto/v2/pkg/components/code" "github.com/johnfercher/maroto/v2/pkg/components/col" "github.com/johnfercher/maroto/v2/pkg/components/page" @@ -20,8 +19,8 @@ type Maroto struct { } func NewMaroto() *Maroto { - m := maroto.New() - return &Maroto{maroto: &m} + // m := maroto.New() + return nil } func (m *Maroto) GeneratePdf() ([]byte, error) { From 8ca8f1517a65efd3c4b8d827c7d27767b5f7cbdf Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sat, 12 Oct 2024 11:47:22 -0300 Subject: [PATCH 020/116] test: validate list creation --- pkg/processor/mappers/listmapper/list_test.go | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/pkg/processor/mappers/listmapper/list_test.go b/pkg/processor/mappers/listmapper/list_test.go index 83325aff..c1aead7f 100644 --- a/pkg/processor/mappers/listmapper/list_test.go +++ b/pkg/processor/mappers/listmapper/list_test.go @@ -1 +1,58 @@ -package listmapper +package listmapper_test + +import ( + "errors" + "testing" + + "github.com/johnfercher/maroto/v2/internal/fixture" + "github.com/johnfercher/maroto/v2/mocks" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/listmapper" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +//se interface invalida for passada erro é retornada +// se componente não puder ser gerado, erro é retornado +// se uma lista de 2 componentes for passada, 1 erro é retornado + +func TestNewList(t *testing.T) { + t.Run("when invalid interface is sent, it should return an error", func(t *testing.T) { + var invalidInterface interface{} = 1 + factory := mocks.NewAbstractFactoryMaps(t) + + doc, err := listmapper.NewList(invalidInterface, "test", factory.NewPage) + + assert.Nil(t, doc) + assert.NotNil(t, err) + }) + + t.Run("when component not can generate, it should return an error", func(t *testing.T) { + templatePages := map[string]interface{}{ + "page_template_1": nil, + "page_template_2": nil, + } + + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewPage", mock.Anything, "page_template_1").Return(nil, errors.New("")) + doc, err := listmapper.NewList(templatePages, "test", factory.NewPage) + + assert.Nil(t, doc) + assert.NotNil(t, err) + }) + + t.Run("when 2-components are sent, it should add 2 componentes in list", func(t *testing.T) { + validPage := fixture.MapperPage() + templatePages := map[string]interface{}{ + "page_template_1": nil, + "page_template_2": nil, + } + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewPage", mock.Anything, "page_template_1").Return(validPage, nil) + factory.On("NewPage", mock.Anything, "page_template_2").Return(validPage, nil) + + doc, err := listmapper.NewList(templatePages, "test", factory.NewPage) + + assert.Nil(t, err) + assert.Equal(t, len(doc.Templates), 2) + }) +} From 7e5d15350164fc50f4011c192e8f339228226250 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sat, 12 Oct 2024 11:48:29 -0300 Subject: [PATCH 021/116] feat: Implement component list creation The list should allow applying list behavior to any component --- pkg/processor/mappers/listmapper/list.go | 36 +++++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/pkg/processor/mappers/listmapper/list.go b/pkg/processor/mappers/listmapper/list.go index 320a7abe..fdfdddcf 100644 --- a/pkg/processor/mappers/listmapper/list.go +++ b/pkg/processor/mappers/listmapper/list.go @@ -2,17 +2,45 @@ package listmapper import ( + "fmt" + "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" ) type List struct { - sourceKey string - templates mappers.Componentmapper + SourceKey string + Templates []mappers.Componentmapper +} + +func NewList(list interface{}, sourceKey string, generate mappers.GenerateComponent) (*List, error) { + listMapper, ok := list.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("ensure list can be converted to map[string] interface{}") + } + + components, err := createComponents(listMapper, generate) + if err != nil { + return nil, err + } + return &List{ + Templates: components, + SourceKey: sourceKey, + }, nil } -func NewList(document interface{}, sourceKey string, generate mappers.GenerateComponent) (*List, error) { - return &List{}, nil +func createComponents(listMapper map[string]interface{}, generate mappers.GenerateComponent) ([]mappers.Componentmapper, error) { + components := make([]mappers.Componentmapper, len(listMapper)) + cont := 0 + for templateName, template := range listMapper { + component, err := generate(template, templateName) + if err != nil { + return nil, err + } + components[cont] = component + cont++ + } + return components, nil } func (r *List) Generate(content map[string]interface{}) (components.PdfComponent, error) { From cf04731f787882ce226e5c723d5b5db4083edfca Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 13 Oct 2024 11:10:03 -0300 Subject: [PATCH 022/116] test: validate row creation --- internal/fixture/processorfixture.go | 3 +- mocks/AbstractFactoryMaps.go | 58 + mocks/Builder.go | 1263 +---------------- pkg/processor/mappers/listmapper/list_test.go | 2 +- pkg/processor/mappers/rowmapper/row_test.go | 62 + 5 files changed, 140 insertions(+), 1248 deletions(-) diff --git a/internal/fixture/processorfixture.go b/internal/fixture/processorfixture.go index 39b33b16..40a38219 100644 --- a/internal/fixture/processorfixture.go +++ b/internal/fixture/processorfixture.go @@ -9,7 +9,8 @@ import ( func MapperRow() *rowmapper.Row { return &rowmapper.Row{ - Test: "1", + Height: 0, + Cols: make([]mappers.Componentmapper, 0), } } diff --git a/mocks/AbstractFactoryMaps.go b/mocks/AbstractFactoryMaps.go index afeec53f..9a73b434 100644 --- a/mocks/AbstractFactoryMaps.go +++ b/mocks/AbstractFactoryMaps.go @@ -20,6 +20,64 @@ func (_m *AbstractFactoryMaps) EXPECT() *AbstractFactoryMaps_Expecter { return &AbstractFactoryMaps_Expecter{mock: &_m.Mock} } +// NewCol provides a mock function with given fields: document +func (_m *AbstractFactoryMaps) NewCol(document interface{}) (mappers.Componentmapper, error) { + ret := _m.Called(document) + + if len(ret) == 0 { + panic("no return value specified for NewCol") + } + + var r0 mappers.Componentmapper + var r1 error + if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + return rf(document) + } + if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + r0 = rf(document) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mappers.Componentmapper) + } + } + + if rf, ok := ret.Get(1).(func(interface{}) error); ok { + r1 = rf(document) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AbstractFactoryMaps_NewCol_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewCol' +type AbstractFactoryMaps_NewCol_Call struct { + *mock.Call +} + +// NewCol is a helper method to define mock.On call +// - document interface{} +func (_e *AbstractFactoryMaps_Expecter) NewCol(document interface{}) *AbstractFactoryMaps_NewCol_Call { + return &AbstractFactoryMaps_NewCol_Call{Call: _e.mock.On("NewCol", document)} +} + +func (_c *AbstractFactoryMaps_NewCol_Call) Run(run func(document interface{})) *AbstractFactoryMaps_NewCol_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{})) + }) + return _c +} + +func (_c *AbstractFactoryMaps_NewCol_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewCol_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AbstractFactoryMaps_NewCol_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewCol_Call { + _c.Call.Return(run) + return _c +} + // NewList provides a mock function with given fields: document, sourceKey, generate func (_m *AbstractFactoryMaps) NewList(document interface{}, sourceKey string, generate mappers.GenerateComponent) (mappers.Componentmapper, error) { ret := _m.Called(document, sourceKey, generate) diff --git a/mocks/Builder.go b/mocks/Builder.go index 2cbe240a..883f7968 100644 --- a/mocks/Builder.go +++ b/mocks/Builder.go @@ -3,22 +3,12 @@ package mocks import ( - config "github.com/johnfercher/maroto/v2/pkg/config" + cache "github.com/johnfercher/maroto/v2/internal/cache" entity "github.com/johnfercher/maroto/v2/pkg/core/entity" - extension "github.com/johnfercher/maroto/v2/pkg/consts/extension" + gofpdf "github.com/johnfercher/maroto/v2/internal/providers/gofpdf" mock "github.com/stretchr/testify/mock" - - orientation "github.com/johnfercher/maroto/v2/pkg/consts/orientation" - - pagesize "github.com/johnfercher/maroto/v2/pkg/consts/pagesize" - - props "github.com/johnfercher/maroto/v2/pkg/props" - - protection "github.com/johnfercher/maroto/v2/pkg/consts/protection" - - time "time" ) // Builder is an autogenerated mock type for the Builder type @@ -34,20 +24,20 @@ func (_m *Builder) EXPECT() *Builder_Expecter { return &Builder_Expecter{mock: &_m.Mock} } -// Build provides a mock function with given fields: -func (_m *Builder) Build() *entity.Config { - ret := _m.Called() +// Build provides a mock function with given fields: cfg, _a1 +func (_m *Builder) Build(cfg *entity.Config, _a1 cache.Cache) *gofpdf.Dependencies { + ret := _m.Called(cfg, _a1) if len(ret) == 0 { panic("no return value specified for Build") } - var r0 *entity.Config - if rf, ok := ret.Get(0).(func() *entity.Config); ok { - r0 = rf() + var r0 *gofpdf.Dependencies + if rf, ok := ret.Get(0).(func(*entity.Config, cache.Cache) *gofpdf.Dependencies); ok { + r0 = rf(cfg, _a1) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*entity.Config) + r0 = ret.Get(0).(*gofpdf.Dependencies) } } @@ -60,1244 +50,25 @@ type Builder_Build_Call struct { } // Build is a helper method to define mock.On call -func (_e *Builder_Expecter) Build() *Builder_Build_Call { - return &Builder_Build_Call{Call: _e.mock.On("Build")} -} - -func (_c *Builder_Build_Call) Run(run func()) *Builder_Build_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *Builder_Build_Call) Return(_a0 *entity.Config) *Builder_Build_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_Build_Call) RunAndReturn(run func() *entity.Config) *Builder_Build_Call { - _c.Call.Return(run) - return _c -} - -// WithAuthor provides a mock function with given fields: author, isUTF8 -func (_m *Builder) WithAuthor(author string, isUTF8 bool) config.Builder { - ret := _m.Called(author, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithAuthor") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(author, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithAuthor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithAuthor' -type Builder_WithAuthor_Call struct { - *mock.Call -} - -// WithAuthor is a helper method to define mock.On call -// - author string -// - isUTF8 bool -func (_e *Builder_Expecter) WithAuthor(author interface{}, isUTF8 interface{}) *Builder_WithAuthor_Call { - return &Builder_WithAuthor_Call{Call: _e.mock.On("WithAuthor", author, isUTF8)} -} - -func (_c *Builder_WithAuthor_Call) Run(run func(author string, isUTF8 bool)) *Builder_WithAuthor_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithAuthor_Call) Return(_a0 config.Builder) *Builder_WithAuthor_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithAuthor_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithAuthor_Call { - _c.Call.Return(run) - return _c -} - -// WithBackgroundImage provides a mock function with given fields: _a0, _a1 -func (_m *Builder) WithBackgroundImage(_a0 []byte, _a1 extension.Type) config.Builder { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for WithBackgroundImage") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func([]byte, extension.Type) config.Builder); ok { - r0 = rf(_a0, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithBackgroundImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBackgroundImage' -type Builder_WithBackgroundImage_Call struct { - *mock.Call -} - -// WithBackgroundImage is a helper method to define mock.On call -// - _a0 []byte -// - _a1 extension.Type -func (_e *Builder_Expecter) WithBackgroundImage(_a0 interface{}, _a1 interface{}) *Builder_WithBackgroundImage_Call { - return &Builder_WithBackgroundImage_Call{Call: _e.mock.On("WithBackgroundImage", _a0, _a1)} -} - -func (_c *Builder_WithBackgroundImage_Call) Run(run func(_a0 []byte, _a1 extension.Type)) *Builder_WithBackgroundImage_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].([]byte), args[1].(extension.Type)) - }) - return _c -} - -func (_c *Builder_WithBackgroundImage_Call) Return(_a0 config.Builder) *Builder_WithBackgroundImage_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithBackgroundImage_Call) RunAndReturn(run func([]byte, extension.Type) config.Builder) *Builder_WithBackgroundImage_Call { - _c.Call.Return(run) - return _c -} - -// WithBottomMargin provides a mock function with given fields: bottom -func (_m *Builder) WithBottomMargin(bottom float64) config.Builder { - ret := _m.Called(bottom) - - if len(ret) == 0 { - panic("no return value specified for WithBottomMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(bottom) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithBottomMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBottomMargin' -type Builder_WithBottomMargin_Call struct { - *mock.Call -} - -// WithBottomMargin is a helper method to define mock.On call -// - bottom float64 -func (_e *Builder_Expecter) WithBottomMargin(bottom interface{}) *Builder_WithBottomMargin_Call { - return &Builder_WithBottomMargin_Call{Call: _e.mock.On("WithBottomMargin", bottom)} -} - -func (_c *Builder_WithBottomMargin_Call) Run(run func(bottom float64)) *Builder_WithBottomMargin_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) - }) - return _c -} - -func (_c *Builder_WithBottomMargin_Call) Return(_a0 config.Builder) *Builder_WithBottomMargin_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithBottomMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithBottomMargin_Call { - _c.Call.Return(run) - return _c -} - -// WithCompression provides a mock function with given fields: compression -func (_m *Builder) WithCompression(compression bool) config.Builder { - ret := _m.Called(compression) - - if len(ret) == 0 { - panic("no return value specified for WithCompression") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { - r0 = rf(compression) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCompression_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCompression' -type Builder_WithCompression_Call struct { - *mock.Call -} - -// WithCompression is a helper method to define mock.On call -// - compression bool -func (_e *Builder_Expecter) WithCompression(compression interface{}) *Builder_WithCompression_Call { - return &Builder_WithCompression_Call{Call: _e.mock.On("WithCompression", compression)} -} - -func (_c *Builder_WithCompression_Call) Run(run func(compression bool)) *Builder_WithCompression_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(bool)) - }) - return _c -} - -func (_c *Builder_WithCompression_Call) Return(_a0 config.Builder) *Builder_WithCompression_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCompression_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithCompression_Call { - _c.Call.Return(run) - return _c -} - -// WithConcurrentMode provides a mock function with given fields: chunkWorkers -func (_m *Builder) WithConcurrentMode(chunkWorkers int) config.Builder { - ret := _m.Called(chunkWorkers) - - if len(ret) == 0 { - panic("no return value specified for WithConcurrentMode") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(int) config.Builder); ok { - r0 = rf(chunkWorkers) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithConcurrentMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithConcurrentMode' -type Builder_WithConcurrentMode_Call struct { - *mock.Call -} - -// WithConcurrentMode is a helper method to define mock.On call -// - chunkWorkers int -func (_e *Builder_Expecter) WithConcurrentMode(chunkWorkers interface{}) *Builder_WithConcurrentMode_Call { - return &Builder_WithConcurrentMode_Call{Call: _e.mock.On("WithConcurrentMode", chunkWorkers)} -} - -func (_c *Builder_WithConcurrentMode_Call) Run(run func(chunkWorkers int)) *Builder_WithConcurrentMode_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(int)) - }) - return _c -} - -func (_c *Builder_WithConcurrentMode_Call) Return(_a0 config.Builder) *Builder_WithConcurrentMode_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithConcurrentMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithConcurrentMode_Call { - _c.Call.Return(run) - return _c -} - -// WithCreationDate provides a mock function with given fields: _a0 -func (_m *Builder) WithCreationDate(_a0 time.Time) config.Builder { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for WithCreationDate") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(time.Time) config.Builder); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCreationDate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreationDate' -type Builder_WithCreationDate_Call struct { - *mock.Call -} - -// WithCreationDate is a helper method to define mock.On call -// - _a0 time.Time -func (_e *Builder_Expecter) WithCreationDate(_a0 interface{}) *Builder_WithCreationDate_Call { - return &Builder_WithCreationDate_Call{Call: _e.mock.On("WithCreationDate", _a0)} -} - -func (_c *Builder_WithCreationDate_Call) Run(run func(_a0 time.Time)) *Builder_WithCreationDate_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(time.Time)) - }) - return _c -} - -func (_c *Builder_WithCreationDate_Call) Return(_a0 config.Builder) *Builder_WithCreationDate_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCreationDate_Call) RunAndReturn(run func(time.Time) config.Builder) *Builder_WithCreationDate_Call { - _c.Call.Return(run) - return _c -} - -// WithCreator provides a mock function with given fields: creator, isUTF8 -func (_m *Builder) WithCreator(creator string, isUTF8 bool) config.Builder { - ret := _m.Called(creator, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithCreator") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(creator, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCreator_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreator' -type Builder_WithCreator_Call struct { - *mock.Call -} - -// WithCreator is a helper method to define mock.On call -// - creator string -// - isUTF8 bool -func (_e *Builder_Expecter) WithCreator(creator interface{}, isUTF8 interface{}) *Builder_WithCreator_Call { - return &Builder_WithCreator_Call{Call: _e.mock.On("WithCreator", creator, isUTF8)} -} - -func (_c *Builder_WithCreator_Call) Run(run func(creator string, isUTF8 bool)) *Builder_WithCreator_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithCreator_Call) Return(_a0 config.Builder) *Builder_WithCreator_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCreator_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithCreator_Call { - _c.Call.Return(run) - return _c -} - -// WithCustomFonts provides a mock function with given fields: _a0 -func (_m *Builder) WithCustomFonts(_a0 []*entity.CustomFont) config.Builder { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for WithCustomFonts") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func([]*entity.CustomFont) config.Builder); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCustomFonts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCustomFonts' -type Builder_WithCustomFonts_Call struct { - *mock.Call -} - -// WithCustomFonts is a helper method to define mock.On call -// - _a0 []*entity.CustomFont -func (_e *Builder_Expecter) WithCustomFonts(_a0 interface{}) *Builder_WithCustomFonts_Call { - return &Builder_WithCustomFonts_Call{Call: _e.mock.On("WithCustomFonts", _a0)} -} - -func (_c *Builder_WithCustomFonts_Call) Run(run func(_a0 []*entity.CustomFont)) *Builder_WithCustomFonts_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].([]*entity.CustomFont)) - }) - return _c -} - -func (_c *Builder_WithCustomFonts_Call) Return(_a0 config.Builder) *Builder_WithCustomFonts_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCustomFonts_Call) RunAndReturn(run func([]*entity.CustomFont) config.Builder) *Builder_WithCustomFonts_Call { - _c.Call.Return(run) - return _c -} - -// WithDebug provides a mock function with given fields: on -func (_m *Builder) WithDebug(on bool) config.Builder { - ret := _m.Called(on) - - if len(ret) == 0 { - panic("no return value specified for WithDebug") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { - r0 = rf(on) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDebug_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDebug' -type Builder_WithDebug_Call struct { - *mock.Call -} - -// WithDebug is a helper method to define mock.On call -// - on bool -func (_e *Builder_Expecter) WithDebug(on interface{}) *Builder_WithDebug_Call { - return &Builder_WithDebug_Call{Call: _e.mock.On("WithDebug", on)} -} - -func (_c *Builder_WithDebug_Call) Run(run func(on bool)) *Builder_WithDebug_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(bool)) - }) - return _c -} - -func (_c *Builder_WithDebug_Call) Return(_a0 config.Builder) *Builder_WithDebug_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDebug_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDebug_Call { - _c.Call.Return(run) - return _c -} - -// WithDefaultFont provides a mock function with given fields: font -func (_m *Builder) WithDefaultFont(font *props.Font) config.Builder { - ret := _m.Called(font) - - if len(ret) == 0 { - panic("no return value specified for WithDefaultFont") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(*props.Font) config.Builder); ok { - r0 = rf(font) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDefaultFont_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDefaultFont' -type Builder_WithDefaultFont_Call struct { - *mock.Call -} - -// WithDefaultFont is a helper method to define mock.On call -// - font *props.Font -func (_e *Builder_Expecter) WithDefaultFont(font interface{}) *Builder_WithDefaultFont_Call { - return &Builder_WithDefaultFont_Call{Call: _e.mock.On("WithDefaultFont", font)} -} - -func (_c *Builder_WithDefaultFont_Call) Run(run func(font *props.Font)) *Builder_WithDefaultFont_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*props.Font)) - }) - return _c -} - -func (_c *Builder_WithDefaultFont_Call) Return(_a0 config.Builder) *Builder_WithDefaultFont_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDefaultFont_Call) RunAndReturn(run func(*props.Font) config.Builder) *Builder_WithDefaultFont_Call { - _c.Call.Return(run) - return _c -} - -// WithDimensions provides a mock function with given fields: width, height -func (_m *Builder) WithDimensions(width float64, height float64) config.Builder { - ret := _m.Called(width, height) - - if len(ret) == 0 { - panic("no return value specified for WithDimensions") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64, float64) config.Builder); ok { - r0 = rf(width, height) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDimensions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDimensions' -type Builder_WithDimensions_Call struct { - *mock.Call -} - -// WithDimensions is a helper method to define mock.On call -// - width float64 -// - height float64 -func (_e *Builder_Expecter) WithDimensions(width interface{}, height interface{}) *Builder_WithDimensions_Call { - return &Builder_WithDimensions_Call{Call: _e.mock.On("WithDimensions", width, height)} -} - -func (_c *Builder_WithDimensions_Call) Run(run func(width float64, height float64)) *Builder_WithDimensions_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64), args[1].(float64)) - }) - return _c -} - -func (_c *Builder_WithDimensions_Call) Return(_a0 config.Builder) *Builder_WithDimensions_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDimensions_Call) RunAndReturn(run func(float64, float64) config.Builder) *Builder_WithDimensions_Call { - _c.Call.Return(run) - return _c -} - -// WithDisableAutoPageBreak provides a mock function with given fields: disabled -func (_m *Builder) WithDisableAutoPageBreak(disabled bool) config.Builder { - ret := _m.Called(disabled) - - if len(ret) == 0 { - panic("no return value specified for WithDisableAutoPageBreak") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { - r0 = rf(disabled) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDisableAutoPageBreak_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDisableAutoPageBreak' -type Builder_WithDisableAutoPageBreak_Call struct { - *mock.Call -} - -// WithDisableAutoPageBreak is a helper method to define mock.On call -// - disabled bool -func (_e *Builder_Expecter) WithDisableAutoPageBreak(disabled interface{}) *Builder_WithDisableAutoPageBreak_Call { - return &Builder_WithDisableAutoPageBreak_Call{Call: _e.mock.On("WithDisableAutoPageBreak", disabled)} -} - -func (_c *Builder_WithDisableAutoPageBreak_Call) Run(run func(disabled bool)) *Builder_WithDisableAutoPageBreak_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(bool)) - }) - return _c -} - -func (_c *Builder_WithDisableAutoPageBreak_Call) Return(_a0 config.Builder) *Builder_WithDisableAutoPageBreak_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDisableAutoPageBreak_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDisableAutoPageBreak_Call { - _c.Call.Return(run) - return _c -} - -// WithKeywords provides a mock function with given fields: keywordsStr, isUTF8 -func (_m *Builder) WithKeywords(keywordsStr string, isUTF8 bool) config.Builder { - ret := _m.Called(keywordsStr, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithKeywords") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(keywordsStr, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithKeywords_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithKeywords' -type Builder_WithKeywords_Call struct { - *mock.Call -} - -// WithKeywords is a helper method to define mock.On call -// - keywordsStr string -// - isUTF8 bool -func (_e *Builder_Expecter) WithKeywords(keywordsStr interface{}, isUTF8 interface{}) *Builder_WithKeywords_Call { - return &Builder_WithKeywords_Call{Call: _e.mock.On("WithKeywords", keywordsStr, isUTF8)} -} - -func (_c *Builder_WithKeywords_Call) Run(run func(keywordsStr string, isUTF8 bool)) *Builder_WithKeywords_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithKeywords_Call) Return(_a0 config.Builder) *Builder_WithKeywords_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithKeywords_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithKeywords_Call { - _c.Call.Return(run) - return _c -} - -// WithLeftMargin provides a mock function with given fields: left -func (_m *Builder) WithLeftMargin(left float64) config.Builder { - ret := _m.Called(left) - - if len(ret) == 0 { - panic("no return value specified for WithLeftMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(left) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithLeftMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithLeftMargin' -type Builder_WithLeftMargin_Call struct { - *mock.Call -} - -// WithLeftMargin is a helper method to define mock.On call -// - left float64 -func (_e *Builder_Expecter) WithLeftMargin(left interface{}) *Builder_WithLeftMargin_Call { - return &Builder_WithLeftMargin_Call{Call: _e.mock.On("WithLeftMargin", left)} -} - -func (_c *Builder_WithLeftMargin_Call) Run(run func(left float64)) *Builder_WithLeftMargin_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) - }) - return _c -} - -func (_c *Builder_WithLeftMargin_Call) Return(_a0 config.Builder) *Builder_WithLeftMargin_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithLeftMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithLeftMargin_Call { - _c.Call.Return(run) - return _c -} - -// WithMaxGridSize provides a mock function with given fields: maxGridSize -func (_m *Builder) WithMaxGridSize(maxGridSize int) config.Builder { - ret := _m.Called(maxGridSize) - - if len(ret) == 0 { - panic("no return value specified for WithMaxGridSize") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(int) config.Builder); ok { - r0 = rf(maxGridSize) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithMaxGridSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithMaxGridSize' -type Builder_WithMaxGridSize_Call struct { - *mock.Call -} - -// WithMaxGridSize is a helper method to define mock.On call -// - maxGridSize int -func (_e *Builder_Expecter) WithMaxGridSize(maxGridSize interface{}) *Builder_WithMaxGridSize_Call { - return &Builder_WithMaxGridSize_Call{Call: _e.mock.On("WithMaxGridSize", maxGridSize)} -} - -func (_c *Builder_WithMaxGridSize_Call) Run(run func(maxGridSize int)) *Builder_WithMaxGridSize_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(int)) - }) - return _c -} - -func (_c *Builder_WithMaxGridSize_Call) Return(_a0 config.Builder) *Builder_WithMaxGridSize_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithMaxGridSize_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithMaxGridSize_Call { - _c.Call.Return(run) - return _c -} - -// WithOrientation provides a mock function with given fields: _a0 -func (_m *Builder) WithOrientation(_a0 orientation.Type) config.Builder { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for WithOrientation") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(orientation.Type) config.Builder); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithOrientation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithOrientation' -type Builder_WithOrientation_Call struct { - *mock.Call -} - -// WithOrientation is a helper method to define mock.On call -// - _a0 orientation.Type -func (_e *Builder_Expecter) WithOrientation(_a0 interface{}) *Builder_WithOrientation_Call { - return &Builder_WithOrientation_Call{Call: _e.mock.On("WithOrientation", _a0)} -} - -func (_c *Builder_WithOrientation_Call) Run(run func(_a0 orientation.Type)) *Builder_WithOrientation_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(orientation.Type)) - }) - return _c -} - -func (_c *Builder_WithOrientation_Call) Return(_a0 config.Builder) *Builder_WithOrientation_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithOrientation_Call) RunAndReturn(run func(orientation.Type) config.Builder) *Builder_WithOrientation_Call { - _c.Call.Return(run) - return _c -} - -// WithPageNumber provides a mock function with given fields: pageNumber -func (_m *Builder) WithPageNumber(pageNumber ...props.PageNumber) config.Builder { - _va := make([]interface{}, len(pageNumber)) - for _i := range pageNumber { - _va[_i] = pageNumber[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - if len(ret) == 0 { - panic("no return value specified for WithPageNumber") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(...props.PageNumber) config.Builder); ok { - r0 = rf(pageNumber...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithPageNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageNumber' -type Builder_WithPageNumber_Call struct { - *mock.Call -} - -// WithPageNumber is a helper method to define mock.On call -// - pageNumber ...props.PageNumber -func (_e *Builder_Expecter) WithPageNumber(pageNumber ...interface{}) *Builder_WithPageNumber_Call { - return &Builder_WithPageNumber_Call{Call: _e.mock.On("WithPageNumber", - append([]interface{}{}, pageNumber...)...)} -} - -func (_c *Builder_WithPageNumber_Call) Run(run func(pageNumber ...props.PageNumber)) *Builder_WithPageNumber_Call { - _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]props.PageNumber, len(args)-0) - for i, a := range args[0:] { - if a != nil { - variadicArgs[i] = a.(props.PageNumber) - } - } - run(variadicArgs...) - }) - return _c -} - -func (_c *Builder_WithPageNumber_Call) Return(_a0 config.Builder) *Builder_WithPageNumber_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithPageNumber_Call) RunAndReturn(run func(...props.PageNumber) config.Builder) *Builder_WithPageNumber_Call { - _c.Call.Return(run) - return _c -} - -// WithPageSize provides a mock function with given fields: size -func (_m *Builder) WithPageSize(size pagesize.Type) config.Builder { - ret := _m.Called(size) - - if len(ret) == 0 { - panic("no return value specified for WithPageSize") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(pagesize.Type) config.Builder); ok { - r0 = rf(size) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithPageSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageSize' -type Builder_WithPageSize_Call struct { - *mock.Call -} - -// WithPageSize is a helper method to define mock.On call -// - size pagesize.Type -func (_e *Builder_Expecter) WithPageSize(size interface{}) *Builder_WithPageSize_Call { - return &Builder_WithPageSize_Call{Call: _e.mock.On("WithPageSize", size)} -} - -func (_c *Builder_WithPageSize_Call) Run(run func(size pagesize.Type)) *Builder_WithPageSize_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(pagesize.Type)) - }) - return _c -} - -func (_c *Builder_WithPageSize_Call) Return(_a0 config.Builder) *Builder_WithPageSize_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithPageSize_Call) RunAndReturn(run func(pagesize.Type) config.Builder) *Builder_WithPageSize_Call { - _c.Call.Return(run) - return _c -} - -// WithProtection provides a mock function with given fields: protectionType, userPassword, ownerPassword -func (_m *Builder) WithProtection(protectionType protection.Type, userPassword string, ownerPassword string) config.Builder { - ret := _m.Called(protectionType, userPassword, ownerPassword) - - if len(ret) == 0 { - panic("no return value specified for WithProtection") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(protection.Type, string, string) config.Builder); ok { - r0 = rf(protectionType, userPassword, ownerPassword) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithProtection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithProtection' -type Builder_WithProtection_Call struct { - *mock.Call -} - -// WithProtection is a helper method to define mock.On call -// - protectionType protection.Type -// - userPassword string -// - ownerPassword string -func (_e *Builder_Expecter) WithProtection(protectionType interface{}, userPassword interface{}, ownerPassword interface{}) *Builder_WithProtection_Call { - return &Builder_WithProtection_Call{Call: _e.mock.On("WithProtection", protectionType, userPassword, ownerPassword)} -} - -func (_c *Builder_WithProtection_Call) Run(run func(protectionType protection.Type, userPassword string, ownerPassword string)) *Builder_WithProtection_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(protection.Type), args[1].(string), args[2].(string)) - }) - return _c -} - -func (_c *Builder_WithProtection_Call) Return(_a0 config.Builder) *Builder_WithProtection_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithProtection_Call) RunAndReturn(run func(protection.Type, string, string) config.Builder) *Builder_WithProtection_Call { - _c.Call.Return(run) - return _c -} - -// WithRightMargin provides a mock function with given fields: right -func (_m *Builder) WithRightMargin(right float64) config.Builder { - ret := _m.Called(right) - - if len(ret) == 0 { - panic("no return value specified for WithRightMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(right) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithRightMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithRightMargin' -type Builder_WithRightMargin_Call struct { - *mock.Call -} - -// WithRightMargin is a helper method to define mock.On call -// - right float64 -func (_e *Builder_Expecter) WithRightMargin(right interface{}) *Builder_WithRightMargin_Call { - return &Builder_WithRightMargin_Call{Call: _e.mock.On("WithRightMargin", right)} -} - -func (_c *Builder_WithRightMargin_Call) Run(run func(right float64)) *Builder_WithRightMargin_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) - }) - return _c -} - -func (_c *Builder_WithRightMargin_Call) Return(_a0 config.Builder) *Builder_WithRightMargin_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithRightMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithRightMargin_Call { - _c.Call.Return(run) - return _c -} - -// WithSequentialLowMemoryMode provides a mock function with given fields: chunkWorkers -func (_m *Builder) WithSequentialLowMemoryMode(chunkWorkers int) config.Builder { - ret := _m.Called(chunkWorkers) - - if len(ret) == 0 { - panic("no return value specified for WithSequentialLowMemoryMode") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(int) config.Builder); ok { - r0 = rf(chunkWorkers) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithSequentialLowMemoryMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialLowMemoryMode' -type Builder_WithSequentialLowMemoryMode_Call struct { - *mock.Call -} - -// WithSequentialLowMemoryMode is a helper method to define mock.On call -// - chunkWorkers int -func (_e *Builder_Expecter) WithSequentialLowMemoryMode(chunkWorkers interface{}) *Builder_WithSequentialLowMemoryMode_Call { - return &Builder_WithSequentialLowMemoryMode_Call{Call: _e.mock.On("WithSequentialLowMemoryMode", chunkWorkers)} -} - -func (_c *Builder_WithSequentialLowMemoryMode_Call) Run(run func(chunkWorkers int)) *Builder_WithSequentialLowMemoryMode_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(int)) - }) - return _c -} - -func (_c *Builder_WithSequentialLowMemoryMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialLowMemoryMode_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithSequentialLowMemoryMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithSequentialLowMemoryMode_Call { - _c.Call.Return(run) - return _c -} - -// WithSequentialMode provides a mock function with given fields: -func (_m *Builder) WithSequentialMode() config.Builder { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for WithSequentialMode") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func() config.Builder); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithSequentialMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialMode' -type Builder_WithSequentialMode_Call struct { - *mock.Call -} - -// WithSequentialMode is a helper method to define mock.On call -func (_e *Builder_Expecter) WithSequentialMode() *Builder_WithSequentialMode_Call { - return &Builder_WithSequentialMode_Call{Call: _e.mock.On("WithSequentialMode")} -} - -func (_c *Builder_WithSequentialMode_Call) Run(run func()) *Builder_WithSequentialMode_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *Builder_WithSequentialMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialMode_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithSequentialMode_Call) RunAndReturn(run func() config.Builder) *Builder_WithSequentialMode_Call { - _c.Call.Return(run) - return _c -} - -// WithSubject provides a mock function with given fields: subject, isUTF8 -func (_m *Builder) WithSubject(subject string, isUTF8 bool) config.Builder { - ret := _m.Called(subject, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithSubject") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(subject, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithSubject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSubject' -type Builder_WithSubject_Call struct { - *mock.Call -} - -// WithSubject is a helper method to define mock.On call -// - subject string -// - isUTF8 bool -func (_e *Builder_Expecter) WithSubject(subject interface{}, isUTF8 interface{}) *Builder_WithSubject_Call { - return &Builder_WithSubject_Call{Call: _e.mock.On("WithSubject", subject, isUTF8)} -} - -func (_c *Builder_WithSubject_Call) Run(run func(subject string, isUTF8 bool)) *Builder_WithSubject_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithSubject_Call) Return(_a0 config.Builder) *Builder_WithSubject_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithSubject_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithSubject_Call { - _c.Call.Return(run) - return _c -} - -// WithTitle provides a mock function with given fields: title, isUTF8 -func (_m *Builder) WithTitle(title string, isUTF8 bool) config.Builder { - ret := _m.Called(title, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithTitle") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(title, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithTitle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTitle' -type Builder_WithTitle_Call struct { - *mock.Call -} - -// WithTitle is a helper method to define mock.On call -// - title string -// - isUTF8 bool -func (_e *Builder_Expecter) WithTitle(title interface{}, isUTF8 interface{}) *Builder_WithTitle_Call { - return &Builder_WithTitle_Call{Call: _e.mock.On("WithTitle", title, isUTF8)} -} - -func (_c *Builder_WithTitle_Call) Run(run func(title string, isUTF8 bool)) *Builder_WithTitle_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithTitle_Call) Return(_a0 config.Builder) *Builder_WithTitle_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithTitle_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithTitle_Call { - _c.Call.Return(run) - return _c -} - -// WithTopMargin provides a mock function with given fields: top -func (_m *Builder) WithTopMargin(top float64) config.Builder { - ret := _m.Called(top) - - if len(ret) == 0 { - panic("no return value specified for WithTopMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(top) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithTopMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTopMargin' -type Builder_WithTopMargin_Call struct { - *mock.Call -} - -// WithTopMargin is a helper method to define mock.On call -// - top float64 -func (_e *Builder_Expecter) WithTopMargin(top interface{}) *Builder_WithTopMargin_Call { - return &Builder_WithTopMargin_Call{Call: _e.mock.On("WithTopMargin", top)} +// - cfg *entity.Config +// - _a1 cache.Cache +func (_e *Builder_Expecter) Build(cfg interface{}, _a1 interface{}) *Builder_Build_Call { + return &Builder_Build_Call{Call: _e.mock.On("Build", cfg, _a1)} } -func (_c *Builder_WithTopMargin_Call) Run(run func(top float64)) *Builder_WithTopMargin_Call { +func (_c *Builder_Build_Call) Run(run func(cfg *entity.Config, _a1 cache.Cache)) *Builder_Build_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) + run(args[0].(*entity.Config), args[1].(cache.Cache)) }) return _c } -func (_c *Builder_WithTopMargin_Call) Return(_a0 config.Builder) *Builder_WithTopMargin_Call { +func (_c *Builder_Build_Call) Return(_a0 *gofpdf.Dependencies) *Builder_Build_Call { _c.Call.Return(_a0) return _c } -func (_c *Builder_WithTopMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithTopMargin_Call { +func (_c *Builder_Build_Call) RunAndReturn(run func(*entity.Config, cache.Cache) *gofpdf.Dependencies) *Builder_Build_Call { _c.Call.Return(run) return _c } diff --git a/pkg/processor/mappers/listmapper/list_test.go b/pkg/processor/mappers/listmapper/list_test.go index c1aead7f..6fd37e3c 100644 --- a/pkg/processor/mappers/listmapper/list_test.go +++ b/pkg/processor/mappers/listmapper/list_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/mock" ) -//se interface invalida for passada erro é retornada +// se interface invalida for passada erro é retornada // se componente não puder ser gerado, erro é retornado // se uma lista de 2 componentes for passada, 1 erro é retornado diff --git a/pkg/processor/mappers/rowmapper/row_test.go b/pkg/processor/mappers/rowmapper/row_test.go index fedb3077..591d2c7f 100644 --- a/pkg/processor/mappers/rowmapper/row_test.go +++ b/pkg/processor/mappers/rowmapper/row_test.go @@ -1 +1,63 @@ package rowmapper_test + +import ( + "testing" + + "github.com/johnfercher/maroto/v2/mocks" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rowmapper" + "github.com/stretchr/testify/assert" +) + +func TestNewRow(t *testing.T) { + t.Run("when invalid interface is sent, should return an error", func(t *testing.T) { + factory := mocks.NewAbstractFactoryMaps(t) + var templateRow interface{} = 1 + + doc, err := rowmapper.NewRow(templateRow, "", factory) + + assert.Nil(t, doc) + assert.NotNil(t, err) + }) + t.Run("when row height is not sent, should set height to 0", func(t *testing.T) { + factory := mocks.NewAbstractFactoryMaps(t) + var templateRow map[string]interface{} + + doc, err := rowmapper.NewRow(templateRow, "", factory) + + assert.Nil(t, err) + assert.Equal(t, 0.0, doc.Height) + }) + t.Run("when invalid height is sent, should return an error", func(t *testing.T) { + factory := mocks.NewAbstractFactoryMaps(t) + templateRow := map[string]interface{}{ + "height": "invalid", + } + + doc, err := rowmapper.NewRow(templateRow, "", factory) + + assert.Nil(t, doc) + assert.NotNil(t, err) + }) + t.Run("when an invalid field is sent, should return an error", func(t *testing.T) { + factory := mocks.NewAbstractFactoryMaps(t) + templateRow := map[string]interface{}{ + "invalid_field": "invalid", + } + + doc, err := rowmapper.NewRow(templateRow, "", factory) + + assert.Nil(t, doc) + assert.NotNil(t, err) + }) + t.Run("when an invalid col is sent, should return an error", func(t *testing.T) { + factory := mocks.NewAbstractFactoryMaps(t) + templateRow := map[string]interface{}{ + "cols": "invalid", + } + + doc, err := rowmapper.NewRow(templateRow, "", factory) + + assert.Nil(t, doc) + assert.NotNil(t, err) + }) +} From 9fc1e9593350faeb6503ffdc8569909fdc8b2970 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 13 Oct 2024 11:11:17 -0300 Subject: [PATCH 023/116] feat: Implement component row creation --- .../abstractfactory/abstractfactory.go | 8 +- pkg/processor/mappers/colmapper/col.go | 13 +++ pkg/processor/mappers/colmapper/col_test.go | 1 + pkg/processor/mappers/component_mapper.go | 1 + pkg/processor/mappers/rowmapper/row.go | 81 ++++++++++++++++++- 5 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 pkg/processor/mappers/colmapper/col.go create mode 100644 pkg/processor/mappers/colmapper/col_test.go diff --git a/pkg/processor/mappers/abstractfactory/abstractfactory.go b/pkg/processor/mappers/abstractfactory/abstractfactory.go index 5da7bd9e..d160ccf0 100644 --- a/pkg/processor/mappers/abstractfactory/abstractfactory.go +++ b/pkg/processor/mappers/abstractfactory/abstractfactory.go @@ -2,6 +2,7 @@ package abstractfactory import ( "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/colmapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/listmapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pagemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rowmapper" @@ -16,7 +17,7 @@ func NewAbstractFactoryMaps() *abstractFactoryMaps { // NewRow is responsible for wrapper the creation of a row func (f *abstractFactoryMaps) NewRow(document interface{}, sourceKey string) (mappers.Componentmapper, error) { - return rowmapper.NewRow(document, sourceKey) + return rowmapper.NewRow(document, sourceKey, f) } // NewPage is responsible for wrapper the creation of a page @@ -24,6 +25,11 @@ func (f *abstractFactoryMaps) NewPage(document interface{}, sourceKey string) (m return pagemapper.NewPage(document, sourceKey, f) } +// NewCol is responsible for wrapper the creation of a col +func (f *abstractFactoryMaps) NewCol(document interface{}) (mappers.Componentmapper, error) { + return colmapper.NewCol(document) +} + // NewList is responsible for wrapper the creation of a list func (f *abstractFactoryMaps) NewList(document interface{}, sourceKey string, generate mappers.GenerateComponent) (mappers.Componentmapper, error) { return listmapper.NewList(document, sourceKey, generate) diff --git a/pkg/processor/mappers/colmapper/col.go b/pkg/processor/mappers/colmapper/col.go new file mode 100644 index 00000000..5de1f7ac --- /dev/null +++ b/pkg/processor/mappers/colmapper/col.go @@ -0,0 +1,13 @@ +package colmapper + +import "github.com/johnfercher/maroto/v2/pkg/processor/components" + +type Col struct{} + +func NewCol(interface{}) (*Col, error) { + return nil, nil +} + +func (c *Col) Generate(content map[string]interface{}) (components.PdfComponent, error) { + return nil, nil +} diff --git a/pkg/processor/mappers/colmapper/col_test.go b/pkg/processor/mappers/colmapper/col_test.go new file mode 100644 index 00000000..87251be4 --- /dev/null +++ b/pkg/processor/mappers/colmapper/col_test.go @@ -0,0 +1 @@ +package colmapper_test diff --git a/pkg/processor/mappers/component_mapper.go b/pkg/processor/mappers/component_mapper.go index 4e894860..cd935854 100644 --- a/pkg/processor/mappers/component_mapper.go +++ b/pkg/processor/mappers/component_mapper.go @@ -11,5 +11,6 @@ type Componentmapper interface { type AbstractFactoryMaps interface { NewRow(document interface{}, sourceKey string) (Componentmapper, error) NewPage(document interface{}, sourceKey string) (Componentmapper, error) + NewCol(document interface{}) (Componentmapper, error) NewList(document interface{}, sourceKey string, generate GenerateComponent) (Componentmapper, error) } diff --git a/pkg/processor/mappers/rowmapper/row.go b/pkg/processor/mappers/rowmapper/row.go index 19d1365e..b7002623 100644 --- a/pkg/processor/mappers/rowmapper/row.go +++ b/pkg/processor/mappers/rowmapper/row.go @@ -1,14 +1,87 @@ // rowmapper is the package responsible for mapping row settings package rowmapper -import "github.com/johnfercher/maroto/v2/pkg/processor/components" +import ( + "fmt" + + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" +) type Row struct { - Test string + Height float64 + Cols []mappers.Componentmapper + factory mappers.AbstractFactoryMaps +} + +func NewRow(templateRows interface{}, sourceKey string, factory mappers.AbstractFactoryMaps) (*Row, error) { + mapRows, ok := templateRows.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("ensure that rows can be converted to map[string] interface{}") + } + row := &Row{ + Height: 0, + Cols: make([]mappers.Componentmapper, 0), + factory: factory, + } + + err := row.addComponents(mapRows) + if err != nil { + return nil, err + } + return row, nil +} + +func (r *Row) addComponents(mapRows map[string]interface{}) error { + fieldMappers := r.getFieldMappers() + + for templateName, template := range mapRows { + mapper, ok := fieldMappers[templateName] + if !ok { + return fmt.Errorf("the field %s present in the row cannot be mapped to any valid component", templateName) + } + err := mapper(template) + if err != nil { + return err + } + } + return nil +} + +func (r *Row) setHeight(template interface{}) error { + height, ok := template.(float64) + if !ok { + return fmt.Errorf("ensure that height can be converted to float64") + } + r.Height = height + return nil +} + +func (r *Row) setCols(template interface{}) error { + cols, ok := template.([]interface{}) + if !ok { + return fmt.Errorf("ensure that cols can be converted to []interface{}") + } + r.Cols = make([]mappers.Componentmapper, len(cols)) + + for i, col := range cols { + newCol, err := r.factory.NewCol(col) + if err != nil { + return err + } + r.Cols[i] = newCol + } + + return nil } -func NewRow(document interface{}, sourceKey string) (*Row, error) { - return &Row{Test: "a"}, nil +// getFieldMappers is responsible for defining which methods are responsible for assembling which components. +// To do this, the component name is linked to a function in a Map. +func (r *Row) getFieldMappers() map[string]func(interface{}) error { + return map[string]func(interface{}) error{ + "height": r.setHeight, + "cols": r.setCols, + } } func (r *Row) Generate(content map[string]interface{}) (components.PdfComponent, error) { From 4ffab234aba812850665155a0548881e48fb9728 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 13 Oct 2024 14:40:05 -0300 Subject: [PATCH 024/116] feat: create component mappers --- internal/fixture/processorfixture.go | 6 +-- .../abstractfactory/abstractfactory.go | 50 +++++++++++++++++-- pkg/processor/mappers/colmapper/col.go | 13 ----- pkg/processor/mappers/component_mapper.go | 7 +++ .../mappers/components/codemapper/barcode.go | 14 ++++++ .../components/codemapper/barcode_test.go | 2 + .../components/codemapper/matrixcode.go | 14 ++++++ .../components/codemapper/matrixcode_test.go | 1 + .../mappers/components/codemapper/qrcode.go | 14 ++++++ .../components/codemapper/qrcode_test.go | 1 + .../mappers/components/colmapper/col.go | 19 +++++++ .../{ => components}/colmapper/col_test.go | 0 .../mappers/components/imagemapper/image.go | 14 ++++++ .../components/imagemapper/image_test.go | 1 + .../mappers/components/linemapper/line.go | 14 ++++++ .../components/linemapper/line_test.go | 2 + .../{ => components}/listmapper/list.go | 0 .../{ => components}/listmapper/list_test.go | 2 +- .../{ => components}/pagemapper/page.go | 0 .../{ => components}/pagemapper/page_test.go | 6 +-- .../mappers/{ => components}/rowmapper/row.go | 0 .../{ => components}/rowmapper/row_test.go | 2 +- .../components/signaturemapper/signature.go | 14 ++++++ .../signaturemapper/signature_test.go | 1 + .../mappers/components/textmapper/text.go | 13 +++++ .../components/textmapper/text_test.go | 1 + .../mappers/documentmapper/document_test.go | 4 +- 27 files changed, 187 insertions(+), 28 deletions(-) delete mode 100644 pkg/processor/mappers/colmapper/col.go create mode 100644 pkg/processor/mappers/components/codemapper/barcode.go create mode 100644 pkg/processor/mappers/components/codemapper/barcode_test.go create mode 100644 pkg/processor/mappers/components/codemapper/matrixcode.go create mode 100644 pkg/processor/mappers/components/codemapper/matrixcode_test.go create mode 100644 pkg/processor/mappers/components/codemapper/qrcode.go create mode 100644 pkg/processor/mappers/components/codemapper/qrcode_test.go create mode 100644 pkg/processor/mappers/components/colmapper/col.go rename pkg/processor/mappers/{ => components}/colmapper/col_test.go (100%) create mode 100644 pkg/processor/mappers/components/imagemapper/image.go create mode 100644 pkg/processor/mappers/components/imagemapper/image_test.go create mode 100644 pkg/processor/mappers/components/linemapper/line.go create mode 100644 pkg/processor/mappers/components/linemapper/line_test.go rename pkg/processor/mappers/{ => components}/listmapper/list.go (100%) rename pkg/processor/mappers/{ => components}/listmapper/list_test.go (95%) rename pkg/processor/mappers/{ => components}/pagemapper/page.go (100%) rename pkg/processor/mappers/{ => components}/pagemapper/page_test.go (87%) rename pkg/processor/mappers/{ => components}/rowmapper/row.go (100%) rename pkg/processor/mappers/{ => components}/rowmapper/row_test.go (95%) create mode 100644 pkg/processor/mappers/components/signaturemapper/signature.go create mode 100644 pkg/processor/mappers/components/signaturemapper/signature_test.go create mode 100644 pkg/processor/mappers/components/textmapper/text.go create mode 100644 pkg/processor/mappers/components/textmapper/text_test.go diff --git a/internal/fixture/processorfixture.go b/internal/fixture/processorfixture.go index 40a38219..6b1e9835 100644 --- a/internal/fixture/processorfixture.go +++ b/internal/fixture/processorfixture.go @@ -2,9 +2,9 @@ package fixture import ( "github.com/johnfercher/maroto/v2/pkg/processor/mappers" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/listmapper" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pagemapper" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rowmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/listmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/pagemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/rowmapper" ) func MapperRow() *rowmapper.Row { diff --git a/pkg/processor/mappers/abstractfactory/abstractfactory.go b/pkg/processor/mappers/abstractfactory/abstractfactory.go index d160ccf0..bc765ab2 100644 --- a/pkg/processor/mappers/abstractfactory/abstractfactory.go +++ b/pkg/processor/mappers/abstractfactory/abstractfactory.go @@ -2,10 +2,15 @@ package abstractfactory import ( "github.com/johnfercher/maroto/v2/pkg/processor/mappers" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/colmapper" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/listmapper" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pagemapper" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rowmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/codemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/colmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/imagemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/linemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/listmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/pagemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/rowmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/signaturemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/textmapper" ) // abstractFactoryMaps is responsible for providing a factory for all mapper components @@ -27,10 +32,45 @@ func (f *abstractFactoryMaps) NewPage(document interface{}, sourceKey string) (m // NewCol is responsible for wrapper the creation of a col func (f *abstractFactoryMaps) NewCol(document interface{}) (mappers.Componentmapper, error) { - return colmapper.NewCol(document) + return colmapper.NewCol(document, f) } // NewList is responsible for wrapper the creation of a list func (f *abstractFactoryMaps) NewList(document interface{}, sourceKey string, generate mappers.GenerateComponent) (mappers.Componentmapper, error) { return listmapper.NewList(document, sourceKey, generate) } + +// NewBarcode is responsible for wrapper the creation of a barcode +func (f *abstractFactoryMaps) NewBarcode(document interface{}) (mappers.Componentmapper, error) { + return codemapper.NewBarcode(document) +} + +// NewMatrixcode is responsible for wrapper the creation of a matrix code +func (f *abstractFactoryMaps) NewMatrixcode(document interface{}) (mappers.Componentmapper, error) { + return codemapper.NewMatrixcode(document) +} + +// NewQrcode is responsible for wrapper the creation of a qrcode +func (f *abstractFactoryMaps) NewQrcode(document interface{}) (mappers.Componentmapper, error) { + return codemapper.NewQrcode(document) +} + +// NewImage is responsible for wrapper the creation of a image +func (f *abstractFactoryMaps) NewImage(document interface{}) (mappers.Componentmapper, error) { + return imagemapper.NewImage(document) +} + +// NewLine is responsible for wrapper the creation of a libe +func (f *abstractFactoryMaps) NewLine(document interface{}) (mappers.Componentmapper, error) { + return linemapper.NewLine(document) +} + +// NewSignature is responsible for wrapper the creation of a signature +func (f *abstractFactoryMaps) NewSignature(document interface{}) (mappers.Componentmapper, error) { + return signaturemapper.NewSignature(document) +} + +// NewText is responsible for wrapper the creation of a text +func (f *abstractFactoryMaps) NewText(document interface{}) (mappers.Componentmapper, error) { + return textmapper.NewText(document) +} diff --git a/pkg/processor/mappers/colmapper/col.go b/pkg/processor/mappers/colmapper/col.go deleted file mode 100644 index 5de1f7ac..00000000 --- a/pkg/processor/mappers/colmapper/col.go +++ /dev/null @@ -1,13 +0,0 @@ -package colmapper - -import "github.com/johnfercher/maroto/v2/pkg/processor/components" - -type Col struct{} - -func NewCol(interface{}) (*Col, error) { - return nil, nil -} - -func (c *Col) Generate(content map[string]interface{}) (components.PdfComponent, error) { - return nil, nil -} diff --git a/pkg/processor/mappers/component_mapper.go b/pkg/processor/mappers/component_mapper.go index cd935854..2a0e41c9 100644 --- a/pkg/processor/mappers/component_mapper.go +++ b/pkg/processor/mappers/component_mapper.go @@ -13,4 +13,11 @@ type AbstractFactoryMaps interface { NewPage(document interface{}, sourceKey string) (Componentmapper, error) NewCol(document interface{}) (Componentmapper, error) NewList(document interface{}, sourceKey string, generate GenerateComponent) (Componentmapper, error) + NewBarcode(document interface{}) (Componentmapper, error) + NewMatrixcode(document interface{}) (Componentmapper, error) + NewQrcode(document interface{}) (Componentmapper, error) + NewImage(document interface{}) (Componentmapper, error) + NewLine(document interface{}) (Componentmapper, error) + NewSignature(document interface{}) (Componentmapper, error) + NewText(document interface{}) (Componentmapper, error) } diff --git a/pkg/processor/mappers/components/codemapper/barcode.go b/pkg/processor/mappers/components/codemapper/barcode.go new file mode 100644 index 00000000..121329f5 --- /dev/null +++ b/pkg/processor/mappers/components/codemapper/barcode.go @@ -0,0 +1,14 @@ +// codemapper code implements creation of Barcode, MatrixCode and QrCode. +package codemapper + +import "github.com/johnfercher/maroto/v2/pkg/processor/components" + +type Barcode struct{} + +func NewBarcode(code interface{}) (*Barcode, error) { + return nil, nil +} + +func (b *Barcode) Generate(content map[string]interface{}) (components.PdfComponent, error) { + return nil, nil +} diff --git a/pkg/processor/mappers/components/codemapper/barcode_test.go b/pkg/processor/mappers/components/codemapper/barcode_test.go new file mode 100644 index 00000000..de28111d --- /dev/null +++ b/pkg/processor/mappers/components/codemapper/barcode_test.go @@ -0,0 +1,2 @@ +// nolint: dupl +package codemapper_test diff --git a/pkg/processor/mappers/components/codemapper/matrixcode.go b/pkg/processor/mappers/components/codemapper/matrixcode.go new file mode 100644 index 00000000..87a5f52d --- /dev/null +++ b/pkg/processor/mappers/components/codemapper/matrixcode.go @@ -0,0 +1,14 @@ +// Package codemapper implements creation of Barcode, MatrixCode and QrCode. +package codemapper + +import "github.com/johnfercher/maroto/v2/pkg/processor/components" + +type Matrixcode struct{} + +func NewMatrixcode(code interface{}) (*Matrixcode, error) { + return nil, nil +} + +func (b *Matrixcode) Generate(content map[string]interface{}) (components.PdfComponent, error) { + return nil, nil +} diff --git a/pkg/processor/mappers/components/codemapper/matrixcode_test.go b/pkg/processor/mappers/components/codemapper/matrixcode_test.go new file mode 100644 index 00000000..cf962105 --- /dev/null +++ b/pkg/processor/mappers/components/codemapper/matrixcode_test.go @@ -0,0 +1 @@ +package codemapper_test diff --git a/pkg/processor/mappers/components/codemapper/qrcode.go b/pkg/processor/mappers/components/codemapper/qrcode.go new file mode 100644 index 00000000..f8a7e0ee --- /dev/null +++ b/pkg/processor/mappers/components/codemapper/qrcode.go @@ -0,0 +1,14 @@ +// Package codemapper implements creation of Barcode, MatrixCode and QrCode. +package codemapper + +import "github.com/johnfercher/maroto/v2/pkg/processor/components" + +type Qrcode struct{} + +func NewQrcode(code interface{}) (*Qrcode, error) { + return nil, nil +} + +func (b *Qrcode) Generate(content map[string]interface{}) (components.PdfComponent, error) { + return nil, nil +} diff --git a/pkg/processor/mappers/components/codemapper/qrcode_test.go b/pkg/processor/mappers/components/codemapper/qrcode_test.go new file mode 100644 index 00000000..cf962105 --- /dev/null +++ b/pkg/processor/mappers/components/codemapper/qrcode_test.go @@ -0,0 +1 @@ +package codemapper_test diff --git a/pkg/processor/mappers/components/colmapper/col.go b/pkg/processor/mappers/components/colmapper/col.go new file mode 100644 index 00000000..19e63f7d --- /dev/null +++ b/pkg/processor/mappers/components/colmapper/col.go @@ -0,0 +1,19 @@ +package colmapper + +import ( + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" +) + +type Col struct { + Size int + Components mappers.Componentmapper +} + +func NewCol(interface{}) (*Col, error) { + return nil, nil +} + +func (c *Col) Generate(content map[string]interface{}) (components.PdfComponent, error) { + return nil, nil +} diff --git a/pkg/processor/mappers/colmapper/col_test.go b/pkg/processor/mappers/components/colmapper/col_test.go similarity index 100% rename from pkg/processor/mappers/colmapper/col_test.go rename to pkg/processor/mappers/components/colmapper/col_test.go diff --git a/pkg/processor/mappers/components/imagemapper/image.go b/pkg/processor/mappers/components/imagemapper/image.go new file mode 100644 index 00000000..86728d91 --- /dev/null +++ b/pkg/processor/mappers/components/imagemapper/image.go @@ -0,0 +1,14 @@ +// Package image implements creation of images from file and bytes. +package imagemapper + +import "github.com/johnfercher/maroto/v2/pkg/processor/components" + +type Image struct{} + +func NewImage(code interface{}) (*Image, error) { + return nil, nil +} + +func (b *Image) Generate(content map[string]interface{}) (components.PdfComponent, error) { + return nil, nil +} diff --git a/pkg/processor/mappers/components/imagemapper/image_test.go b/pkg/processor/mappers/components/imagemapper/image_test.go new file mode 100644 index 00000000..b53f0fc8 --- /dev/null +++ b/pkg/processor/mappers/components/imagemapper/image_test.go @@ -0,0 +1 @@ +package imagemapper_test diff --git a/pkg/processor/mappers/components/linemapper/line.go b/pkg/processor/mappers/components/linemapper/line.go new file mode 100644 index 00000000..2e39278e --- /dev/null +++ b/pkg/processor/mappers/components/linemapper/line.go @@ -0,0 +1,14 @@ +// Package line implements creation of lines. +package linemapper + +import "github.com/johnfercher/maroto/v2/pkg/processor/components" + +type Line struct{} + +func NewLine(code interface{}) (*Line, error) { + return nil, nil +} + +func (b *Line) Generate(content map[string]interface{}) (components.PdfComponent, error) { + return nil, nil +} diff --git a/pkg/processor/mappers/components/linemapper/line_test.go b/pkg/processor/mappers/components/linemapper/line_test.go new file mode 100644 index 00000000..d44fe8a1 --- /dev/null +++ b/pkg/processor/mappers/components/linemapper/line_test.go @@ -0,0 +1,2 @@ +// Package line implements creation of lines. +package linemapper_test diff --git a/pkg/processor/mappers/listmapper/list.go b/pkg/processor/mappers/components/listmapper/list.go similarity index 100% rename from pkg/processor/mappers/listmapper/list.go rename to pkg/processor/mappers/components/listmapper/list.go diff --git a/pkg/processor/mappers/listmapper/list_test.go b/pkg/processor/mappers/components/listmapper/list_test.go similarity index 95% rename from pkg/processor/mappers/listmapper/list_test.go rename to pkg/processor/mappers/components/listmapper/list_test.go index 6fd37e3c..5f9a48cf 100644 --- a/pkg/processor/mappers/listmapper/list_test.go +++ b/pkg/processor/mappers/components/listmapper/list_test.go @@ -6,7 +6,7 @@ import ( "github.com/johnfercher/maroto/v2/internal/fixture" "github.com/johnfercher/maroto/v2/mocks" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/listmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/listmapper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) diff --git a/pkg/processor/mappers/pagemapper/page.go b/pkg/processor/mappers/components/pagemapper/page.go similarity index 100% rename from pkg/processor/mappers/pagemapper/page.go rename to pkg/processor/mappers/components/pagemapper/page.go diff --git a/pkg/processor/mappers/pagemapper/page_test.go b/pkg/processor/mappers/components/pagemapper/page_test.go similarity index 87% rename from pkg/processor/mappers/pagemapper/page_test.go rename to pkg/processor/mappers/components/pagemapper/page_test.go index c6db7cde..5dbe0bcf 100644 --- a/pkg/processor/mappers/pagemapper/page_test.go +++ b/pkg/processor/mappers/components/pagemapper/page_test.go @@ -5,9 +5,9 @@ import ( "github.com/johnfercher/maroto/v2/internal/fixture" "github.com/johnfercher/maroto/v2/mocks" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/listmapper" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pagemapper" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rowmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/listmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/pagemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/rowmapper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) diff --git a/pkg/processor/mappers/rowmapper/row.go b/pkg/processor/mappers/components/rowmapper/row.go similarity index 100% rename from pkg/processor/mappers/rowmapper/row.go rename to pkg/processor/mappers/components/rowmapper/row.go diff --git a/pkg/processor/mappers/rowmapper/row_test.go b/pkg/processor/mappers/components/rowmapper/row_test.go similarity index 95% rename from pkg/processor/mappers/rowmapper/row_test.go rename to pkg/processor/mappers/components/rowmapper/row_test.go index 591d2c7f..b279a2de 100644 --- a/pkg/processor/mappers/rowmapper/row_test.go +++ b/pkg/processor/mappers/components/rowmapper/row_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/johnfercher/maroto/v2/mocks" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/rowmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/rowmapper" "github.com/stretchr/testify/assert" ) diff --git a/pkg/processor/mappers/components/signaturemapper/signature.go b/pkg/processor/mappers/components/signaturemapper/signature.go new file mode 100644 index 00000000..a8070d24 --- /dev/null +++ b/pkg/processor/mappers/components/signaturemapper/signature.go @@ -0,0 +1,14 @@ +// Package signature implements creation of signatures. +package signaturemapper + +import "github.com/johnfercher/maroto/v2/pkg/processor/components" + +type Signature struct{} + +func NewSignature(code interface{}) (*Signature, error) { + return nil, nil +} + +func (b *Signature) Generate(content map[string]interface{}) (components.PdfComponent, error) { + return nil, nil +} diff --git a/pkg/processor/mappers/components/signaturemapper/signature_test.go b/pkg/processor/mappers/components/signaturemapper/signature_test.go new file mode 100644 index 00000000..19b4aa4a --- /dev/null +++ b/pkg/processor/mappers/components/signaturemapper/signature_test.go @@ -0,0 +1 @@ +package signaturemapper_test diff --git a/pkg/processor/mappers/components/textmapper/text.go b/pkg/processor/mappers/components/textmapper/text.go new file mode 100644 index 00000000..b4df8a91 --- /dev/null +++ b/pkg/processor/mappers/components/textmapper/text.go @@ -0,0 +1,13 @@ +package textmapper + +import "github.com/johnfercher/maroto/v2/pkg/processor/components" + +type Text struct{} + +func NewText(code interface{}) (*Text, error) { + return nil, nil +} + +func (b *Text) Generate(content map[string]interface{}) (components.PdfComponent, error) { + return nil, nil +} diff --git a/pkg/processor/mappers/components/textmapper/text_test.go b/pkg/processor/mappers/components/textmapper/text_test.go new file mode 100644 index 00000000..fdf1c835 --- /dev/null +++ b/pkg/processor/mappers/components/textmapper/text_test.go @@ -0,0 +1 @@ +package textmapper_test diff --git a/pkg/processor/mappers/documentmapper/document_test.go b/pkg/processor/mappers/documentmapper/document_test.go index 018c6d08..ac214018 100644 --- a/pkg/processor/mappers/documentmapper/document_test.go +++ b/pkg/processor/mappers/documentmapper/document_test.go @@ -6,8 +6,8 @@ import ( "github.com/johnfercher/maroto/v2/internal/fixture" "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/processor/deserializer" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/listmapper" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/pagemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/listmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/pagemapper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) From 2645fb1d6d1e89cec28b2700b982eb9fed988f05 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 13 Oct 2024 16:47:16 -0300 Subject: [PATCH 025/116] test: valid col creation --- internal/fixture/processorfixture.go | 33 ++++ .../mappers/components/colmapper/col_test.go | 167 ++++++++++++++++++ 2 files changed, 200 insertions(+) diff --git a/internal/fixture/processorfixture.go b/internal/fixture/processorfixture.go index 6b1e9835..47206a2e 100644 --- a/internal/fixture/processorfixture.go +++ b/internal/fixture/processorfixture.go @@ -2,9 +2,14 @@ package fixture import ( "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/codemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/imagemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/linemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/listmapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/pagemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/rowmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/signaturemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/textmapper" ) func MapperRow() *rowmapper.Row { @@ -24,3 +29,31 @@ func MapperPage() *pagemapper.Page { func MapperList() *listmapper.List { return &listmapper.List{} } + +func Barcode() *codemapper.Barcode { + return &codemapper.Barcode{} +} + +func Matrixcode() *codemapper.Matrixcode { + return &codemapper.Matrixcode{} +} + +func Qrcode() *codemapper.Qrcode { + return &codemapper.Qrcode{} +} + +func Image() *imagemapper.Image { + return &imagemapper.Image{} +} + +func Line() *linemapper.Line { + return &linemapper.Line{} +} + +func Signature() *signaturemapper.Signature { + return &signaturemapper.Signature{} +} + +func Text() *textmapper.Text { + return &textmapper.Text{} +} diff --git a/pkg/processor/mappers/components/colmapper/col_test.go b/pkg/processor/mappers/components/colmapper/col_test.go index 87251be4..0473caca 100644 --- a/pkg/processor/mappers/components/colmapper/col_test.go +++ b/pkg/processor/mappers/components/colmapper/col_test.go @@ -1 +1,168 @@ package colmapper_test + +import ( + "errors" + "testing" + + "github.com/johnfercher/maroto/v2/internal/fixture" + "github.com/johnfercher/maroto/v2/mocks" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/codemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/colmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/imagemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/linemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/signaturemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/textmapper" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +func TestNewCol(t *testing.T) { + t.Run("when a barcode is sent, a barcode is created", func(t *testing.T) { + col := map[string]interface{}{"bar_code": nil} + validBarcode := fixture.Barcode() + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewBarcode", mock.Anything).Return(validBarcode, nil) + + doc, err := colmapper.NewCol(col, factory) + + assert.Nil(t, err) + assert.Len(t, doc.Components, 1) + assert.IsType(t, &codemapper.Barcode{}, doc.Components[0]) + }) + t.Run("when a matrixcode is sent, a matrixcode is created", func(t *testing.T) { + col := map[string]interface{}{"matrix_code": nil} + validMatrixcode := fixture.Matrixcode() + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewMatrixcode", mock.Anything).Return(validMatrixcode, nil) + + doc, err := colmapper.NewCol(col, factory) + + assert.Nil(t, err) + assert.Len(t, doc.Components, 1) + assert.IsType(t, &codemapper.Matrixcode{}, doc.Components[0]) + }) + t.Run("when a qrcode is sent, a qrcode is created", func(t *testing.T) { + col := map[string]interface{}{"qr_code": nil} + validQrcode := fixture.Qrcode() + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewQrcode", mock.Anything).Return(validQrcode, nil) + + doc, err := colmapper.NewCol(col, factory) + + assert.Nil(t, err) + assert.Len(t, doc.Components, 1) + assert.IsType(t, &codemapper.Qrcode{}, doc.Components[0]) + }) + t.Run("when a image is sent, a image is created", func(t *testing.T) { + col := map[string]interface{}{"image": nil} + validImage := fixture.Image() + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewImage", mock.Anything).Return(validImage, nil) + + doc, err := colmapper.NewCol(col, factory) + + assert.Nil(t, err) + assert.Len(t, doc.Components, 1) + assert.IsType(t, &imagemapper.Image{}, doc.Components[0]) + }) + t.Run("when a line is sent, a line is created", func(t *testing.T) { + col := map[string]interface{}{"line": nil} + validLine := fixture.Line() + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewLine", mock.Anything).Return(validLine, nil) + + doc, err := colmapper.NewCol(col, factory) + + assert.Nil(t, err) + assert.Len(t, doc.Components, 1) + assert.IsType(t, &linemapper.Line{}, doc.Components[0]) + }) + t.Run("when a signature is sent, a signature is created", func(t *testing.T) { + col := map[string]interface{}{"signature": nil} + validSignature := fixture.Signature() + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewSignature", mock.Anything).Return(validSignature, nil) + + doc, err := colmapper.NewCol(col, factory) + + assert.Nil(t, err) + assert.Len(t, doc.Components, 1) + assert.IsType(t, &signaturemapper.Signature{}, doc.Components[0]) + }) + t.Run("when a text is sent, a text is created", func(t *testing.T) { + col := map[string]interface{}{"text": nil} + validText := fixture.Text() + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewText", mock.Anything).Return(validText, nil) + + doc, err := colmapper.NewCol(col, factory) + + assert.Nil(t, err) + assert.Len(t, doc.Components, 1) + assert.IsType(t, &textmapper.Text{}, doc.Components[0]) + }) + t.Run("when no component is sent, no component is added", func(t *testing.T) { + col := map[string]interface{}{} + factory := mocks.NewAbstractFactoryMaps(t) + + doc, err := colmapper.NewCol(col, factory) + + assert.Nil(t, err) + assert.Len(t, doc.Components, 0) + }) + t.Run("when an invalid field is sent, an error is returned", func(t *testing.T) { + col := map[string]interface{}{"invalid_field": nil} + factory := mocks.NewAbstractFactoryMaps(t) + + doc, err := colmapper.NewCol(col, factory) + + assert.Nil(t, doc) + assert.NotNil(t, err) + }) + t.Run("when an invalid interface is sent, an error is returned", func(t *testing.T) { + var col interface{} = 1 + factory := mocks.NewAbstractFactoryMaps(t) + + doc, err := colmapper.NewCol(col, factory) + + assert.Nil(t, doc) + assert.NotNil(t, err) + }) + t.Run("when the component cannot be created, it should return an error", func(t *testing.T) { + col := map[string]interface{}{"text": nil} + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewText", mock.Anything).Return(nil, errors.New("any")) + + doc, err := colmapper.NewCol(col, factory) + + assert.Nil(t, doc) + assert.NotNil(t, err) + }) + t.Run("when an invalid size is sent, an error is returned", func(t *testing.T) { + col := map[string]interface{}{"size": "invalid"} + factory := mocks.NewAbstractFactoryMaps(t) + + doc, err := colmapper.NewCol(col, factory) + + assert.Nil(t, doc) + assert.NotNil(t, err) + }) + t.Run("when no size is sent, should set size to 0", func(t *testing.T) { + col := map[string]interface{}{} + factory := mocks.NewAbstractFactoryMaps(t) + + doc, err := colmapper.NewCol(col, factory) + + assert.Nil(t, err) + assert.Equal(t, doc.Size, 0) + }) + t.Run("when size is sent, should set size", func(t *testing.T) { + col := map[string]interface{}{"size": 6.0} + factory := mocks.NewAbstractFactoryMaps(t) + + doc, err := colmapper.NewCol(col, factory) + + assert.Nil(t, err) + assert.Equal(t, doc.Size, 6) + }) +} From 4d753474d83b62834adb97a7f4d8b341cfffd804 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 13 Oct 2024 16:48:12 -0300 Subject: [PATCH 026/116] feat: Implement component col creation --- mocks/AbstractFactoryMaps.go | 406 ++++++ mocks/Builder.go | 1263 ++++++++++++++++- mocks/Repository.go | 159 ++- .../mappers/components/colmapper/col.go | 67 +- 4 files changed, 1826 insertions(+), 69 deletions(-) diff --git a/mocks/AbstractFactoryMaps.go b/mocks/AbstractFactoryMaps.go index 9a73b434..97faa243 100644 --- a/mocks/AbstractFactoryMaps.go +++ b/mocks/AbstractFactoryMaps.go @@ -20,6 +20,64 @@ func (_m *AbstractFactoryMaps) EXPECT() *AbstractFactoryMaps_Expecter { return &AbstractFactoryMaps_Expecter{mock: &_m.Mock} } +// NewBarcode provides a mock function with given fields: document +func (_m *AbstractFactoryMaps) NewBarcode(document interface{}) (mappers.Componentmapper, error) { + ret := _m.Called(document) + + if len(ret) == 0 { + panic("no return value specified for NewBarcode") + } + + var r0 mappers.Componentmapper + var r1 error + if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + return rf(document) + } + if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + r0 = rf(document) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mappers.Componentmapper) + } + } + + if rf, ok := ret.Get(1).(func(interface{}) error); ok { + r1 = rf(document) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AbstractFactoryMaps_NewBarcode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewBarcode' +type AbstractFactoryMaps_NewBarcode_Call struct { + *mock.Call +} + +// NewBarcode is a helper method to define mock.On call +// - document interface{} +func (_e *AbstractFactoryMaps_Expecter) NewBarcode(document interface{}) *AbstractFactoryMaps_NewBarcode_Call { + return &AbstractFactoryMaps_NewBarcode_Call{Call: _e.mock.On("NewBarcode", document)} +} + +func (_c *AbstractFactoryMaps_NewBarcode_Call) Run(run func(document interface{})) *AbstractFactoryMaps_NewBarcode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{})) + }) + return _c +} + +func (_c *AbstractFactoryMaps_NewBarcode_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewBarcode_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AbstractFactoryMaps_NewBarcode_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewBarcode_Call { + _c.Call.Return(run) + return _c +} + // NewCol provides a mock function with given fields: document func (_m *AbstractFactoryMaps) NewCol(document interface{}) (mappers.Componentmapper, error) { ret := _m.Called(document) @@ -78,6 +136,122 @@ func (_c *AbstractFactoryMaps_NewCol_Call) RunAndReturn(run func(interface{}) (m return _c } +// NewImage provides a mock function with given fields: document +func (_m *AbstractFactoryMaps) NewImage(document interface{}) (mappers.Componentmapper, error) { + ret := _m.Called(document) + + if len(ret) == 0 { + panic("no return value specified for NewImage") + } + + var r0 mappers.Componentmapper + var r1 error + if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + return rf(document) + } + if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + r0 = rf(document) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mappers.Componentmapper) + } + } + + if rf, ok := ret.Get(1).(func(interface{}) error); ok { + r1 = rf(document) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AbstractFactoryMaps_NewImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewImage' +type AbstractFactoryMaps_NewImage_Call struct { + *mock.Call +} + +// NewImage is a helper method to define mock.On call +// - document interface{} +func (_e *AbstractFactoryMaps_Expecter) NewImage(document interface{}) *AbstractFactoryMaps_NewImage_Call { + return &AbstractFactoryMaps_NewImage_Call{Call: _e.mock.On("NewImage", document)} +} + +func (_c *AbstractFactoryMaps_NewImage_Call) Run(run func(document interface{})) *AbstractFactoryMaps_NewImage_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{})) + }) + return _c +} + +func (_c *AbstractFactoryMaps_NewImage_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewImage_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AbstractFactoryMaps_NewImage_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewImage_Call { + _c.Call.Return(run) + return _c +} + +// NewLine provides a mock function with given fields: document +func (_m *AbstractFactoryMaps) NewLine(document interface{}) (mappers.Componentmapper, error) { + ret := _m.Called(document) + + if len(ret) == 0 { + panic("no return value specified for NewLine") + } + + var r0 mappers.Componentmapper + var r1 error + if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + return rf(document) + } + if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + r0 = rf(document) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mappers.Componentmapper) + } + } + + if rf, ok := ret.Get(1).(func(interface{}) error); ok { + r1 = rf(document) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AbstractFactoryMaps_NewLine_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewLine' +type AbstractFactoryMaps_NewLine_Call struct { + *mock.Call +} + +// NewLine is a helper method to define mock.On call +// - document interface{} +func (_e *AbstractFactoryMaps_Expecter) NewLine(document interface{}) *AbstractFactoryMaps_NewLine_Call { + return &AbstractFactoryMaps_NewLine_Call{Call: _e.mock.On("NewLine", document)} +} + +func (_c *AbstractFactoryMaps_NewLine_Call) Run(run func(document interface{})) *AbstractFactoryMaps_NewLine_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{})) + }) + return _c +} + +func (_c *AbstractFactoryMaps_NewLine_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewLine_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AbstractFactoryMaps_NewLine_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewLine_Call { + _c.Call.Return(run) + return _c +} + // NewList provides a mock function with given fields: document, sourceKey, generate func (_m *AbstractFactoryMaps) NewList(document interface{}, sourceKey string, generate mappers.GenerateComponent) (mappers.Componentmapper, error) { ret := _m.Called(document, sourceKey, generate) @@ -138,6 +312,64 @@ func (_c *AbstractFactoryMaps_NewList_Call) RunAndReturn(run func(interface{}, s return _c } +// NewMatrixcode provides a mock function with given fields: document +func (_m *AbstractFactoryMaps) NewMatrixcode(document interface{}) (mappers.Componentmapper, error) { + ret := _m.Called(document) + + if len(ret) == 0 { + panic("no return value specified for NewMatrixcode") + } + + var r0 mappers.Componentmapper + var r1 error + if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + return rf(document) + } + if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + r0 = rf(document) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mappers.Componentmapper) + } + } + + if rf, ok := ret.Get(1).(func(interface{}) error); ok { + r1 = rf(document) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AbstractFactoryMaps_NewMatrixcode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewMatrixcode' +type AbstractFactoryMaps_NewMatrixcode_Call struct { + *mock.Call +} + +// NewMatrixcode is a helper method to define mock.On call +// - document interface{} +func (_e *AbstractFactoryMaps_Expecter) NewMatrixcode(document interface{}) *AbstractFactoryMaps_NewMatrixcode_Call { + return &AbstractFactoryMaps_NewMatrixcode_Call{Call: _e.mock.On("NewMatrixcode", document)} +} + +func (_c *AbstractFactoryMaps_NewMatrixcode_Call) Run(run func(document interface{})) *AbstractFactoryMaps_NewMatrixcode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{})) + }) + return _c +} + +func (_c *AbstractFactoryMaps_NewMatrixcode_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewMatrixcode_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AbstractFactoryMaps_NewMatrixcode_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewMatrixcode_Call { + _c.Call.Return(run) + return _c +} + // NewPage provides a mock function with given fields: document, sourceKey func (_m *AbstractFactoryMaps) NewPage(document interface{}, sourceKey string) (mappers.Componentmapper, error) { ret := _m.Called(document, sourceKey) @@ -197,6 +429,64 @@ func (_c *AbstractFactoryMaps_NewPage_Call) RunAndReturn(run func(interface{}, s return _c } +// NewQrcode provides a mock function with given fields: document +func (_m *AbstractFactoryMaps) NewQrcode(document interface{}) (mappers.Componentmapper, error) { + ret := _m.Called(document) + + if len(ret) == 0 { + panic("no return value specified for NewQrcode") + } + + var r0 mappers.Componentmapper + var r1 error + if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + return rf(document) + } + if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + r0 = rf(document) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mappers.Componentmapper) + } + } + + if rf, ok := ret.Get(1).(func(interface{}) error); ok { + r1 = rf(document) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AbstractFactoryMaps_NewQrcode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewQrcode' +type AbstractFactoryMaps_NewQrcode_Call struct { + *mock.Call +} + +// NewQrcode is a helper method to define mock.On call +// - document interface{} +func (_e *AbstractFactoryMaps_Expecter) NewQrcode(document interface{}) *AbstractFactoryMaps_NewQrcode_Call { + return &AbstractFactoryMaps_NewQrcode_Call{Call: _e.mock.On("NewQrcode", document)} +} + +func (_c *AbstractFactoryMaps_NewQrcode_Call) Run(run func(document interface{})) *AbstractFactoryMaps_NewQrcode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{})) + }) + return _c +} + +func (_c *AbstractFactoryMaps_NewQrcode_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewQrcode_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AbstractFactoryMaps_NewQrcode_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewQrcode_Call { + _c.Call.Return(run) + return _c +} + // NewRow provides a mock function with given fields: document, sourceKey func (_m *AbstractFactoryMaps) NewRow(document interface{}, sourceKey string) (mappers.Componentmapper, error) { ret := _m.Called(document, sourceKey) @@ -256,6 +546,122 @@ func (_c *AbstractFactoryMaps_NewRow_Call) RunAndReturn(run func(interface{}, st return _c } +// NewSignature provides a mock function with given fields: document +func (_m *AbstractFactoryMaps) NewSignature(document interface{}) (mappers.Componentmapper, error) { + ret := _m.Called(document) + + if len(ret) == 0 { + panic("no return value specified for NewSignature") + } + + var r0 mappers.Componentmapper + var r1 error + if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + return rf(document) + } + if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + r0 = rf(document) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mappers.Componentmapper) + } + } + + if rf, ok := ret.Get(1).(func(interface{}) error); ok { + r1 = rf(document) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AbstractFactoryMaps_NewSignature_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewSignature' +type AbstractFactoryMaps_NewSignature_Call struct { + *mock.Call +} + +// NewSignature is a helper method to define mock.On call +// - document interface{} +func (_e *AbstractFactoryMaps_Expecter) NewSignature(document interface{}) *AbstractFactoryMaps_NewSignature_Call { + return &AbstractFactoryMaps_NewSignature_Call{Call: _e.mock.On("NewSignature", document)} +} + +func (_c *AbstractFactoryMaps_NewSignature_Call) Run(run func(document interface{})) *AbstractFactoryMaps_NewSignature_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{})) + }) + return _c +} + +func (_c *AbstractFactoryMaps_NewSignature_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewSignature_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AbstractFactoryMaps_NewSignature_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewSignature_Call { + _c.Call.Return(run) + return _c +} + +// NewText provides a mock function with given fields: document +func (_m *AbstractFactoryMaps) NewText(document interface{}) (mappers.Componentmapper, error) { + ret := _m.Called(document) + + if len(ret) == 0 { + panic("no return value specified for NewText") + } + + var r0 mappers.Componentmapper + var r1 error + if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + return rf(document) + } + if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + r0 = rf(document) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mappers.Componentmapper) + } + } + + if rf, ok := ret.Get(1).(func(interface{}) error); ok { + r1 = rf(document) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// AbstractFactoryMaps_NewText_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NewText' +type AbstractFactoryMaps_NewText_Call struct { + *mock.Call +} + +// NewText is a helper method to define mock.On call +// - document interface{} +func (_e *AbstractFactoryMaps_Expecter) NewText(document interface{}) *AbstractFactoryMaps_NewText_Call { + return &AbstractFactoryMaps_NewText_Call{Call: _e.mock.On("NewText", document)} +} + +func (_c *AbstractFactoryMaps_NewText_Call) Run(run func(document interface{})) *AbstractFactoryMaps_NewText_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{})) + }) + return _c +} + +func (_c *AbstractFactoryMaps_NewText_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewText_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *AbstractFactoryMaps_NewText_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewText_Call { + _c.Call.Return(run) + return _c +} + // NewAbstractFactoryMaps creates a new instance of AbstractFactoryMaps. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewAbstractFactoryMaps(t interface { diff --git a/mocks/Builder.go b/mocks/Builder.go index 883f7968..2cbe240a 100644 --- a/mocks/Builder.go +++ b/mocks/Builder.go @@ -3,12 +3,22 @@ package mocks import ( - cache "github.com/johnfercher/maroto/v2/internal/cache" + config "github.com/johnfercher/maroto/v2/pkg/config" entity "github.com/johnfercher/maroto/v2/pkg/core/entity" - gofpdf "github.com/johnfercher/maroto/v2/internal/providers/gofpdf" + extension "github.com/johnfercher/maroto/v2/pkg/consts/extension" mock "github.com/stretchr/testify/mock" + + orientation "github.com/johnfercher/maroto/v2/pkg/consts/orientation" + + pagesize "github.com/johnfercher/maroto/v2/pkg/consts/pagesize" + + props "github.com/johnfercher/maroto/v2/pkg/props" + + protection "github.com/johnfercher/maroto/v2/pkg/consts/protection" + + time "time" ) // Builder is an autogenerated mock type for the Builder type @@ -24,20 +34,20 @@ func (_m *Builder) EXPECT() *Builder_Expecter { return &Builder_Expecter{mock: &_m.Mock} } -// Build provides a mock function with given fields: cfg, _a1 -func (_m *Builder) Build(cfg *entity.Config, _a1 cache.Cache) *gofpdf.Dependencies { - ret := _m.Called(cfg, _a1) +// Build provides a mock function with given fields: +func (_m *Builder) Build() *entity.Config { + ret := _m.Called() if len(ret) == 0 { panic("no return value specified for Build") } - var r0 *gofpdf.Dependencies - if rf, ok := ret.Get(0).(func(*entity.Config, cache.Cache) *gofpdf.Dependencies); ok { - r0 = rf(cfg, _a1) + var r0 *entity.Config + if rf, ok := ret.Get(0).(func() *entity.Config); ok { + r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*gofpdf.Dependencies) + r0 = ret.Get(0).(*entity.Config) } } @@ -50,25 +60,1244 @@ type Builder_Build_Call struct { } // Build is a helper method to define mock.On call -// - cfg *entity.Config -// - _a1 cache.Cache -func (_e *Builder_Expecter) Build(cfg interface{}, _a1 interface{}) *Builder_Build_Call { - return &Builder_Build_Call{Call: _e.mock.On("Build", cfg, _a1)} +func (_e *Builder_Expecter) Build() *Builder_Build_Call { + return &Builder_Build_Call{Call: _e.mock.On("Build")} +} + +func (_c *Builder_Build_Call) Run(run func()) *Builder_Build_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Builder_Build_Call) Return(_a0 *entity.Config) *Builder_Build_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_Build_Call) RunAndReturn(run func() *entity.Config) *Builder_Build_Call { + _c.Call.Return(run) + return _c +} + +// WithAuthor provides a mock function with given fields: author, isUTF8 +func (_m *Builder) WithAuthor(author string, isUTF8 bool) config.Builder { + ret := _m.Called(author, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithAuthor") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(author, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithAuthor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithAuthor' +type Builder_WithAuthor_Call struct { + *mock.Call +} + +// WithAuthor is a helper method to define mock.On call +// - author string +// - isUTF8 bool +func (_e *Builder_Expecter) WithAuthor(author interface{}, isUTF8 interface{}) *Builder_WithAuthor_Call { + return &Builder_WithAuthor_Call{Call: _e.mock.On("WithAuthor", author, isUTF8)} +} + +func (_c *Builder_WithAuthor_Call) Run(run func(author string, isUTF8 bool)) *Builder_WithAuthor_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithAuthor_Call) Return(_a0 config.Builder) *Builder_WithAuthor_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithAuthor_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithAuthor_Call { + _c.Call.Return(run) + return _c +} + +// WithBackgroundImage provides a mock function with given fields: _a0, _a1 +func (_m *Builder) WithBackgroundImage(_a0 []byte, _a1 extension.Type) config.Builder { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for WithBackgroundImage") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func([]byte, extension.Type) config.Builder); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithBackgroundImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBackgroundImage' +type Builder_WithBackgroundImage_Call struct { + *mock.Call +} + +// WithBackgroundImage is a helper method to define mock.On call +// - _a0 []byte +// - _a1 extension.Type +func (_e *Builder_Expecter) WithBackgroundImage(_a0 interface{}, _a1 interface{}) *Builder_WithBackgroundImage_Call { + return &Builder_WithBackgroundImage_Call{Call: _e.mock.On("WithBackgroundImage", _a0, _a1)} +} + +func (_c *Builder_WithBackgroundImage_Call) Run(run func(_a0 []byte, _a1 extension.Type)) *Builder_WithBackgroundImage_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]byte), args[1].(extension.Type)) + }) + return _c +} + +func (_c *Builder_WithBackgroundImage_Call) Return(_a0 config.Builder) *Builder_WithBackgroundImage_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithBackgroundImage_Call) RunAndReturn(run func([]byte, extension.Type) config.Builder) *Builder_WithBackgroundImage_Call { + _c.Call.Return(run) + return _c +} + +// WithBottomMargin provides a mock function with given fields: bottom +func (_m *Builder) WithBottomMargin(bottom float64) config.Builder { + ret := _m.Called(bottom) + + if len(ret) == 0 { + panic("no return value specified for WithBottomMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(bottom) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithBottomMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBottomMargin' +type Builder_WithBottomMargin_Call struct { + *mock.Call +} + +// WithBottomMargin is a helper method to define mock.On call +// - bottom float64 +func (_e *Builder_Expecter) WithBottomMargin(bottom interface{}) *Builder_WithBottomMargin_Call { + return &Builder_WithBottomMargin_Call{Call: _e.mock.On("WithBottomMargin", bottom)} +} + +func (_c *Builder_WithBottomMargin_Call) Run(run func(bottom float64)) *Builder_WithBottomMargin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Builder_WithBottomMargin_Call) Return(_a0 config.Builder) *Builder_WithBottomMargin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithBottomMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithBottomMargin_Call { + _c.Call.Return(run) + return _c +} + +// WithCompression provides a mock function with given fields: compression +func (_m *Builder) WithCompression(compression bool) config.Builder { + ret := _m.Called(compression) + + if len(ret) == 0 { + panic("no return value specified for WithCompression") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { + r0 = rf(compression) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCompression_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCompression' +type Builder_WithCompression_Call struct { + *mock.Call +} + +// WithCompression is a helper method to define mock.On call +// - compression bool +func (_e *Builder_Expecter) WithCompression(compression interface{}) *Builder_WithCompression_Call { + return &Builder_WithCompression_Call{Call: _e.mock.On("WithCompression", compression)} +} + +func (_c *Builder_WithCompression_Call) Run(run func(compression bool)) *Builder_WithCompression_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Builder_WithCompression_Call) Return(_a0 config.Builder) *Builder_WithCompression_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCompression_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithCompression_Call { + _c.Call.Return(run) + return _c +} + +// WithConcurrentMode provides a mock function with given fields: chunkWorkers +func (_m *Builder) WithConcurrentMode(chunkWorkers int) config.Builder { + ret := _m.Called(chunkWorkers) + + if len(ret) == 0 { + panic("no return value specified for WithConcurrentMode") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(int) config.Builder); ok { + r0 = rf(chunkWorkers) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithConcurrentMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithConcurrentMode' +type Builder_WithConcurrentMode_Call struct { + *mock.Call +} + +// WithConcurrentMode is a helper method to define mock.On call +// - chunkWorkers int +func (_e *Builder_Expecter) WithConcurrentMode(chunkWorkers interface{}) *Builder_WithConcurrentMode_Call { + return &Builder_WithConcurrentMode_Call{Call: _e.mock.On("WithConcurrentMode", chunkWorkers)} +} + +func (_c *Builder_WithConcurrentMode_Call) Run(run func(chunkWorkers int)) *Builder_WithConcurrentMode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Builder_WithConcurrentMode_Call) Return(_a0 config.Builder) *Builder_WithConcurrentMode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithConcurrentMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithConcurrentMode_Call { + _c.Call.Return(run) + return _c +} + +// WithCreationDate provides a mock function with given fields: _a0 +func (_m *Builder) WithCreationDate(_a0 time.Time) config.Builder { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for WithCreationDate") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(time.Time) config.Builder); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCreationDate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreationDate' +type Builder_WithCreationDate_Call struct { + *mock.Call +} + +// WithCreationDate is a helper method to define mock.On call +// - _a0 time.Time +func (_e *Builder_Expecter) WithCreationDate(_a0 interface{}) *Builder_WithCreationDate_Call { + return &Builder_WithCreationDate_Call{Call: _e.mock.On("WithCreationDate", _a0)} +} + +func (_c *Builder_WithCreationDate_Call) Run(run func(_a0 time.Time)) *Builder_WithCreationDate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(time.Time)) + }) + return _c +} + +func (_c *Builder_WithCreationDate_Call) Return(_a0 config.Builder) *Builder_WithCreationDate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCreationDate_Call) RunAndReturn(run func(time.Time) config.Builder) *Builder_WithCreationDate_Call { + _c.Call.Return(run) + return _c +} + +// WithCreator provides a mock function with given fields: creator, isUTF8 +func (_m *Builder) WithCreator(creator string, isUTF8 bool) config.Builder { + ret := _m.Called(creator, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithCreator") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(creator, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCreator_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreator' +type Builder_WithCreator_Call struct { + *mock.Call +} + +// WithCreator is a helper method to define mock.On call +// - creator string +// - isUTF8 bool +func (_e *Builder_Expecter) WithCreator(creator interface{}, isUTF8 interface{}) *Builder_WithCreator_Call { + return &Builder_WithCreator_Call{Call: _e.mock.On("WithCreator", creator, isUTF8)} +} + +func (_c *Builder_WithCreator_Call) Run(run func(creator string, isUTF8 bool)) *Builder_WithCreator_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithCreator_Call) Return(_a0 config.Builder) *Builder_WithCreator_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCreator_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithCreator_Call { + _c.Call.Return(run) + return _c +} + +// WithCustomFonts provides a mock function with given fields: _a0 +func (_m *Builder) WithCustomFonts(_a0 []*entity.CustomFont) config.Builder { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for WithCustomFonts") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func([]*entity.CustomFont) config.Builder); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCustomFonts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCustomFonts' +type Builder_WithCustomFonts_Call struct { + *mock.Call +} + +// WithCustomFonts is a helper method to define mock.On call +// - _a0 []*entity.CustomFont +func (_e *Builder_Expecter) WithCustomFonts(_a0 interface{}) *Builder_WithCustomFonts_Call { + return &Builder_WithCustomFonts_Call{Call: _e.mock.On("WithCustomFonts", _a0)} +} + +func (_c *Builder_WithCustomFonts_Call) Run(run func(_a0 []*entity.CustomFont)) *Builder_WithCustomFonts_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]*entity.CustomFont)) + }) + return _c +} + +func (_c *Builder_WithCustomFonts_Call) Return(_a0 config.Builder) *Builder_WithCustomFonts_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCustomFonts_Call) RunAndReturn(run func([]*entity.CustomFont) config.Builder) *Builder_WithCustomFonts_Call { + _c.Call.Return(run) + return _c +} + +// WithDebug provides a mock function with given fields: on +func (_m *Builder) WithDebug(on bool) config.Builder { + ret := _m.Called(on) + + if len(ret) == 0 { + panic("no return value specified for WithDebug") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { + r0 = rf(on) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDebug_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDebug' +type Builder_WithDebug_Call struct { + *mock.Call +} + +// WithDebug is a helper method to define mock.On call +// - on bool +func (_e *Builder_Expecter) WithDebug(on interface{}) *Builder_WithDebug_Call { + return &Builder_WithDebug_Call{Call: _e.mock.On("WithDebug", on)} +} + +func (_c *Builder_WithDebug_Call) Run(run func(on bool)) *Builder_WithDebug_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Builder_WithDebug_Call) Return(_a0 config.Builder) *Builder_WithDebug_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDebug_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDebug_Call { + _c.Call.Return(run) + return _c +} + +// WithDefaultFont provides a mock function with given fields: font +func (_m *Builder) WithDefaultFont(font *props.Font) config.Builder { + ret := _m.Called(font) + + if len(ret) == 0 { + panic("no return value specified for WithDefaultFont") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(*props.Font) config.Builder); ok { + r0 = rf(font) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDefaultFont_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDefaultFont' +type Builder_WithDefaultFont_Call struct { + *mock.Call +} + +// WithDefaultFont is a helper method to define mock.On call +// - font *props.Font +func (_e *Builder_Expecter) WithDefaultFont(font interface{}) *Builder_WithDefaultFont_Call { + return &Builder_WithDefaultFont_Call{Call: _e.mock.On("WithDefaultFont", font)} +} + +func (_c *Builder_WithDefaultFont_Call) Run(run func(font *props.Font)) *Builder_WithDefaultFont_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*props.Font)) + }) + return _c +} + +func (_c *Builder_WithDefaultFont_Call) Return(_a0 config.Builder) *Builder_WithDefaultFont_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDefaultFont_Call) RunAndReturn(run func(*props.Font) config.Builder) *Builder_WithDefaultFont_Call { + _c.Call.Return(run) + return _c +} + +// WithDimensions provides a mock function with given fields: width, height +func (_m *Builder) WithDimensions(width float64, height float64) config.Builder { + ret := _m.Called(width, height) + + if len(ret) == 0 { + panic("no return value specified for WithDimensions") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64, float64) config.Builder); ok { + r0 = rf(width, height) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDimensions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDimensions' +type Builder_WithDimensions_Call struct { + *mock.Call +} + +// WithDimensions is a helper method to define mock.On call +// - width float64 +// - height float64 +func (_e *Builder_Expecter) WithDimensions(width interface{}, height interface{}) *Builder_WithDimensions_Call { + return &Builder_WithDimensions_Call{Call: _e.mock.On("WithDimensions", width, height)} +} + +func (_c *Builder_WithDimensions_Call) Run(run func(width float64, height float64)) *Builder_WithDimensions_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64), args[1].(float64)) + }) + return _c +} + +func (_c *Builder_WithDimensions_Call) Return(_a0 config.Builder) *Builder_WithDimensions_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDimensions_Call) RunAndReturn(run func(float64, float64) config.Builder) *Builder_WithDimensions_Call { + _c.Call.Return(run) + return _c +} + +// WithDisableAutoPageBreak provides a mock function with given fields: disabled +func (_m *Builder) WithDisableAutoPageBreak(disabled bool) config.Builder { + ret := _m.Called(disabled) + + if len(ret) == 0 { + panic("no return value specified for WithDisableAutoPageBreak") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { + r0 = rf(disabled) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDisableAutoPageBreak_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDisableAutoPageBreak' +type Builder_WithDisableAutoPageBreak_Call struct { + *mock.Call +} + +// WithDisableAutoPageBreak is a helper method to define mock.On call +// - disabled bool +func (_e *Builder_Expecter) WithDisableAutoPageBreak(disabled interface{}) *Builder_WithDisableAutoPageBreak_Call { + return &Builder_WithDisableAutoPageBreak_Call{Call: _e.mock.On("WithDisableAutoPageBreak", disabled)} +} + +func (_c *Builder_WithDisableAutoPageBreak_Call) Run(run func(disabled bool)) *Builder_WithDisableAutoPageBreak_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Builder_WithDisableAutoPageBreak_Call) Return(_a0 config.Builder) *Builder_WithDisableAutoPageBreak_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDisableAutoPageBreak_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDisableAutoPageBreak_Call { + _c.Call.Return(run) + return _c +} + +// WithKeywords provides a mock function with given fields: keywordsStr, isUTF8 +func (_m *Builder) WithKeywords(keywordsStr string, isUTF8 bool) config.Builder { + ret := _m.Called(keywordsStr, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithKeywords") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(keywordsStr, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithKeywords_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithKeywords' +type Builder_WithKeywords_Call struct { + *mock.Call +} + +// WithKeywords is a helper method to define mock.On call +// - keywordsStr string +// - isUTF8 bool +func (_e *Builder_Expecter) WithKeywords(keywordsStr interface{}, isUTF8 interface{}) *Builder_WithKeywords_Call { + return &Builder_WithKeywords_Call{Call: _e.mock.On("WithKeywords", keywordsStr, isUTF8)} +} + +func (_c *Builder_WithKeywords_Call) Run(run func(keywordsStr string, isUTF8 bool)) *Builder_WithKeywords_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithKeywords_Call) Return(_a0 config.Builder) *Builder_WithKeywords_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithKeywords_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithKeywords_Call { + _c.Call.Return(run) + return _c +} + +// WithLeftMargin provides a mock function with given fields: left +func (_m *Builder) WithLeftMargin(left float64) config.Builder { + ret := _m.Called(left) + + if len(ret) == 0 { + panic("no return value specified for WithLeftMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(left) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithLeftMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithLeftMargin' +type Builder_WithLeftMargin_Call struct { + *mock.Call +} + +// WithLeftMargin is a helper method to define mock.On call +// - left float64 +func (_e *Builder_Expecter) WithLeftMargin(left interface{}) *Builder_WithLeftMargin_Call { + return &Builder_WithLeftMargin_Call{Call: _e.mock.On("WithLeftMargin", left)} +} + +func (_c *Builder_WithLeftMargin_Call) Run(run func(left float64)) *Builder_WithLeftMargin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Builder_WithLeftMargin_Call) Return(_a0 config.Builder) *Builder_WithLeftMargin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithLeftMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithLeftMargin_Call { + _c.Call.Return(run) + return _c +} + +// WithMaxGridSize provides a mock function with given fields: maxGridSize +func (_m *Builder) WithMaxGridSize(maxGridSize int) config.Builder { + ret := _m.Called(maxGridSize) + + if len(ret) == 0 { + panic("no return value specified for WithMaxGridSize") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(int) config.Builder); ok { + r0 = rf(maxGridSize) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithMaxGridSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithMaxGridSize' +type Builder_WithMaxGridSize_Call struct { + *mock.Call +} + +// WithMaxGridSize is a helper method to define mock.On call +// - maxGridSize int +func (_e *Builder_Expecter) WithMaxGridSize(maxGridSize interface{}) *Builder_WithMaxGridSize_Call { + return &Builder_WithMaxGridSize_Call{Call: _e.mock.On("WithMaxGridSize", maxGridSize)} +} + +func (_c *Builder_WithMaxGridSize_Call) Run(run func(maxGridSize int)) *Builder_WithMaxGridSize_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Builder_WithMaxGridSize_Call) Return(_a0 config.Builder) *Builder_WithMaxGridSize_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithMaxGridSize_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithMaxGridSize_Call { + _c.Call.Return(run) + return _c +} + +// WithOrientation provides a mock function with given fields: _a0 +func (_m *Builder) WithOrientation(_a0 orientation.Type) config.Builder { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for WithOrientation") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(orientation.Type) config.Builder); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithOrientation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithOrientation' +type Builder_WithOrientation_Call struct { + *mock.Call +} + +// WithOrientation is a helper method to define mock.On call +// - _a0 orientation.Type +func (_e *Builder_Expecter) WithOrientation(_a0 interface{}) *Builder_WithOrientation_Call { + return &Builder_WithOrientation_Call{Call: _e.mock.On("WithOrientation", _a0)} +} + +func (_c *Builder_WithOrientation_Call) Run(run func(_a0 orientation.Type)) *Builder_WithOrientation_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(orientation.Type)) + }) + return _c +} + +func (_c *Builder_WithOrientation_Call) Return(_a0 config.Builder) *Builder_WithOrientation_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithOrientation_Call) RunAndReturn(run func(orientation.Type) config.Builder) *Builder_WithOrientation_Call { + _c.Call.Return(run) + return _c +} + +// WithPageNumber provides a mock function with given fields: pageNumber +func (_m *Builder) WithPageNumber(pageNumber ...props.PageNumber) config.Builder { + _va := make([]interface{}, len(pageNumber)) + for _i := range pageNumber { + _va[_i] = pageNumber[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for WithPageNumber") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(...props.PageNumber) config.Builder); ok { + r0 = rf(pageNumber...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithPageNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageNumber' +type Builder_WithPageNumber_Call struct { + *mock.Call +} + +// WithPageNumber is a helper method to define mock.On call +// - pageNumber ...props.PageNumber +func (_e *Builder_Expecter) WithPageNumber(pageNumber ...interface{}) *Builder_WithPageNumber_Call { + return &Builder_WithPageNumber_Call{Call: _e.mock.On("WithPageNumber", + append([]interface{}{}, pageNumber...)...)} +} + +func (_c *Builder_WithPageNumber_Call) Run(run func(pageNumber ...props.PageNumber)) *Builder_WithPageNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]props.PageNumber, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(props.PageNumber) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *Builder_WithPageNumber_Call) Return(_a0 config.Builder) *Builder_WithPageNumber_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithPageNumber_Call) RunAndReturn(run func(...props.PageNumber) config.Builder) *Builder_WithPageNumber_Call { + _c.Call.Return(run) + return _c +} + +// WithPageSize provides a mock function with given fields: size +func (_m *Builder) WithPageSize(size pagesize.Type) config.Builder { + ret := _m.Called(size) + + if len(ret) == 0 { + panic("no return value specified for WithPageSize") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(pagesize.Type) config.Builder); ok { + r0 = rf(size) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithPageSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageSize' +type Builder_WithPageSize_Call struct { + *mock.Call +} + +// WithPageSize is a helper method to define mock.On call +// - size pagesize.Type +func (_e *Builder_Expecter) WithPageSize(size interface{}) *Builder_WithPageSize_Call { + return &Builder_WithPageSize_Call{Call: _e.mock.On("WithPageSize", size)} +} + +func (_c *Builder_WithPageSize_Call) Run(run func(size pagesize.Type)) *Builder_WithPageSize_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(pagesize.Type)) + }) + return _c +} + +func (_c *Builder_WithPageSize_Call) Return(_a0 config.Builder) *Builder_WithPageSize_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithPageSize_Call) RunAndReturn(run func(pagesize.Type) config.Builder) *Builder_WithPageSize_Call { + _c.Call.Return(run) + return _c +} + +// WithProtection provides a mock function with given fields: protectionType, userPassword, ownerPassword +func (_m *Builder) WithProtection(protectionType protection.Type, userPassword string, ownerPassword string) config.Builder { + ret := _m.Called(protectionType, userPassword, ownerPassword) + + if len(ret) == 0 { + panic("no return value specified for WithProtection") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(protection.Type, string, string) config.Builder); ok { + r0 = rf(protectionType, userPassword, ownerPassword) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithProtection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithProtection' +type Builder_WithProtection_Call struct { + *mock.Call +} + +// WithProtection is a helper method to define mock.On call +// - protectionType protection.Type +// - userPassword string +// - ownerPassword string +func (_e *Builder_Expecter) WithProtection(protectionType interface{}, userPassword interface{}, ownerPassword interface{}) *Builder_WithProtection_Call { + return &Builder_WithProtection_Call{Call: _e.mock.On("WithProtection", protectionType, userPassword, ownerPassword)} +} + +func (_c *Builder_WithProtection_Call) Run(run func(protectionType protection.Type, userPassword string, ownerPassword string)) *Builder_WithProtection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(protection.Type), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *Builder_WithProtection_Call) Return(_a0 config.Builder) *Builder_WithProtection_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithProtection_Call) RunAndReturn(run func(protection.Type, string, string) config.Builder) *Builder_WithProtection_Call { + _c.Call.Return(run) + return _c +} + +// WithRightMargin provides a mock function with given fields: right +func (_m *Builder) WithRightMargin(right float64) config.Builder { + ret := _m.Called(right) + + if len(ret) == 0 { + panic("no return value specified for WithRightMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(right) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithRightMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithRightMargin' +type Builder_WithRightMargin_Call struct { + *mock.Call +} + +// WithRightMargin is a helper method to define mock.On call +// - right float64 +func (_e *Builder_Expecter) WithRightMargin(right interface{}) *Builder_WithRightMargin_Call { + return &Builder_WithRightMargin_Call{Call: _e.mock.On("WithRightMargin", right)} +} + +func (_c *Builder_WithRightMargin_Call) Run(run func(right float64)) *Builder_WithRightMargin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Builder_WithRightMargin_Call) Return(_a0 config.Builder) *Builder_WithRightMargin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithRightMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithRightMargin_Call { + _c.Call.Return(run) + return _c +} + +// WithSequentialLowMemoryMode provides a mock function with given fields: chunkWorkers +func (_m *Builder) WithSequentialLowMemoryMode(chunkWorkers int) config.Builder { + ret := _m.Called(chunkWorkers) + + if len(ret) == 0 { + panic("no return value specified for WithSequentialLowMemoryMode") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(int) config.Builder); ok { + r0 = rf(chunkWorkers) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithSequentialLowMemoryMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialLowMemoryMode' +type Builder_WithSequentialLowMemoryMode_Call struct { + *mock.Call +} + +// WithSequentialLowMemoryMode is a helper method to define mock.On call +// - chunkWorkers int +func (_e *Builder_Expecter) WithSequentialLowMemoryMode(chunkWorkers interface{}) *Builder_WithSequentialLowMemoryMode_Call { + return &Builder_WithSequentialLowMemoryMode_Call{Call: _e.mock.On("WithSequentialLowMemoryMode", chunkWorkers)} +} + +func (_c *Builder_WithSequentialLowMemoryMode_Call) Run(run func(chunkWorkers int)) *Builder_WithSequentialLowMemoryMode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Builder_WithSequentialLowMemoryMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialLowMemoryMode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithSequentialLowMemoryMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithSequentialLowMemoryMode_Call { + _c.Call.Return(run) + return _c +} + +// WithSequentialMode provides a mock function with given fields: +func (_m *Builder) WithSequentialMode() config.Builder { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for WithSequentialMode") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func() config.Builder); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithSequentialMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialMode' +type Builder_WithSequentialMode_Call struct { + *mock.Call +} + +// WithSequentialMode is a helper method to define mock.On call +func (_e *Builder_Expecter) WithSequentialMode() *Builder_WithSequentialMode_Call { + return &Builder_WithSequentialMode_Call{Call: _e.mock.On("WithSequentialMode")} +} + +func (_c *Builder_WithSequentialMode_Call) Run(run func()) *Builder_WithSequentialMode_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Builder_WithSequentialMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialMode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithSequentialMode_Call) RunAndReturn(run func() config.Builder) *Builder_WithSequentialMode_Call { + _c.Call.Return(run) + return _c +} + +// WithSubject provides a mock function with given fields: subject, isUTF8 +func (_m *Builder) WithSubject(subject string, isUTF8 bool) config.Builder { + ret := _m.Called(subject, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithSubject") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(subject, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithSubject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSubject' +type Builder_WithSubject_Call struct { + *mock.Call +} + +// WithSubject is a helper method to define mock.On call +// - subject string +// - isUTF8 bool +func (_e *Builder_Expecter) WithSubject(subject interface{}, isUTF8 interface{}) *Builder_WithSubject_Call { + return &Builder_WithSubject_Call{Call: _e.mock.On("WithSubject", subject, isUTF8)} +} + +func (_c *Builder_WithSubject_Call) Run(run func(subject string, isUTF8 bool)) *Builder_WithSubject_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithSubject_Call) Return(_a0 config.Builder) *Builder_WithSubject_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithSubject_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithSubject_Call { + _c.Call.Return(run) + return _c +} + +// WithTitle provides a mock function with given fields: title, isUTF8 +func (_m *Builder) WithTitle(title string, isUTF8 bool) config.Builder { + ret := _m.Called(title, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithTitle") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(title, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithTitle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTitle' +type Builder_WithTitle_Call struct { + *mock.Call +} + +// WithTitle is a helper method to define mock.On call +// - title string +// - isUTF8 bool +func (_e *Builder_Expecter) WithTitle(title interface{}, isUTF8 interface{}) *Builder_WithTitle_Call { + return &Builder_WithTitle_Call{Call: _e.mock.On("WithTitle", title, isUTF8)} +} + +func (_c *Builder_WithTitle_Call) Run(run func(title string, isUTF8 bool)) *Builder_WithTitle_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithTitle_Call) Return(_a0 config.Builder) *Builder_WithTitle_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithTitle_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithTitle_Call { + _c.Call.Return(run) + return _c +} + +// WithTopMargin provides a mock function with given fields: top +func (_m *Builder) WithTopMargin(top float64) config.Builder { + ret := _m.Called(top) + + if len(ret) == 0 { + panic("no return value specified for WithTopMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(top) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithTopMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTopMargin' +type Builder_WithTopMargin_Call struct { + *mock.Call +} + +// WithTopMargin is a helper method to define mock.On call +// - top float64 +func (_e *Builder_Expecter) WithTopMargin(top interface{}) *Builder_WithTopMargin_Call { + return &Builder_WithTopMargin_Call{Call: _e.mock.On("WithTopMargin", top)} } -func (_c *Builder_Build_Call) Run(run func(cfg *entity.Config, _a1 cache.Cache)) *Builder_Build_Call { +func (_c *Builder_WithTopMargin_Call) Run(run func(top float64)) *Builder_WithTopMargin_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*entity.Config), args[1].(cache.Cache)) + run(args[0].(float64)) }) return _c } -func (_c *Builder_Build_Call) Return(_a0 *gofpdf.Dependencies) *Builder_Build_Call { +func (_c *Builder_WithTopMargin_Call) Return(_a0 config.Builder) *Builder_WithTopMargin_Call { _c.Call.Return(_a0) return _c } -func (_c *Builder_Build_Call) RunAndReturn(run func(*entity.Config, cache.Cache) *gofpdf.Dependencies) *Builder_Build_Call { +func (_c *Builder_WithTopMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithTopMargin_Call { _c.Call.Return(run) return _c } diff --git a/mocks/Repository.go b/mocks/Repository.go index dd241eb4..3977c94e 100644 --- a/mocks/Repository.go +++ b/mocks/Repository.go @@ -2,7 +2,14 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + fontstyle "github.com/johnfercher/maroto/v2/pkg/consts/fontstyle" + entity "github.com/johnfercher/maroto/v2/pkg/core/entity" + + mock "github.com/stretchr/testify/mock" + + repository "github.com/johnfercher/maroto/v2/pkg/repository" +) // Repository is an autogenerated mock type for the Repository type type Repository struct { @@ -17,105 +24,159 @@ func (_m *Repository) EXPECT() *Repository_Expecter { return &Repository_Expecter{mock: &_m.Mock} } -// ReadTemplate provides a mock function with given fields: templateName -func (_m *Repository) ReadTemplate(templateName string) (string, error) { - ret := _m.Called(templateName) +// AddUTF8Font provides a mock function with given fields: family, style, file +func (_m *Repository) AddUTF8Font(family string, style fontstyle.Type, file string) repository.Repository { + ret := _m.Called(family, style, file) if len(ret) == 0 { - panic("no return value specified for ReadTemplate") + panic("no return value specified for AddUTF8Font") } - var r0 string - var r1 error - if rf, ok := ret.Get(0).(func(string) (string, error)); ok { - return rf(templateName) - } - if rf, ok := ret.Get(0).(func(string) string); ok { - r0 = rf(templateName) + var r0 repository.Repository + if rf, ok := ret.Get(0).(func(string, fontstyle.Type, string) repository.Repository); ok { + r0 = rf(family, style, file) } else { - r0 = ret.Get(0).(string) + if ret.Get(0) != nil { + r0 = ret.Get(0).(repository.Repository) + } + } + + return r0 +} + +// Repository_AddUTF8Font_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddUTF8Font' +type Repository_AddUTF8Font_Call struct { + *mock.Call +} + +// AddUTF8Font is a helper method to define mock.On call +// - family string +// - style fontstyle.Type +// - file string +func (_e *Repository_Expecter) AddUTF8Font(family interface{}, style interface{}, file interface{}) *Repository_AddUTF8Font_Call { + return &Repository_AddUTF8Font_Call{Call: _e.mock.On("AddUTF8Font", family, style, file)} +} + +func (_c *Repository_AddUTF8Font_Call) Run(run func(family string, style fontstyle.Type, file string)) *Repository_AddUTF8Font_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(fontstyle.Type), args[2].(string)) + }) + return _c +} + +func (_c *Repository_AddUTF8Font_Call) Return(_a0 repository.Repository) *Repository_AddUTF8Font_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Repository_AddUTF8Font_Call) RunAndReturn(run func(string, fontstyle.Type, string) repository.Repository) *Repository_AddUTF8Font_Call { + _c.Call.Return(run) + return _c +} + +// AddUTF8FontFromBytes provides a mock function with given fields: family, style, bytes +func (_m *Repository) AddUTF8FontFromBytes(family string, style fontstyle.Type, bytes []byte) repository.Repository { + ret := _m.Called(family, style, bytes) + + if len(ret) == 0 { + panic("no return value specified for AddUTF8FontFromBytes") } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(templateName) + var r0 repository.Repository + if rf, ok := ret.Get(0).(func(string, fontstyle.Type, []byte) repository.Repository); ok { + r0 = rf(family, style, bytes) } else { - r1 = ret.Error(1) + if ret.Get(0) != nil { + r0 = ret.Get(0).(repository.Repository) + } } - return r0, r1 + return r0 } -// Repository_ReadTemplate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReadTemplate' -type Repository_ReadTemplate_Call struct { +// Repository_AddUTF8FontFromBytes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddUTF8FontFromBytes' +type Repository_AddUTF8FontFromBytes_Call struct { *mock.Call } -// ReadTemplate is a helper method to define mock.On call -// - templateName string -func (_e *Repository_Expecter) ReadTemplate(templateName interface{}) *Repository_ReadTemplate_Call { - return &Repository_ReadTemplate_Call{Call: _e.mock.On("ReadTemplate", templateName)} +// AddUTF8FontFromBytes is a helper method to define mock.On call +// - family string +// - style fontstyle.Type +// - bytes []byte +func (_e *Repository_Expecter) AddUTF8FontFromBytes(family interface{}, style interface{}, bytes interface{}) *Repository_AddUTF8FontFromBytes_Call { + return &Repository_AddUTF8FontFromBytes_Call{Call: _e.mock.On("AddUTF8FontFromBytes", family, style, bytes)} } -func (_c *Repository_ReadTemplate_Call) Run(run func(templateName string)) *Repository_ReadTemplate_Call { +func (_c *Repository_AddUTF8FontFromBytes_Call) Run(run func(family string, style fontstyle.Type, bytes []byte)) *Repository_AddUTF8FontFromBytes_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) + run(args[0].(string), args[1].(fontstyle.Type), args[2].([]byte)) }) return _c } -func (_c *Repository_ReadTemplate_Call) Return(_a0 string, _a1 error) *Repository_ReadTemplate_Call { - _c.Call.Return(_a0, _a1) +func (_c *Repository_AddUTF8FontFromBytes_Call) Return(_a0 repository.Repository) *Repository_AddUTF8FontFromBytes_Call { + _c.Call.Return(_a0) return _c } -func (_c *Repository_ReadTemplate_Call) RunAndReturn(run func(string) (string, error)) *Repository_ReadTemplate_Call { +func (_c *Repository_AddUTF8FontFromBytes_Call) RunAndReturn(run func(string, fontstyle.Type, []byte) repository.Repository) *Repository_AddUTF8FontFromBytes_Call { _c.Call.Return(run) return _c } -// RegisterTemplate provides a mock function with given fields: name, template -func (_m *Repository) RegisterTemplate(name string, template string) error { - ret := _m.Called(name, template) +// Load provides a mock function with given fields: +func (_m *Repository) Load() ([]*entity.CustomFont, error) { + ret := _m.Called() if len(ret) == 0 { - panic("no return value specified for RegisterTemplate") + panic("no return value specified for Load") } - var r0 error - if rf, ok := ret.Get(0).(func(string, string) error); ok { - r0 = rf(name, template) + var r0 []*entity.CustomFont + var r1 error + if rf, ok := ret.Get(0).(func() ([]*entity.CustomFont, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []*entity.CustomFont); ok { + r0 = rf() } else { - r0 = ret.Error(0) + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*entity.CustomFont) + } } - return r0 + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 } -// Repository_RegisterTemplate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterTemplate' -type Repository_RegisterTemplate_Call struct { +// Repository_Load_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Load' +type Repository_Load_Call struct { *mock.Call } -// RegisterTemplate is a helper method to define mock.On call -// - name string -// - template string -func (_e *Repository_Expecter) RegisterTemplate(name interface{}, template interface{}) *Repository_RegisterTemplate_Call { - return &Repository_RegisterTemplate_Call{Call: _e.mock.On("RegisterTemplate", name, template)} +// Load is a helper method to define mock.On call +func (_e *Repository_Expecter) Load() *Repository_Load_Call { + return &Repository_Load_Call{Call: _e.mock.On("Load")} } -func (_c *Repository_RegisterTemplate_Call) Run(run func(name string, template string)) *Repository_RegisterTemplate_Call { +func (_c *Repository_Load_Call) Run(run func()) *Repository_Load_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(string)) + run() }) return _c } -func (_c *Repository_RegisterTemplate_Call) Return(_a0 error) *Repository_RegisterTemplate_Call { - _c.Call.Return(_a0) +func (_c *Repository_Load_Call) Return(_a0 []*entity.CustomFont, _a1 error) *Repository_Load_Call { + _c.Call.Return(_a0, _a1) return _c } -func (_c *Repository_RegisterTemplate_Call) RunAndReturn(run func(string, string) error) *Repository_RegisterTemplate_Call { +func (_c *Repository_Load_Call) RunAndReturn(run func() ([]*entity.CustomFont, error)) *Repository_Load_Call { _c.Call.Return(run) return _c } diff --git a/pkg/processor/mappers/components/colmapper/col.go b/pkg/processor/mappers/components/colmapper/col.go index 19e63f7d..a9c84db7 100644 --- a/pkg/processor/mappers/components/colmapper/col.go +++ b/pkg/processor/mappers/components/colmapper/col.go @@ -1,19 +1,80 @@ package colmapper import ( + "fmt" + "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" ) type Col struct { Size int - Components mappers.Componentmapper + Components []mappers.Componentmapper + factory mappers.AbstractFactoryMaps } -func NewCol(interface{}) (*Col, error) { - return nil, nil +func NewCol(templateCols interface{}, factory mappers.AbstractFactoryMaps) (*Col, error) { + mapCols, ok := templateCols.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("ensure that rows can be converted to map[string] interface{}") + } + + col := &Col{Size: 0, Components: make([]mappers.Componentmapper, 0), factory: factory} + + if err := col.setSize(&mapCols); err != nil { + return nil, err + } + + if err := col.addComponents(mapCols); err != nil { + return nil, err + } + return col, nil } func (c *Col) Generate(content map[string]interface{}) (components.PdfComponent, error) { return nil, nil } + +func (c *Col) addComponents(mapComponents map[string]interface{}) error { + fieldMappers := c.getFieldMappers() + + for templateName, template := range mapComponents { + mapper, ok := fieldMappers[templateName] + if !ok { + return fmt.Errorf("the field %s present in the col cannot be mapped to any valid component", templateName) + } + component, err := mapper(template) + if err != nil { + return err + } + c.Components = append(c.Components, component) + } + return nil +} + +func (c *Col) setSize(template *map[string]interface{}) error { + defer delete(*template, "size") + templateSize, ok := (*template)["size"] + if ok { + size, ok := templateSize.(float64) + if !ok { + return fmt.Errorf("ensure that size can be converted to int") + } + c.Size = int(size) + } + return nil +} + +// getFieldMappers is responsible for defining which methods are responsible for assembling which components. +// To do this, the component name is linked to a function in a Map. +func (c *Col) getFieldMappers() map[string]func(interface{}) (mappers.Componentmapper, error) { + return map[string]func(interface{}) (mappers.Componentmapper, error){ + "bar_code": c.factory.NewBarcode, + "matrix_code": c.factory.NewMatrixcode, + "qr_code": c.factory.NewQrcode, + "image": c.factory.NewImage, + "line": c.factory.NewLine, + "signature": c.factory.NewSignature, + "text": c.factory.NewText, + } +} From db71615c0b8a782a82ae163999e5aefb82a28e5d Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 15 Oct 2024 21:07:57 -0300 Subject: [PATCH 027/116] feat: create component property mapper --- pkg/processor/mappers/propsmapper/barcode.go | 38 +++++++++ .../mappers/propsmapper/barcode_test.go | 1 + pkg/processor/mappers/propsmapper/consts.go | 77 +++++++++++++++++++ pkg/processor/mappers/propsmapper/line.go | 35 +++++++++ .../mappers/propsmapper/line_test.go | 1 + .../mappers/propsmapper/proportion.go | 23 ++++++ .../mappers/propsmapper/protection.go | 17 +--- pkg/processor/mappers/propsmapper/rect.go | 35 +++++++++ .../mappers/propsmapper/rect_test.go | 1 + .../mappers/propsmapper/signature.go | 45 +++++++++++ .../mappers/propsmapper/signature_test.go | 1 + pkg/processor/mappers/propsmapper/text.go | 50 ++++++++++++ .../mappers/propsmapper/text_test.go | 1 + 13 files changed, 309 insertions(+), 16 deletions(-) create mode 100644 pkg/processor/mappers/propsmapper/barcode.go create mode 100644 pkg/processor/mappers/propsmapper/barcode_test.go create mode 100644 pkg/processor/mappers/propsmapper/consts.go create mode 100644 pkg/processor/mappers/propsmapper/line.go create mode 100644 pkg/processor/mappers/propsmapper/line_test.go create mode 100644 pkg/processor/mappers/propsmapper/proportion.go create mode 100644 pkg/processor/mappers/propsmapper/rect.go create mode 100644 pkg/processor/mappers/propsmapper/rect_test.go create mode 100644 pkg/processor/mappers/propsmapper/signature.go create mode 100644 pkg/processor/mappers/propsmapper/signature_test.go create mode 100644 pkg/processor/mappers/propsmapper/text.go create mode 100644 pkg/processor/mappers/propsmapper/text_test.go diff --git a/pkg/processor/mappers/propsmapper/barcode.go b/pkg/processor/mappers/propsmapper/barcode.go new file mode 100644 index 00000000..94867dee --- /dev/null +++ b/pkg/processor/mappers/propsmapper/barcode.go @@ -0,0 +1,38 @@ +package propsmapper + +// Barcode represents properties from a barcode inside a cell. +type Barcode struct { + // Left is the space between the left cell boundary to the barcode, if center is false. + Left float64 + // Top is space between the upper cell limit to the barcode, if center is false. + Top float64 + // Percent is how much the barcode will occupy the cell, + // ex 100%: The barcode will fulfill the entire cell + // ex 50%: The greater side from the barcode will have half the size of the cell. + Percent float64 + // Proportion is the proportion between size of the barcode. + // Ex: 16x9, 4x3... + Proportion Proportion + // Center define that the barcode will be vertically and horizontally centralized. + Center bool + // Type represents the barcode type. Default: code128 + Type string +} + +// NewBarcode is responsible for creating the barcode, if the font fields cannot be +// converted, an invalid value is set. +func NewBarcode(barcode interface{}) *Barcode { + barcodeMap, ok := barcode.(map[string]interface{}) + if !ok { + return nil + } + + return &Barcode{ + Left: *convertFields(barcodeMap["left"], -1.0), + Top: *convertFields(barcodeMap["top"], -1.0), + Percent: *convertFields(barcodeMap["percent"], -1.0), + Proportion: *NewProportion(barcodeMap["proportion"]), + Center: *convertFields(barcodeMap["center"], false), + Type: NewCodeType(*convertFields(barcodeMap["type"], "")), + } +} diff --git a/pkg/processor/mappers/propsmapper/barcode_test.go b/pkg/processor/mappers/propsmapper/barcode_test.go new file mode 100644 index 00000000..9426b76e --- /dev/null +++ b/pkg/processor/mappers/propsmapper/barcode_test.go @@ -0,0 +1 @@ +package propsmapper_test diff --git a/pkg/processor/mappers/propsmapper/consts.go b/pkg/processor/mappers/propsmapper/consts.go new file mode 100644 index 00000000..d17a7f46 --- /dev/null +++ b/pkg/processor/mappers/propsmapper/consts.go @@ -0,0 +1,77 @@ +package propsmapper + +func NewAlign(align string) string { + mapAligns := map[string]string{ + "Left": "L", "Right": "R", "Center": "C", "Top": "T", "Bottom": "B", "Middle": "M", "Justify": "J", + } + align, ok := mapAligns[align] + if !ok { + return "" + } + return align +} + +func NewBreakLineStrategy(strategy string) string { + switch strategy { + case "EmptySpaceStrategy": + return "empty_space_strategy" + case "DashStrategy": + return "dash_strategy" + } + return "" +} + +func NewCodeType(typeProtection string) string { + if typeProtection == "EAN" { + return "ean" + } + return "code128" +} + +func NewLineStyle(style string) string { + switch style { + case "dashed": + return "dashed" + case "solid": + return "dashed" + } + return "" +} + +func NewOrientation(orientation string) string { + switch orientation { + case "vertical": + return "vertical" + case "horizontal": + return "horizontal" + } + return "" +} + +func NewTypeProtection(typeProtection string) byte { + switch typeProtection { + case "Print": + return 4 + case "Modify": + return 8 + case "Copy": + return 16 + case "AnnotForms": + return 32 + } + + return 0 +} + +func NewFontStyle(fontType string) string { + switch fontType { + case "Bold": + return "B" + case "Italic": + return "I" + case "BoldItalic": + return "BI" + } + + return "" +} diff --git a/pkg/processor/mappers/propsmapper/line.go b/pkg/processor/mappers/propsmapper/line.go new file mode 100644 index 00000000..269dd25c --- /dev/null +++ b/pkg/processor/mappers/propsmapper/line.go @@ -0,0 +1,35 @@ +package propsmapper + +// Line represents properties from a Line inside a cell. +type Line struct { + // Color define the line color. + Color *Color + // Style define the line style (solid or dashed). + Style string + // Thickness define the line thicknesl. + Thickness float64 + // Orientation define if line would be horizontal or vertical. + Orientation string + // OffsetPercent define where the line would be placed, 0 is the start of cell, 50 the middle and 100 the end. + OffsetPercent float64 + // SizePercent define the size of the line inside cell. + SizePercent float64 +} + +// NewLine is responsible for creating the Line, if the font fields cannot be +// converted, an invalid value is set. +func NewLine(line interface{}) *Line { + lineMap, ok := line.(map[string]interface{}) + if !ok { + return nil + } + + return &Line{ + Color: NewColor(lineMap["color"]), + Style: NewLineStyle(*convertFields(lineMap["style"], "")), + Thickness: *convertFields(lineMap["thickness"], 0.0), + Orientation: NewOrientation(*convertFields(lineMap["orientation"], "")), + OffsetPercent: *convertFields(lineMap["offset_percent"], -1.0), + SizePercent: *convertFields(lineMap["size_percent"], -1.0), + } +} diff --git a/pkg/processor/mappers/propsmapper/line_test.go b/pkg/processor/mappers/propsmapper/line_test.go new file mode 100644 index 00000000..9426b76e --- /dev/null +++ b/pkg/processor/mappers/propsmapper/line_test.go @@ -0,0 +1 @@ +package propsmapper_test diff --git a/pkg/processor/mappers/propsmapper/proportion.go b/pkg/processor/mappers/propsmapper/proportion.go new file mode 100644 index 00000000..5ab8498f --- /dev/null +++ b/pkg/processor/mappers/propsmapper/proportion.go @@ -0,0 +1,23 @@ +package propsmapper + +// Proportion represents a proportion from a rectangle, example: 16x9, 4x3... +type Proportion struct { + // Width from the rectangle: Barcode, image and etc. + Width float64 + // Height from the rectangle: Barcode, image and etc. + Height float64 +} + +// NewProportion is responsible for creating the proportion, if the font fields cannot be +// converted, an invalid value is set. +func NewProportion(barcode interface{}) *Proportion { + barcodeMap, ok := barcode.(map[string]interface{}) + if !ok { + return nil + } + + return &Proportion{ + Width: *convertFields(barcodeMap["width"], 0.0), + Height: *convertFields(barcodeMap["height"], 0.0), + } +} diff --git a/pkg/processor/mappers/propsmapper/protection.go b/pkg/processor/mappers/propsmapper/protection.go index 339538f9..a9fe83f4 100644 --- a/pkg/processor/mappers/propsmapper/protection.go +++ b/pkg/processor/mappers/propsmapper/protection.go @@ -16,23 +16,8 @@ func NewProtection(protection interface{}) *Protection { } return &Protection{ - Type: factoryTypeProtection(*convertFields(protectionMap["type"], "None")), + Type: NewTypeProtection(*convertFields(protectionMap["type"], "None")), UserPassword: *convertFields(protectionMap["user_password"], ""), OwnerPassword: *convertFields(protectionMap["owner_password"], ""), } } - -func factoryTypeProtection(typeProtection string) byte { - switch typeProtection { - case "Print": - return 4 - case "Modify": - return 8 - case "Copy": - return 16 - case "AnnotForms": - return 32 - } - - return 0 -} diff --git a/pkg/processor/mappers/propsmapper/rect.go b/pkg/processor/mappers/propsmapper/rect.go new file mode 100644 index 00000000..9f2eb161 --- /dev/null +++ b/pkg/processor/mappers/propsmapper/rect.go @@ -0,0 +1,35 @@ +package propsmapper + +// Rect represents properties from a rectangle (Image, QrCode or Barcode) inside a cell. +type Rect struct { + // Left is the space between the left cell boundary to the rectangle, if center is false. + Left float64 + // Top is space between the upper cell limit to the barcode, if center is false. + Top float64 + // Percent is how much the rectangle will occupy the cell, + // ex 100%: The rectangle will fulfill the entire cell + // ex 50%: The greater side from the rectangle will have half the size of the cell. + Percent float64 + // indicate whether only the width should be used as a reference to calculate the component size, disregarding the height + // ex true: The component will be scaled only based on the available width, disregarding the available height + JustReferenceWidth bool + // Center define that the barcode will be vertically and horizontally centralized. + Center bool +} + +// NewRect is responsible for creating the Rect, if the font fields cannot be +// converted, an invalid value is set. +func NewRect(rect interface{}) *Rect { + rectMap, ok := rect.(map[string]interface{}) + if !ok { + return nil + } + + return &Rect{ + Left: *convertFields(rectMap["left"], -1.0), + Top: *convertFields(rectMap["top"], -1.0), + Percent: *convertFields(rectMap["percent"], -1.0), + JustReferenceWidth: *convertFields(rectMap["just_reference_width"], false), + Center: *convertFields(rectMap["center"], false), + } +} diff --git a/pkg/processor/mappers/propsmapper/rect_test.go b/pkg/processor/mappers/propsmapper/rect_test.go new file mode 100644 index 00000000..9426b76e --- /dev/null +++ b/pkg/processor/mappers/propsmapper/rect_test.go @@ -0,0 +1 @@ +package propsmapper_test diff --git a/pkg/processor/mappers/propsmapper/signature.go b/pkg/processor/mappers/propsmapper/signature.go new file mode 100644 index 00000000..83e7f080 --- /dev/null +++ b/pkg/processor/mappers/propsmapper/signature.go @@ -0,0 +1,45 @@ +package propsmapper + +import ( + "github.com/johnfercher/maroto/v2/pkg/consts/linestyle" +) + +// Signature represents properties from a signature. +type Signature struct { + // FontFamily of the text, ex: consts.Arial, helvetica and etc. + FontFamily string + // FontStyle of the text, ex: consts.Normal, bold and etc. + FontStyle string + // FontSize of the text. + FontSize float64 + // FontColor define the font color. + FontColor *Color + // LineColor define the line color. + LineColor *Color + // LineStyle define the line style (solid or dashed). + LineStyle linestyle.Type + // LineThickness define the line thickness. + LineThickness float64 + + SafePadding float64 +} + +// NewSignature is responsible for creating the Signature, if the font fields cannot be +// converted, an invalid value is set. +func NewSignature(signature interface{}) *Signature { + signatureMap, ok := signature.(map[string]interface{}) + if !ok { + return nil + } + + return &Signature{ + FontFamily: *convertFields(signatureMap["font_family"], ""), + FontStyle: NewFontStyle(*convertFields(signatureMap["font_style"], "")), + FontSize: *convertFields(signatureMap["font_size"], 0.0), + FontColor: NewColor(signatureMap["font_Color"]), + LineColor: NewColor(signatureMap["line_color"]), + LineStyle: linestyle.Type(NewLineStyle(*convertFields(signatureMap["line_style"], ""))), + LineThickness: *convertFields(signatureMap["line_thickness"], 0.0), + SafePadding: *convertFields(signatureMap["safe_padding"], -1.0), + } +} diff --git a/pkg/processor/mappers/propsmapper/signature_test.go b/pkg/processor/mappers/propsmapper/signature_test.go new file mode 100644 index 00000000..9426b76e --- /dev/null +++ b/pkg/processor/mappers/propsmapper/signature_test.go @@ -0,0 +1 @@ +package propsmapper_test diff --git a/pkg/processor/mappers/propsmapper/text.go b/pkg/processor/mappers/propsmapper/text.go new file mode 100644 index 00000000..dfd5db7d --- /dev/null +++ b/pkg/processor/mappers/propsmapper/text.go @@ -0,0 +1,50 @@ +package propsmapper + +// Text represents properties from a Text inside a cell. +type Text struct { + // Top is the amount of space between the upper cell limit and the text. + Top float64 + // Left is the minimal amount of space between the left cell boundary and the text. + Left float64 + // Right is the minimal amount of space between the right cell boundary and the text. + Right float64 + // Family of the text, ex: consts.Arial, helvetica and etc. + Family string + // Style of the text, ex: consts.Normal, bold and etc. + Style string + // Size of the text. + Size float64 + // Align of the text. + Align string + // BreakLineStrategy define the break line strategy. + BreakLineStrategy string + // VerticalPadding define an additional space between linet. + VerticalPadding float64 + // Color define the font style color. + Color *Color + // Hyperlink define a link to be opened when the text is clicked. + Hyperlink string +} + +// NewText is responsible for creating the Text, if the font fields cannot be +// converted, an invalid value is set. +func NewText(signature interface{}) *Text { + signatureMap, ok := signature.(map[string]interface{}) + if !ok { + return nil + } + + return &Text{ + Top: *convertFields(signatureMap["top"], -1.0), + Left: *convertFields(signatureMap["left"], -1.0), + Right: *convertFields(signatureMap["right"], -1.0), + Family: *convertFields(signatureMap["family"], ""), + Style: NewFontStyle(*convertFields(signatureMap["style"], "")), + Size: *convertFields(signatureMap["size"], 0.0), + Align: NewAlign(*convertFields(signatureMap["align"], "")), + BreakLineStrategy: NewBreakLineStrategy(*convertFields(signatureMap["break_line_strategy"], "")), + VerticalPadding: *convertFields(signatureMap["vertical_padding"], -1.0), + Color: NewColor(signatureMap["color"]), + Hyperlink: *convertFields(signatureMap["hyperlink"], ""), + } +} diff --git a/pkg/processor/mappers/propsmapper/text_test.go b/pkg/processor/mappers/propsmapper/text_test.go new file mode 100644 index 00000000..9426b76e --- /dev/null +++ b/pkg/processor/mappers/propsmapper/text_test.go @@ -0,0 +1 @@ +package propsmapper_test From e0068d5ff454366d962ae454838be07076aecc23 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 22 Oct 2024 20:53:50 -0300 Subject: [PATCH 028/116] test: validate barcode component creation --- .../components/codemapper/barcode_test.go | 92 ++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/pkg/processor/mappers/components/codemapper/barcode_test.go b/pkg/processor/mappers/components/codemapper/barcode_test.go index de28111d..94d0e753 100644 --- a/pkg/processor/mappers/components/codemapper/barcode_test.go +++ b/pkg/processor/mappers/components/codemapper/barcode_test.go @@ -1,2 +1,92 @@ -// nolint: dupl package codemapper_test + +import ( + "testing" + + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/codemapper" + "github.com/stretchr/testify/assert" +) + +func TestNewBarcode(t *testing.T) { + t.Run("when props is not sent, barcode is created", func(t *testing.T) { + barcodeTemplate := map[string]interface{}{ + "code": "123456789", + } + + barcode, err := codemapper.NewBarcode(barcodeTemplate) + + assert.Nil(t, err) + assert.NotNil(t, barcode) + }) + t.Run("when invalid props is sent, should return an error", func(t *testing.T) { + barcodeTemplate := map[string]interface{}{ + "props": 1, + "code": "123456789", + } + + barcode, err := codemapper.NewBarcode(barcodeTemplate) + + assert.Nil(t, barcode) + assert.NotNil(t, err) + }) + t.Run("when invalid field is sent, should return an error", func(t *testing.T) { + barcodeTemplate := map[string]interface{}{ + "invalid_field": 1, + "code": "123456789", + } + + barcode, err := codemapper.NewBarcode(barcodeTemplate) + + assert.Nil(t, barcode) + assert.NotNil(t, err) + }) + t.Run("when source_key and code are not sent, should return an error", func(t *testing.T) { + barcodeTemplate := map[string]interface{}{} + + barcode, err := codemapper.NewBarcode(barcodeTemplate) + + assert.Nil(t, barcode) + assert.NotNil(t, err) + }) + t.Run("when invalid code is sent, should return an error", func(t *testing.T) { + barcodeTemplate := map[string]interface{}{ + "code": 123, + } + + barcode, err := codemapper.NewBarcode(barcodeTemplate) + + assert.Nil(t, barcode) + assert.NotNil(t, err) + }) + t.Run("when invalid source_key is sent, should return an error", func(t *testing.T) { + barcodeTemplate := map[string]interface{}{ + "source_key": 123, + } + + barcode, err := codemapper.NewBarcode(barcodeTemplate) + + assert.Nil(t, barcode) + assert.NotNil(t, err) + }) + t.Run("when code is not sent, should add source key", func(t *testing.T) { + barcodeTemplate := map[string]interface{}{ + "source_key": "source", + } + + barcode, err := codemapper.NewBarcode(barcodeTemplate) + + assert.Nil(t, err) + assert.Equal(t, barcode.SourceKey, "source") + }) + + t.Run("when source_key is not sent, should add code", func(t *testing.T) { + barcodeTemplate := map[string]interface{}{ + "code": "code", + } + + barcode, err := codemapper.NewBarcode(barcodeTemplate) + + assert.Nil(t, err) + assert.Equal(t, barcode.Code, "code") + }) +} From f76f2638791b42eddbaa71e694da5d418d2c08a2 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 22 Oct 2024 20:54:34 -0300 Subject: [PATCH 029/116] feat: create barcode from map --- .../mappers/components/codemapper/barcode.go | 90 ++++++++++++++++++- .../mappers/components/rowmapper/row.go | 2 + pkg/processor/mappers/propsmapper/barcode.go | 8 +- .../mappers/propsmapper/convert_fields.go | 2 + 4 files changed, 96 insertions(+), 6 deletions(-) diff --git a/pkg/processor/mappers/components/codemapper/barcode.go b/pkg/processor/mappers/components/codemapper/barcode.go index 121329f5..fff21dbc 100644 --- a/pkg/processor/mappers/components/codemapper/barcode.go +++ b/pkg/processor/mappers/components/codemapper/barcode.go @@ -1,12 +1,96 @@ // codemapper code implements creation of Barcode, MatrixCode and QrCode. package codemapper -import "github.com/johnfercher/maroto/v2/pkg/processor/components" +import ( + "fmt" -type Barcode struct{} + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" +) + +type Barcode struct { + SourceKey string + Code string + Props *propsmapper.Barcode +} func NewBarcode(code interface{}) (*Barcode, error) { - return nil, nil + barcodeMap, ok := code.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("ensure barcode can be converted to map[string] interface{}") + } + + barcode := &Barcode{} + if err := barcode.addFields(barcodeMap); err != nil { + return nil, err + } + if err := barcode.validateFields(); err != nil { + return nil, err + } + + return barcode, nil +} + +// addFields is responsible for adding the barcode fields according to +// the properties informed in the map +func (b *Barcode) addFields(mapRows map[string]interface{}) error { + fieldMappers := b.getFieldMappers() + + for templateName, template := range mapRows { + mapper, ok := fieldMappers[templateName] + if !ok { + return fmt.Errorf("the field %s present in the barcode cannot be mapped to any valid field", templateName) + } + err := mapper(template) + if err != nil { + return err + } + } + return nil +} + +// getFieldMappers is responsible for defining which methods are responsible for assembling which components. +// To do this, the component name is linked to a function in a Map. +func (b *Barcode) getFieldMappers() map[string]func(interface{}) error { + return map[string]func(interface{}) error{ + "source_key": b.setSourceKey, + "code": b.setCode, + "props": b.setProps, + } +} + +func (b *Barcode) setSourceKey(template interface{}) error { + sourceKey, ok := template.(string) + if !ok { + return fmt.Errorf("source_key cannot be converted to a string") + } + b.SourceKey = sourceKey + return nil +} + +func (b *Barcode) setCode(template interface{}) error { + code, ok := template.(string) + if !ok { + return fmt.Errorf("code cannot be converted to a string") + } + b.Code = code + return nil +} + +func (b *Barcode) setProps(template interface{}) error { + props, err := propsmapper.NewBarcode(template) + if err != nil { + return err + } + b.Props = props + return nil +} + +func (b *Barcode) validateFields() error { + if b.Code == "" && b.SourceKey == "" { + return fmt.Errorf("no value passed for barcode. Add the 'source_key' or a code") + } + return nil } func (b *Barcode) Generate(content map[string]interface{}) (components.PdfComponent, error) { diff --git a/pkg/processor/mappers/components/rowmapper/row.go b/pkg/processor/mappers/components/rowmapper/row.go index b7002623..a6850829 100644 --- a/pkg/processor/mappers/components/rowmapper/row.go +++ b/pkg/processor/mappers/components/rowmapper/row.go @@ -32,6 +32,8 @@ func NewRow(templateRows interface{}, sourceKey string, factory mappers.Abstract return row, nil } +// addComponents is responsible for adding the row components according to +// the properties informed in the map func (r *Row) addComponents(mapRows map[string]interface{}) error { fieldMappers := r.getFieldMappers() diff --git a/pkg/processor/mappers/propsmapper/barcode.go b/pkg/processor/mappers/propsmapper/barcode.go index 94867dee..2fefbb39 100644 --- a/pkg/processor/mappers/propsmapper/barcode.go +++ b/pkg/processor/mappers/propsmapper/barcode.go @@ -1,5 +1,7 @@ package propsmapper +import "fmt" + // Barcode represents properties from a barcode inside a cell. type Barcode struct { // Left is the space between the left cell boundary to the barcode, if center is false. @@ -21,10 +23,10 @@ type Barcode struct { // NewBarcode is responsible for creating the barcode, if the font fields cannot be // converted, an invalid value is set. -func NewBarcode(barcode interface{}) *Barcode { +func NewBarcode(barcode interface{}) (*Barcode, error) { barcodeMap, ok := barcode.(map[string]interface{}) if !ok { - return nil + return nil, fmt.Errorf("ensure barcode props can be converted to map[string] interface{}") } return &Barcode{ @@ -34,5 +36,5 @@ func NewBarcode(barcode interface{}) *Barcode { Proportion: *NewProportion(barcodeMap["proportion"]), Center: *convertFields(barcodeMap["center"], false), Type: NewCodeType(*convertFields(barcodeMap["type"], "")), - } + }, nil } diff --git a/pkg/processor/mappers/propsmapper/convert_fields.go b/pkg/processor/mappers/propsmapper/convert_fields.go index 6385f49e..1abc0a92 100644 --- a/pkg/processor/mappers/propsmapper/convert_fields.go +++ b/pkg/processor/mappers/propsmapper/convert_fields.go @@ -2,6 +2,8 @@ package propsmapper import "time" +// convertFields is responsible for converting a value to a type. +// if it is not possible to convert, a default value is used func convertFields[T any](val interface{}, defaultValue T) *T { result, ok := val.(T) if !ok { From ebca07e551ea3ede3401195d832d1b0845d54a3b Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 22 Oct 2024 21:06:37 -0300 Subject: [PATCH 030/116] test: validate matrixcode component creation --- .../components/codemapper/matrixcode_test.go | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/pkg/processor/mappers/components/codemapper/matrixcode_test.go b/pkg/processor/mappers/components/codemapper/matrixcode_test.go index cf962105..45bfd4c4 100644 --- a/pkg/processor/mappers/components/codemapper/matrixcode_test.go +++ b/pkg/processor/mappers/components/codemapper/matrixcode_test.go @@ -1 +1,92 @@ package codemapper_test + +import ( + "testing" + + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/codemapper" + "github.com/stretchr/testify/assert" +) + +func TestNewMatrixcode(t *testing.T) { + t.Run("when props is not sent, matrixcode is created", func(t *testing.T) { + matrixcodeTemplate := map[string]interface{}{ + "code": "123456789", + } + + matrixcode, err := codemapper.NewMatrixcode(matrixcodeTemplate) + + assert.Nil(t, err) + assert.NotNil(t, matrixcode) + }) + t.Run("when invalid props is sent, should return an error", func(t *testing.T) { + matrixcodeTemplate := map[string]interface{}{ + "props": 1, + "code": "123456789", + } + + matrixcode, err := codemapper.NewMatrixcode(matrixcodeTemplate) + + assert.Nil(t, matrixcode) + assert.NotNil(t, err) + }) + t.Run("when invalid field is sent, should return an error", func(t *testing.T) { + matrixcodeTemplate := map[string]interface{}{ + "invalid_field": 1, + "code": "123456789", + } + + matrixcode, err := codemapper.NewMatrixcode(matrixcodeTemplate) + + assert.Nil(t, matrixcode) + assert.NotNil(t, err) + }) + t.Run("when source_key and code are not sent, should return an error", func(t *testing.T) { + matrixcodeTemplate := map[string]interface{}{} + + matrixcode, err := codemapper.NewMatrixcode(matrixcodeTemplate) + + assert.Nil(t, matrixcode) + assert.NotNil(t, err) + }) + t.Run("when invalid code is sent, should return an error", func(t *testing.T) { + matrixcodeTemplate := map[string]interface{}{ + "code": 123, + } + + matrixcode, err := codemapper.NewMatrixcode(matrixcodeTemplate) + + assert.Nil(t, matrixcode) + assert.NotNil(t, err) + }) + t.Run("when invalid source_key is sent, should return an error", func(t *testing.T) { + matrixcodeTemplate := map[string]interface{}{ + "source_key": 123, + } + + matrixcode, err := codemapper.NewMatrixcode(matrixcodeTemplate) + + assert.Nil(t, matrixcode) + assert.NotNil(t, err) + }) + t.Run("when code is not sent, should add source key", func(t *testing.T) { + matrixcodeTemplate := map[string]interface{}{ + "source_key": "source", + } + + matrixcode, err := codemapper.NewMatrixcode(matrixcodeTemplate) + + assert.Nil(t, err) + assert.Equal(t, matrixcode.SourceKey, "source") + }) + + t.Run("when source_key is not sent, should add code", func(t *testing.T) { + matrixcodeTemplate := map[string]interface{}{ + "code": "code", + } + + matrixcode, err := codemapper.NewMatrixcode(matrixcodeTemplate) + + assert.Nil(t, err) + assert.Equal(t, matrixcode.Code, "code") + }) +} From 65b0170315bd4b44bc22f81780b44a29f5f57e5a Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 22 Oct 2024 21:07:13 -0300 Subject: [PATCH 031/116] feat: create matrixcode from map --- .../components/codemapper/matrixcode.go | 94 ++++++++++++++++++- pkg/processor/mappers/propsmapper/rect.go | 8 +- 2 files changed, 94 insertions(+), 8 deletions(-) diff --git a/pkg/processor/mappers/components/codemapper/matrixcode.go b/pkg/processor/mappers/components/codemapper/matrixcode.go index 87a5f52d..edd0a60e 100644 --- a/pkg/processor/mappers/components/codemapper/matrixcode.go +++ b/pkg/processor/mappers/components/codemapper/matrixcode.go @@ -1,14 +1,98 @@ -// Package codemapper implements creation of Barcode, MatrixCode and QrCode. +// Package codemapper implements creation of matrixCode, MatrixCode and QrCode. package codemapper -import "github.com/johnfercher/maroto/v2/pkg/processor/components" +import ( + "fmt" -type Matrixcode struct{} + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" +) + +type Matrixcode struct { + SourceKey string + Code string + Props *propsmapper.Rect +} func NewMatrixcode(code interface{}) (*Matrixcode, error) { - return nil, nil + matrixcodeMap, ok := code.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("ensure matrixcode can be converted to map[string] interface{}") + } + + matrixCode := &Matrixcode{} + if err := matrixCode.addFields(matrixcodeMap); err != nil { + return nil, err + } + if err := matrixCode.validateFields(); err != nil { + return nil, err + } + + return matrixCode, nil +} + +// addFields is responsible for adding the matrix code fields according to +// the properties informed in the map +func (m *Matrixcode) addFields(mapRows map[string]interface{}) error { + fieldMappers := m.getFieldMappers() + + for templateName, template := range mapRows { + mapper, ok := fieldMappers[templateName] + if !ok { + return fmt.Errorf("the field %s present in the matrix code cannot be mapped to any valid field", templateName) + } + err := mapper(template) + if err != nil { + return err + } + } + return nil +} + +// getFieldMappers is responsible for defining which methods are responsible for assembling which components. +// To do this, the component name is linked to a function in a Map. +func (m *Matrixcode) getFieldMappers() map[string]func(interface{}) error { + return map[string]func(interface{}) error{ + "source_key": m.setSourceKey, + "code": m.setCode, + "props": m.setProps, + } +} + +func (m *Matrixcode) setSourceKey(template interface{}) error { + sourceKey, ok := template.(string) + if !ok { + return fmt.Errorf("source_key cannot be converted to a string") + } + m.SourceKey = sourceKey + return nil +} + +func (m *Matrixcode) setCode(template interface{}) error { + code, ok := template.(string) + if !ok { + return fmt.Errorf("code cannot be converted to a string") + } + m.Code = code + return nil +} + +func (m *Matrixcode) setProps(template interface{}) error { + props, err := propsmapper.NewRect(template) + if err != nil { + return err + } + m.Props = props + return nil +} + +func (m *Matrixcode) validateFields() error { + if m.Code == "" && m.SourceKey == "" { + return fmt.Errorf("no value passed for matrixCode. Add the 'source_key' or a code") + } + return nil } -func (b *Matrixcode) Generate(content map[string]interface{}) (components.PdfComponent, error) { +func (m *Matrixcode) Generate(content map[string]interface{}) (components.PdfComponent, error) { return nil, nil } diff --git a/pkg/processor/mappers/propsmapper/rect.go b/pkg/processor/mappers/propsmapper/rect.go index 9f2eb161..63206f66 100644 --- a/pkg/processor/mappers/propsmapper/rect.go +++ b/pkg/processor/mappers/propsmapper/rect.go @@ -1,5 +1,7 @@ package propsmapper +import "fmt" + // Rect represents properties from a rectangle (Image, QrCode or Barcode) inside a cell. type Rect struct { // Left is the space between the left cell boundary to the rectangle, if center is false. @@ -19,10 +21,10 @@ type Rect struct { // NewRect is responsible for creating the Rect, if the font fields cannot be // converted, an invalid value is set. -func NewRect(rect interface{}) *Rect { +func NewRect(rect interface{}) (*Rect, error) { rectMap, ok := rect.(map[string]interface{}) if !ok { - return nil + return nil, fmt.Errorf("ensure matrix code props can be converted to map[string] interface{}") } return &Rect{ @@ -31,5 +33,5 @@ func NewRect(rect interface{}) *Rect { Percent: *convertFields(rectMap["percent"], -1.0), JustReferenceWidth: *convertFields(rectMap["just_reference_width"], false), Center: *convertFields(rectMap["center"], false), - } + }, nil } From ddedb1e3ad950245409ff4a82a2093be304fd6dc Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 22 Oct 2024 21:17:27 -0300 Subject: [PATCH 032/116] test: validate qrcode component creation --- .../components/codemapper/barcode_test.go | 8 ++ .../components/codemapper/matrixcode_test.go | 8 ++ .../components/codemapper/qrcode_test.go | 99 +++++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/pkg/processor/mappers/components/codemapper/barcode_test.go b/pkg/processor/mappers/components/codemapper/barcode_test.go index 94d0e753..d451dcd8 100644 --- a/pkg/processor/mappers/components/codemapper/barcode_test.go +++ b/pkg/processor/mappers/components/codemapper/barcode_test.go @@ -8,6 +8,14 @@ import ( ) func TestNewBarcode(t *testing.T) { + t.Run("when invalid barcode is sent, should return an error", func(t *testing.T) { + barcodeTemplate := 1 + + barcode, err := codemapper.NewMatrixcode(barcodeTemplate) + + assert.Nil(t, barcode) + assert.NotNil(t, err) + }) t.Run("when props is not sent, barcode is created", func(t *testing.T) { barcodeTemplate := map[string]interface{}{ "code": "123456789", diff --git a/pkg/processor/mappers/components/codemapper/matrixcode_test.go b/pkg/processor/mappers/components/codemapper/matrixcode_test.go index 45bfd4c4..3fe0f82d 100644 --- a/pkg/processor/mappers/components/codemapper/matrixcode_test.go +++ b/pkg/processor/mappers/components/codemapper/matrixcode_test.go @@ -8,6 +8,14 @@ import ( ) func TestNewMatrixcode(t *testing.T) { + t.Run("when invalid matrixcode is sent, should return an error", func(t *testing.T) { + matrixcodeTemplate := 1 + + matrixcode, err := codemapper.NewMatrixcode(matrixcodeTemplate) + + assert.Nil(t, matrixcode) + assert.NotNil(t, err) + }) t.Run("when props is not sent, matrixcode is created", func(t *testing.T) { matrixcodeTemplate := map[string]interface{}{ "code": "123456789", diff --git a/pkg/processor/mappers/components/codemapper/qrcode_test.go b/pkg/processor/mappers/components/codemapper/qrcode_test.go index cf962105..3409d734 100644 --- a/pkg/processor/mappers/components/codemapper/qrcode_test.go +++ b/pkg/processor/mappers/components/codemapper/qrcode_test.go @@ -1 +1,100 @@ package codemapper_test + +import ( + "testing" + + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/codemapper" + "github.com/stretchr/testify/assert" +) + +func TestNewQrCode(t *testing.T) { + t.Run("when invalid qrcode is sent, should return an error", func(t *testing.T) { + qrcodeTemplate := 1 + + qrcode, err := codemapper.NewQrcode(qrcodeTemplate) + + assert.Nil(t, qrcode) + assert.NotNil(t, err) + }) + t.Run("when props is not sent, should create qrcode", func(t *testing.T) { + qrcodeTemplate := map[string]interface{}{ + "code": "123456789", + } + + qrcode, err := codemapper.NewQrcode(qrcodeTemplate) + + assert.Nil(t, err) + assert.NotNil(t, qrcode) + }) + t.Run("when invalid props is sent, should return an error", func(t *testing.T) { + qrcodeTemplate := map[string]interface{}{ + "props": 1, + "code": "123456789", + } + + qrcode, err := codemapper.NewQrcode(qrcodeTemplate) + + assert.Nil(t, qrcode) + assert.NotNil(t, err) + }) + t.Run("when invalid field is sent, should return an error", func(t *testing.T) { + qrcodeTemplate := map[string]interface{}{ + "invalid_field": 1, + "code": "123456789", + } + + qrcode, err := codemapper.NewQrcode(qrcodeTemplate) + + assert.Nil(t, qrcode) + assert.NotNil(t, err) + }) + t.Run("when source_key and code are not sent, should return an error", func(t *testing.T) { + qrcodeTemplate := map[string]interface{}{} + + qrcode, err := codemapper.NewQrcode(qrcodeTemplate) + + assert.Nil(t, qrcode) + assert.NotNil(t, err) + }) + t.Run("when invalid code is sent, should return an error", func(t *testing.T) { + qrcodeTemplate := map[string]interface{}{ + "code": 123, + } + + qrcode, err := codemapper.NewQrcode(qrcodeTemplate) + + assert.Nil(t, qrcode) + assert.NotNil(t, err) + }) + t.Run("when invalid source_key is sent, should return an error", func(t *testing.T) { + qrcodeTemplate := map[string]interface{}{ + "source_key": 123, + } + + qrcode, err := codemapper.NewQrcode(qrcodeTemplate) + + assert.Nil(t, qrcode) + assert.NotNil(t, err) + }) + t.Run("when code is not sent, should add source key", func(t *testing.T) { + qrcodeTemplate := map[string]interface{}{ + "source_key": "source", + } + + qrcode, err := codemapper.NewQrcode(qrcodeTemplate) + + assert.Nil(t, err) + assert.Equal(t, qrcode.SourceKey, "source") + }) + + t.Run("when source_key is not sent, should add code", func(t *testing.T) { + qrcodeTemplate := map[string]interface{}{ + "code": "code", + } + + qrcode, err := codemapper.NewQrcode(qrcodeTemplate) + + assert.Nil(t, err) + assert.Equal(t, qrcode.Code, "code") + }) +} From f0f2e43ebfb987b43981afb86522fa0ac748e462 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 22 Oct 2024 21:18:15 -0300 Subject: [PATCH 033/116] feat: create qrcode from map --- .../mappers/components/codemapper/qrcode.go | 94 ++++++++++++++++++- 1 file changed, 89 insertions(+), 5 deletions(-) diff --git a/pkg/processor/mappers/components/codemapper/qrcode.go b/pkg/processor/mappers/components/codemapper/qrcode.go index f8a7e0ee..df5eee62 100644 --- a/pkg/processor/mappers/components/codemapper/qrcode.go +++ b/pkg/processor/mappers/components/codemapper/qrcode.go @@ -1,14 +1,98 @@ -// Package codemapper implements creation of Barcode, MatrixCode and QrCode. +// Package codemapper implements creation of qrcode, MatrixCode and QrCode. package codemapper -import "github.com/johnfercher/maroto/v2/pkg/processor/components" +import ( + "fmt" -type Qrcode struct{} + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" +) + +type Qrcode struct { + SourceKey string + Code string + Props *propsmapper.Rect +} func NewQrcode(code interface{}) (*Qrcode, error) { - return nil, nil + qrcodeMap, ok := code.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("ensure qrcode can be converted to map[string] interface{}") + } + + qrcode := &Qrcode{} + if err := qrcode.addFields(qrcodeMap); err != nil { + return nil, err + } + if err := qrcode.validateFields(); err != nil { + return nil, err + } + + return qrcode, nil +} + +// addFields is responsible for adding the qrcode fields according to +// the properties informed in the map +func (b *Qrcode) addFields(mapRows map[string]interface{}) error { + fieldMappers := b.getFieldMappers() + + for templateName, template := range mapRows { + mapper, ok := fieldMappers[templateName] + if !ok { + return fmt.Errorf("the field %s present in the qrcode cannot be mapped to any valid field", templateName) + } + err := mapper(template) + if err != nil { + return err + } + } + return nil +} + +// getFieldMappers is responsible for defining which methods are responsible for assembling which components. +// To do this, the component name is linked to a function in a Map. +func (b *Qrcode) getFieldMappers() map[string]func(interface{}) error { + return map[string]func(interface{}) error{ + "source_key": b.setSourceKey, + "code": b.setCode, + "props": b.setProps, + } +} + +func (b *Qrcode) setSourceKey(template interface{}) error { + sourceKey, ok := template.(string) + if !ok { + return fmt.Errorf("source_key cannot be converted to a string") + } + b.SourceKey = sourceKey + return nil +} + +func (b *Qrcode) setCode(template interface{}) error { + code, ok := template.(string) + if !ok { + return fmt.Errorf("code cannot be converted to a string") + } + b.Code = code + return nil +} + +func (b *Qrcode) setProps(template interface{}) error { + props, err := propsmapper.NewRect(template) + if err != nil { + return err + } + b.Props = props + return nil +} + +func (b *Qrcode) validateFields() error { + if b.Code == "" && b.SourceKey == "" { + return fmt.Errorf("no value passed for qrcode. Add the 'source_key' or a code") + } + return nil } -func (b *Qrcode) Generate(content map[string]interface{}) (components.PdfComponent, error) { +func (q *Qrcode) Generate(content map[string]interface{}) (components.PdfComponent, error) { return nil, nil } From e355c2fb43b3a9fb5d249d6bc6b7e134c6758048 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 22 Oct 2024 21:55:47 -0300 Subject: [PATCH 034/116] test: validate line component creation --- .../components/linemapper/line_test.go | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/pkg/processor/mappers/components/linemapper/line_test.go b/pkg/processor/mappers/components/linemapper/line_test.go index d44fe8a1..d989e2d9 100644 --- a/pkg/processor/mappers/components/linemapper/line_test.go +++ b/pkg/processor/mappers/components/linemapper/line_test.go @@ -1,2 +1,49 @@ // Package line implements creation of lines. package linemapper_test + +import ( + "testing" + + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/linemapper" + "github.com/stretchr/testify/assert" +) + +func TestNewLine(t *testing.T) { + t.Run("when invalid line is sent, should return an error", func(t *testing.T) { + lineTemplate := 1 + + line, err := linemapper.NewLine(lineTemplate) + + assert.Nil(t, line) + assert.NotNil(t, err) + }) + t.Run("when props is not sent, line is created", func(t *testing.T) { + lineTemplate := map[string]interface{}{} + + line, err := linemapper.NewLine(lineTemplate) + + assert.Nil(t, err) + assert.NotNil(t, line) + }) + t.Run("when invalid props is sent, should return an error", func(t *testing.T) { + lineTemplate := map[string]interface{}{ + "props": 1, + } + + line, err := linemapper.NewLine(lineTemplate) + + assert.Nil(t, line) + assert.NotNil(t, err) + }) + t.Run("when invalid field is sent, should return an error", func(t *testing.T) { + lineTemplate := map[string]interface{}{ + "invalid_field": 1, + "code": "123456789", + } + + line, err := linemapper.NewLine(lineTemplate) + + assert.Nil(t, line) + assert.NotNil(t, err) + }) +} From 51cd9652a7b71a65f11d2cec686bf56ed917c1a2 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 22 Oct 2024 21:56:03 -0300 Subject: [PATCH 035/116] feat: create line from map --- .../mappers/components/linemapper/line.go | 57 ++++++++++++++++++- pkg/processor/mappers/propsmapper/line.go | 8 ++- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/pkg/processor/mappers/components/linemapper/line.go b/pkg/processor/mappers/components/linemapper/line.go index 2e39278e..8de66786 100644 --- a/pkg/processor/mappers/components/linemapper/line.go +++ b/pkg/processor/mappers/components/linemapper/line.go @@ -1,12 +1,63 @@ // Package line implements creation of lines. package linemapper -import "github.com/johnfercher/maroto/v2/pkg/processor/components" +import ( + "fmt" -type Line struct{} + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" +) + +type Line struct { + Props *propsmapper.Line +} func NewLine(code interface{}) (*Line, error) { - return nil, nil + lineMapper, ok := code.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("ensure line can be converted to map[string] interface{}") + } + line := &Line{} + + if err := line.addFields(lineMapper); err != nil { + return nil, err + } + return line, nil +} + +// addFields is responsible for adding the barcode fields according to +// the properties informed in the map +func (l *Line) addFields(lineMapper map[string]interface{}) error { + fieldMappers := l.getFieldMappers() + + for templateName, template := range lineMapper { + mapper, ok := fieldMappers[templateName] + if !ok { + return fmt.Errorf("the field %s present in the line cannot be mapped to any valid field", templateName) + } + err := mapper(template) + if err != nil { + return err + } + } + return nil +} + +// getFieldMappers is responsible for defining which methods are responsible for assembling which components. +// To do this, the component name is linked to a function in a Map. +func (l *Line) getFieldMappers() map[string]func(interface{}) error { + return map[string]func(interface{}) error{ + "props": l.setProps, + } +} + +func (l *Line) setProps(templateProps interface{}) error { + propsLine, err := propsmapper.NewLine(templateProps) + if err != nil { + return err + } + l.Props = propsLine + return nil } func (b *Line) Generate(content map[string]interface{}) (components.PdfComponent, error) { diff --git a/pkg/processor/mappers/propsmapper/line.go b/pkg/processor/mappers/propsmapper/line.go index 269dd25c..2e63a2ad 100644 --- a/pkg/processor/mappers/propsmapper/line.go +++ b/pkg/processor/mappers/propsmapper/line.go @@ -1,5 +1,7 @@ package propsmapper +import "fmt" + // Line represents properties from a Line inside a cell. type Line struct { // Color define the line color. @@ -18,10 +20,10 @@ type Line struct { // NewLine is responsible for creating the Line, if the font fields cannot be // converted, an invalid value is set. -func NewLine(line interface{}) *Line { +func NewLine(line interface{}) (*Line, error) { lineMap, ok := line.(map[string]interface{}) if !ok { - return nil + return nil, fmt.Errorf("ensure line props can be converted to map[string] interface{}") } return &Line{ @@ -31,5 +33,5 @@ func NewLine(line interface{}) *Line { Orientation: NewOrientation(*convertFields(lineMap["orientation"], "")), OffsetPercent: *convertFields(lineMap["offset_percent"], -1.0), SizePercent: *convertFields(lineMap["size_percent"], -1.0), - } + }, nil } From c2da8018f9bb3495fd37a726fae18b0ff12c6aec Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 22 Oct 2024 21:56:24 -0300 Subject: [PATCH 036/116] refactor: update parameter name --- pkg/processor/mappers/components/codemapper/barcode.go | 4 ++-- pkg/processor/mappers/components/codemapper/matrixcode.go | 4 ++-- pkg/processor/mappers/components/codemapper/qrcode.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/processor/mappers/components/codemapper/barcode.go b/pkg/processor/mappers/components/codemapper/barcode.go index fff21dbc..cd145b5a 100644 --- a/pkg/processor/mappers/components/codemapper/barcode.go +++ b/pkg/processor/mappers/components/codemapper/barcode.go @@ -33,10 +33,10 @@ func NewBarcode(code interface{}) (*Barcode, error) { // addFields is responsible for adding the barcode fields according to // the properties informed in the map -func (b *Barcode) addFields(mapRows map[string]interface{}) error { +func (b *Barcode) addFields(codeMap map[string]interface{}) error { fieldMappers := b.getFieldMappers() - for templateName, template := range mapRows { + for templateName, template := range codeMap { mapper, ok := fieldMappers[templateName] if !ok { return fmt.Errorf("the field %s present in the barcode cannot be mapped to any valid field", templateName) diff --git a/pkg/processor/mappers/components/codemapper/matrixcode.go b/pkg/processor/mappers/components/codemapper/matrixcode.go index edd0a60e..6029b0e0 100644 --- a/pkg/processor/mappers/components/codemapper/matrixcode.go +++ b/pkg/processor/mappers/components/codemapper/matrixcode.go @@ -33,10 +33,10 @@ func NewMatrixcode(code interface{}) (*Matrixcode, error) { // addFields is responsible for adding the matrix code fields according to // the properties informed in the map -func (m *Matrixcode) addFields(mapRows map[string]interface{}) error { +func (m *Matrixcode) addFields(codeMap map[string]interface{}) error { fieldMappers := m.getFieldMappers() - for templateName, template := range mapRows { + for templateName, template := range codeMap { mapper, ok := fieldMappers[templateName] if !ok { return fmt.Errorf("the field %s present in the matrix code cannot be mapped to any valid field", templateName) diff --git a/pkg/processor/mappers/components/codemapper/qrcode.go b/pkg/processor/mappers/components/codemapper/qrcode.go index df5eee62..c1d4406c 100644 --- a/pkg/processor/mappers/components/codemapper/qrcode.go +++ b/pkg/processor/mappers/components/codemapper/qrcode.go @@ -33,10 +33,10 @@ func NewQrcode(code interface{}) (*Qrcode, error) { // addFields is responsible for adding the qrcode fields according to // the properties informed in the map -func (b *Qrcode) addFields(mapRows map[string]interface{}) error { +func (b *Qrcode) addFields(codeMap map[string]interface{}) error { fieldMappers := b.getFieldMappers() - for templateName, template := range mapRows { + for templateName, template := range codeMap { mapper, ok := fieldMappers[templateName] if !ok { return fmt.Errorf("the field %s present in the qrcode cannot be mapped to any valid field", templateName) From c34333e318e5c959176532af7f7a707cb56d4d88 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 22 Oct 2024 22:11:52 -0300 Subject: [PATCH 037/116] test: validate line component creation --- .../signaturemapper/signature_test.go | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/pkg/processor/mappers/components/signaturemapper/signature_test.go b/pkg/processor/mappers/components/signaturemapper/signature_test.go index 19b4aa4a..7938a783 100644 --- a/pkg/processor/mappers/components/signaturemapper/signature_test.go +++ b/pkg/processor/mappers/components/signaturemapper/signature_test.go @@ -1 +1,99 @@ package signaturemapper_test + +import ( + "testing" + + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/signaturemapper" + "github.com/stretchr/testify/assert" +) + +func TestNewSignature(t *testing.T) { + t.Run("when invalid signature is sent, should return an error", func(t *testing.T) { + signatureTemplate := 1 + + signature, err := signaturemapper.NewSignature(signatureTemplate) + + assert.Nil(t, signature) + assert.NotNil(t, err) + }) + t.Run("when props is not sent, signature is created", func(t *testing.T) { + signatureTemplate := map[string]interface{}{ + "value": "123456789", + } + + signature, err := signaturemapper.NewSignature(signatureTemplate) + + assert.Nil(t, err) + assert.NotNil(t, signature) + }) + t.Run("when invalid props is sent, should return an error", func(t *testing.T) { + signatureTemplate := map[string]interface{}{ + "props": 1, + "value": "123456789", + } + + signature, err := signaturemapper.NewSignature(signatureTemplate) + + assert.Nil(t, signature) + assert.NotNil(t, err) + }) + t.Run("when invalid field is sent, should return an error", func(t *testing.T) { + signatureTemplate := map[string]interface{}{ + "invalid_field": 1, + } + + signature, err := signaturemapper.NewSignature(signatureTemplate) + + assert.Nil(t, signature) + assert.NotNil(t, err) + }) + t.Run("when source_key and value are not sent, should return an error", func(t *testing.T) { + signatureTemplate := map[string]interface{}{} + + signature, err := signaturemapper.NewSignature(signatureTemplate) + + assert.Nil(t, signature) + assert.NotNil(t, err) + }) + t.Run("when invalid value is sent, should return an error", func(t *testing.T) { + signatureTemplate := map[string]interface{}{ + "value": 123, + } + + signature, err := signaturemapper.NewSignature(signatureTemplate) + + assert.Nil(t, signature) + assert.NotNil(t, err) + }) + t.Run("when invalid source_key is sent, should return an error", func(t *testing.T) { + signatureTemplate := map[string]interface{}{ + "source_key": 123, + } + + signature, err := signaturemapper.NewSignature(signatureTemplate) + + assert.Nil(t, signature) + assert.NotNil(t, err) + }) + t.Run("when value is not sent, should add source key", func(t *testing.T) { + signatureTemplate := map[string]interface{}{ + "source_key": "source", + } + + signature, err := signaturemapper.NewSignature(signatureTemplate) + + assert.Nil(t, err) + assert.Equal(t, signature.SourceKey, "source") + }) + + t.Run("when source_key is not sent, should add code", func(t *testing.T) { + signatureTemplate := map[string]interface{}{ + "value": "value", + } + + signature, err := signaturemapper.NewSignature(signatureTemplate) + + assert.Nil(t, err) + assert.Equal(t, signature.Value, "value") + }) +} From 2a2c65f22a751caa560c0ffe1948d2d8d7c07c34 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 22 Oct 2024 22:12:16 -0300 Subject: [PATCH 038/116] feat: create signature from map --- .../components/signaturemapper/signature.go | 90 ++++++++++++++++++- .../mappers/propsmapper/signature.go | 8 +- 2 files changed, 92 insertions(+), 6 deletions(-) diff --git a/pkg/processor/mappers/components/signaturemapper/signature.go b/pkg/processor/mappers/components/signaturemapper/signature.go index a8070d24..5e6d7f9e 100644 --- a/pkg/processor/mappers/components/signaturemapper/signature.go +++ b/pkg/processor/mappers/components/signaturemapper/signature.go @@ -1,12 +1,96 @@ // Package signature implements creation of signatures. package signaturemapper -import "github.com/johnfercher/maroto/v2/pkg/processor/components" +import ( + "fmt" -type Signature struct{} + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" +) + +type Signature struct { + SourceKey string + Value string + Props *propsmapper.Signature +} func NewSignature(code interface{}) (*Signature, error) { - return nil, nil + signatureMap, ok := code.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("ensure signature can be converted to map[string] interface{}") + } + + signature := &Signature{} + if err := signature.addFields(signatureMap); err != nil { + return nil, err + } + if err := signature.validateFields(); err != nil { + return nil, err + } + + return signature, nil +} + +// addFields is responsible for adding the signature fields according to +// the properties informed in the map +func (s *Signature) addFields(csignatureMap map[string]interface{}) error { + fieldMappers := s.getFieldMappers() + + for templateName, template := range csignatureMap { + mapper, ok := fieldMappers[templateName] + if !ok { + return fmt.Errorf("the field %s present in the signature cannot be mapped to any valid field", templateName) + } + err := mapper(template) + if err != nil { + return err + } + } + return nil +} + +// getFieldMappers is responsible for defining which methods are responsible for assembling which components. +// To do this, the component name is linked to a function in a Map. +func (s *Signature) getFieldMappers() map[string]func(interface{}) error { + return map[string]func(interface{}) error{ + "source_key": s.setSourceKey, + "value": s.setValue, + "props": s.setProps, + } +} + +func (s *Signature) setSourceKey(template interface{}) error { + sourceKey, ok := template.(string) + if !ok { + return fmt.Errorf("source_key cannot be converted to a string") + } + s.SourceKey = sourceKey + return nil +} + +func (s *Signature) setValue(template interface{}) error { + value, ok := template.(string) + if !ok { + return fmt.Errorf("value cannot be converted to a string") + } + s.Value = value + return nil +} + +func (s *Signature) setProps(template interface{}) error { + props, err := propsmapper.NewSignature(template) + if err != nil { + return err + } + s.Props = props + return nil +} + +func (s *Signature) validateFields() error { + if s.Value == "" && s.SourceKey == "" { + return fmt.Errorf("no value passed for signature. Add the 'source_key' or a value") + } + return nil } func (b *Signature) Generate(content map[string]interface{}) (components.PdfComponent, error) { diff --git a/pkg/processor/mappers/propsmapper/signature.go b/pkg/processor/mappers/propsmapper/signature.go index 83e7f080..fc1cbaeb 100644 --- a/pkg/processor/mappers/propsmapper/signature.go +++ b/pkg/processor/mappers/propsmapper/signature.go @@ -1,6 +1,8 @@ package propsmapper import ( + "fmt" + "github.com/johnfercher/maroto/v2/pkg/consts/linestyle" ) @@ -26,10 +28,10 @@ type Signature struct { // NewSignature is responsible for creating the Signature, if the font fields cannot be // converted, an invalid value is set. -func NewSignature(signature interface{}) *Signature { +func NewSignature(signature interface{}) (*Signature, error) { signatureMap, ok := signature.(map[string]interface{}) if !ok { - return nil + return nil, fmt.Errorf("ensure barcode props can be converted to map[string] interface{}") } return &Signature{ @@ -41,5 +43,5 @@ func NewSignature(signature interface{}) *Signature { LineStyle: linestyle.Type(NewLineStyle(*convertFields(signatureMap["line_style"], ""))), LineThickness: *convertFields(signatureMap["line_thickness"], 0.0), SafePadding: *convertFields(signatureMap["safe_padding"], -1.0), - } + }, nil } From 42108d6a6777cf08b9a0f48583ec4321f58ec792 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 22 Oct 2024 22:25:01 -0300 Subject: [PATCH 039/116] test: validate text component creation --- .../components/textmapper/text_test.go | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/pkg/processor/mappers/components/textmapper/text_test.go b/pkg/processor/mappers/components/textmapper/text_test.go index fdf1c835..99f5c698 100644 --- a/pkg/processor/mappers/components/textmapper/text_test.go +++ b/pkg/processor/mappers/components/textmapper/text_test.go @@ -1 +1,100 @@ package textmapper_test + +import ( + "testing" + + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/textmapper" + "github.com/stretchr/testify/assert" +) + +func TestNewText(t *testing.T) { + t.Run("when invalid text is sent, should return an error", func(t *testing.T) { + textTemplate := 1 + + text, err := textmapper.NewText(textTemplate) + + assert.Nil(t, text) + assert.NotNil(t, err) + }) + t.Run("when props is not sent, text is created", func(t *testing.T) { + textTemplate := map[string]interface{}{ + "value": "123456789", + } + + text, err := textmapper.NewText(textTemplate) + + assert.Nil(t, err) + assert.NotNil(t, text) + }) + t.Run("when invalid props is sent, should return an error", func(t *testing.T) { + textTemplate := map[string]interface{}{ + "props": 1, + "value": "123456789", + } + + text, err := textmapper.NewText(textTemplate) + + assert.Nil(t, text) + assert.NotNil(t, err) + }) + t.Run("when invalid field is sent, should return an error", func(t *testing.T) { + textTemplate := map[string]interface{}{ + "invalid_field": 1, + "value": "123456789", + } + + text, err := textmapper.NewText(textTemplate) + + assert.Nil(t, text) + assert.NotNil(t, err) + }) + t.Run("when source_key and value are not sent, should return an error", func(t *testing.T) { + textTemplate := map[string]interface{}{} + + text, err := textmapper.NewText(textTemplate) + + assert.Nil(t, text) + assert.NotNil(t, err) + }) + t.Run("when invalid value is sent, should return an error", func(t *testing.T) { + textTemplate := map[string]interface{}{ + "value": 123, + } + + text, err := textmapper.NewText(textTemplate) + + assert.Nil(t, text) + assert.NotNil(t, err) + }) + t.Run("when invalid source_key is sent, should return an error", func(t *testing.T) { + textTemplate := map[string]interface{}{ + "source_key": 123, + } + + text, err := textmapper.NewText(textTemplate) + + assert.Nil(t, text) + assert.NotNil(t, err) + }) + t.Run("when value is not sent, should add source key", func(t *testing.T) { + textTemplate := map[string]interface{}{ + "source_key": "source", + } + + text, err := textmapper.NewText(textTemplate) + + assert.Nil(t, err) + assert.Equal(t, text.SourceKey, "source") + }) + + t.Run("when source_key is not sent, should add value", func(t *testing.T) { + textTemplate := map[string]interface{}{ + "value": "value", + } + + text, err := textmapper.NewText(textTemplate) + + assert.Nil(t, err) + assert.Equal(t, text.Value, "value") + }) +} From 056853239557af7570d50d1201819d2a5d745197 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 22 Oct 2024 22:25:24 -0300 Subject: [PATCH 040/116] feat: create text from map --- .../components/signaturemapper/signature.go | 4 +- .../mappers/components/textmapper/text.go | 94 ++++++++++++++++++- pkg/processor/mappers/propsmapper/text.go | 8 +- 3 files changed, 96 insertions(+), 10 deletions(-) diff --git a/pkg/processor/mappers/components/signaturemapper/signature.go b/pkg/processor/mappers/components/signaturemapper/signature.go index 5e6d7f9e..e8fdf30c 100644 --- a/pkg/processor/mappers/components/signaturemapper/signature.go +++ b/pkg/processor/mappers/components/signaturemapper/signature.go @@ -33,10 +33,10 @@ func NewSignature(code interface{}) (*Signature, error) { // addFields is responsible for adding the signature fields according to // the properties informed in the map -func (s *Signature) addFields(csignatureMap map[string]interface{}) error { +func (s *Signature) addFields(signatureMap map[string]interface{}) error { fieldMappers := s.getFieldMappers() - for templateName, template := range csignatureMap { + for templateName, template := range signatureMap { mapper, ok := fieldMappers[templateName] if !ok { return fmt.Errorf("the field %s present in the signature cannot be mapped to any valid field", templateName) diff --git a/pkg/processor/mappers/components/textmapper/text.go b/pkg/processor/mappers/components/textmapper/text.go index b4df8a91..9b07fb68 100644 --- a/pkg/processor/mappers/components/textmapper/text.go +++ b/pkg/processor/mappers/components/textmapper/text.go @@ -1,13 +1,97 @@ package textmapper -import "github.com/johnfercher/maroto/v2/pkg/processor/components" +import ( + "fmt" -type Text struct{} + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" +) -func NewText(code interface{}) (*Text, error) { - return nil, nil +type Text struct { + SourceKey string + Value string + Props *propsmapper.Text +} + +func NewText(templateText interface{}) (*Text, error) { + textMap, ok := templateText.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("ensure text can be converted to map[string] interface{}") + } + + text := &Text{} + if err := text.addFields(textMap); err != nil { + return nil, err + } + if err := text.validateFields(); err != nil { + return nil, err + } + + return text, nil +} + +// addFields is responsible for adding the text fields according to +// the properties informed in the map +func (t *Text) addFields(valueMap map[string]interface{}) error { + fieldMappers := t.getFieldMappers() + + for templateName, template := range valueMap { + mapper, ok := fieldMappers[templateName] + if !ok { + return fmt.Errorf("the field %s present in the text cannot be mapped to any valid field", templateName) + } + err := mapper(template) + if err != nil { + return err + } + } + return nil +} + +// getFieldMappers is responsible for defining which methods are responsible for assembling which components. +// To do this, the component name is linked to a function in a Map. +func (t *Text) getFieldMappers() map[string]func(interface{}) error { + return map[string]func(interface{}) error{ + "source_key": t.setSourceKey, + "value": t.setValue, + "props": t.setProps, + } +} + +func (t *Text) setSourceKey(template interface{}) error { + sourceKey, ok := template.(string) + if !ok { + return fmt.Errorf("source_key cannot be converted to a string") + } + t.SourceKey = sourceKey + return nil +} + +func (t *Text) setValue(template interface{}) error { + value, ok := template.(string) + if !ok { + return fmt.Errorf("value cannot be converted to a string") + } + t.Value = value + return nil +} + +func (t *Text) setProps(template interface{}) error { + props, err := propsmapper.NewText(template) + if err != nil { + return err + } + t.Props = props + return nil +} + +func (t *Text) validateFields() error { + if t.Value == "" && t.SourceKey == "" { + return fmt.Errorf("no value passed for text. Add the 'source_key' or a value") + } + return nil } -func (b *Text) Generate(content map[string]interface{}) (components.PdfComponent, error) { +func (t *Text) Generate(content map[string]interface{}) (components.PdfComponent, error) { return nil, nil } diff --git a/pkg/processor/mappers/propsmapper/text.go b/pkg/processor/mappers/propsmapper/text.go index dfd5db7d..e8a3f31b 100644 --- a/pkg/processor/mappers/propsmapper/text.go +++ b/pkg/processor/mappers/propsmapper/text.go @@ -1,5 +1,7 @@ package propsmapper +import "fmt" + // Text represents properties from a Text inside a cell. type Text struct { // Top is the amount of space between the upper cell limit and the text. @@ -28,10 +30,10 @@ type Text struct { // NewText is responsible for creating the Text, if the font fields cannot be // converted, an invalid value is set. -func NewText(signature interface{}) *Text { +func NewText(signature interface{}) (*Text, error) { signatureMap, ok := signature.(map[string]interface{}) if !ok { - return nil + return nil, fmt.Errorf("ensure text props can be converted to map[string] interface{}") } return &Text{ @@ -46,5 +48,5 @@ func NewText(signature interface{}) *Text { VerticalPadding: *convertFields(signatureMap["vertical_padding"], -1.0), Color: NewColor(signatureMap["color"]), Hyperlink: *convertFields(signatureMap["hyperlink"], ""), - } + }, nil } From 5bfc846f7ec1cf5698b9485f0ab32581718bd67b Mon Sep 17 00:00:00 2001 From: zjom <143974822+zjom@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:18:39 +1100 Subject: [PATCH 041/116] feature/repository-loader (#490) * changed type of template from string to map[string]any the repository should be able to store assets after they have been loaded into memory. switching from string to map[string]any facilitates this * change repository interface in core * feat: loader - interface responsible loading assets into memory Loader decouples file loading/ fetching logic from the rest of the processor. Loader should be used when deserialising a template with constant assets to be stored in the repository. Loader should also be used when deserialising content with assets * add loader as depdency to jsonDeserializer If there are assets found in the template in the process of deserialising, they should be loaded into memory. * add doc comments for loader * fix jsonDeserializer typo --- pkg/processor/core/core.go | 10 +- ...n_desserialize.go => json_deserializer.go} | 11 +- pkg/processor/loader/loader.go | 105 ++++++++++++++++++ pkg/processor/loader/loader_test.go | 43 +++++++ .../mappers/documentmapper/document.go | 9 +- .../mappers/documentmapper/document_test.go | 52 +++++---- pkg/processor/processor.go | 16 ++- pkg/processor/repository/memory_storage.go | 8 +- 8 files changed, 215 insertions(+), 39 deletions(-) rename pkg/processor/deserializer/{json_desserialize.go => json_deserializer.go} (59%) create mode 100644 pkg/processor/loader/loader.go create mode 100644 pkg/processor/loader/loader_test.go diff --git a/pkg/processor/core/core.go b/pkg/processor/core/core.go index c9f81fc1..39f0f99c 100644 --- a/pkg/processor/core/core.go +++ b/pkg/processor/core/core.go @@ -6,10 +6,16 @@ type Processor interface { } type Repository interface { - RegisterTemplate(name string, template string) error - ReadTemplate(templateName string) (string, error) + RegisterTemplate(templateName string, template map[string]any) error + ReadTemplate(templateName string) (map[string]any, error) } type Deserializer interface { Deserialize(document string) (map[string]interface{}, error) } + +// Takes a path and returns its bytes +// path may be file path or url +type Loader interface { + Load(path string) ([]byte, error) +} diff --git a/pkg/processor/deserializer/json_desserialize.go b/pkg/processor/deserializer/json_deserializer.go similarity index 59% rename from pkg/processor/deserializer/json_desserialize.go rename to pkg/processor/deserializer/json_deserializer.go index 27daeeac..765517c2 100644 --- a/pkg/processor/deserializer/json_desserialize.go +++ b/pkg/processor/deserializer/json_deserializer.go @@ -3,12 +3,17 @@ package deserializer import ( "encoding/json" + + "github.com/johnfercher/maroto/v2/pkg/processor/core" + "github.com/johnfercher/maroto/v2/pkg/processor/loader" ) -type jsonDeserializer struct{} +type jsonDeserializer struct { + loader core.Loader +} -func NewJsonDeserialize() *jsonDeserializer { - return &jsonDeserializer{} +func NewJsonDeserializer() *jsonDeserializer { + return &jsonDeserializer{loader: loader.NewLoader()} } func (j *jsonDeserializer) Deserialize(documentJson string) (map[string]interface{}, error) { diff --git a/pkg/processor/loader/loader.go b/pkg/processor/loader/loader.go new file mode 100644 index 00000000..ee6d5058 --- /dev/null +++ b/pkg/processor/loader/loader.go @@ -0,0 +1,105 @@ +package loader + +import ( + "io" + "net/http" + "net/url" + "os" + "path/filepath" + "strings" + + "github.com/pkg/errors" +) + +type loader struct{} + +func NewLoader() *loader { + return &loader{} +} + +// Load takes the path/url/uri of an asset (image, font) +// and returns its contents. +func (l *loader) Load(path string) ([]byte, error) { + ext := getExt(path) + if _, ok := validExts[ext]; !ok { + return nil, errors.Wrap(ErrUnsupportedExtension, ext) + } + + uri, err := url.Parse(path) + if err != nil { + return nil, errors.Wrap(ErrInvalidPath, path) + } + + loadFn, ok := loadFuncs[uri.Scheme] + if !ok { + return nil, errors.Wrap(ErrUnsupportedProtocol, uri.Scheme) + } + + r, err := loadFn(uri.String()) + if err != nil { + return nil, errors.Wrap(ErrAccessFail, err.Error()) + } + defer r.Close() + + data, err := io.ReadAll(r) + if err != nil { + return nil, errors.Wrap(ErrReadFail, err.Error()) + } + + return data, nil +} + +func getExt(path string) string { + toks := strings.Split(path, ".") + if len(toks) < 2 { + return "" + } + return toks[len(toks)-1] +} + +var validExts = map[string]struct{}{ + "png": {}, + "jpg": {}, + "svg": {}, + "jpeg": {}, + "ttf": {}, +} + +var loadFuncs = map[string]func(string) (io.ReadCloser, error){ + "http": loadHttp, + "https": loadHttp, + "file": loadLocal, + "": loadLocal, +} + +func loadLocal(path string) (io.ReadCloser, error) { + if strings.HasPrefix(path, "file://") { + path = path[len("file://"):] + } + absolutePath, err := filepath.Abs(path) + if err != nil { + return nil, err + } + f, err := os.Open(absolutePath) + if err != nil { + return nil, err + } + return f, nil +} + +func loadHttp(path string) (io.ReadCloser, error) { + resp, err := http.Get(path) + if err != nil { + return nil, err + } + + return resp.Body, nil +} + +var ( + ErrUnsupportedProtocol = errors.New("unsupported protocol") + ErrUnsupportedExtension = errors.New("unsupported extension") + ErrInvalidPath = errors.New("invalid path") + ErrAccessFail = errors.New("failed to access asset") + ErrReadFail = errors.New("failed to read asset") +) diff --git a/pkg/processor/loader/loader_test.go b/pkg/processor/loader/loader_test.go new file mode 100644 index 00000000..55a0e946 --- /dev/null +++ b/pkg/processor/loader/loader_test.go @@ -0,0 +1,43 @@ +package loader_test + +import ( + "testing" + + "github.com/johnfercher/maroto/v2/pkg/processor/loader" + "github.com/stretchr/testify/assert" +) + +func TestLoad(t *testing.T) { + t.Run("when invalid extension sent, should return ErrUnsupportedExtension", func(t *testing.T) { + _, err := loader.NewLoader().Load("README.md") + assert.ErrorIs(t, err, loader.ErrUnsupportedExtension) + }) + + t.Run("when invalid path sent, should return ErrInvalidPath", func(t *testing.T) { + _, err := loader.NewLoader().Load("http://hi this is an invalid path.png") + assert.ErrorIs(t, err, loader.ErrInvalidPath) + }) + + t.Run("when path with unsupported protocol sent, should return ErrSupportedProtocol", func(t *testing.T) { + _, err := loader.NewLoader().Load("irc://foobar.com/asset.png") + assert.ErrorIs(t, err, loader.ErrUnsupportedProtocol) + }) + + t.Run("when valid local path sent, should return bytes of file", func(t *testing.T) { + p, err := loader.NewLoader().Load("../../../docs/assets/images/logo.png") + assert.NoError(t, err) + assert.NotNil(t, p) + }) + + t.Run("when valid file uri sent, should return bytes of file", func(t *testing.T) { + p, err := loader.NewLoader().Load("file://../../../docs/assets/images/logo.png") + assert.NoError(t, err) + assert.NotNil(t, p) + }) + + t.Run("when valid network path sent, should return bytes of asset", func(t *testing.T) { + p, err := loader.NewLoader().Load("https://www.iana.org/_img/2013.1/rir-map.svg") + assert.NoError(t, err) + assert.NotNil(t, p) + }) +} diff --git a/pkg/processor/mappers/documentmapper/document.go b/pkg/processor/mappers/documentmapper/document.go index 89ac16db..097ea463 100644 --- a/pkg/processor/mappers/documentmapper/document.go +++ b/pkg/processor/mappers/documentmapper/document.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/johnfercher/maroto/v2/pkg/processor/components/pdf" - "github.com/johnfercher/maroto/v2/pkg/processor/core" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/buildermapper" ) @@ -20,14 +19,10 @@ type Document struct { } // NewPdf is responsible for creating the pdf template -func NewPdf(document string, deserializer core.Deserializer, factory mappers.AbstractFactoryMaps) (*Document, error) { +func NewPdf(template map[string]any, factory mappers.AbstractFactoryMaps) (*Document, error) { newPdf := Document{factory: factory} - template, err := deserializer.Deserialize(document) - if err != nil { - return nil, err - } - err = newPdf.addComponentsToPdf(template) + err := newPdf.addComponentsToPdf(template) if err != nil { return nil, err } diff --git a/pkg/processor/mappers/documentmapper/document_test.go b/pkg/processor/mappers/documentmapper/document_test.go index ac214018..236cc2a5 100644 --- a/pkg/processor/mappers/documentmapper/document_test.go +++ b/pkg/processor/mappers/documentmapper/document_test.go @@ -13,16 +13,6 @@ import ( ) func TestNewPdf(t *testing.T) { - t.Run("When an invalid field is submitted, should return an error", func(t *testing.T) { - invalidDocument := `{"invalid": 123}` - factory := mocks.NewAbstractFactoryMaps(t) - - doc, err := NewPdf(invalidDocument, deserializer.NewJsonDeserialize(), factory) - - assert.Nil(t, doc) - assert.NotNil(t, err) - }) - t.Run("when builder is sent, should set builder", func(t *testing.T) { builderDocument := ` { @@ -31,8 +21,10 @@ func TestNewPdf(t *testing.T) { ` factory := mocks.NewAbstractFactoryMaps(t) - doc, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + assert.Nil(t, err) + doc, err := NewPdf(template, factory) assert.Nil(t, err) assert.Equal(t, doc.Builder.ChunkWorkers, 10) }) @@ -41,7 +33,10 @@ func TestNewPdf(t *testing.T) { builderDocument := `{"builder": 10}` factory := mocks.NewAbstractFactoryMaps(t) - doc, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + assert.Nil(t, err) + + doc, err := NewPdf(template, factory) assert.NotNil(t, err) assert.Nil(t, doc) @@ -58,7 +53,10 @@ func TestNewPdf(t *testing.T) { factory := mocks.NewAbstractFactoryMaps(t) factory.On("NewRow", mock.Anything, mock.Anything).Return(validRow, nil) - doc, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + assert.Nil(t, err) + + doc, err := NewPdf(template, factory) assert.Nil(t, err) assert.Equal(t, 2, len(doc.Header)) @@ -68,8 +66,10 @@ func TestNewPdf(t *testing.T) { builderDocument := `{"header": 1}` factory := mocks.NewAbstractFactoryMaps(t) - _, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + assert.Nil(t, err) + _, err = NewPdf(template, factory) assert.NotNil(t, err) }) @@ -84,7 +84,10 @@ func TestNewPdf(t *testing.T) { factory := mocks.NewAbstractFactoryMaps(t) factory.On("NewRow", mock.Anything, mock.Anything).Return(validRow, nil) - doc, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + assert.Nil(t, err) + + doc, err := NewPdf(template, factory) assert.Nil(t, err) assert.Equal(t, 2, len(doc.Footer)) @@ -94,7 +97,10 @@ func TestNewPdf(t *testing.T) { builderDocument := `{"footer": 1}` factory := mocks.NewAbstractFactoryMaps(t) - _, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + assert.Nil(t, err) + + _, err = NewPdf(template, factory) assert.NotNil(t, err) }) @@ -111,7 +117,10 @@ func TestNewPdf(t *testing.T) { factory.On("NewPage", mock.Anything, "page_template_1").Return(validPage, nil) factory.On("NewPage", mock.Anything, "page_template_2").Return(validPage, nil) - doc, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + assert.Nil(t, err) + + doc, err := NewPdf(template, factory) assert.Nil(t, err) assert.Equal(t, len(doc.pages), 2) @@ -128,7 +137,10 @@ func TestNewPdf(t *testing.T) { factory := mocks.NewAbstractFactoryMaps(t) factory.On("NewList", mock.Anything, "list_template_1", mock.Anything).Return(validPage, nil) - doc, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + assert.Nil(t, err) + + doc, err := NewPdf(template, factory) assert.Nil(t, err) assert.Equal(t, len(doc.pages), 1) @@ -139,8 +151,10 @@ func TestNewPdf(t *testing.T) { builderDocument := `{"pages": 1}` factory := mocks.NewAbstractFactoryMaps(t) - _, err := NewPdf(builderDocument, deserializer.NewJsonDeserialize(), factory) + template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + assert.Nil(t, err) + _, err = NewPdf(template, factory) assert.NotNil(t, err) }) } diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index a21a464b..afb21252 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -13,23 +13,31 @@ import ( type processor struct { repository core.Repository deserializer core.Deserializer + loader core.Loader } func NewProcessor() *processor { - return &processor{repository: repository.NewMemoryStorage(), deserializer: deserializer.NewJsonDeserialize()} + return &processor{ + repository: repository.NewMemoryStorage(), + deserializer: deserializer.NewJsonDeserializer(), + } } func (p *processor) RegisterTemplate(templateName string, template string) error { - return p.repository.RegisterTemplate(templateName, template) + t, err := p.deserializer.Deserialize(template) + if err != nil { + return err + } + return p.repository.RegisterTemplate(templateName, t) } func (p *processor) GenerateDocument(templateName string, content string) ([]byte, error) { - templateJson, err := p.repository.ReadTemplate(templateName) + template, err := p.repository.ReadTemplate(templateName) if err != nil { return nil, err } - document, err := documentmapper.NewPdf(templateJson, p.deserializer, abstractfactory.NewAbstractFactoryMaps()) + document, err := documentmapper.NewPdf(template, abstractfactory.NewAbstractFactoryMaps()) if err != nil { return nil, err } diff --git a/pkg/processor/repository/memory_storage.go b/pkg/processor/repository/memory_storage.go index b0d0058d..dcf13d35 100644 --- a/pkg/processor/repository/memory_storage.go +++ b/pkg/processor/repository/memory_storage.go @@ -2,25 +2,25 @@ package repository type memoryStorage struct { - template map[string]string + template map[string]map[string]any } func NewMemoryStorage() *memoryStorage { return &memoryStorage{ - template: make(map[string]string), + template: make(map[string]map[string]any), } } // RegisterTemplate is responsible for register a template in memory // - name is the model identifier and is used to access it // - template is the template that will be stored -func (m *memoryStorage) RegisterTemplate(name string, template string) error { +func (m *memoryStorage) RegisterTemplate(name string, template map[string]any) error { m.template[name] = template return nil } // ReadTemplate is responsible for fetching the stored template // - name is the model identifier and is used to access it -func (m *memoryStorage) ReadTemplate(templateName string) (string, error) { +func (m *memoryStorage) ReadTemplate(templateName string) (map[string]any, error) { return m.template[templateName], nil } From 359336e83fb2cf5af847f2fc69b0961ea1c611ad Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Fri, 25 Oct 2024 18:44:13 -0300 Subject: [PATCH 042/116] style: fix errors reported by lint --- .../deserializer/json_deserializer.go | 6 ++-- pkg/processor/loader/loader.go | 10 +++---- .../abstractfactory/abstractfactory.go | 4 ++- .../mappers/buildermapper/bulder_test.go | 16 +++++++--- .../mappers/components/codemapper/barcode.go | 1 + .../components/codemapper/barcode_test.go | 1 + .../components/codemapper/matrixcode.go | 1 + .../components/codemapper/matrixcode_test.go | 1 + .../mappers/components/codemapper/qrcode.go | 29 ++++++++++--------- .../components/codemapper/qrcode_test.go | 1 + .../mappers/components/linemapper/line.go | 2 +- .../components/listmapper/list_test.go | 6 +--- .../mappers/components/pagemapper/page.go | 2 +- .../components/signaturemapper/signature.go | 2 +- .../mappers/documentmapper/document_test.go | 18 ++++++------ pkg/processor/mappers/propsmapper/consts.go | 9 ++---- pkg/processor/processor.go | 2 +- pkg/processor/processorprovider/Maroto.go | 2 +- 18 files changed, 60 insertions(+), 53 deletions(-) diff --git a/pkg/processor/deserializer/json_deserializer.go b/pkg/processor/deserializer/json_deserializer.go index 765517c2..11a3e2cf 100644 --- a/pkg/processor/deserializer/json_deserializer.go +++ b/pkg/processor/deserializer/json_deserializer.go @@ -12,12 +12,12 @@ type jsonDeserializer struct { loader core.Loader } -func NewJsonDeserializer() *jsonDeserializer { +func NewJSONDeserializer() *jsonDeserializer { return &jsonDeserializer{loader: loader.NewLoader()} } -func (j *jsonDeserializer) Deserialize(documentJson string) (map[string]interface{}, error) { +func (j *jsonDeserializer) Deserialize(documentJSON string) (map[string]interface{}, error) { var document map[string]interface{} - err := json.Unmarshal([]byte(documentJson), &document) + err := json.Unmarshal([]byte(documentJSON), &document) return document, err } diff --git a/pkg/processor/loader/loader.go b/pkg/processor/loader/loader.go index ee6d5058..0ac806d0 100644 --- a/pkg/processor/loader/loader.go +++ b/pkg/processor/loader/loader.go @@ -66,16 +66,14 @@ var validExts = map[string]struct{}{ } var loadFuncs = map[string]func(string) (io.ReadCloser, error){ - "http": loadHttp, - "https": loadHttp, + "http": loadHTTP, + "https": loadHTTP, "file": loadLocal, "": loadLocal, } func loadLocal(path string) (io.ReadCloser, error) { - if strings.HasPrefix(path, "file://") { - path = path[len("file://"):] - } + path = strings.TrimPrefix(path, "file://") absolutePath, err := filepath.Abs(path) if err != nil { return nil, err @@ -87,7 +85,7 @@ func loadLocal(path string) (io.ReadCloser, error) { return f, nil } -func loadHttp(path string) (io.ReadCloser, error) { +func loadHTTP(path string) (io.ReadCloser, error) { resp, err := http.Get(path) if err != nil { return nil, err diff --git a/pkg/processor/mappers/abstractfactory/abstractfactory.go b/pkg/processor/mappers/abstractfactory/abstractfactory.go index bc765ab2..686561b8 100644 --- a/pkg/processor/mappers/abstractfactory/abstractfactory.go +++ b/pkg/processor/mappers/abstractfactory/abstractfactory.go @@ -36,7 +36,9 @@ func (f *abstractFactoryMaps) NewCol(document interface{}) (mappers.Componentmap } // NewList is responsible for wrapper the creation of a list -func (f *abstractFactoryMaps) NewList(document interface{}, sourceKey string, generate mappers.GenerateComponent) (mappers.Componentmapper, error) { +func (f *abstractFactoryMaps) NewList(document interface{}, sourceKey string, + generate mappers.GenerateComponent, +) (mappers.Componentmapper, error) { return listmapper.NewList(document, sourceKey, generate) } diff --git a/pkg/processor/mappers/buildermapper/bulder_test.go b/pkg/processor/mappers/buildermapper/bulder_test.go index b341af10..e74cb242 100644 --- a/pkg/processor/mappers/buildermapper/bulder_test.go +++ b/pkg/processor/mappers/buildermapper/bulder_test.go @@ -63,7 +63,10 @@ func TestNewBuilder(t *testing.T) { file, _ := test.NewFileReader().LoadFile("processor/all_builder_pros.json") var builderInterface interface{} - json.Unmarshal(file, &builderInterface) + if err := json.Unmarshal(file, &builderInterface); err != nil { + t.Error("could not deserialize json") + return + } generateBuilder, err := NewBuilder(builderInterface) assert.Nil(t, err) @@ -75,7 +78,10 @@ func TestNewBuilder(t *testing.T) { const defaultDimensions = -1.0 var builderInterface interface{} - json.Unmarshal(file, &builderInterface) + if err := json.Unmarshal(file, &builderInterface); err != nil { + t.Error("could not deserialize json") + return + } generateBuilder, err := NewBuilder(builderInterface) assert.Nil(t, err) @@ -86,8 +92,10 @@ func TestNewBuilder(t *testing.T) { file, _ := test.NewFileReader().LoadFile("processor/without_builder_props.json") var builderInterface interface{} - json.Unmarshal(file, &builderInterface) - + if err := json.Unmarshal(file, &builderInterface); err != nil { + t.Error("could not deserialize json") + return + } _, err := NewBuilder(builderInterface) assert.Nil(t, err) }) diff --git a/pkg/processor/mappers/components/codemapper/barcode.go b/pkg/processor/mappers/components/codemapper/barcode.go index cd145b5a..212afba6 100644 --- a/pkg/processor/mappers/components/codemapper/barcode.go +++ b/pkg/processor/mappers/components/codemapper/barcode.go @@ -1,4 +1,5 @@ // codemapper code implements creation of Barcode, MatrixCode and QrCode. +// nolint:dupl package codemapper import ( diff --git a/pkg/processor/mappers/components/codemapper/barcode_test.go b/pkg/processor/mappers/components/codemapper/barcode_test.go index d451dcd8..77827b2f 100644 --- a/pkg/processor/mappers/components/codemapper/barcode_test.go +++ b/pkg/processor/mappers/components/codemapper/barcode_test.go @@ -1,3 +1,4 @@ +// nolint:dupl package codemapper_test import ( diff --git a/pkg/processor/mappers/components/codemapper/matrixcode.go b/pkg/processor/mappers/components/codemapper/matrixcode.go index 6029b0e0..604c7b76 100644 --- a/pkg/processor/mappers/components/codemapper/matrixcode.go +++ b/pkg/processor/mappers/components/codemapper/matrixcode.go @@ -1,4 +1,5 @@ // Package codemapper implements creation of matrixCode, MatrixCode and QrCode. +// nolint:dupl package codemapper import ( diff --git a/pkg/processor/mappers/components/codemapper/matrixcode_test.go b/pkg/processor/mappers/components/codemapper/matrixcode_test.go index 3fe0f82d..a2d6746b 100644 --- a/pkg/processor/mappers/components/codemapper/matrixcode_test.go +++ b/pkg/processor/mappers/components/codemapper/matrixcode_test.go @@ -1,3 +1,4 @@ +// nolint:dupl package codemapper_test import ( diff --git a/pkg/processor/mappers/components/codemapper/qrcode.go b/pkg/processor/mappers/components/codemapper/qrcode.go index c1d4406c..035ad9a8 100644 --- a/pkg/processor/mappers/components/codemapper/qrcode.go +++ b/pkg/processor/mappers/components/codemapper/qrcode.go @@ -1,4 +1,5 @@ // Package codemapper implements creation of qrcode, MatrixCode and QrCode. +// nolint:dupl package codemapper import ( @@ -33,8 +34,8 @@ func NewQrcode(code interface{}) (*Qrcode, error) { // addFields is responsible for adding the qrcode fields according to // the properties informed in the map -func (b *Qrcode) addFields(codeMap map[string]interface{}) error { - fieldMappers := b.getFieldMappers() +func (q *Qrcode) addFields(codeMap map[string]interface{}) error { + fieldMappers := q.getFieldMappers() for templateName, template := range codeMap { mapper, ok := fieldMappers[templateName] @@ -51,43 +52,43 @@ func (b *Qrcode) addFields(codeMap map[string]interface{}) error { // getFieldMappers is responsible for defining which methods are responsible for assembling which components. // To do this, the component name is linked to a function in a Map. -func (b *Qrcode) getFieldMappers() map[string]func(interface{}) error { +func (q *Qrcode) getFieldMappers() map[string]func(interface{}) error { return map[string]func(interface{}) error{ - "source_key": b.setSourceKey, - "code": b.setCode, - "props": b.setProps, + "source_key": q.setSourceKey, + "code": q.setCode, + "props": q.setProps, } } -func (b *Qrcode) setSourceKey(template interface{}) error { +func (q *Qrcode) setSourceKey(template interface{}) error { sourceKey, ok := template.(string) if !ok { return fmt.Errorf("source_key cannot be converted to a string") } - b.SourceKey = sourceKey + q.SourceKey = sourceKey return nil } -func (b *Qrcode) setCode(template interface{}) error { +func (q *Qrcode) setCode(template interface{}) error { code, ok := template.(string) if !ok { return fmt.Errorf("code cannot be converted to a string") } - b.Code = code + q.Code = code return nil } -func (b *Qrcode) setProps(template interface{}) error { +func (q *Qrcode) setProps(template interface{}) error { props, err := propsmapper.NewRect(template) if err != nil { return err } - b.Props = props + q.Props = props return nil } -func (b *Qrcode) validateFields() error { - if b.Code == "" && b.SourceKey == "" { +func (q *Qrcode) validateFields() error { + if q.Code == "" && q.SourceKey == "" { return fmt.Errorf("no value passed for qrcode. Add the 'source_key' or a code") } return nil diff --git a/pkg/processor/mappers/components/codemapper/qrcode_test.go b/pkg/processor/mappers/components/codemapper/qrcode_test.go index 3409d734..6a0b761e 100644 --- a/pkg/processor/mappers/components/codemapper/qrcode_test.go +++ b/pkg/processor/mappers/components/codemapper/qrcode_test.go @@ -1,3 +1,4 @@ +// nolint:dupl package codemapper_test import ( diff --git a/pkg/processor/mappers/components/linemapper/line.go b/pkg/processor/mappers/components/linemapper/line.go index 8de66786..01018150 100644 --- a/pkg/processor/mappers/components/linemapper/line.go +++ b/pkg/processor/mappers/components/linemapper/line.go @@ -60,6 +60,6 @@ func (l *Line) setProps(templateProps interface{}) error { return nil } -func (b *Line) Generate(content map[string]interface{}) (components.PdfComponent, error) { +func (l *Line) Generate(content map[string]interface{}) (components.PdfComponent, error) { return nil, nil } diff --git a/pkg/processor/mappers/components/listmapper/list_test.go b/pkg/processor/mappers/components/listmapper/list_test.go index 5f9a48cf..5c86b802 100644 --- a/pkg/processor/mappers/components/listmapper/list_test.go +++ b/pkg/processor/mappers/components/listmapper/list_test.go @@ -11,10 +11,6 @@ import ( "github.com/stretchr/testify/mock" ) -// se interface invalida for passada erro é retornada -// se componente não puder ser gerado, erro é retornado -// se uma lista de 2 componentes for passada, 1 erro é retornado - func TestNewList(t *testing.T) { t.Run("when invalid interface is sent, it should return an error", func(t *testing.T) { var invalidInterface interface{} = 1 @@ -40,7 +36,7 @@ func TestNewList(t *testing.T) { assert.NotNil(t, err) }) - t.Run("when 2-components are sent, it should add 2 componentes in list", func(t *testing.T) { + t.Run("when 2-components are sent, it should add 2 components in list", func(t *testing.T) { validPage := fixture.MapperPage() templatePages := map[string]interface{}{ "page_template_1": nil, diff --git a/pkg/processor/mappers/components/pagemapper/page.go b/pkg/processor/mappers/components/pagemapper/page.go index d1e03ec0..3e3ddce6 100644 --- a/pkg/processor/mappers/components/pagemapper/page.go +++ b/pkg/processor/mappers/components/pagemapper/page.go @@ -54,6 +54,6 @@ func (p *Page) setRows(rowsDoc interface{}) error { return nil } -func (r *Page) Generate(content map[string]interface{}) (components.PdfComponent, error) { +func (p *Page) Generate(content map[string]interface{}) (components.PdfComponent, error) { return nil, nil } diff --git a/pkg/processor/mappers/components/signaturemapper/signature.go b/pkg/processor/mappers/components/signaturemapper/signature.go index e8fdf30c..0025f408 100644 --- a/pkg/processor/mappers/components/signaturemapper/signature.go +++ b/pkg/processor/mappers/components/signaturemapper/signature.go @@ -93,6 +93,6 @@ func (s *Signature) validateFields() error { return nil } -func (b *Signature) Generate(content map[string]interface{}) (components.PdfComponent, error) { +func (s *Signature) Generate(content map[string]interface{}) (components.PdfComponent, error) { return nil, nil } diff --git a/pkg/processor/mappers/documentmapper/document_test.go b/pkg/processor/mappers/documentmapper/document_test.go index 236cc2a5..def6301e 100644 --- a/pkg/processor/mappers/documentmapper/document_test.go +++ b/pkg/processor/mappers/documentmapper/document_test.go @@ -21,7 +21,7 @@ func TestNewPdf(t *testing.T) { ` factory := mocks.NewAbstractFactoryMaps(t) - template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) doc, err := NewPdf(template, factory) @@ -33,7 +33,7 @@ func TestNewPdf(t *testing.T) { builderDocument := `{"builder": 10}` factory := mocks.NewAbstractFactoryMaps(t) - template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) doc, err := NewPdf(template, factory) @@ -53,7 +53,7 @@ func TestNewPdf(t *testing.T) { factory := mocks.NewAbstractFactoryMaps(t) factory.On("NewRow", mock.Anything, mock.Anything).Return(validRow, nil) - template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) doc, err := NewPdf(template, factory) @@ -66,7 +66,7 @@ func TestNewPdf(t *testing.T) { builderDocument := `{"header": 1}` factory := mocks.NewAbstractFactoryMaps(t) - template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) _, err = NewPdf(template, factory) @@ -84,7 +84,7 @@ func TestNewPdf(t *testing.T) { factory := mocks.NewAbstractFactoryMaps(t) factory.On("NewRow", mock.Anything, mock.Anything).Return(validRow, nil) - template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) doc, err := NewPdf(template, factory) @@ -97,7 +97,7 @@ func TestNewPdf(t *testing.T) { builderDocument := `{"footer": 1}` factory := mocks.NewAbstractFactoryMaps(t) - template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) _, err = NewPdf(template, factory) @@ -117,7 +117,7 @@ func TestNewPdf(t *testing.T) { factory.On("NewPage", mock.Anything, "page_template_1").Return(validPage, nil) factory.On("NewPage", mock.Anything, "page_template_2").Return(validPage, nil) - template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) doc, err := NewPdf(template, factory) @@ -137,7 +137,7 @@ func TestNewPdf(t *testing.T) { factory := mocks.NewAbstractFactoryMaps(t) factory.On("NewList", mock.Anything, "list_template_1", mock.Anything).Return(validPage, nil) - template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) doc, err := NewPdf(template, factory) @@ -151,7 +151,7 @@ func TestNewPdf(t *testing.T) { builderDocument := `{"pages": 1}` factory := mocks.NewAbstractFactoryMaps(t) - template, err := deserializer.NewJsonDeserializer().Deserialize(builderDocument) + template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) _, err = NewPdf(template, factory) diff --git a/pkg/processor/mappers/propsmapper/consts.go b/pkg/processor/mappers/propsmapper/consts.go index d17a7f46..133ec450 100644 --- a/pkg/processor/mappers/propsmapper/consts.go +++ b/pkg/processor/mappers/propsmapper/consts.go @@ -29,13 +29,10 @@ func NewCodeType(typeProtection string) string { } func NewLineStyle(style string) string { - switch style { - case "dashed": - return "dashed" - case "solid": - return "dashed" + if style != "dashed" && style != "solid" { + return "" } - return "" + return style } func NewOrientation(orientation string) string { diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index afb21252..abeef616 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -19,7 +19,7 @@ type processor struct { func NewProcessor() *processor { return &processor{ repository: repository.NewMemoryStorage(), - deserializer: deserializer.NewJsonDeserializer(), + deserializer: deserializer.NewJSONDeserializer(), } } diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index 341aea8d..363fb51b 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -28,7 +28,7 @@ func (m *Maroto) GeneratePdf() ([]byte, error) { if err != nil { return nil, err } - doc.Save("docs/assets/pdf/backgroundv2.pdf") + return doc.GetBytes(), nil } From 3712af8a39cfcd598202bb08c01be4ee7acbf891 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Fri, 25 Oct 2024 22:12:44 -0300 Subject: [PATCH 043/116] docs: document methods and functions --- pkg/processor/deserializer/json_deserializer.go | 2 ++ pkg/processor/mappers/abstractfactory/abstractfactory.go | 2 +- pkg/processor/mappers/documentmapper/document.go | 1 + pkg/processor/processor.go | 7 +++++++ pkg/processor/repository/memory_storage.go | 2 ++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/processor/deserializer/json_deserializer.go b/pkg/processor/deserializer/json_deserializer.go index 11a3e2cf..a673d299 100644 --- a/pkg/processor/deserializer/json_deserializer.go +++ b/pkg/processor/deserializer/json_deserializer.go @@ -12,10 +12,12 @@ type jsonDeserializer struct { loader core.Loader } +// The new JSONserializer is responsible for creating a json deserializer func NewJSONDeserializer() *jsonDeserializer { return &jsonDeserializer{loader: loader.NewLoader()} } +// Deserialize is responsible for parsing a json document and creating an interface map func (j *jsonDeserializer) Deserialize(documentJSON string) (map[string]interface{}, error) { var document map[string]interface{} err := json.Unmarshal([]byte(documentJSON), &document) diff --git a/pkg/processor/mappers/abstractfactory/abstractfactory.go b/pkg/processor/mappers/abstractfactory/abstractfactory.go index 686561b8..683bf1ba 100644 --- a/pkg/processor/mappers/abstractfactory/abstractfactory.go +++ b/pkg/processor/mappers/abstractfactory/abstractfactory.go @@ -13,9 +13,9 @@ import ( "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/textmapper" ) -// abstractFactoryMaps is responsible for providing a factory for all mapper components type abstractFactoryMaps struct{} +// NewAbstractFactoryMaps is responsible for creating an object that encapsulates the creation of components func NewAbstractFactoryMaps() *abstractFactoryMaps { return &abstractFactoryMaps{} } diff --git a/pkg/processor/mappers/documentmapper/document.go b/pkg/processor/mappers/documentmapper/document.go index 097ea463..d895c63f 100644 --- a/pkg/processor/mappers/documentmapper/document.go +++ b/pkg/processor/mappers/documentmapper/document.go @@ -19,6 +19,7 @@ type Document struct { } // NewPdf is responsible for creating the pdf template +// parse the model and create the pdf object func NewPdf(template map[string]any, factory mappers.AbstractFactoryMaps) (*Document, error) { newPdf := Document{factory: factory} diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index abeef616..511ddd6b 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -16,6 +16,8 @@ type processor struct { loader core.Loader } +// NewProcessor is responsible for creating a processor object +// The processor object should be used to create PDF from a serialized document func NewProcessor() *processor { return &processor{ repository: repository.NewMemoryStorage(), @@ -23,6 +25,8 @@ func NewProcessor() *processor { } } +// RegisterTemplate is responsible for recording the document template. +// Each template must be accompanied by a name that will identify it. func (p *processor) RegisterTemplate(templateName string, template string) error { t, err := p.deserializer.Deserialize(template) if err != nil { @@ -31,6 +35,9 @@ func (p *processor) RegisterTemplate(templateName string, template string) error return p.repository.RegisterTemplate(templateName, t) } +// GenerateDocument is responsible for generating the pdf +// templateName must reference a previously saved template, +// this template will be computed with the data sent in content func (p *processor) GenerateDocument(templateName string, content string) ([]byte, error) { template, err := p.repository.ReadTemplate(templateName) if err != nil { diff --git a/pkg/processor/repository/memory_storage.go b/pkg/processor/repository/memory_storage.go index dcf13d35..2a4e4eec 100644 --- a/pkg/processor/repository/memory_storage.go +++ b/pkg/processor/repository/memory_storage.go @@ -5,6 +5,8 @@ type memoryStorage struct { template map[string]map[string]any } +// NewMemoryStorage is responsible for creating a repository +// implementation that stores data in memory func NewMemoryStorage() *memoryStorage { return &memoryStorage{ template: make(map[string]map[string]any), From 168a943b5ac1592eb39b9db6d950fb48b011c734 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sat, 26 Oct 2024 23:09:36 -0300 Subject: [PATCH 044/116] test: validate image component creation --- .../components/imagemapper/image_test.go | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/pkg/processor/mappers/components/imagemapper/image_test.go b/pkg/processor/mappers/components/imagemapper/image_test.go index b53f0fc8..0e8754d9 100644 --- a/pkg/processor/mappers/components/imagemapper/image_test.go +++ b/pkg/processor/mappers/components/imagemapper/image_test.go @@ -1 +1,92 @@ package imagemapper_test + +import ( + "testing" + + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/imagemapper" + "github.com/stretchr/testify/assert" +) + +func TestNewImage(t *testing.T) { + t.Run("when invalid image is sent, should return an error", func(t *testing.T) { + imageTemplate := 1 + + image, err := imagemapper.NewImage(imageTemplate) + + assert.Nil(t, image) + assert.NotNil(t, err) + }) + t.Run("when props is not sent, image is created", func(t *testing.T) { + imageTemplate := map[string]interface{}{ + "source_key": "source key", + } + + image, err := imagemapper.NewImage(imageTemplate) + + assert.Nil(t, err) + assert.NotNil(t, image) + }) + t.Run("when invalid props is sent, should return an error", func(t *testing.T) { + imageTemplate := map[string]interface{}{ + "props": 1, + "source_key": "name", + } + + image, err := imagemapper.NewImage(imageTemplate) + + assert.Nil(t, image) + assert.NotNil(t, err) + }) + t.Run("when invalid field is sent, should return an error", func(t *testing.T) { + imageTemplate := map[string]interface{}{ + "invalid_field": 1, + "source_key": "name", + } + + image, err := imagemapper.NewImage(imageTemplate) + + assert.Nil(t, image) + assert.NotNil(t, err) + }) + t.Run("when source_key is not sent, should return an error", func(t *testing.T) { + imageTemplate := map[string]interface{}{} + + image, err := imagemapper.NewImage(imageTemplate) + + assert.Nil(t, image) + assert.NotNil(t, err) + }) + t.Run("when invalid source_key is sent, should return an error", func(t *testing.T) { + imageTemplate := map[string]interface{}{ + "source_key": 123, + } + + image, err := imagemapper.NewImage(imageTemplate) + + assert.Nil(t, image) + assert.NotNil(t, err) + }) + t.Run("when source_key is sent, should add source_key", func(t *testing.T) { + imageTemplate := map[string]interface{}{ + "source_key": "icon", + } + + image, err := imagemapper.NewImage(imageTemplate) + + assert.Nil(t, err) + assert.Equal(t, image.SourceKey, "icon") + }) + t.Run("when props is sent, should add props", func(t *testing.T) { + imageTemplate := map[string]interface{}{ + "source_key": "name", + "props": map[string]interface{}{ + "left": 10.0, + }, + } + + image, err := imagemapper.NewImage(imageTemplate) + + assert.Nil(t, err) + assert.Equal(t, 10.0, image.Props.Left) + }) +} From e5a596e3f7d811719a72a692b1e6fab012da2024 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sat, 26 Oct 2024 23:09:49 -0300 Subject: [PATCH 045/116] feat: create image from map --- .../mappers/components/imagemapper/image.go | 75 ++++++++++++++++++- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/pkg/processor/mappers/components/imagemapper/image.go b/pkg/processor/mappers/components/imagemapper/image.go index 86728d91..a9f0a7c0 100644 --- a/pkg/processor/mappers/components/imagemapper/image.go +++ b/pkg/processor/mappers/components/imagemapper/image.go @@ -1,12 +1,79 @@ // Package image implements creation of images from file and bytes. package imagemapper -import "github.com/johnfercher/maroto/v2/pkg/processor/components" +import ( + "fmt" -type Image struct{} + "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" +) -func NewImage(code interface{}) (*Image, error) { - return nil, nil +type Image struct { + SourceKey string + Props *propsmapper.Rect +} + +func NewImage(templateImage interface{}) (*Image, error) { + imageMap, ok := templateImage.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("ensure image can be converted to map[string] interface{}") + } + + image := &Image{} + if err := image.addFields(imageMap); err != nil { + return nil, err + } + if image.SourceKey == "" { + return nil, fmt.Errorf("no value passed for image. Add the 'source_key'") + } + + return image, nil + +} + +// addFields is responsible for adding the barcode fields according to +// the properties informed in the map +func (i *Image) addFields(imageMap map[string]interface{}) error { + fieldMappers := i.getFieldMappers() + + for templateName, template := range imageMap { + mapper, ok := fieldMappers[templateName] + if !ok { + return fmt.Errorf("the field %s present in the image cannot be mapped to any valid field", templateName) + } + err := mapper(template) + if err != nil { + return err + } + } + return nil +} + +// getFieldMappers is responsible for defining which methods are responsible for assembling which components. +// To do this, the component name is linked to a function in a Map. +func (i *Image) getFieldMappers() map[string]func(interface{}) error { + return map[string]func(interface{}) error{ + "source_key": i.setSourceKey, + "props": i.setProps, + } +} + +func (i *Image) setSourceKey(template interface{}) error { + sourceKey, ok := template.(string) + if !ok { + return fmt.Errorf("source_key cannot be converted to a string") + } + i.SourceKey = sourceKey + return nil +} + +func (b *Image) setProps(template interface{}) error { + props, err := propsmapper.NewRect(template) + if err != nil { + return err + } + b.Props = props + return nil } func (b *Image) Generate(content map[string]interface{}) (components.PdfComponent, error) { From a59e9acb4bfc7492c3a7e9b53384710905f81e01 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 27 Oct 2024 12:01:17 -0300 Subject: [PATCH 046/116] test:validate barcode component creation --- mocks/Builder.go | 1263 +---------------- mocks/Componentmapper.go | 38 +- mocks/Loader.go | 91 ++ mocks/PDFComponent.go | 201 +++ mocks/PdfComponent.go | 86 -- mocks/ProcessorProvider.go | 502 +------ mocks/Repository.go | 157 +- .../components/codemapper/barcode_test.go | 53 + .../processorprovider/Maroto_test.go | 26 + test/maroto/processor/provider/barcode.json | 11 + 10 files changed, 492 insertions(+), 1936 deletions(-) create mode 100644 mocks/Loader.go create mode 100644 mocks/PDFComponent.go delete mode 100644 mocks/PdfComponent.go create mode 100644 pkg/processor/processorprovider/Maroto_test.go create mode 100644 test/maroto/processor/provider/barcode.json diff --git a/mocks/Builder.go b/mocks/Builder.go index 2cbe240a..883f7968 100644 --- a/mocks/Builder.go +++ b/mocks/Builder.go @@ -3,22 +3,12 @@ package mocks import ( - config "github.com/johnfercher/maroto/v2/pkg/config" + cache "github.com/johnfercher/maroto/v2/internal/cache" entity "github.com/johnfercher/maroto/v2/pkg/core/entity" - extension "github.com/johnfercher/maroto/v2/pkg/consts/extension" + gofpdf "github.com/johnfercher/maroto/v2/internal/providers/gofpdf" mock "github.com/stretchr/testify/mock" - - orientation "github.com/johnfercher/maroto/v2/pkg/consts/orientation" - - pagesize "github.com/johnfercher/maroto/v2/pkg/consts/pagesize" - - props "github.com/johnfercher/maroto/v2/pkg/props" - - protection "github.com/johnfercher/maroto/v2/pkg/consts/protection" - - time "time" ) // Builder is an autogenerated mock type for the Builder type @@ -34,20 +24,20 @@ func (_m *Builder) EXPECT() *Builder_Expecter { return &Builder_Expecter{mock: &_m.Mock} } -// Build provides a mock function with given fields: -func (_m *Builder) Build() *entity.Config { - ret := _m.Called() +// Build provides a mock function with given fields: cfg, _a1 +func (_m *Builder) Build(cfg *entity.Config, _a1 cache.Cache) *gofpdf.Dependencies { + ret := _m.Called(cfg, _a1) if len(ret) == 0 { panic("no return value specified for Build") } - var r0 *entity.Config - if rf, ok := ret.Get(0).(func() *entity.Config); ok { - r0 = rf() + var r0 *gofpdf.Dependencies + if rf, ok := ret.Get(0).(func(*entity.Config, cache.Cache) *gofpdf.Dependencies); ok { + r0 = rf(cfg, _a1) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*entity.Config) + r0 = ret.Get(0).(*gofpdf.Dependencies) } } @@ -60,1244 +50,25 @@ type Builder_Build_Call struct { } // Build is a helper method to define mock.On call -func (_e *Builder_Expecter) Build() *Builder_Build_Call { - return &Builder_Build_Call{Call: _e.mock.On("Build")} -} - -func (_c *Builder_Build_Call) Run(run func()) *Builder_Build_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *Builder_Build_Call) Return(_a0 *entity.Config) *Builder_Build_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_Build_Call) RunAndReturn(run func() *entity.Config) *Builder_Build_Call { - _c.Call.Return(run) - return _c -} - -// WithAuthor provides a mock function with given fields: author, isUTF8 -func (_m *Builder) WithAuthor(author string, isUTF8 bool) config.Builder { - ret := _m.Called(author, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithAuthor") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(author, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithAuthor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithAuthor' -type Builder_WithAuthor_Call struct { - *mock.Call -} - -// WithAuthor is a helper method to define mock.On call -// - author string -// - isUTF8 bool -func (_e *Builder_Expecter) WithAuthor(author interface{}, isUTF8 interface{}) *Builder_WithAuthor_Call { - return &Builder_WithAuthor_Call{Call: _e.mock.On("WithAuthor", author, isUTF8)} -} - -func (_c *Builder_WithAuthor_Call) Run(run func(author string, isUTF8 bool)) *Builder_WithAuthor_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithAuthor_Call) Return(_a0 config.Builder) *Builder_WithAuthor_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithAuthor_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithAuthor_Call { - _c.Call.Return(run) - return _c -} - -// WithBackgroundImage provides a mock function with given fields: _a0, _a1 -func (_m *Builder) WithBackgroundImage(_a0 []byte, _a1 extension.Type) config.Builder { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for WithBackgroundImage") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func([]byte, extension.Type) config.Builder); ok { - r0 = rf(_a0, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithBackgroundImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBackgroundImage' -type Builder_WithBackgroundImage_Call struct { - *mock.Call -} - -// WithBackgroundImage is a helper method to define mock.On call -// - _a0 []byte -// - _a1 extension.Type -func (_e *Builder_Expecter) WithBackgroundImage(_a0 interface{}, _a1 interface{}) *Builder_WithBackgroundImage_Call { - return &Builder_WithBackgroundImage_Call{Call: _e.mock.On("WithBackgroundImage", _a0, _a1)} -} - -func (_c *Builder_WithBackgroundImage_Call) Run(run func(_a0 []byte, _a1 extension.Type)) *Builder_WithBackgroundImage_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].([]byte), args[1].(extension.Type)) - }) - return _c -} - -func (_c *Builder_WithBackgroundImage_Call) Return(_a0 config.Builder) *Builder_WithBackgroundImage_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithBackgroundImage_Call) RunAndReturn(run func([]byte, extension.Type) config.Builder) *Builder_WithBackgroundImage_Call { - _c.Call.Return(run) - return _c -} - -// WithBottomMargin provides a mock function with given fields: bottom -func (_m *Builder) WithBottomMargin(bottom float64) config.Builder { - ret := _m.Called(bottom) - - if len(ret) == 0 { - panic("no return value specified for WithBottomMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(bottom) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithBottomMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBottomMargin' -type Builder_WithBottomMargin_Call struct { - *mock.Call -} - -// WithBottomMargin is a helper method to define mock.On call -// - bottom float64 -func (_e *Builder_Expecter) WithBottomMargin(bottom interface{}) *Builder_WithBottomMargin_Call { - return &Builder_WithBottomMargin_Call{Call: _e.mock.On("WithBottomMargin", bottom)} -} - -func (_c *Builder_WithBottomMargin_Call) Run(run func(bottom float64)) *Builder_WithBottomMargin_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) - }) - return _c -} - -func (_c *Builder_WithBottomMargin_Call) Return(_a0 config.Builder) *Builder_WithBottomMargin_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithBottomMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithBottomMargin_Call { - _c.Call.Return(run) - return _c -} - -// WithCompression provides a mock function with given fields: compression -func (_m *Builder) WithCompression(compression bool) config.Builder { - ret := _m.Called(compression) - - if len(ret) == 0 { - panic("no return value specified for WithCompression") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { - r0 = rf(compression) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCompression_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCompression' -type Builder_WithCompression_Call struct { - *mock.Call -} - -// WithCompression is a helper method to define mock.On call -// - compression bool -func (_e *Builder_Expecter) WithCompression(compression interface{}) *Builder_WithCompression_Call { - return &Builder_WithCompression_Call{Call: _e.mock.On("WithCompression", compression)} -} - -func (_c *Builder_WithCompression_Call) Run(run func(compression bool)) *Builder_WithCompression_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(bool)) - }) - return _c -} - -func (_c *Builder_WithCompression_Call) Return(_a0 config.Builder) *Builder_WithCompression_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCompression_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithCompression_Call { - _c.Call.Return(run) - return _c -} - -// WithConcurrentMode provides a mock function with given fields: chunkWorkers -func (_m *Builder) WithConcurrentMode(chunkWorkers int) config.Builder { - ret := _m.Called(chunkWorkers) - - if len(ret) == 0 { - panic("no return value specified for WithConcurrentMode") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(int) config.Builder); ok { - r0 = rf(chunkWorkers) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithConcurrentMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithConcurrentMode' -type Builder_WithConcurrentMode_Call struct { - *mock.Call -} - -// WithConcurrentMode is a helper method to define mock.On call -// - chunkWorkers int -func (_e *Builder_Expecter) WithConcurrentMode(chunkWorkers interface{}) *Builder_WithConcurrentMode_Call { - return &Builder_WithConcurrentMode_Call{Call: _e.mock.On("WithConcurrentMode", chunkWorkers)} -} - -func (_c *Builder_WithConcurrentMode_Call) Run(run func(chunkWorkers int)) *Builder_WithConcurrentMode_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(int)) - }) - return _c -} - -func (_c *Builder_WithConcurrentMode_Call) Return(_a0 config.Builder) *Builder_WithConcurrentMode_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithConcurrentMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithConcurrentMode_Call { - _c.Call.Return(run) - return _c -} - -// WithCreationDate provides a mock function with given fields: _a0 -func (_m *Builder) WithCreationDate(_a0 time.Time) config.Builder { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for WithCreationDate") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(time.Time) config.Builder); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCreationDate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreationDate' -type Builder_WithCreationDate_Call struct { - *mock.Call -} - -// WithCreationDate is a helper method to define mock.On call -// - _a0 time.Time -func (_e *Builder_Expecter) WithCreationDate(_a0 interface{}) *Builder_WithCreationDate_Call { - return &Builder_WithCreationDate_Call{Call: _e.mock.On("WithCreationDate", _a0)} -} - -func (_c *Builder_WithCreationDate_Call) Run(run func(_a0 time.Time)) *Builder_WithCreationDate_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(time.Time)) - }) - return _c -} - -func (_c *Builder_WithCreationDate_Call) Return(_a0 config.Builder) *Builder_WithCreationDate_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCreationDate_Call) RunAndReturn(run func(time.Time) config.Builder) *Builder_WithCreationDate_Call { - _c.Call.Return(run) - return _c -} - -// WithCreator provides a mock function with given fields: creator, isUTF8 -func (_m *Builder) WithCreator(creator string, isUTF8 bool) config.Builder { - ret := _m.Called(creator, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithCreator") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(creator, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCreator_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreator' -type Builder_WithCreator_Call struct { - *mock.Call -} - -// WithCreator is a helper method to define mock.On call -// - creator string -// - isUTF8 bool -func (_e *Builder_Expecter) WithCreator(creator interface{}, isUTF8 interface{}) *Builder_WithCreator_Call { - return &Builder_WithCreator_Call{Call: _e.mock.On("WithCreator", creator, isUTF8)} -} - -func (_c *Builder_WithCreator_Call) Run(run func(creator string, isUTF8 bool)) *Builder_WithCreator_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithCreator_Call) Return(_a0 config.Builder) *Builder_WithCreator_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCreator_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithCreator_Call { - _c.Call.Return(run) - return _c -} - -// WithCustomFonts provides a mock function with given fields: _a0 -func (_m *Builder) WithCustomFonts(_a0 []*entity.CustomFont) config.Builder { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for WithCustomFonts") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func([]*entity.CustomFont) config.Builder); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCustomFonts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCustomFonts' -type Builder_WithCustomFonts_Call struct { - *mock.Call -} - -// WithCustomFonts is a helper method to define mock.On call -// - _a0 []*entity.CustomFont -func (_e *Builder_Expecter) WithCustomFonts(_a0 interface{}) *Builder_WithCustomFonts_Call { - return &Builder_WithCustomFonts_Call{Call: _e.mock.On("WithCustomFonts", _a0)} -} - -func (_c *Builder_WithCustomFonts_Call) Run(run func(_a0 []*entity.CustomFont)) *Builder_WithCustomFonts_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].([]*entity.CustomFont)) - }) - return _c -} - -func (_c *Builder_WithCustomFonts_Call) Return(_a0 config.Builder) *Builder_WithCustomFonts_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCustomFonts_Call) RunAndReturn(run func([]*entity.CustomFont) config.Builder) *Builder_WithCustomFonts_Call { - _c.Call.Return(run) - return _c -} - -// WithDebug provides a mock function with given fields: on -func (_m *Builder) WithDebug(on bool) config.Builder { - ret := _m.Called(on) - - if len(ret) == 0 { - panic("no return value specified for WithDebug") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { - r0 = rf(on) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDebug_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDebug' -type Builder_WithDebug_Call struct { - *mock.Call -} - -// WithDebug is a helper method to define mock.On call -// - on bool -func (_e *Builder_Expecter) WithDebug(on interface{}) *Builder_WithDebug_Call { - return &Builder_WithDebug_Call{Call: _e.mock.On("WithDebug", on)} -} - -func (_c *Builder_WithDebug_Call) Run(run func(on bool)) *Builder_WithDebug_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(bool)) - }) - return _c -} - -func (_c *Builder_WithDebug_Call) Return(_a0 config.Builder) *Builder_WithDebug_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDebug_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDebug_Call { - _c.Call.Return(run) - return _c -} - -// WithDefaultFont provides a mock function with given fields: font -func (_m *Builder) WithDefaultFont(font *props.Font) config.Builder { - ret := _m.Called(font) - - if len(ret) == 0 { - panic("no return value specified for WithDefaultFont") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(*props.Font) config.Builder); ok { - r0 = rf(font) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDefaultFont_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDefaultFont' -type Builder_WithDefaultFont_Call struct { - *mock.Call -} - -// WithDefaultFont is a helper method to define mock.On call -// - font *props.Font -func (_e *Builder_Expecter) WithDefaultFont(font interface{}) *Builder_WithDefaultFont_Call { - return &Builder_WithDefaultFont_Call{Call: _e.mock.On("WithDefaultFont", font)} -} - -func (_c *Builder_WithDefaultFont_Call) Run(run func(font *props.Font)) *Builder_WithDefaultFont_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*props.Font)) - }) - return _c -} - -func (_c *Builder_WithDefaultFont_Call) Return(_a0 config.Builder) *Builder_WithDefaultFont_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDefaultFont_Call) RunAndReturn(run func(*props.Font) config.Builder) *Builder_WithDefaultFont_Call { - _c.Call.Return(run) - return _c -} - -// WithDimensions provides a mock function with given fields: width, height -func (_m *Builder) WithDimensions(width float64, height float64) config.Builder { - ret := _m.Called(width, height) - - if len(ret) == 0 { - panic("no return value specified for WithDimensions") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64, float64) config.Builder); ok { - r0 = rf(width, height) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDimensions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDimensions' -type Builder_WithDimensions_Call struct { - *mock.Call -} - -// WithDimensions is a helper method to define mock.On call -// - width float64 -// - height float64 -func (_e *Builder_Expecter) WithDimensions(width interface{}, height interface{}) *Builder_WithDimensions_Call { - return &Builder_WithDimensions_Call{Call: _e.mock.On("WithDimensions", width, height)} -} - -func (_c *Builder_WithDimensions_Call) Run(run func(width float64, height float64)) *Builder_WithDimensions_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64), args[1].(float64)) - }) - return _c -} - -func (_c *Builder_WithDimensions_Call) Return(_a0 config.Builder) *Builder_WithDimensions_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDimensions_Call) RunAndReturn(run func(float64, float64) config.Builder) *Builder_WithDimensions_Call { - _c.Call.Return(run) - return _c -} - -// WithDisableAutoPageBreak provides a mock function with given fields: disabled -func (_m *Builder) WithDisableAutoPageBreak(disabled bool) config.Builder { - ret := _m.Called(disabled) - - if len(ret) == 0 { - panic("no return value specified for WithDisableAutoPageBreak") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { - r0 = rf(disabled) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDisableAutoPageBreak_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDisableAutoPageBreak' -type Builder_WithDisableAutoPageBreak_Call struct { - *mock.Call -} - -// WithDisableAutoPageBreak is a helper method to define mock.On call -// - disabled bool -func (_e *Builder_Expecter) WithDisableAutoPageBreak(disabled interface{}) *Builder_WithDisableAutoPageBreak_Call { - return &Builder_WithDisableAutoPageBreak_Call{Call: _e.mock.On("WithDisableAutoPageBreak", disabled)} -} - -func (_c *Builder_WithDisableAutoPageBreak_Call) Run(run func(disabled bool)) *Builder_WithDisableAutoPageBreak_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(bool)) - }) - return _c -} - -func (_c *Builder_WithDisableAutoPageBreak_Call) Return(_a0 config.Builder) *Builder_WithDisableAutoPageBreak_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDisableAutoPageBreak_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDisableAutoPageBreak_Call { - _c.Call.Return(run) - return _c -} - -// WithKeywords provides a mock function with given fields: keywordsStr, isUTF8 -func (_m *Builder) WithKeywords(keywordsStr string, isUTF8 bool) config.Builder { - ret := _m.Called(keywordsStr, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithKeywords") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(keywordsStr, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithKeywords_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithKeywords' -type Builder_WithKeywords_Call struct { - *mock.Call -} - -// WithKeywords is a helper method to define mock.On call -// - keywordsStr string -// - isUTF8 bool -func (_e *Builder_Expecter) WithKeywords(keywordsStr interface{}, isUTF8 interface{}) *Builder_WithKeywords_Call { - return &Builder_WithKeywords_Call{Call: _e.mock.On("WithKeywords", keywordsStr, isUTF8)} -} - -func (_c *Builder_WithKeywords_Call) Run(run func(keywordsStr string, isUTF8 bool)) *Builder_WithKeywords_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithKeywords_Call) Return(_a0 config.Builder) *Builder_WithKeywords_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithKeywords_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithKeywords_Call { - _c.Call.Return(run) - return _c -} - -// WithLeftMargin provides a mock function with given fields: left -func (_m *Builder) WithLeftMargin(left float64) config.Builder { - ret := _m.Called(left) - - if len(ret) == 0 { - panic("no return value specified for WithLeftMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(left) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithLeftMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithLeftMargin' -type Builder_WithLeftMargin_Call struct { - *mock.Call -} - -// WithLeftMargin is a helper method to define mock.On call -// - left float64 -func (_e *Builder_Expecter) WithLeftMargin(left interface{}) *Builder_WithLeftMargin_Call { - return &Builder_WithLeftMargin_Call{Call: _e.mock.On("WithLeftMargin", left)} -} - -func (_c *Builder_WithLeftMargin_Call) Run(run func(left float64)) *Builder_WithLeftMargin_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) - }) - return _c -} - -func (_c *Builder_WithLeftMargin_Call) Return(_a0 config.Builder) *Builder_WithLeftMargin_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithLeftMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithLeftMargin_Call { - _c.Call.Return(run) - return _c -} - -// WithMaxGridSize provides a mock function with given fields: maxGridSize -func (_m *Builder) WithMaxGridSize(maxGridSize int) config.Builder { - ret := _m.Called(maxGridSize) - - if len(ret) == 0 { - panic("no return value specified for WithMaxGridSize") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(int) config.Builder); ok { - r0 = rf(maxGridSize) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithMaxGridSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithMaxGridSize' -type Builder_WithMaxGridSize_Call struct { - *mock.Call -} - -// WithMaxGridSize is a helper method to define mock.On call -// - maxGridSize int -func (_e *Builder_Expecter) WithMaxGridSize(maxGridSize interface{}) *Builder_WithMaxGridSize_Call { - return &Builder_WithMaxGridSize_Call{Call: _e.mock.On("WithMaxGridSize", maxGridSize)} -} - -func (_c *Builder_WithMaxGridSize_Call) Run(run func(maxGridSize int)) *Builder_WithMaxGridSize_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(int)) - }) - return _c -} - -func (_c *Builder_WithMaxGridSize_Call) Return(_a0 config.Builder) *Builder_WithMaxGridSize_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithMaxGridSize_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithMaxGridSize_Call { - _c.Call.Return(run) - return _c -} - -// WithOrientation provides a mock function with given fields: _a0 -func (_m *Builder) WithOrientation(_a0 orientation.Type) config.Builder { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for WithOrientation") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(orientation.Type) config.Builder); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithOrientation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithOrientation' -type Builder_WithOrientation_Call struct { - *mock.Call -} - -// WithOrientation is a helper method to define mock.On call -// - _a0 orientation.Type -func (_e *Builder_Expecter) WithOrientation(_a0 interface{}) *Builder_WithOrientation_Call { - return &Builder_WithOrientation_Call{Call: _e.mock.On("WithOrientation", _a0)} -} - -func (_c *Builder_WithOrientation_Call) Run(run func(_a0 orientation.Type)) *Builder_WithOrientation_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(orientation.Type)) - }) - return _c -} - -func (_c *Builder_WithOrientation_Call) Return(_a0 config.Builder) *Builder_WithOrientation_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithOrientation_Call) RunAndReturn(run func(orientation.Type) config.Builder) *Builder_WithOrientation_Call { - _c.Call.Return(run) - return _c -} - -// WithPageNumber provides a mock function with given fields: pageNumber -func (_m *Builder) WithPageNumber(pageNumber ...props.PageNumber) config.Builder { - _va := make([]interface{}, len(pageNumber)) - for _i := range pageNumber { - _va[_i] = pageNumber[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - if len(ret) == 0 { - panic("no return value specified for WithPageNumber") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(...props.PageNumber) config.Builder); ok { - r0 = rf(pageNumber...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithPageNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageNumber' -type Builder_WithPageNumber_Call struct { - *mock.Call -} - -// WithPageNumber is a helper method to define mock.On call -// - pageNumber ...props.PageNumber -func (_e *Builder_Expecter) WithPageNumber(pageNumber ...interface{}) *Builder_WithPageNumber_Call { - return &Builder_WithPageNumber_Call{Call: _e.mock.On("WithPageNumber", - append([]interface{}{}, pageNumber...)...)} -} - -func (_c *Builder_WithPageNumber_Call) Run(run func(pageNumber ...props.PageNumber)) *Builder_WithPageNumber_Call { - _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]props.PageNumber, len(args)-0) - for i, a := range args[0:] { - if a != nil { - variadicArgs[i] = a.(props.PageNumber) - } - } - run(variadicArgs...) - }) - return _c -} - -func (_c *Builder_WithPageNumber_Call) Return(_a0 config.Builder) *Builder_WithPageNumber_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithPageNumber_Call) RunAndReturn(run func(...props.PageNumber) config.Builder) *Builder_WithPageNumber_Call { - _c.Call.Return(run) - return _c -} - -// WithPageSize provides a mock function with given fields: size -func (_m *Builder) WithPageSize(size pagesize.Type) config.Builder { - ret := _m.Called(size) - - if len(ret) == 0 { - panic("no return value specified for WithPageSize") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(pagesize.Type) config.Builder); ok { - r0 = rf(size) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithPageSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageSize' -type Builder_WithPageSize_Call struct { - *mock.Call -} - -// WithPageSize is a helper method to define mock.On call -// - size pagesize.Type -func (_e *Builder_Expecter) WithPageSize(size interface{}) *Builder_WithPageSize_Call { - return &Builder_WithPageSize_Call{Call: _e.mock.On("WithPageSize", size)} -} - -func (_c *Builder_WithPageSize_Call) Run(run func(size pagesize.Type)) *Builder_WithPageSize_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(pagesize.Type)) - }) - return _c -} - -func (_c *Builder_WithPageSize_Call) Return(_a0 config.Builder) *Builder_WithPageSize_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithPageSize_Call) RunAndReturn(run func(pagesize.Type) config.Builder) *Builder_WithPageSize_Call { - _c.Call.Return(run) - return _c -} - -// WithProtection provides a mock function with given fields: protectionType, userPassword, ownerPassword -func (_m *Builder) WithProtection(protectionType protection.Type, userPassword string, ownerPassword string) config.Builder { - ret := _m.Called(protectionType, userPassword, ownerPassword) - - if len(ret) == 0 { - panic("no return value specified for WithProtection") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(protection.Type, string, string) config.Builder); ok { - r0 = rf(protectionType, userPassword, ownerPassword) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithProtection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithProtection' -type Builder_WithProtection_Call struct { - *mock.Call -} - -// WithProtection is a helper method to define mock.On call -// - protectionType protection.Type -// - userPassword string -// - ownerPassword string -func (_e *Builder_Expecter) WithProtection(protectionType interface{}, userPassword interface{}, ownerPassword interface{}) *Builder_WithProtection_Call { - return &Builder_WithProtection_Call{Call: _e.mock.On("WithProtection", protectionType, userPassword, ownerPassword)} -} - -func (_c *Builder_WithProtection_Call) Run(run func(protectionType protection.Type, userPassword string, ownerPassword string)) *Builder_WithProtection_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(protection.Type), args[1].(string), args[2].(string)) - }) - return _c -} - -func (_c *Builder_WithProtection_Call) Return(_a0 config.Builder) *Builder_WithProtection_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithProtection_Call) RunAndReturn(run func(protection.Type, string, string) config.Builder) *Builder_WithProtection_Call { - _c.Call.Return(run) - return _c -} - -// WithRightMargin provides a mock function with given fields: right -func (_m *Builder) WithRightMargin(right float64) config.Builder { - ret := _m.Called(right) - - if len(ret) == 0 { - panic("no return value specified for WithRightMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(right) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithRightMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithRightMargin' -type Builder_WithRightMargin_Call struct { - *mock.Call -} - -// WithRightMargin is a helper method to define mock.On call -// - right float64 -func (_e *Builder_Expecter) WithRightMargin(right interface{}) *Builder_WithRightMargin_Call { - return &Builder_WithRightMargin_Call{Call: _e.mock.On("WithRightMargin", right)} -} - -func (_c *Builder_WithRightMargin_Call) Run(run func(right float64)) *Builder_WithRightMargin_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) - }) - return _c -} - -func (_c *Builder_WithRightMargin_Call) Return(_a0 config.Builder) *Builder_WithRightMargin_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithRightMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithRightMargin_Call { - _c.Call.Return(run) - return _c -} - -// WithSequentialLowMemoryMode provides a mock function with given fields: chunkWorkers -func (_m *Builder) WithSequentialLowMemoryMode(chunkWorkers int) config.Builder { - ret := _m.Called(chunkWorkers) - - if len(ret) == 0 { - panic("no return value specified for WithSequentialLowMemoryMode") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(int) config.Builder); ok { - r0 = rf(chunkWorkers) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithSequentialLowMemoryMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialLowMemoryMode' -type Builder_WithSequentialLowMemoryMode_Call struct { - *mock.Call -} - -// WithSequentialLowMemoryMode is a helper method to define mock.On call -// - chunkWorkers int -func (_e *Builder_Expecter) WithSequentialLowMemoryMode(chunkWorkers interface{}) *Builder_WithSequentialLowMemoryMode_Call { - return &Builder_WithSequentialLowMemoryMode_Call{Call: _e.mock.On("WithSequentialLowMemoryMode", chunkWorkers)} -} - -func (_c *Builder_WithSequentialLowMemoryMode_Call) Run(run func(chunkWorkers int)) *Builder_WithSequentialLowMemoryMode_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(int)) - }) - return _c -} - -func (_c *Builder_WithSequentialLowMemoryMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialLowMemoryMode_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithSequentialLowMemoryMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithSequentialLowMemoryMode_Call { - _c.Call.Return(run) - return _c -} - -// WithSequentialMode provides a mock function with given fields: -func (_m *Builder) WithSequentialMode() config.Builder { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for WithSequentialMode") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func() config.Builder); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithSequentialMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialMode' -type Builder_WithSequentialMode_Call struct { - *mock.Call -} - -// WithSequentialMode is a helper method to define mock.On call -func (_e *Builder_Expecter) WithSequentialMode() *Builder_WithSequentialMode_Call { - return &Builder_WithSequentialMode_Call{Call: _e.mock.On("WithSequentialMode")} -} - -func (_c *Builder_WithSequentialMode_Call) Run(run func()) *Builder_WithSequentialMode_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *Builder_WithSequentialMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialMode_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithSequentialMode_Call) RunAndReturn(run func() config.Builder) *Builder_WithSequentialMode_Call { - _c.Call.Return(run) - return _c -} - -// WithSubject provides a mock function with given fields: subject, isUTF8 -func (_m *Builder) WithSubject(subject string, isUTF8 bool) config.Builder { - ret := _m.Called(subject, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithSubject") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(subject, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithSubject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSubject' -type Builder_WithSubject_Call struct { - *mock.Call -} - -// WithSubject is a helper method to define mock.On call -// - subject string -// - isUTF8 bool -func (_e *Builder_Expecter) WithSubject(subject interface{}, isUTF8 interface{}) *Builder_WithSubject_Call { - return &Builder_WithSubject_Call{Call: _e.mock.On("WithSubject", subject, isUTF8)} -} - -func (_c *Builder_WithSubject_Call) Run(run func(subject string, isUTF8 bool)) *Builder_WithSubject_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithSubject_Call) Return(_a0 config.Builder) *Builder_WithSubject_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithSubject_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithSubject_Call { - _c.Call.Return(run) - return _c -} - -// WithTitle provides a mock function with given fields: title, isUTF8 -func (_m *Builder) WithTitle(title string, isUTF8 bool) config.Builder { - ret := _m.Called(title, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithTitle") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(title, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithTitle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTitle' -type Builder_WithTitle_Call struct { - *mock.Call -} - -// WithTitle is a helper method to define mock.On call -// - title string -// - isUTF8 bool -func (_e *Builder_Expecter) WithTitle(title interface{}, isUTF8 interface{}) *Builder_WithTitle_Call { - return &Builder_WithTitle_Call{Call: _e.mock.On("WithTitle", title, isUTF8)} -} - -func (_c *Builder_WithTitle_Call) Run(run func(title string, isUTF8 bool)) *Builder_WithTitle_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithTitle_Call) Return(_a0 config.Builder) *Builder_WithTitle_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithTitle_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithTitle_Call { - _c.Call.Return(run) - return _c -} - -// WithTopMargin provides a mock function with given fields: top -func (_m *Builder) WithTopMargin(top float64) config.Builder { - ret := _m.Called(top) - - if len(ret) == 0 { - panic("no return value specified for WithTopMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(top) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithTopMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTopMargin' -type Builder_WithTopMargin_Call struct { - *mock.Call -} - -// WithTopMargin is a helper method to define mock.On call -// - top float64 -func (_e *Builder_Expecter) WithTopMargin(top interface{}) *Builder_WithTopMargin_Call { - return &Builder_WithTopMargin_Call{Call: _e.mock.On("WithTopMargin", top)} +// - cfg *entity.Config +// - _a1 cache.Cache +func (_e *Builder_Expecter) Build(cfg interface{}, _a1 interface{}) *Builder_Build_Call { + return &Builder_Build_Call{Call: _e.mock.On("Build", cfg, _a1)} } -func (_c *Builder_WithTopMargin_Call) Run(run func(top float64)) *Builder_WithTopMargin_Call { +func (_c *Builder_Build_Call) Run(run func(cfg *entity.Config, _a1 cache.Cache)) *Builder_Build_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) + run(args[0].(*entity.Config), args[1].(cache.Cache)) }) return _c } -func (_c *Builder_WithTopMargin_Call) Return(_a0 config.Builder) *Builder_WithTopMargin_Call { +func (_c *Builder_Build_Call) Return(_a0 *gofpdf.Dependencies) *Builder_Build_Call { _c.Call.Return(_a0) return _c } -func (_c *Builder_WithTopMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithTopMargin_Call { +func (_c *Builder_Build_Call) RunAndReturn(run func(*entity.Config, cache.Cache) *gofpdf.Dependencies) *Builder_Build_Call { _c.Call.Return(run) return _c } diff --git a/mocks/Componentmapper.go b/mocks/Componentmapper.go index 3da8c065..b7e91bb4 100644 --- a/mocks/Componentmapper.go +++ b/mocks/Componentmapper.go @@ -3,8 +3,7 @@ package mocks import ( - components "github.com/johnfercher/maroto/v2/pkg/processor/components" - + processorprovider "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" mock "github.com/stretchr/testify/mock" ) @@ -21,29 +20,29 @@ func (_m *Componentmapper) EXPECT() *Componentmapper_Expecter { return &Componentmapper_Expecter{mock: &_m.Mock} } -// Generate provides a mock function with given fields: content -func (_m *Componentmapper) Generate(content map[string]interface{}) (components.PdfComponent, error) { - ret := _m.Called(content) +// Generate provides a mock function with given fields: content, provider +func (_m *Componentmapper) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { + ret := _m.Called(content, provider) if len(ret) == 0 { panic("no return value specified for Generate") } - var r0 components.PdfComponent + var r0 processorprovider.PDFComponent var r1 error - if rf, ok := ret.Get(0).(func(map[string]interface{}) (components.PdfComponent, error)); ok { - return rf(content) + if rf, ok := ret.Get(0).(func(map[string]interface{}, processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error)); ok { + return rf(content, provider) } - if rf, ok := ret.Get(0).(func(map[string]interface{}) components.PdfComponent); ok { - r0 = rf(content) + if rf, ok := ret.Get(0).(func(map[string]interface{}, processorprovider.ProcessorProvider) processorprovider.PDFComponent); ok { + r0 = rf(content, provider) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(components.PdfComponent) + r0 = ret.Get(0).(processorprovider.PDFComponent) } } - if rf, ok := ret.Get(1).(func(map[string]interface{}) error); ok { - r1 = rf(content) + if rf, ok := ret.Get(1).(func(map[string]interface{}, processorprovider.ProcessorProvider) error); ok { + r1 = rf(content, provider) } else { r1 = ret.Error(1) } @@ -58,23 +57,24 @@ type Componentmapper_Generate_Call struct { // Generate is a helper method to define mock.On call // - content map[string]interface{} -func (_e *Componentmapper_Expecter) Generate(content interface{}) *Componentmapper_Generate_Call { - return &Componentmapper_Generate_Call{Call: _e.mock.On("Generate", content)} +// - provider processorprovider.ProcessorProvider +func (_e *Componentmapper_Expecter) Generate(content interface{}, provider interface{}) *Componentmapper_Generate_Call { + return &Componentmapper_Generate_Call{Call: _e.mock.On("Generate", content, provider)} } -func (_c *Componentmapper_Generate_Call) Run(run func(content map[string]interface{})) *Componentmapper_Generate_Call { +func (_c *Componentmapper_Generate_Call) Run(run func(content map[string]interface{}, provider processorprovider.ProcessorProvider)) *Componentmapper_Generate_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(map[string]interface{})) + run(args[0].(map[string]interface{}), args[1].(processorprovider.ProcessorProvider)) }) return _c } -func (_c *Componentmapper_Generate_Call) Return(_a0 components.PdfComponent, _a1 error) *Componentmapper_Generate_Call { +func (_c *Componentmapper_Generate_Call) Return(_a0 processorprovider.PDFComponent, _a1 error) *Componentmapper_Generate_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *Componentmapper_Generate_Call) RunAndReturn(run func(map[string]interface{}) (components.PdfComponent, error)) *Componentmapper_Generate_Call { +func (_c *Componentmapper_Generate_Call) RunAndReturn(run func(map[string]interface{}, processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error)) *Componentmapper_Generate_Call { _c.Call.Return(run) return _c } diff --git a/mocks/Loader.go b/mocks/Loader.go new file mode 100644 index 00000000..044dc497 --- /dev/null +++ b/mocks/Loader.go @@ -0,0 +1,91 @@ +// Code generated by mockery v2.42.0. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// Loader is an autogenerated mock type for the Loader type +type Loader struct { + mock.Mock +} + +type Loader_Expecter struct { + mock *mock.Mock +} + +func (_m *Loader) EXPECT() *Loader_Expecter { + return &Loader_Expecter{mock: &_m.Mock} +} + +// Load provides a mock function with given fields: path +func (_m *Loader) Load(path string) ([]byte, error) { + ret := _m.Called(path) + + if len(ret) == 0 { + panic("no return value specified for Load") + } + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(string) ([]byte, error)); ok { + return rf(path) + } + if rf, ok := ret.Get(0).(func(string) []byte); ok { + r0 = rf(path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(path) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Loader_Load_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Load' +type Loader_Load_Call struct { + *mock.Call +} + +// Load is a helper method to define mock.On call +// - path string +func (_e *Loader_Expecter) Load(path interface{}) *Loader_Load_Call { + return &Loader_Load_Call{Call: _e.mock.On("Load", path)} +} + +func (_c *Loader_Load_Call) Run(run func(path string)) *Loader_Load_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Loader_Load_Call) Return(_a0 []byte, _a1 error) *Loader_Load_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *Loader_Load_Call) RunAndReturn(run func(string) ([]byte, error)) *Loader_Load_Call { + _c.Call.Return(run) + return _c +} + +// NewLoader creates a new instance of Loader. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewLoader(t interface { + mock.TestingT + Cleanup(func()) +}, +) *Loader { + mock := &Loader{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/PDFComponent.go b/mocks/PDFComponent.go new file mode 100644 index 00000000..880dbbb5 --- /dev/null +++ b/mocks/PDFComponent.go @@ -0,0 +1,201 @@ +// Code generated by mockery v2.42.0. DO NOT EDIT. + +package mocks + +import ( + core "github.com/johnfercher/maroto/v2/pkg/core" + entity "github.com/johnfercher/maroto/v2/pkg/core/entity" + + mock "github.com/stretchr/testify/mock" + + node "github.com/johnfercher/go-tree/node" +) + +// PDFComponent is an autogenerated mock type for the PDFComponent type +type PDFComponent struct { + mock.Mock +} + +type PDFComponent_Expecter struct { + mock *mock.Mock +} + +func (_m *PDFComponent) EXPECT() *PDFComponent_Expecter { + return &PDFComponent_Expecter{mock: &_m.Mock} +} + +// GetHeight provides a mock function with given fields: provider, cell +func (_m *PDFComponent) GetHeight(provider core.Provider, cell *entity.Cell) float64 { + ret := _m.Called(provider, cell) + + if len(ret) == 0 { + panic("no return value specified for GetHeight") + } + + var r0 float64 + if rf, ok := ret.Get(0).(func(core.Provider, *entity.Cell) float64); ok { + r0 = rf(provider, cell) + } else { + r0 = ret.Get(0).(float64) + } + + return r0 +} + +// PDFComponent_GetHeight_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetHeight' +type PDFComponent_GetHeight_Call struct { + *mock.Call +} + +// GetHeight is a helper method to define mock.On call +// - provider core.Provider +// - cell *entity.Cell +func (_e *PDFComponent_Expecter) GetHeight(provider interface{}, cell interface{}) *PDFComponent_GetHeight_Call { + return &PDFComponent_GetHeight_Call{Call: _e.mock.On("GetHeight", provider, cell)} +} + +func (_c *PDFComponent_GetHeight_Call) Run(run func(provider core.Provider, cell *entity.Cell)) *PDFComponent_GetHeight_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(core.Provider), args[1].(*entity.Cell)) + }) + return _c +} + +func (_c *PDFComponent_GetHeight_Call) Return(_a0 float64) *PDFComponent_GetHeight_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PDFComponent_GetHeight_Call) RunAndReturn(run func(core.Provider, *entity.Cell) float64) *PDFComponent_GetHeight_Call { + _c.Call.Return(run) + return _c +} + +// GetStructure provides a mock function with given fields: +func (_m *PDFComponent) GetStructure() *node.Node[core.Structure] { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetStructure") + } + + var r0 *node.Node[core.Structure] + if rf, ok := ret.Get(0).(func() *node.Node[core.Structure]); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*node.Node[core.Structure]) + } + } + + return r0 +} + +// PDFComponent_GetStructure_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetStructure' +type PDFComponent_GetStructure_Call struct { + *mock.Call +} + +// GetStructure is a helper method to define mock.On call +func (_e *PDFComponent_Expecter) GetStructure() *PDFComponent_GetStructure_Call { + return &PDFComponent_GetStructure_Call{Call: _e.mock.On("GetStructure")} +} + +func (_c *PDFComponent_GetStructure_Call) Run(run func()) *PDFComponent_GetStructure_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *PDFComponent_GetStructure_Call) Return(_a0 *node.Node[core.Structure]) *PDFComponent_GetStructure_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PDFComponent_GetStructure_Call) RunAndReturn(run func() *node.Node[core.Structure]) *PDFComponent_GetStructure_Call { + _c.Call.Return(run) + return _c +} + +// Render provides a mock function with given fields: provider, cell +func (_m *PDFComponent) Render(provider core.Provider, cell *entity.Cell) { + _m.Called(provider, cell) +} + +// PDFComponent_Render_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Render' +type PDFComponent_Render_Call struct { + *mock.Call +} + +// Render is a helper method to define mock.On call +// - provider core.Provider +// - cell *entity.Cell +func (_e *PDFComponent_Expecter) Render(provider interface{}, cell interface{}) *PDFComponent_Render_Call { + return &PDFComponent_Render_Call{Call: _e.mock.On("Render", provider, cell)} +} + +func (_c *PDFComponent_Render_Call) Run(run func(provider core.Provider, cell *entity.Cell)) *PDFComponent_Render_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(core.Provider), args[1].(*entity.Cell)) + }) + return _c +} + +func (_c *PDFComponent_Render_Call) Return() *PDFComponent_Render_Call { + _c.Call.Return() + return _c +} + +func (_c *PDFComponent_Render_Call) RunAndReturn(run func(core.Provider, *entity.Cell)) *PDFComponent_Render_Call { + _c.Call.Return(run) + return _c +} + +// SetConfig provides a mock function with given fields: config +func (_m *PDFComponent) SetConfig(config *entity.Config) { + _m.Called(config) +} + +// PDFComponent_SetConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetConfig' +type PDFComponent_SetConfig_Call struct { + *mock.Call +} + +// SetConfig is a helper method to define mock.On call +// - config *entity.Config +func (_e *PDFComponent_Expecter) SetConfig(config interface{}) *PDFComponent_SetConfig_Call { + return &PDFComponent_SetConfig_Call{Call: _e.mock.On("SetConfig", config)} +} + +func (_c *PDFComponent_SetConfig_Call) Run(run func(config *entity.Config)) *PDFComponent_SetConfig_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*entity.Config)) + }) + return _c +} + +func (_c *PDFComponent_SetConfig_Call) Return() *PDFComponent_SetConfig_Call { + _c.Call.Return() + return _c +} + +func (_c *PDFComponent_SetConfig_Call) RunAndReturn(run func(*entity.Config)) *PDFComponent_SetConfig_Call { + _c.Call.Return(run) + return _c +} + +// NewPDFComponent creates a new instance of PDFComponent. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewPDFComponent(t interface { + mock.TestingT + Cleanup(func()) +}, +) *PDFComponent { + mock := &PDFComponent{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/PdfComponent.go b/mocks/PdfComponent.go deleted file mode 100644 index 73fffc01..00000000 --- a/mocks/PdfComponent.go +++ /dev/null @@ -1,86 +0,0 @@ -// Code generated by mockery v2.42.0. DO NOT EDIT. - -package mocks - -import ( - core "github.com/johnfercher/maroto/v2/pkg/core" - mock "github.com/stretchr/testify/mock" - - processorprovider "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" -) - -// PdfComponent is an autogenerated mock type for the PdfComponent type -type PdfComponent struct { - mock.Mock -} - -type PdfComponent_Expecter struct { - mock *mock.Mock -} - -func (_m *PdfComponent) EXPECT() *PdfComponent_Expecter { - return &PdfComponent_Expecter{mock: &_m.Mock} -} - -// Generate provides a mock function with given fields: provider -func (_m *PdfComponent) Generate(provider processorprovider.ProcessorProvider) core.Component { - ret := _m.Called(provider) - - if len(ret) == 0 { - panic("no return value specified for Generate") - } - - var r0 core.Component - if rf, ok := ret.Get(0).(func(processorprovider.ProcessorProvider) core.Component); ok { - r0 = rf(provider) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(core.Component) - } - } - - return r0 -} - -// PdfComponent_Generate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Generate' -type PdfComponent_Generate_Call struct { - *mock.Call -} - -// Generate is a helper method to define mock.On call -// - provider processorprovider.ProcessorProvider -func (_e *PdfComponent_Expecter) Generate(provider interface{}) *PdfComponent_Generate_Call { - return &PdfComponent_Generate_Call{Call: _e.mock.On("Generate", provider)} -} - -func (_c *PdfComponent_Generate_Call) Run(run func(provider processorprovider.ProcessorProvider)) *PdfComponent_Generate_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(processorprovider.ProcessorProvider)) - }) - return _c -} - -func (_c *PdfComponent_Generate_Call) Return(_a0 core.Component) *PdfComponent_Generate_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *PdfComponent_Generate_Call) RunAndReturn(run func(processorprovider.ProcessorProvider) core.Component) *PdfComponent_Generate_Call { - _c.Call.Return(run) - return _c -} - -// NewPdfComponent creates a new instance of PdfComponent. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewPdfComponent(t interface { - mock.TestingT - Cleanup(func()) -}, -) *PdfComponent { - mock := &PdfComponent{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/mocks/ProcessorProvider.go b/mocks/ProcessorProvider.go index a570981d..a79fd196 100644 --- a/mocks/ProcessorProvider.go +++ b/mocks/ProcessorProvider.go @@ -3,14 +3,9 @@ package mocks import ( - core "github.com/johnfercher/maroto/v2/pkg/core" - builder "github.com/johnfercher/maroto/v2/pkg/processor/components/builder" - - mock "github.com/stretchr/testify/mock" - + propsmapper "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" processorprovider "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" - - props "github.com/johnfercher/maroto/v2/pkg/processor/components/props" + mock "github.com/stretchr/testify/mock" ) // ProcessorProvider is an autogenerated mock type for the ProcessorProvider type @@ -26,68 +21,27 @@ func (_m *ProcessorProvider) EXPECT() *ProcessorProvider_Expecter { return &ProcessorProvider_Expecter{mock: &_m.Mock} } -// ConfigureBuilder provides a mock function with given fields: _a0 -func (_m *ProcessorProvider) ConfigureBuilder(_a0 builder.Builder) processorprovider.ProcessorProvider { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for ConfigureBuilder") - } - - var r0 processorprovider.ProcessorProvider - if rf, ok := ret.Get(0).(func(builder.Builder) processorprovider.ProcessorProvider); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(processorprovider.ProcessorProvider) - } +// CreateBarCode provides a mock function with given fields: value, props +func (_m *ProcessorProvider) CreateBarCode(value string, props ...*propsmapper.Barcode) processorprovider.PDFComponent { + _va := make([]interface{}, len(props)) + for _i := range props { + _va[_i] = props[_i] } - - return r0 -} - -// ProcessorProvider_ConfigureBuilder_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ConfigureBuilder' -type ProcessorProvider_ConfigureBuilder_Call struct { - *mock.Call -} - -// ConfigureBuilder is a helper method to define mock.On call -// - _a0 builder.Builder -func (_e *ProcessorProvider_Expecter) ConfigureBuilder(_a0 interface{}) *ProcessorProvider_ConfigureBuilder_Call { - return &ProcessorProvider_ConfigureBuilder_Call{Call: _e.mock.On("ConfigureBuilder", _a0)} -} - -func (_c *ProcessorProvider_ConfigureBuilder_Call) Run(run func(_a0 builder.Builder)) *ProcessorProvider_ConfigureBuilder_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(builder.Builder)) - }) - return _c -} - -func (_c *ProcessorProvider_ConfigureBuilder_Call) Return(_a0 processorprovider.ProcessorProvider) *ProcessorProvider_ConfigureBuilder_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *ProcessorProvider_ConfigureBuilder_Call) RunAndReturn(run func(builder.Builder) processorprovider.ProcessorProvider) *ProcessorProvider_ConfigureBuilder_Call { - _c.Call.Return(run) - return _c -} - -// CreateBarCode provides a mock function with given fields: value, _a1 -func (_m *ProcessorProvider) CreateBarCode(value string, _a1 props.BarCodeProps) core.Component { - ret := _m.Called(value, _a1) + var _ca []interface{} + _ca = append(_ca, value) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) if len(ret) == 0 { panic("no return value specified for CreateBarCode") } - var r0 core.Component - if rf, ok := ret.Get(0).(func(string, props.BarCodeProps) core.Component); ok { - r0 = rf(value, _a1) + var r0 processorprovider.PDFComponent + if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Barcode) processorprovider.PDFComponent); ok { + r0 = rf(value, props...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(core.Component) + r0 = ret.Get(0).(processorprovider.PDFComponent) } } @@ -101,437 +55,31 @@ type ProcessorProvider_CreateBarCode_Call struct { // CreateBarCode is a helper method to define mock.On call // - value string -// - _a1 props.BarCodeProps -func (_e *ProcessorProvider_Expecter) CreateBarCode(value interface{}, _a1 interface{}) *ProcessorProvider_CreateBarCode_Call { - return &ProcessorProvider_CreateBarCode_Call{Call: _e.mock.On("CreateBarCode", value, _a1)} -} - -func (_c *ProcessorProvider_CreateBarCode_Call) Run(run func(value string, _a1 props.BarCodeProps)) *ProcessorProvider_CreateBarCode_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(props.BarCodeProps)) - }) - return _c -} - -func (_c *ProcessorProvider_CreateBarCode_Call) Return(_a0 core.Component) *ProcessorProvider_CreateBarCode_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *ProcessorProvider_CreateBarCode_Call) RunAndReturn(run func(string, props.BarCodeProps) core.Component) *ProcessorProvider_CreateBarCode_Call { - _c.Call.Return(run) - return _c -} - -// CreateCol provides a mock function with given fields: size, components -func (_m *ProcessorProvider) CreateCol(size int, components ...core.Component) core.Col { - _va := make([]interface{}, len(components)) - for _i := range components { - _va[_i] = components[_i] - } - var _ca []interface{} - _ca = append(_ca, size) - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - if len(ret) == 0 { - panic("no return value specified for CreateCol") - } - - var r0 core.Col - if rf, ok := ret.Get(0).(func(int, ...core.Component) core.Col); ok { - r0 = rf(size, components...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(core.Col) - } - } - - return r0 -} - -// ProcessorProvider_CreateCol_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateCol' -type ProcessorProvider_CreateCol_Call struct { - *mock.Call -} - -// CreateCol is a helper method to define mock.On call -// - size int -// - components ...core.Component -func (_e *ProcessorProvider_Expecter) CreateCol(size interface{}, components ...interface{}) *ProcessorProvider_CreateCol_Call { - return &ProcessorProvider_CreateCol_Call{Call: _e.mock.On("CreateCol", - append([]interface{}{size}, components...)...)} +// - props ...*propsmapper.Barcode +func (_e *ProcessorProvider_Expecter) CreateBarCode(value interface{}, props ...interface{}) *ProcessorProvider_CreateBarCode_Call { + return &ProcessorProvider_CreateBarCode_Call{Call: _e.mock.On("CreateBarCode", + append([]interface{}{value}, props...)...)} } -func (_c *ProcessorProvider_CreateCol_Call) Run(run func(size int, components ...core.Component)) *ProcessorProvider_CreateCol_Call { +func (_c *ProcessorProvider_CreateBarCode_Call) Run(run func(value string, props ...*propsmapper.Barcode)) *ProcessorProvider_CreateBarCode_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]core.Component, len(args)-1) + variadicArgs := make([]*propsmapper.Barcode, len(args)-1) for i, a := range args[1:] { if a != nil { - variadicArgs[i] = a.(core.Component) - } - } - run(args[0].(int), variadicArgs...) - }) - return _c -} - -func (_c *ProcessorProvider_CreateCol_Call) Return(_a0 core.Col) *ProcessorProvider_CreateCol_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *ProcessorProvider_CreateCol_Call) RunAndReturn(run func(int, ...core.Component) core.Col) *ProcessorProvider_CreateCol_Call { - _c.Call.Return(run) - return _c -} - -// CreatePage provides a mock function with given fields: components -func (_m *ProcessorProvider) CreatePage(components ...core.Row) core.Page { - _va := make([]interface{}, len(components)) - for _i := range components { - _va[_i] = components[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - if len(ret) == 0 { - panic("no return value specified for CreatePage") - } - - var r0 core.Page - if rf, ok := ret.Get(0).(func(...core.Row) core.Page); ok { - r0 = rf(components...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(core.Page) - } - } - - return r0 -} - -// ProcessorProvider_CreatePage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreatePage' -type ProcessorProvider_CreatePage_Call struct { - *mock.Call -} - -// CreatePage is a helper method to define mock.On call -// - components ...core.Row -func (_e *ProcessorProvider_Expecter) CreatePage(components ...interface{}) *ProcessorProvider_CreatePage_Call { - return &ProcessorProvider_CreatePage_Call{Call: _e.mock.On("CreatePage", - append([]interface{}{}, components...)...)} -} - -func (_c *ProcessorProvider_CreatePage_Call) Run(run func(components ...core.Row)) *ProcessorProvider_CreatePage_Call { - _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]core.Row, len(args)-0) - for i, a := range args[0:] { - if a != nil { - variadicArgs[i] = a.(core.Row) - } - } - run(variadicArgs...) - }) - return _c -} - -func (_c *ProcessorProvider_CreatePage_Call) Return(_a0 core.Page) *ProcessorProvider_CreatePage_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *ProcessorProvider_CreatePage_Call) RunAndReturn(run func(...core.Row) core.Page) *ProcessorProvider_CreatePage_Call { - _c.Call.Return(run) - return _c -} - -// CreateRow provides a mock function with given fields: components -func (_m *ProcessorProvider) CreateRow(components ...core.Col) core.Row { - _va := make([]interface{}, len(components)) - for _i := range components { - _va[_i] = components[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - if len(ret) == 0 { - panic("no return value specified for CreateRow") - } - - var r0 core.Row - if rf, ok := ret.Get(0).(func(...core.Col) core.Row); ok { - r0 = rf(components...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(core.Row) - } - } - - return r0 -} - -// ProcessorProvider_CreateRow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRow' -type ProcessorProvider_CreateRow_Call struct { - *mock.Call -} - -// CreateRow is a helper method to define mock.On call -// - components ...core.Col -func (_e *ProcessorProvider_Expecter) CreateRow(components ...interface{}) *ProcessorProvider_CreateRow_Call { - return &ProcessorProvider_CreateRow_Call{Call: _e.mock.On("CreateRow", - append([]interface{}{}, components...)...)} -} - -func (_c *ProcessorProvider_CreateRow_Call) Run(run func(components ...core.Col)) *ProcessorProvider_CreateRow_Call { - _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]core.Col, len(args)-0) - for i, a := range args[0:] { - if a != nil { - variadicArgs[i] = a.(core.Col) - } - } - run(variadicArgs...) - }) - return _c -} - -func (_c *ProcessorProvider_CreateRow_Call) Return(_a0 core.Row) *ProcessorProvider_CreateRow_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *ProcessorProvider_CreateRow_Call) RunAndReturn(run func(...core.Col) core.Row) *ProcessorProvider_CreateRow_Call { - _c.Call.Return(run) - return _c -} - -// CreateText provides a mock function with given fields: value, _a1 -func (_m *ProcessorProvider) CreateText(value string, _a1 props.TextProps) core.Component { - ret := _m.Called(value, _a1) - - if len(ret) == 0 { - panic("no return value specified for CreateText") - } - - var r0 core.Component - if rf, ok := ret.Get(0).(func(string, props.TextProps) core.Component); ok { - r0 = rf(value, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(core.Component) - } - } - - return r0 -} - -// ProcessorProvider_CreateText_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateText' -type ProcessorProvider_CreateText_Call struct { - *mock.Call -} - -// CreateText is a helper method to define mock.On call -// - value string -// - _a1 props.TextProps -func (_e *ProcessorProvider_Expecter) CreateText(value interface{}, _a1 interface{}) *ProcessorProvider_CreateText_Call { - return &ProcessorProvider_CreateText_Call{Call: _e.mock.On("CreateText", value, _a1)} -} - -func (_c *ProcessorProvider_CreateText_Call) Run(run func(value string, _a1 props.TextProps)) *ProcessorProvider_CreateText_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(props.TextProps)) - }) - return _c -} - -func (_c *ProcessorProvider_CreateText_Call) Return(_a0 core.Component) *ProcessorProvider_CreateText_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *ProcessorProvider_CreateText_Call) RunAndReturn(run func(string, props.TextProps) core.Component) *ProcessorProvider_CreateText_Call { - _c.Call.Return(run) - return _c -} - -// GeneratePdf provides a mock function with given fields: -func (_m *ProcessorProvider) GeneratePdf() ([]byte, error) { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for GeneratePdf") - } - - var r0 []byte - var r1 error - if rf, ok := ret.Get(0).(func() ([]byte, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() []byte); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]byte) - } - } - - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// ProcessorProvider_GeneratePdf_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GeneratePdf' -type ProcessorProvider_GeneratePdf_Call struct { - *mock.Call -} - -// GeneratePdf is a helper method to define mock.On call -func (_e *ProcessorProvider_Expecter) GeneratePdf() *ProcessorProvider_GeneratePdf_Call { - return &ProcessorProvider_GeneratePdf_Call{Call: _e.mock.On("GeneratePdf")} -} - -func (_c *ProcessorProvider_GeneratePdf_Call) Run(run func()) *ProcessorProvider_GeneratePdf_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *ProcessorProvider_GeneratePdf_Call) Return(_a0 []byte, _a1 error) *ProcessorProvider_GeneratePdf_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *ProcessorProvider_GeneratePdf_Call) RunAndReturn(run func() ([]byte, error)) *ProcessorProvider_GeneratePdf_Call { - _c.Call.Return(run) - return _c -} - -// RegisterFooter provides a mock function with given fields: rows -func (_m *ProcessorProvider) RegisterFooter(rows ...core.Row) processorprovider.ProcessorProvider { - _va := make([]interface{}, len(rows)) - for _i := range rows { - _va[_i] = rows[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - if len(ret) == 0 { - panic("no return value specified for RegisterFooter") - } - - var r0 processorprovider.ProcessorProvider - if rf, ok := ret.Get(0).(func(...core.Row) processorprovider.ProcessorProvider); ok { - r0 = rf(rows...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(processorprovider.ProcessorProvider) - } - } - - return r0 -} - -// ProcessorProvider_RegisterFooter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterFooter' -type ProcessorProvider_RegisterFooter_Call struct { - *mock.Call -} - -// RegisterFooter is a helper method to define mock.On call -// - rows ...core.Row -func (_e *ProcessorProvider_Expecter) RegisterFooter(rows ...interface{}) *ProcessorProvider_RegisterFooter_Call { - return &ProcessorProvider_RegisterFooter_Call{Call: _e.mock.On("RegisterFooter", - append([]interface{}{}, rows...)...)} -} - -func (_c *ProcessorProvider_RegisterFooter_Call) Run(run func(rows ...core.Row)) *ProcessorProvider_RegisterFooter_Call { - _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]core.Row, len(args)-0) - for i, a := range args[0:] { - if a != nil { - variadicArgs[i] = a.(core.Row) - } - } - run(variadicArgs...) - }) - return _c -} - -func (_c *ProcessorProvider_RegisterFooter_Call) Return(_a0 processorprovider.ProcessorProvider) *ProcessorProvider_RegisterFooter_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *ProcessorProvider_RegisterFooter_Call) RunAndReturn(run func(...core.Row) processorprovider.ProcessorProvider) *ProcessorProvider_RegisterFooter_Call { - _c.Call.Return(run) - return _c -} - -// RegisterHeader provides a mock function with given fields: rows -func (_m *ProcessorProvider) RegisterHeader(rows ...core.Row) processorprovider.ProcessorProvider { - _va := make([]interface{}, len(rows)) - for _i := range rows { - _va[_i] = rows[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - if len(ret) == 0 { - panic("no return value specified for RegisterHeader") - } - - var r0 processorprovider.ProcessorProvider - if rf, ok := ret.Get(0).(func(...core.Row) processorprovider.ProcessorProvider); ok { - r0 = rf(rows...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(processorprovider.ProcessorProvider) - } - } - - return r0 -} - -// ProcessorProvider_RegisterHeader_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterHeader' -type ProcessorProvider_RegisterHeader_Call struct { - *mock.Call -} - -// RegisterHeader is a helper method to define mock.On call -// - rows ...core.Row -func (_e *ProcessorProvider_Expecter) RegisterHeader(rows ...interface{}) *ProcessorProvider_RegisterHeader_Call { - return &ProcessorProvider_RegisterHeader_Call{Call: _e.mock.On("RegisterHeader", - append([]interface{}{}, rows...)...)} -} - -func (_c *ProcessorProvider_RegisterHeader_Call) Run(run func(rows ...core.Row)) *ProcessorProvider_RegisterHeader_Call { - _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]core.Row, len(args)-0) - for i, a := range args[0:] { - if a != nil { - variadicArgs[i] = a.(core.Row) + variadicArgs[i] = a.(*propsmapper.Barcode) } } - run(variadicArgs...) + run(args[0].(string), variadicArgs...) }) return _c } -func (_c *ProcessorProvider_RegisterHeader_Call) Return(_a0 processorprovider.ProcessorProvider) *ProcessorProvider_RegisterHeader_Call { +func (_c *ProcessorProvider_CreateBarCode_Call) Return(_a0 processorprovider.PDFComponent) *ProcessorProvider_CreateBarCode_Call { _c.Call.Return(_a0) return _c } -func (_c *ProcessorProvider_RegisterHeader_Call) RunAndReturn(run func(...core.Row) processorprovider.ProcessorProvider) *ProcessorProvider_RegisterHeader_Call { +func (_c *ProcessorProvider_CreateBarCode_Call) RunAndReturn(run func(string, ...*propsmapper.Barcode) processorprovider.PDFComponent) *ProcessorProvider_CreateBarCode_Call { _c.Call.Return(run) return _c } diff --git a/mocks/Repository.go b/mocks/Repository.go index 3977c94e..e5fec24e 100644 --- a/mocks/Repository.go +++ b/mocks/Repository.go @@ -2,14 +2,7 @@ package mocks -import ( - fontstyle "github.com/johnfercher/maroto/v2/pkg/consts/fontstyle" - entity "github.com/johnfercher/maroto/v2/pkg/core/entity" - - mock "github.com/stretchr/testify/mock" - - repository "github.com/johnfercher/maroto/v2/pkg/repository" -) +import mock "github.com/stretchr/testify/mock" // Repository is an autogenerated mock type for the Repository type type Repository struct { @@ -24,159 +17,107 @@ func (_m *Repository) EXPECT() *Repository_Expecter { return &Repository_Expecter{mock: &_m.Mock} } -// AddUTF8Font provides a mock function with given fields: family, style, file -func (_m *Repository) AddUTF8Font(family string, style fontstyle.Type, file string) repository.Repository { - ret := _m.Called(family, style, file) +// ReadTemplate provides a mock function with given fields: templateName +func (_m *Repository) ReadTemplate(templateName string) (map[string]interface{}, error) { + ret := _m.Called(templateName) if len(ret) == 0 { - panic("no return value specified for AddUTF8Font") + panic("no return value specified for ReadTemplate") } - var r0 repository.Repository - if rf, ok := ret.Get(0).(func(string, fontstyle.Type, string) repository.Repository); ok { - r0 = rf(family, style, file) + var r0 map[string]interface{} + var r1 error + if rf, ok := ret.Get(0).(func(string) (map[string]interface{}, error)); ok { + return rf(templateName) + } + if rf, ok := ret.Get(0).(func(string) map[string]interface{}); ok { + r0 = rf(templateName) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(repository.Repository) + r0 = ret.Get(0).(map[string]interface{}) } } - return r0 -} - -// Repository_AddUTF8Font_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddUTF8Font' -type Repository_AddUTF8Font_Call struct { - *mock.Call -} - -// AddUTF8Font is a helper method to define mock.On call -// - family string -// - style fontstyle.Type -// - file string -func (_e *Repository_Expecter) AddUTF8Font(family interface{}, style interface{}, file interface{}) *Repository_AddUTF8Font_Call { - return &Repository_AddUTF8Font_Call{Call: _e.mock.On("AddUTF8Font", family, style, file)} -} - -func (_c *Repository_AddUTF8Font_Call) Run(run func(family string, style fontstyle.Type, file string)) *Repository_AddUTF8Font_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(fontstyle.Type), args[2].(string)) - }) - return _c -} - -func (_c *Repository_AddUTF8Font_Call) Return(_a0 repository.Repository) *Repository_AddUTF8Font_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Repository_AddUTF8Font_Call) RunAndReturn(run func(string, fontstyle.Type, string) repository.Repository) *Repository_AddUTF8Font_Call { - _c.Call.Return(run) - return _c -} - -// AddUTF8FontFromBytes provides a mock function with given fields: family, style, bytes -func (_m *Repository) AddUTF8FontFromBytes(family string, style fontstyle.Type, bytes []byte) repository.Repository { - ret := _m.Called(family, style, bytes) - - if len(ret) == 0 { - panic("no return value specified for AddUTF8FontFromBytes") - } - - var r0 repository.Repository - if rf, ok := ret.Get(0).(func(string, fontstyle.Type, []byte) repository.Repository); ok { - r0 = rf(family, style, bytes) + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(templateName) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(repository.Repository) - } + r1 = ret.Error(1) } - return r0 + return r0, r1 } -// Repository_AddUTF8FontFromBytes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddUTF8FontFromBytes' -type Repository_AddUTF8FontFromBytes_Call struct { +// Repository_ReadTemplate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReadTemplate' +type Repository_ReadTemplate_Call struct { *mock.Call } -// AddUTF8FontFromBytes is a helper method to define mock.On call -// - family string -// - style fontstyle.Type -// - bytes []byte -func (_e *Repository_Expecter) AddUTF8FontFromBytes(family interface{}, style interface{}, bytes interface{}) *Repository_AddUTF8FontFromBytes_Call { - return &Repository_AddUTF8FontFromBytes_Call{Call: _e.mock.On("AddUTF8FontFromBytes", family, style, bytes)} +// ReadTemplate is a helper method to define mock.On call +// - templateName string +func (_e *Repository_Expecter) ReadTemplate(templateName interface{}) *Repository_ReadTemplate_Call { + return &Repository_ReadTemplate_Call{Call: _e.mock.On("ReadTemplate", templateName)} } -func (_c *Repository_AddUTF8FontFromBytes_Call) Run(run func(family string, style fontstyle.Type, bytes []byte)) *Repository_AddUTF8FontFromBytes_Call { +func (_c *Repository_ReadTemplate_Call) Run(run func(templateName string)) *Repository_ReadTemplate_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(fontstyle.Type), args[2].([]byte)) + run(args[0].(string)) }) return _c } -func (_c *Repository_AddUTF8FontFromBytes_Call) Return(_a0 repository.Repository) *Repository_AddUTF8FontFromBytes_Call { - _c.Call.Return(_a0) +func (_c *Repository_ReadTemplate_Call) Return(_a0 map[string]interface{}, _a1 error) *Repository_ReadTemplate_Call { + _c.Call.Return(_a0, _a1) return _c } -func (_c *Repository_AddUTF8FontFromBytes_Call) RunAndReturn(run func(string, fontstyle.Type, []byte) repository.Repository) *Repository_AddUTF8FontFromBytes_Call { +func (_c *Repository_ReadTemplate_Call) RunAndReturn(run func(string) (map[string]interface{}, error)) *Repository_ReadTemplate_Call { _c.Call.Return(run) return _c } -// Load provides a mock function with given fields: -func (_m *Repository) Load() ([]*entity.CustomFont, error) { - ret := _m.Called() +// RegisterTemplate provides a mock function with given fields: templateName, template +func (_m *Repository) RegisterTemplate(templateName string, template map[string]interface{}) error { + ret := _m.Called(templateName, template) if len(ret) == 0 { - panic("no return value specified for Load") + panic("no return value specified for RegisterTemplate") } - var r0 []*entity.CustomFont - var r1 error - if rf, ok := ret.Get(0).(func() ([]*entity.CustomFont, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() []*entity.CustomFont); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*entity.CustomFont) - } - } - - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() + var r0 error + if rf, ok := ret.Get(0).(func(string, map[string]interface{}) error); ok { + r0 = rf(templateName, template) } else { - r1 = ret.Error(1) + r0 = ret.Error(0) } - return r0, r1 + return r0 } -// Repository_Load_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Load' -type Repository_Load_Call struct { +// Repository_RegisterTemplate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterTemplate' +type Repository_RegisterTemplate_Call struct { *mock.Call } -// Load is a helper method to define mock.On call -func (_e *Repository_Expecter) Load() *Repository_Load_Call { - return &Repository_Load_Call{Call: _e.mock.On("Load")} +// RegisterTemplate is a helper method to define mock.On call +// - templateName string +// - template map[string]interface{} +func (_e *Repository_Expecter) RegisterTemplate(templateName interface{}, template interface{}) *Repository_RegisterTemplate_Call { + return &Repository_RegisterTemplate_Call{Call: _e.mock.On("RegisterTemplate", templateName, template)} } -func (_c *Repository_Load_Call) Run(run func()) *Repository_Load_Call { +func (_c *Repository_RegisterTemplate_Call) Run(run func(templateName string, template map[string]interface{})) *Repository_RegisterTemplate_Call { _c.Call.Run(func(args mock.Arguments) { - run() + run(args[0].(string), args[1].(map[string]interface{})) }) return _c } -func (_c *Repository_Load_Call) Return(_a0 []*entity.CustomFont, _a1 error) *Repository_Load_Call { - _c.Call.Return(_a0, _a1) +func (_c *Repository_RegisterTemplate_Call) Return(_a0 error) *Repository_RegisterTemplate_Call { + _c.Call.Return(_a0) return _c } -func (_c *Repository_Load_Call) RunAndReturn(run func() ([]*entity.CustomFont, error)) *Repository_Load_Call { +func (_c *Repository_RegisterTemplate_Call) RunAndReturn(run func(string, map[string]interface{}) error) *Repository_RegisterTemplate_Call { _c.Call.Return(run) return _c } diff --git a/pkg/processor/mappers/components/codemapper/barcode_test.go b/pkg/processor/mappers/components/codemapper/barcode_test.go index 77827b2f..ad4e3617 100644 --- a/pkg/processor/mappers/components/codemapper/barcode_test.go +++ b/pkg/processor/mappers/components/codemapper/barcode_test.go @@ -4,6 +4,7 @@ package codemapper_test import ( "testing" + "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/codemapper" "github.com/stretchr/testify/assert" ) @@ -99,3 +100,55 @@ func TestNewBarcode(t *testing.T) { assert.Equal(t, barcode.Code, "code") }) } + +func TestGenerate(t *testing.T) { + t.Run("if source key is not found, should return an error", func(t *testing.T) { + content := map[string]interface{}{} + provider := mocks.NewProcessorProvider(t) + + barcode := codemapper.Barcode{SourceKey: "code"} + component, err := barcode.Generate(content, provider) + + assert.Nil(t, component) + assert.NotNil(t, err) + }) + t.Run("if source key content is not valid, should return an error", func(t *testing.T) { + content := map[string]interface{}{ + "code": 1, + } + provider := mocks.NewProcessorProvider(t) + + barcode := codemapper.Barcode{SourceKey: "code"} + component, err := barcode.Generate(content, provider) + + assert.Nil(t, component) + assert.NotNil(t, err) + }) + t.Run("If the barcode has no props, the props will not be sent", func(t *testing.T) { + content := map[string]interface{}{ + "code": "code", + } + + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateBarCode("code").Return(nil) + + barcode := codemapper.Barcode{SourceKey: "code"} + _, err := barcode.Generate(content, provider) + + assert.Nil(t, err) + provider.AssertNumberOfCalls(t, "CreateBarCode", 1) + }) + t.Run("when valid code is sent, should generate barcode", func(t *testing.T) { + content := map[string]interface{}{} + + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateBarCode("code").Return(nil) + + barcode := codemapper.Barcode{Code: "code"} + _, err := barcode.Generate(content, provider) + + assert.Nil(t, err) + provider.AssertNumberOfCalls(t, "CreateBarCode", 1) + }) + +} diff --git a/pkg/processor/processorprovider/Maroto_test.go b/pkg/processor/processorprovider/Maroto_test.go new file mode 100644 index 00000000..1b7d6a43 --- /dev/null +++ b/pkg/processor/processorprovider/Maroto_test.go @@ -0,0 +1,26 @@ +package processorprovider_test + +import ( + "testing" + + "github.com/johnfercher/maroto/v2/pkg/components/code" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" + "github.com/johnfercher/maroto/v2/pkg/test" + "github.com/stretchr/testify/assert" +) + +func TestCreateBarCode(t *testing.T) { + t.Run("when CreateBarCode is called, should generate a barcode", func(t *testing.T) { + m := processorprovider.NewMaroto() + barcode := m.CreateBarCode("code", + &propsmapper.Barcode{Left: 10.0, Top: 10.0, Percent: 100.0, + Proportion: propsmapper.Proportion{Width: 10, Height: 2}, + Center: false, Type: propsmapper.NewCodeType("code128"), + }, + ) + + assert.IsType(t, barcode, &code.Barcode{}) + test.New(t).Assert(barcode.GetStructure()).Equals("processor/provider/barcode.json") + }) +} diff --git a/test/maroto/processor/provider/barcode.json b/test/maroto/processor/provider/barcode.json new file mode 100644 index 00000000..5df7311b --- /dev/null +++ b/test/maroto/processor/provider/barcode.json @@ -0,0 +1,11 @@ +{ + "value": "code", + "type": "barcode", + "details": { + "prop_left": 10, + "prop_percent": 100, + "prop_proportion_height": 2, + "prop_proportion_width": 10, + "prop_top": 10 + } +} \ No newline at end of file From bf188487a9991ad4455aa88a3773e7c97ae3c246 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 27 Oct 2024 12:02:05 -0300 Subject: [PATCH 047/116] feat: create barcode component remove component package --- pkg/processor/components/barcode/bar_code.go | 23 ------- pkg/processor/components/builder/builder.go | 7 --- pkg/processor/components/col/col.go | 29 --------- pkg/processor/components/components.go | 10 ---- pkg/processor/components/image/image.go | 9 --- pkg/processor/components/page/page.go | 26 -------- pkg/processor/components/pdf/pdf.go | 27 --------- pkg/processor/components/props/bar_code.go | 5 -- pkg/processor/components/props/col.go | 5 -- pkg/processor/components/props/text.go | 5 -- pkg/processor/components/row/row.go | 26 -------- pkg/processor/components/text/text.go | 23 ------- .../mappers/components/codemapper/barcode.go | 30 +++++++++- pkg/processor/processorprovider/Maroto.go | 60 ++++--------------- pkg/processor/processorprovider/provider.go | 21 ++++--- 15 files changed, 47 insertions(+), 259 deletions(-) delete mode 100644 pkg/processor/components/barcode/bar_code.go delete mode 100644 pkg/processor/components/builder/builder.go delete mode 100644 pkg/processor/components/col/col.go delete mode 100644 pkg/processor/components/components.go delete mode 100644 pkg/processor/components/image/image.go delete mode 100644 pkg/processor/components/page/page.go delete mode 100644 pkg/processor/components/pdf/pdf.go delete mode 100644 pkg/processor/components/props/bar_code.go delete mode 100644 pkg/processor/components/props/col.go delete mode 100644 pkg/processor/components/props/text.go delete mode 100644 pkg/processor/components/row/row.go delete mode 100644 pkg/processor/components/text/text.go diff --git a/pkg/processor/components/barcode/bar_code.go b/pkg/processor/components/barcode/bar_code.go deleted file mode 100644 index 18074155..00000000 --- a/pkg/processor/components/barcode/bar_code.go +++ /dev/null @@ -1,23 +0,0 @@ -package barcode - -import ( - "github.com/johnfercher/maroto/v2/pkg/core" - "github.com/johnfercher/maroto/v2/pkg/processor/components/props" - "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" -) - -type BarCode struct { - Props props.BarCodeProps - Code string -} - -func NewBarCode(props props.BarCodeProps, code string) *BarCode { - return &BarCode{ - Code: code, - Props: props, - } -} - -func (b *BarCode) Generate(provider processorprovider.ProcessorProvider) core.Component { - return provider.CreateBarCode(b.Code, b.Props) -} diff --git a/pkg/processor/components/builder/builder.go b/pkg/processor/components/builder/builder.go deleted file mode 100644 index 7870c7c0..00000000 --- a/pkg/processor/components/builder/builder.go +++ /dev/null @@ -1,7 +0,0 @@ -package builder - -type Builder struct{} - -func NewBuilder() *Builder { - return nil -} diff --git a/pkg/processor/components/col/col.go b/pkg/processor/components/col/col.go deleted file mode 100644 index b0677795..00000000 --- a/pkg/processor/components/col/col.go +++ /dev/null @@ -1,29 +0,0 @@ -package col - -import ( - "github.com/johnfercher/maroto/v2/pkg/core" - "github.com/johnfercher/maroto/v2/pkg/processor/components" - "github.com/johnfercher/maroto/v2/pkg/processor/components/props" - "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" -) - -type Col struct { - Props props.ColProps - Components []components.PdfComponent -} - -func NewCol(props props.ColProps, components ...components.PdfComponent) *Col { - return &Col{ - Props: props, - Components: components, - } -} - -func (c *Col) Generate(provider processorprovider.ProcessorProvider) core.Col { - components := make([]core.Component, len(c.Components)) - - for i, component := range c.Components { - components[i] = component.Generate(provider) - } - return provider.CreateCol(c.Props.Size, components...) -} diff --git a/pkg/processor/components/components.go b/pkg/processor/components/components.go deleted file mode 100644 index aac7332d..00000000 --- a/pkg/processor/components/components.go +++ /dev/null @@ -1,10 +0,0 @@ -package components - -import ( - "github.com/johnfercher/maroto/v2/pkg/core" - "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" -) - -type PdfComponent interface { - Generate(provider processorprovider.ProcessorProvider) core.Component -} diff --git a/pkg/processor/components/image/image.go b/pkg/processor/components/image/image.go deleted file mode 100644 index 4e87b064..00000000 --- a/pkg/processor/components/image/image.go +++ /dev/null @@ -1,9 +0,0 @@ -package image - -type Image struct { - SourceKey string -} - -func NewImage() *Image { - return &Image{} -} diff --git a/pkg/processor/components/page/page.go b/pkg/processor/components/page/page.go deleted file mode 100644 index e435670d..00000000 --- a/pkg/processor/components/page/page.go +++ /dev/null @@ -1,26 +0,0 @@ -package page - -import ( - "github.com/johnfercher/maroto/v2/pkg/core" - "github.com/johnfercher/maroto/v2/pkg/processor/components/row" - "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" -) - -type Page struct { - Rows []row.Row -} - -func NewPage(header, rows []row.Row) *Page { - return &Page{ - Rows: rows, - } -} - -func (p *Page) Generate(provider processorprovider.ProcessorProvider) { - rows := make([]core.Row, len(p.Rows)) - - for i, row := range p.Rows { - rows[i] = row.Generate(provider) - } - provider.CreatePage(rows...) -} diff --git a/pkg/processor/components/pdf/pdf.go b/pkg/processor/components/pdf/pdf.go deleted file mode 100644 index e503f9f4..00000000 --- a/pkg/processor/components/pdf/pdf.go +++ /dev/null @@ -1,27 +0,0 @@ -package pdf - -import ( - "github.com/johnfercher/maroto/v2/pkg/processor/components/builder" - "github.com/johnfercher/maroto/v2/pkg/processor/components/page" - "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" -) - -type Pdf struct { - Builder *builder.Builder - Pages []*page.Page -} - -func NewPdf(builder *builder.Builder, pages ...*page.Page) *Pdf { - return &Pdf{ - Builder: builder, - Pages: pages, - } -} - -func (p *Pdf) Generate(provider processorprovider.ProcessorProvider) processorprovider.ProcessorProvider { - for _, page := range p.Pages { - page.Generate(provider) - } - - return provider -} diff --git a/pkg/processor/components/props/bar_code.go b/pkg/processor/components/props/bar_code.go deleted file mode 100644 index 05a44481..00000000 --- a/pkg/processor/components/props/bar_code.go +++ /dev/null @@ -1,5 +0,0 @@ -package props - -type BarCodeProps struct { - Align string -} diff --git a/pkg/processor/components/props/col.go b/pkg/processor/components/props/col.go deleted file mode 100644 index a773f6c8..00000000 --- a/pkg/processor/components/props/col.go +++ /dev/null @@ -1,5 +0,0 @@ -package props - -type ColProps struct { - Size int -} diff --git a/pkg/processor/components/props/text.go b/pkg/processor/components/props/text.go deleted file mode 100644 index 04109095..00000000 --- a/pkg/processor/components/props/text.go +++ /dev/null @@ -1,5 +0,0 @@ -package props - -type TextProps struct { - Align string -} diff --git a/pkg/processor/components/row/row.go b/pkg/processor/components/row/row.go deleted file mode 100644 index 6389803f..00000000 --- a/pkg/processor/components/row/row.go +++ /dev/null @@ -1,26 +0,0 @@ -package row - -import ( - "github.com/johnfercher/maroto/v2/pkg/core" - "github.com/johnfercher/maroto/v2/pkg/processor/components/col" - "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" -) - -type Row struct { - Cols []col.Col -} - -func NewRow(cols ...col.Col) *Row { - return &Row{ - Cols: cols, - } -} - -func (r *Row) Generate(provider processorprovider.ProcessorProvider) core.Row { - cols := make([]core.Col, len(r.Cols)) - - for i, col := range r.Cols { - cols[i] = col.Generate(provider) - } - return provider.CreateRow(cols...) -} diff --git a/pkg/processor/components/text/text.go b/pkg/processor/components/text/text.go deleted file mode 100644 index 46bc133b..00000000 --- a/pkg/processor/components/text/text.go +++ /dev/null @@ -1,23 +0,0 @@ -package text - -import ( - "github.com/johnfercher/maroto/v2/pkg/core" - "github.com/johnfercher/maroto/v2/pkg/processor/components/props" - "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" -) - -type Text struct { - Props props.TextProps - Value string -} - -func NewText(props props.TextProps, value string) *Text { - return &Text{ - Props: props, - Value: value, - } -} - -func (t *Text) Generate(provider processorprovider.ProcessorProvider) core.Component { - return provider.CreateText(t.Value, t.Props) -} diff --git a/pkg/processor/mappers/components/codemapper/barcode.go b/pkg/processor/mappers/components/codemapper/barcode.go index 212afba6..73bf3301 100644 --- a/pkg/processor/mappers/components/codemapper/barcode.go +++ b/pkg/processor/mappers/components/codemapper/barcode.go @@ -5,8 +5,8 @@ package codemapper import ( "fmt" - "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Barcode struct { @@ -94,6 +94,30 @@ func (b *Barcode) validateFields() error { return nil } -func (b *Barcode) Generate(content map[string]interface{}) (components.PdfComponent, error) { - return nil, nil +func (b *Barcode) getCode(content map[string]interface{}) (string, error) { + if b.Code != "" { + return b.Code, nil + } + codeFound, ok := content[b.SourceKey] + if !ok { + return "", fmt.Errorf("barcode requires a source key named %s, but it was not found", b.SourceKey) + } + codeValid, ok := codeFound.(string) + if !ok { + return "", fmt.Errorf("unable to generate barcode, invalid code. source key %s", b.SourceKey) + } + return codeValid, nil +} + +func (b *Barcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { + code, err := b.getCode(content) + if err != nil { + return nil, err + } + b.Code = code + + if b.Props != nil { + return provider.CreateBarCode(b.Code, b.Props), nil + } + return provider.CreateBarCode(b.Code), nil } diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index 363fb51b..07a42a7c 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -2,16 +2,10 @@ package processorprovider import ( "github.com/johnfercher/maroto/v2/pkg/components/code" - "github.com/johnfercher/maroto/v2/pkg/components/col" - "github.com/johnfercher/maroto/v2/pkg/components/page" - "github.com/johnfercher/maroto/v2/pkg/components/row" - marototext "github.com/johnfercher/maroto/v2/pkg/components/text" - marotoprops "github.com/johnfercher/maroto/v2/pkg/props" - - "github.com/johnfercher/maroto/v2/pkg/consts/align" + "github.com/johnfercher/maroto/v2/pkg/consts/barcode" "github.com/johnfercher/maroto/v2/pkg/core" - "github.com/johnfercher/maroto/v2/pkg/processor/components/builder" - "github.com/johnfercher/maroto/v2/pkg/processor/components/props" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" + "github.com/johnfercher/maroto/v2/pkg/props" ) type Maroto struct { @@ -23,47 +17,13 @@ func NewMaroto() *Maroto { return nil } -func (m *Maroto) GeneratePdf() ([]byte, error) { - doc, err := (*m.maroto).Generate() - if err != nil { - return nil, err +func (m *Maroto) CreateBarCode(codeValue string, codeProps ...*propsmapper.Barcode) PDFComponent { + cProps := propsmapper.Barcode{} + if len(codeProps) > 0 { + cProps = *codeProps[0] } - return doc.GetBytes(), nil -} - -func (m *Maroto) ConfigureBuilder(builder builder.Builder) ProcessorProvider { - return nil -} - -func (m *Maroto) RegisterHeader(rows ...core.Row) ProcessorProvider { - (*m.maroto).RegisterHeader(rows...) - return m -} - -func (m *Maroto) RegisterFooter(rows ...core.Row) ProcessorProvider { - (*m.maroto).RegisterFooter(rows...) - return m -} - -func (m *Maroto) CreatePage(components ...core.Row) core.Page { - newPage := page.New().Add(components...) - (*m.maroto).AddPages(newPage) - return newPage -} - -func (m *Maroto) CreateRow(cols ...core.Col) core.Row { - return row.New().Add(cols...) -} - -func (m *Maroto) CreateCol(size int, components ...core.Component) core.Col { - return col.New(size).Add(components...) -} - -func (m *Maroto) CreateText(value string, props props.TextProps) core.Component { - return marototext.New(value, marotoprops.Text{Align: align.Type(props.Align)}) -} - -func (m *Maroto) CreateBarCode(codeValue string, props props.BarCodeProps) core.Component { - return code.NewBar(codeValue) + return code.NewBar(codeValue, props.Barcode{Left: cProps.Left, Top: cProps.Top, Percent: cProps.Percent, + Proportion: props.Proportion(cProps.Proportion), Center: cProps.Center, Type: barcode.Type(cProps.Type), + }) } diff --git a/pkg/processor/processorprovider/provider.go b/pkg/processor/processorprovider/provider.go index 4e1aec05..a0a9f156 100644 --- a/pkg/processor/processorprovider/provider.go +++ b/pkg/processor/processorprovider/provider.go @@ -2,18 +2,17 @@ package processorprovider import ( "github.com/johnfercher/maroto/v2/pkg/core" - "github.com/johnfercher/maroto/v2/pkg/processor/components/builder" - "github.com/johnfercher/maroto/v2/pkg/processor/components/props" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" ) +// PDFComponent provides the interface of the components that +// will be generated by the provider (Maroto) +type PDFComponent interface { + core.Component +} + +// ProcessorProvider provides an interface with all the methods that +// Maroto provides for pdf builder type ProcessorProvider interface { - GeneratePdf() ([]byte, error) - ConfigureBuilder(builder builder.Builder) ProcessorProvider - RegisterHeader(rows ...core.Row) ProcessorProvider - RegisterFooter(rows ...core.Row) ProcessorProvider - CreatePage(components ...core.Row) core.Page - CreateRow(components ...core.Col) core.Row - CreateCol(size int, components ...core.Component) core.Col - CreateText(value string, props props.TextProps) core.Component - CreateBarCode(value string, props props.BarCodeProps) core.Component + CreateBarCode(value string, props ...*propsmapper.Barcode) PDFComponent } From 186664f106a2eb048a57a189727eab2cf3083d99 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 27 Oct 2024 12:19:40 -0300 Subject: [PATCH 048/116] test: validate creation of matrixcode component --- mocks/ProcessorProvider.go | 63 +++++++++++++++++++ .../components/codemapper/matrixcode_test.go | 52 +++++++++++++++ .../processorprovider/Maroto_test.go | 13 +++- .../maroto/processor/provider/matrixcode.json | 9 +++ 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 test/maroto/processor/provider/matrixcode.json diff --git a/mocks/ProcessorProvider.go b/mocks/ProcessorProvider.go index a79fd196..a8cea020 100644 --- a/mocks/ProcessorProvider.go +++ b/mocks/ProcessorProvider.go @@ -84,6 +84,69 @@ func (_c *ProcessorProvider_CreateBarCode_Call) RunAndReturn(run func(string, .. return _c } +// CreateMatrixCode provides a mock function with given fields: value, props +func (_m *ProcessorProvider) CreateMatrixCode(value string, props ...*propsmapper.Rect) processorprovider.PDFComponent { + _va := make([]interface{}, len(props)) + for _i := range props { + _va[_i] = props[_i] + } + var _ca []interface{} + _ca = append(_ca, value) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for CreateMatrixCode") + } + + var r0 processorprovider.PDFComponent + if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Rect) processorprovider.PDFComponent); ok { + r0 = rf(value, props...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(processorprovider.PDFComponent) + } + } + + return r0 +} + +// ProcessorProvider_CreateMatrixCode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateMatrixCode' +type ProcessorProvider_CreateMatrixCode_Call struct { + *mock.Call +} + +// CreateMatrixCode is a helper method to define mock.On call +// - value string +// - props ...*propsmapper.Rect +func (_e *ProcessorProvider_Expecter) CreateMatrixCode(value interface{}, props ...interface{}) *ProcessorProvider_CreateMatrixCode_Call { + return &ProcessorProvider_CreateMatrixCode_Call{Call: _e.mock.On("CreateMatrixCode", + append([]interface{}{value}, props...)...)} +} + +func (_c *ProcessorProvider_CreateMatrixCode_Call) Run(run func(value string, props ...*propsmapper.Rect)) *ProcessorProvider_CreateMatrixCode_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]*propsmapper.Rect, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(*propsmapper.Rect) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_CreateMatrixCode_Call) Return(_a0 processorprovider.PDFComponent) *ProcessorProvider_CreateMatrixCode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorProvider_CreateMatrixCode_Call) RunAndReturn(run func(string, ...*propsmapper.Rect) processorprovider.PDFComponent) *ProcessorProvider_CreateMatrixCode_Call { + _c.Call.Return(run) + return _c +} + // NewProcessorProvider creates a new instance of ProcessorProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewProcessorProvider(t interface { diff --git a/pkg/processor/mappers/components/codemapper/matrixcode_test.go b/pkg/processor/mappers/components/codemapper/matrixcode_test.go index a2d6746b..91a43162 100644 --- a/pkg/processor/mappers/components/codemapper/matrixcode_test.go +++ b/pkg/processor/mappers/components/codemapper/matrixcode_test.go @@ -4,6 +4,7 @@ package codemapper_test import ( "testing" + "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/codemapper" "github.com/stretchr/testify/assert" ) @@ -99,3 +100,54 @@ func TestNewMatrixcode(t *testing.T) { assert.Equal(t, matrixcode.Code, "code") }) } + +func TestMatrixcodeGenerate(t *testing.T) { + t.Run("if source key is not found, should return an error", func(t *testing.T) { + content := map[string]interface{}{} + provider := mocks.NewProcessorProvider(t) + + matrixcode := codemapper.Matrixcode{SourceKey: "code"} + component, err := matrixcode.Generate(content, provider) + + assert.Nil(t, component) + assert.NotNil(t, err) + }) + t.Run("if source key content is not valid, should return an error", func(t *testing.T) { + content := map[string]interface{}{ + "code": 1, + } + provider := mocks.NewProcessorProvider(t) + + matrixcode := codemapper.Matrixcode{SourceKey: "code"} + component, err := matrixcode.Generate(content, provider) + + assert.Nil(t, component) + assert.NotNil(t, err) + }) + t.Run("If the matrixcode has no props, the props will not be sent", func(t *testing.T) { + content := map[string]interface{}{ + "code": "code", + } + + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateMatrixCode("code").Return(nil) + + matrixcode := codemapper.Matrixcode{SourceKey: "code"} + _, err := matrixcode.Generate(content, provider) + + assert.Nil(t, err) + provider.AssertNumberOfCalls(t, "CreateMatrixCode", 1) + }) + t.Run("when valid code is sent, should generate matrixcode", func(t *testing.T) { + content := map[string]interface{}{} + + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateMatrixCode("code").Return(nil) + + matrixcode := codemapper.Matrixcode{Code: "code"} + _, err := matrixcode.Generate(content, provider) + + assert.Nil(t, err) + provider.AssertNumberOfCalls(t, "CreateMatrixCode", 1) + }) +} diff --git a/pkg/processor/processorprovider/Maroto_test.go b/pkg/processor/processorprovider/Maroto_test.go index 1b7d6a43..a223bace 100644 --- a/pkg/processor/processorprovider/Maroto_test.go +++ b/pkg/processor/processorprovider/Maroto_test.go @@ -14,7 +14,8 @@ func TestCreateBarCode(t *testing.T) { t.Run("when CreateBarCode is called, should generate a barcode", func(t *testing.T) { m := processorprovider.NewMaroto() barcode := m.CreateBarCode("code", - &propsmapper.Barcode{Left: 10.0, Top: 10.0, Percent: 100.0, + &propsmapper.Barcode{ + Left: 10.0, Top: 10.0, Percent: 100.0, Proportion: propsmapper.Proportion{Width: 10, Height: 2}, Center: false, Type: propsmapper.NewCodeType("code128"), }, @@ -24,3 +25,13 @@ func TestCreateBarCode(t *testing.T) { test.New(t).Assert(barcode.GetStructure()).Equals("processor/provider/barcode.json") }) } +func TestCreateMatrixCode(t *testing.T) { + t.Run("when CreateMatrixCode is called, should generate a matrixcode", func(t *testing.T) { + m := processorprovider.NewMaroto() + barcode := m.CreateMatrixCode("code", + &propsmapper.Rect{Left: 10.0, Top: 10.0, Percent: 100.0, JustReferenceWidth: false, Center: false}, + ) + + test.New(t).Assert(barcode.GetStructure()).Equals("processor/provider/matrixcode.json") + }) +} diff --git a/test/maroto/processor/provider/matrixcode.json b/test/maroto/processor/provider/matrixcode.json new file mode 100644 index 00000000..bb63e3c8 --- /dev/null +++ b/test/maroto/processor/provider/matrixcode.json @@ -0,0 +1,9 @@ +{ + "value": "code", + "type": "matrixcode", + "details": { + "prop_left": 10, + "prop_percent": 100, + "prop_top": 10 + } +} \ No newline at end of file From 859d6f20c286c551d0220f4a7a6b11cd5052505b Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 27 Oct 2024 12:22:28 -0300 Subject: [PATCH 049/116] feat: matrixcode component creation --- .../components/codemapper/matrixcode.go | 30 +++++++++++++++++-- pkg/processor/processorprovider/Maroto.go | 15 +++++++++- pkg/processor/processorprovider/provider.go | 1 + 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/pkg/processor/mappers/components/codemapper/matrixcode.go b/pkg/processor/mappers/components/codemapper/matrixcode.go index 604c7b76..9b584aa8 100644 --- a/pkg/processor/mappers/components/codemapper/matrixcode.go +++ b/pkg/processor/mappers/components/codemapper/matrixcode.go @@ -5,8 +5,8 @@ package codemapper import ( "fmt" - "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Matrixcode struct { @@ -94,6 +94,30 @@ func (m *Matrixcode) validateFields() error { return nil } -func (m *Matrixcode) Generate(content map[string]interface{}) (components.PdfComponent, error) { - return nil, nil +func (m *Matrixcode) getCode(content map[string]interface{}) (string, error) { + if m.Code != "" { + return m.Code, nil + } + codeFound, ok := content[m.SourceKey] + if !ok { + return "", fmt.Errorf("matrixcode requires a source key named %s, but it was not found", m.SourceKey) + } + codeValid, ok := codeFound.(string) + if !ok { + return "", fmt.Errorf("unable to generate matrixcode, invalid code. source key %s", m.SourceKey) + } + return codeValid, nil +} + +func (m *Matrixcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { + code, err := m.getCode(content) + if err != nil { + return nil, err + } + m.Code = code + + if m.Props != nil { + return provider.CreateMatrixCode(m.Code, m.Props), nil + } + return provider.CreateMatrixCode(m.Code), nil } diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index 07a42a7c..abe28411 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -17,13 +17,26 @@ func NewMaroto() *Maroto { return nil } +func (m *Maroto) CreateMatrixCode(codeValue string, codeProps ...*propsmapper.Rect) PDFComponent { + cProps := propsmapper.Rect{} + if len(codeProps) > 0 { + cProps = *codeProps[0] + } + + return code.NewMatrix(codeValue, props.Rect{ + Left: cProps.Left, Top: cProps.Top, Percent: cProps.Percent, + JustReferenceWidth: cProps.JustReferenceWidth, Center: cProps.Center, + }) +} + func (m *Maroto) CreateBarCode(codeValue string, codeProps ...*propsmapper.Barcode) PDFComponent { cProps := propsmapper.Barcode{} if len(codeProps) > 0 { cProps = *codeProps[0] } - return code.NewBar(codeValue, props.Barcode{Left: cProps.Left, Top: cProps.Top, Percent: cProps.Percent, + return code.NewBar(codeValue, props.Barcode{ + Left: cProps.Left, Top: cProps.Top, Percent: cProps.Percent, Proportion: props.Proportion(cProps.Proportion), Center: cProps.Center, Type: barcode.Type(cProps.Type), }) } diff --git a/pkg/processor/processorprovider/provider.go b/pkg/processor/processorprovider/provider.go index a0a9f156..b2f70545 100644 --- a/pkg/processor/processorprovider/provider.go +++ b/pkg/processor/processorprovider/provider.go @@ -15,4 +15,5 @@ type PDFComponent interface { // Maroto provides for pdf builder type ProcessorProvider interface { CreateBarCode(value string, props ...*propsmapper.Barcode) PDFComponent + CreateMatrixCode(value string, props ...*propsmapper.Rect) PDFComponent } From 040828c04e6b67533f62358c98e4ca04294b9e0f Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 30 Oct 2024 21:08:15 -0300 Subject: [PATCH 050/116] test: validate the creation of the qrcode --- mocks/Builder.go | 1263 ++++++++++++++++- mocks/ProcessorProvider.go | 63 + .../components/codemapper/qrcode_test.go | 52 + .../processorprovider/Maroto_test.go | 10 + test/maroto/processor/provider/qrcode.json | 9 + 5 files changed, 1380 insertions(+), 17 deletions(-) create mode 100644 test/maroto/processor/provider/qrcode.json diff --git a/mocks/Builder.go b/mocks/Builder.go index 883f7968..2cbe240a 100644 --- a/mocks/Builder.go +++ b/mocks/Builder.go @@ -3,12 +3,22 @@ package mocks import ( - cache "github.com/johnfercher/maroto/v2/internal/cache" + config "github.com/johnfercher/maroto/v2/pkg/config" entity "github.com/johnfercher/maroto/v2/pkg/core/entity" - gofpdf "github.com/johnfercher/maroto/v2/internal/providers/gofpdf" + extension "github.com/johnfercher/maroto/v2/pkg/consts/extension" mock "github.com/stretchr/testify/mock" + + orientation "github.com/johnfercher/maroto/v2/pkg/consts/orientation" + + pagesize "github.com/johnfercher/maroto/v2/pkg/consts/pagesize" + + props "github.com/johnfercher/maroto/v2/pkg/props" + + protection "github.com/johnfercher/maroto/v2/pkg/consts/protection" + + time "time" ) // Builder is an autogenerated mock type for the Builder type @@ -24,20 +34,20 @@ func (_m *Builder) EXPECT() *Builder_Expecter { return &Builder_Expecter{mock: &_m.Mock} } -// Build provides a mock function with given fields: cfg, _a1 -func (_m *Builder) Build(cfg *entity.Config, _a1 cache.Cache) *gofpdf.Dependencies { - ret := _m.Called(cfg, _a1) +// Build provides a mock function with given fields: +func (_m *Builder) Build() *entity.Config { + ret := _m.Called() if len(ret) == 0 { panic("no return value specified for Build") } - var r0 *gofpdf.Dependencies - if rf, ok := ret.Get(0).(func(*entity.Config, cache.Cache) *gofpdf.Dependencies); ok { - r0 = rf(cfg, _a1) + var r0 *entity.Config + if rf, ok := ret.Get(0).(func() *entity.Config); ok { + r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*gofpdf.Dependencies) + r0 = ret.Get(0).(*entity.Config) } } @@ -50,25 +60,1244 @@ type Builder_Build_Call struct { } // Build is a helper method to define mock.On call -// - cfg *entity.Config -// - _a1 cache.Cache -func (_e *Builder_Expecter) Build(cfg interface{}, _a1 interface{}) *Builder_Build_Call { - return &Builder_Build_Call{Call: _e.mock.On("Build", cfg, _a1)} +func (_e *Builder_Expecter) Build() *Builder_Build_Call { + return &Builder_Build_Call{Call: _e.mock.On("Build")} +} + +func (_c *Builder_Build_Call) Run(run func()) *Builder_Build_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Builder_Build_Call) Return(_a0 *entity.Config) *Builder_Build_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_Build_Call) RunAndReturn(run func() *entity.Config) *Builder_Build_Call { + _c.Call.Return(run) + return _c +} + +// WithAuthor provides a mock function with given fields: author, isUTF8 +func (_m *Builder) WithAuthor(author string, isUTF8 bool) config.Builder { + ret := _m.Called(author, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithAuthor") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(author, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithAuthor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithAuthor' +type Builder_WithAuthor_Call struct { + *mock.Call +} + +// WithAuthor is a helper method to define mock.On call +// - author string +// - isUTF8 bool +func (_e *Builder_Expecter) WithAuthor(author interface{}, isUTF8 interface{}) *Builder_WithAuthor_Call { + return &Builder_WithAuthor_Call{Call: _e.mock.On("WithAuthor", author, isUTF8)} +} + +func (_c *Builder_WithAuthor_Call) Run(run func(author string, isUTF8 bool)) *Builder_WithAuthor_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithAuthor_Call) Return(_a0 config.Builder) *Builder_WithAuthor_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithAuthor_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithAuthor_Call { + _c.Call.Return(run) + return _c +} + +// WithBackgroundImage provides a mock function with given fields: _a0, _a1 +func (_m *Builder) WithBackgroundImage(_a0 []byte, _a1 extension.Type) config.Builder { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for WithBackgroundImage") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func([]byte, extension.Type) config.Builder); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithBackgroundImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBackgroundImage' +type Builder_WithBackgroundImage_Call struct { + *mock.Call +} + +// WithBackgroundImage is a helper method to define mock.On call +// - _a0 []byte +// - _a1 extension.Type +func (_e *Builder_Expecter) WithBackgroundImage(_a0 interface{}, _a1 interface{}) *Builder_WithBackgroundImage_Call { + return &Builder_WithBackgroundImage_Call{Call: _e.mock.On("WithBackgroundImage", _a0, _a1)} +} + +func (_c *Builder_WithBackgroundImage_Call) Run(run func(_a0 []byte, _a1 extension.Type)) *Builder_WithBackgroundImage_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]byte), args[1].(extension.Type)) + }) + return _c +} + +func (_c *Builder_WithBackgroundImage_Call) Return(_a0 config.Builder) *Builder_WithBackgroundImage_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithBackgroundImage_Call) RunAndReturn(run func([]byte, extension.Type) config.Builder) *Builder_WithBackgroundImage_Call { + _c.Call.Return(run) + return _c +} + +// WithBottomMargin provides a mock function with given fields: bottom +func (_m *Builder) WithBottomMargin(bottom float64) config.Builder { + ret := _m.Called(bottom) + + if len(ret) == 0 { + panic("no return value specified for WithBottomMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(bottom) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithBottomMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBottomMargin' +type Builder_WithBottomMargin_Call struct { + *mock.Call +} + +// WithBottomMargin is a helper method to define mock.On call +// - bottom float64 +func (_e *Builder_Expecter) WithBottomMargin(bottom interface{}) *Builder_WithBottomMargin_Call { + return &Builder_WithBottomMargin_Call{Call: _e.mock.On("WithBottomMargin", bottom)} +} + +func (_c *Builder_WithBottomMargin_Call) Run(run func(bottom float64)) *Builder_WithBottomMargin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Builder_WithBottomMargin_Call) Return(_a0 config.Builder) *Builder_WithBottomMargin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithBottomMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithBottomMargin_Call { + _c.Call.Return(run) + return _c +} + +// WithCompression provides a mock function with given fields: compression +func (_m *Builder) WithCompression(compression bool) config.Builder { + ret := _m.Called(compression) + + if len(ret) == 0 { + panic("no return value specified for WithCompression") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { + r0 = rf(compression) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCompression_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCompression' +type Builder_WithCompression_Call struct { + *mock.Call +} + +// WithCompression is a helper method to define mock.On call +// - compression bool +func (_e *Builder_Expecter) WithCompression(compression interface{}) *Builder_WithCompression_Call { + return &Builder_WithCompression_Call{Call: _e.mock.On("WithCompression", compression)} +} + +func (_c *Builder_WithCompression_Call) Run(run func(compression bool)) *Builder_WithCompression_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Builder_WithCompression_Call) Return(_a0 config.Builder) *Builder_WithCompression_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCompression_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithCompression_Call { + _c.Call.Return(run) + return _c +} + +// WithConcurrentMode provides a mock function with given fields: chunkWorkers +func (_m *Builder) WithConcurrentMode(chunkWorkers int) config.Builder { + ret := _m.Called(chunkWorkers) + + if len(ret) == 0 { + panic("no return value specified for WithConcurrentMode") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(int) config.Builder); ok { + r0 = rf(chunkWorkers) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithConcurrentMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithConcurrentMode' +type Builder_WithConcurrentMode_Call struct { + *mock.Call +} + +// WithConcurrentMode is a helper method to define mock.On call +// - chunkWorkers int +func (_e *Builder_Expecter) WithConcurrentMode(chunkWorkers interface{}) *Builder_WithConcurrentMode_Call { + return &Builder_WithConcurrentMode_Call{Call: _e.mock.On("WithConcurrentMode", chunkWorkers)} +} + +func (_c *Builder_WithConcurrentMode_Call) Run(run func(chunkWorkers int)) *Builder_WithConcurrentMode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Builder_WithConcurrentMode_Call) Return(_a0 config.Builder) *Builder_WithConcurrentMode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithConcurrentMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithConcurrentMode_Call { + _c.Call.Return(run) + return _c +} + +// WithCreationDate provides a mock function with given fields: _a0 +func (_m *Builder) WithCreationDate(_a0 time.Time) config.Builder { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for WithCreationDate") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(time.Time) config.Builder); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCreationDate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreationDate' +type Builder_WithCreationDate_Call struct { + *mock.Call +} + +// WithCreationDate is a helper method to define mock.On call +// - _a0 time.Time +func (_e *Builder_Expecter) WithCreationDate(_a0 interface{}) *Builder_WithCreationDate_Call { + return &Builder_WithCreationDate_Call{Call: _e.mock.On("WithCreationDate", _a0)} +} + +func (_c *Builder_WithCreationDate_Call) Run(run func(_a0 time.Time)) *Builder_WithCreationDate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(time.Time)) + }) + return _c +} + +func (_c *Builder_WithCreationDate_Call) Return(_a0 config.Builder) *Builder_WithCreationDate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCreationDate_Call) RunAndReturn(run func(time.Time) config.Builder) *Builder_WithCreationDate_Call { + _c.Call.Return(run) + return _c +} + +// WithCreator provides a mock function with given fields: creator, isUTF8 +func (_m *Builder) WithCreator(creator string, isUTF8 bool) config.Builder { + ret := _m.Called(creator, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithCreator") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(creator, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCreator_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreator' +type Builder_WithCreator_Call struct { + *mock.Call +} + +// WithCreator is a helper method to define mock.On call +// - creator string +// - isUTF8 bool +func (_e *Builder_Expecter) WithCreator(creator interface{}, isUTF8 interface{}) *Builder_WithCreator_Call { + return &Builder_WithCreator_Call{Call: _e.mock.On("WithCreator", creator, isUTF8)} +} + +func (_c *Builder_WithCreator_Call) Run(run func(creator string, isUTF8 bool)) *Builder_WithCreator_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithCreator_Call) Return(_a0 config.Builder) *Builder_WithCreator_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCreator_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithCreator_Call { + _c.Call.Return(run) + return _c +} + +// WithCustomFonts provides a mock function with given fields: _a0 +func (_m *Builder) WithCustomFonts(_a0 []*entity.CustomFont) config.Builder { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for WithCustomFonts") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func([]*entity.CustomFont) config.Builder); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCustomFonts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCustomFonts' +type Builder_WithCustomFonts_Call struct { + *mock.Call +} + +// WithCustomFonts is a helper method to define mock.On call +// - _a0 []*entity.CustomFont +func (_e *Builder_Expecter) WithCustomFonts(_a0 interface{}) *Builder_WithCustomFonts_Call { + return &Builder_WithCustomFonts_Call{Call: _e.mock.On("WithCustomFonts", _a0)} +} + +func (_c *Builder_WithCustomFonts_Call) Run(run func(_a0 []*entity.CustomFont)) *Builder_WithCustomFonts_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]*entity.CustomFont)) + }) + return _c +} + +func (_c *Builder_WithCustomFonts_Call) Return(_a0 config.Builder) *Builder_WithCustomFonts_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCustomFonts_Call) RunAndReturn(run func([]*entity.CustomFont) config.Builder) *Builder_WithCustomFonts_Call { + _c.Call.Return(run) + return _c +} + +// WithDebug provides a mock function with given fields: on +func (_m *Builder) WithDebug(on bool) config.Builder { + ret := _m.Called(on) + + if len(ret) == 0 { + panic("no return value specified for WithDebug") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { + r0 = rf(on) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDebug_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDebug' +type Builder_WithDebug_Call struct { + *mock.Call +} + +// WithDebug is a helper method to define mock.On call +// - on bool +func (_e *Builder_Expecter) WithDebug(on interface{}) *Builder_WithDebug_Call { + return &Builder_WithDebug_Call{Call: _e.mock.On("WithDebug", on)} +} + +func (_c *Builder_WithDebug_Call) Run(run func(on bool)) *Builder_WithDebug_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Builder_WithDebug_Call) Return(_a0 config.Builder) *Builder_WithDebug_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDebug_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDebug_Call { + _c.Call.Return(run) + return _c +} + +// WithDefaultFont provides a mock function with given fields: font +func (_m *Builder) WithDefaultFont(font *props.Font) config.Builder { + ret := _m.Called(font) + + if len(ret) == 0 { + panic("no return value specified for WithDefaultFont") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(*props.Font) config.Builder); ok { + r0 = rf(font) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDefaultFont_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDefaultFont' +type Builder_WithDefaultFont_Call struct { + *mock.Call +} + +// WithDefaultFont is a helper method to define mock.On call +// - font *props.Font +func (_e *Builder_Expecter) WithDefaultFont(font interface{}) *Builder_WithDefaultFont_Call { + return &Builder_WithDefaultFont_Call{Call: _e.mock.On("WithDefaultFont", font)} +} + +func (_c *Builder_WithDefaultFont_Call) Run(run func(font *props.Font)) *Builder_WithDefaultFont_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*props.Font)) + }) + return _c +} + +func (_c *Builder_WithDefaultFont_Call) Return(_a0 config.Builder) *Builder_WithDefaultFont_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDefaultFont_Call) RunAndReturn(run func(*props.Font) config.Builder) *Builder_WithDefaultFont_Call { + _c.Call.Return(run) + return _c +} + +// WithDimensions provides a mock function with given fields: width, height +func (_m *Builder) WithDimensions(width float64, height float64) config.Builder { + ret := _m.Called(width, height) + + if len(ret) == 0 { + panic("no return value specified for WithDimensions") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64, float64) config.Builder); ok { + r0 = rf(width, height) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDimensions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDimensions' +type Builder_WithDimensions_Call struct { + *mock.Call +} + +// WithDimensions is a helper method to define mock.On call +// - width float64 +// - height float64 +func (_e *Builder_Expecter) WithDimensions(width interface{}, height interface{}) *Builder_WithDimensions_Call { + return &Builder_WithDimensions_Call{Call: _e.mock.On("WithDimensions", width, height)} +} + +func (_c *Builder_WithDimensions_Call) Run(run func(width float64, height float64)) *Builder_WithDimensions_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64), args[1].(float64)) + }) + return _c +} + +func (_c *Builder_WithDimensions_Call) Return(_a0 config.Builder) *Builder_WithDimensions_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDimensions_Call) RunAndReturn(run func(float64, float64) config.Builder) *Builder_WithDimensions_Call { + _c.Call.Return(run) + return _c +} + +// WithDisableAutoPageBreak provides a mock function with given fields: disabled +func (_m *Builder) WithDisableAutoPageBreak(disabled bool) config.Builder { + ret := _m.Called(disabled) + + if len(ret) == 0 { + panic("no return value specified for WithDisableAutoPageBreak") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { + r0 = rf(disabled) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDisableAutoPageBreak_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDisableAutoPageBreak' +type Builder_WithDisableAutoPageBreak_Call struct { + *mock.Call +} + +// WithDisableAutoPageBreak is a helper method to define mock.On call +// - disabled bool +func (_e *Builder_Expecter) WithDisableAutoPageBreak(disabled interface{}) *Builder_WithDisableAutoPageBreak_Call { + return &Builder_WithDisableAutoPageBreak_Call{Call: _e.mock.On("WithDisableAutoPageBreak", disabled)} +} + +func (_c *Builder_WithDisableAutoPageBreak_Call) Run(run func(disabled bool)) *Builder_WithDisableAutoPageBreak_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Builder_WithDisableAutoPageBreak_Call) Return(_a0 config.Builder) *Builder_WithDisableAutoPageBreak_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDisableAutoPageBreak_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDisableAutoPageBreak_Call { + _c.Call.Return(run) + return _c +} + +// WithKeywords provides a mock function with given fields: keywordsStr, isUTF8 +func (_m *Builder) WithKeywords(keywordsStr string, isUTF8 bool) config.Builder { + ret := _m.Called(keywordsStr, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithKeywords") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(keywordsStr, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithKeywords_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithKeywords' +type Builder_WithKeywords_Call struct { + *mock.Call +} + +// WithKeywords is a helper method to define mock.On call +// - keywordsStr string +// - isUTF8 bool +func (_e *Builder_Expecter) WithKeywords(keywordsStr interface{}, isUTF8 interface{}) *Builder_WithKeywords_Call { + return &Builder_WithKeywords_Call{Call: _e.mock.On("WithKeywords", keywordsStr, isUTF8)} +} + +func (_c *Builder_WithKeywords_Call) Run(run func(keywordsStr string, isUTF8 bool)) *Builder_WithKeywords_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithKeywords_Call) Return(_a0 config.Builder) *Builder_WithKeywords_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithKeywords_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithKeywords_Call { + _c.Call.Return(run) + return _c +} + +// WithLeftMargin provides a mock function with given fields: left +func (_m *Builder) WithLeftMargin(left float64) config.Builder { + ret := _m.Called(left) + + if len(ret) == 0 { + panic("no return value specified for WithLeftMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(left) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithLeftMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithLeftMargin' +type Builder_WithLeftMargin_Call struct { + *mock.Call +} + +// WithLeftMargin is a helper method to define mock.On call +// - left float64 +func (_e *Builder_Expecter) WithLeftMargin(left interface{}) *Builder_WithLeftMargin_Call { + return &Builder_WithLeftMargin_Call{Call: _e.mock.On("WithLeftMargin", left)} +} + +func (_c *Builder_WithLeftMargin_Call) Run(run func(left float64)) *Builder_WithLeftMargin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Builder_WithLeftMargin_Call) Return(_a0 config.Builder) *Builder_WithLeftMargin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithLeftMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithLeftMargin_Call { + _c.Call.Return(run) + return _c +} + +// WithMaxGridSize provides a mock function with given fields: maxGridSize +func (_m *Builder) WithMaxGridSize(maxGridSize int) config.Builder { + ret := _m.Called(maxGridSize) + + if len(ret) == 0 { + panic("no return value specified for WithMaxGridSize") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(int) config.Builder); ok { + r0 = rf(maxGridSize) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithMaxGridSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithMaxGridSize' +type Builder_WithMaxGridSize_Call struct { + *mock.Call +} + +// WithMaxGridSize is a helper method to define mock.On call +// - maxGridSize int +func (_e *Builder_Expecter) WithMaxGridSize(maxGridSize interface{}) *Builder_WithMaxGridSize_Call { + return &Builder_WithMaxGridSize_Call{Call: _e.mock.On("WithMaxGridSize", maxGridSize)} +} + +func (_c *Builder_WithMaxGridSize_Call) Run(run func(maxGridSize int)) *Builder_WithMaxGridSize_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Builder_WithMaxGridSize_Call) Return(_a0 config.Builder) *Builder_WithMaxGridSize_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithMaxGridSize_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithMaxGridSize_Call { + _c.Call.Return(run) + return _c +} + +// WithOrientation provides a mock function with given fields: _a0 +func (_m *Builder) WithOrientation(_a0 orientation.Type) config.Builder { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for WithOrientation") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(orientation.Type) config.Builder); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithOrientation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithOrientation' +type Builder_WithOrientation_Call struct { + *mock.Call +} + +// WithOrientation is a helper method to define mock.On call +// - _a0 orientation.Type +func (_e *Builder_Expecter) WithOrientation(_a0 interface{}) *Builder_WithOrientation_Call { + return &Builder_WithOrientation_Call{Call: _e.mock.On("WithOrientation", _a0)} +} + +func (_c *Builder_WithOrientation_Call) Run(run func(_a0 orientation.Type)) *Builder_WithOrientation_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(orientation.Type)) + }) + return _c +} + +func (_c *Builder_WithOrientation_Call) Return(_a0 config.Builder) *Builder_WithOrientation_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithOrientation_Call) RunAndReturn(run func(orientation.Type) config.Builder) *Builder_WithOrientation_Call { + _c.Call.Return(run) + return _c +} + +// WithPageNumber provides a mock function with given fields: pageNumber +func (_m *Builder) WithPageNumber(pageNumber ...props.PageNumber) config.Builder { + _va := make([]interface{}, len(pageNumber)) + for _i := range pageNumber { + _va[_i] = pageNumber[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for WithPageNumber") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(...props.PageNumber) config.Builder); ok { + r0 = rf(pageNumber...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithPageNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageNumber' +type Builder_WithPageNumber_Call struct { + *mock.Call +} + +// WithPageNumber is a helper method to define mock.On call +// - pageNumber ...props.PageNumber +func (_e *Builder_Expecter) WithPageNumber(pageNumber ...interface{}) *Builder_WithPageNumber_Call { + return &Builder_WithPageNumber_Call{Call: _e.mock.On("WithPageNumber", + append([]interface{}{}, pageNumber...)...)} +} + +func (_c *Builder_WithPageNumber_Call) Run(run func(pageNumber ...props.PageNumber)) *Builder_WithPageNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]props.PageNumber, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(props.PageNumber) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *Builder_WithPageNumber_Call) Return(_a0 config.Builder) *Builder_WithPageNumber_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithPageNumber_Call) RunAndReturn(run func(...props.PageNumber) config.Builder) *Builder_WithPageNumber_Call { + _c.Call.Return(run) + return _c +} + +// WithPageSize provides a mock function with given fields: size +func (_m *Builder) WithPageSize(size pagesize.Type) config.Builder { + ret := _m.Called(size) + + if len(ret) == 0 { + panic("no return value specified for WithPageSize") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(pagesize.Type) config.Builder); ok { + r0 = rf(size) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithPageSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageSize' +type Builder_WithPageSize_Call struct { + *mock.Call +} + +// WithPageSize is a helper method to define mock.On call +// - size pagesize.Type +func (_e *Builder_Expecter) WithPageSize(size interface{}) *Builder_WithPageSize_Call { + return &Builder_WithPageSize_Call{Call: _e.mock.On("WithPageSize", size)} +} + +func (_c *Builder_WithPageSize_Call) Run(run func(size pagesize.Type)) *Builder_WithPageSize_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(pagesize.Type)) + }) + return _c +} + +func (_c *Builder_WithPageSize_Call) Return(_a0 config.Builder) *Builder_WithPageSize_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithPageSize_Call) RunAndReturn(run func(pagesize.Type) config.Builder) *Builder_WithPageSize_Call { + _c.Call.Return(run) + return _c +} + +// WithProtection provides a mock function with given fields: protectionType, userPassword, ownerPassword +func (_m *Builder) WithProtection(protectionType protection.Type, userPassword string, ownerPassword string) config.Builder { + ret := _m.Called(protectionType, userPassword, ownerPassword) + + if len(ret) == 0 { + panic("no return value specified for WithProtection") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(protection.Type, string, string) config.Builder); ok { + r0 = rf(protectionType, userPassword, ownerPassword) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithProtection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithProtection' +type Builder_WithProtection_Call struct { + *mock.Call +} + +// WithProtection is a helper method to define mock.On call +// - protectionType protection.Type +// - userPassword string +// - ownerPassword string +func (_e *Builder_Expecter) WithProtection(protectionType interface{}, userPassword interface{}, ownerPassword interface{}) *Builder_WithProtection_Call { + return &Builder_WithProtection_Call{Call: _e.mock.On("WithProtection", protectionType, userPassword, ownerPassword)} +} + +func (_c *Builder_WithProtection_Call) Run(run func(protectionType protection.Type, userPassword string, ownerPassword string)) *Builder_WithProtection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(protection.Type), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *Builder_WithProtection_Call) Return(_a0 config.Builder) *Builder_WithProtection_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithProtection_Call) RunAndReturn(run func(protection.Type, string, string) config.Builder) *Builder_WithProtection_Call { + _c.Call.Return(run) + return _c +} + +// WithRightMargin provides a mock function with given fields: right +func (_m *Builder) WithRightMargin(right float64) config.Builder { + ret := _m.Called(right) + + if len(ret) == 0 { + panic("no return value specified for WithRightMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(right) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithRightMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithRightMargin' +type Builder_WithRightMargin_Call struct { + *mock.Call +} + +// WithRightMargin is a helper method to define mock.On call +// - right float64 +func (_e *Builder_Expecter) WithRightMargin(right interface{}) *Builder_WithRightMargin_Call { + return &Builder_WithRightMargin_Call{Call: _e.mock.On("WithRightMargin", right)} +} + +func (_c *Builder_WithRightMargin_Call) Run(run func(right float64)) *Builder_WithRightMargin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Builder_WithRightMargin_Call) Return(_a0 config.Builder) *Builder_WithRightMargin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithRightMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithRightMargin_Call { + _c.Call.Return(run) + return _c +} + +// WithSequentialLowMemoryMode provides a mock function with given fields: chunkWorkers +func (_m *Builder) WithSequentialLowMemoryMode(chunkWorkers int) config.Builder { + ret := _m.Called(chunkWorkers) + + if len(ret) == 0 { + panic("no return value specified for WithSequentialLowMemoryMode") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(int) config.Builder); ok { + r0 = rf(chunkWorkers) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithSequentialLowMemoryMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialLowMemoryMode' +type Builder_WithSequentialLowMemoryMode_Call struct { + *mock.Call +} + +// WithSequentialLowMemoryMode is a helper method to define mock.On call +// - chunkWorkers int +func (_e *Builder_Expecter) WithSequentialLowMemoryMode(chunkWorkers interface{}) *Builder_WithSequentialLowMemoryMode_Call { + return &Builder_WithSequentialLowMemoryMode_Call{Call: _e.mock.On("WithSequentialLowMemoryMode", chunkWorkers)} +} + +func (_c *Builder_WithSequentialLowMemoryMode_Call) Run(run func(chunkWorkers int)) *Builder_WithSequentialLowMemoryMode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Builder_WithSequentialLowMemoryMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialLowMemoryMode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithSequentialLowMemoryMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithSequentialLowMemoryMode_Call { + _c.Call.Return(run) + return _c +} + +// WithSequentialMode provides a mock function with given fields: +func (_m *Builder) WithSequentialMode() config.Builder { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for WithSequentialMode") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func() config.Builder); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithSequentialMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialMode' +type Builder_WithSequentialMode_Call struct { + *mock.Call +} + +// WithSequentialMode is a helper method to define mock.On call +func (_e *Builder_Expecter) WithSequentialMode() *Builder_WithSequentialMode_Call { + return &Builder_WithSequentialMode_Call{Call: _e.mock.On("WithSequentialMode")} +} + +func (_c *Builder_WithSequentialMode_Call) Run(run func()) *Builder_WithSequentialMode_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Builder_WithSequentialMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialMode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithSequentialMode_Call) RunAndReturn(run func() config.Builder) *Builder_WithSequentialMode_Call { + _c.Call.Return(run) + return _c +} + +// WithSubject provides a mock function with given fields: subject, isUTF8 +func (_m *Builder) WithSubject(subject string, isUTF8 bool) config.Builder { + ret := _m.Called(subject, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithSubject") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(subject, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithSubject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSubject' +type Builder_WithSubject_Call struct { + *mock.Call +} + +// WithSubject is a helper method to define mock.On call +// - subject string +// - isUTF8 bool +func (_e *Builder_Expecter) WithSubject(subject interface{}, isUTF8 interface{}) *Builder_WithSubject_Call { + return &Builder_WithSubject_Call{Call: _e.mock.On("WithSubject", subject, isUTF8)} +} + +func (_c *Builder_WithSubject_Call) Run(run func(subject string, isUTF8 bool)) *Builder_WithSubject_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithSubject_Call) Return(_a0 config.Builder) *Builder_WithSubject_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithSubject_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithSubject_Call { + _c.Call.Return(run) + return _c +} + +// WithTitle provides a mock function with given fields: title, isUTF8 +func (_m *Builder) WithTitle(title string, isUTF8 bool) config.Builder { + ret := _m.Called(title, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithTitle") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(title, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithTitle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTitle' +type Builder_WithTitle_Call struct { + *mock.Call +} + +// WithTitle is a helper method to define mock.On call +// - title string +// - isUTF8 bool +func (_e *Builder_Expecter) WithTitle(title interface{}, isUTF8 interface{}) *Builder_WithTitle_Call { + return &Builder_WithTitle_Call{Call: _e.mock.On("WithTitle", title, isUTF8)} +} + +func (_c *Builder_WithTitle_Call) Run(run func(title string, isUTF8 bool)) *Builder_WithTitle_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithTitle_Call) Return(_a0 config.Builder) *Builder_WithTitle_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithTitle_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithTitle_Call { + _c.Call.Return(run) + return _c +} + +// WithTopMargin provides a mock function with given fields: top +func (_m *Builder) WithTopMargin(top float64) config.Builder { + ret := _m.Called(top) + + if len(ret) == 0 { + panic("no return value specified for WithTopMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(top) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithTopMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTopMargin' +type Builder_WithTopMargin_Call struct { + *mock.Call +} + +// WithTopMargin is a helper method to define mock.On call +// - top float64 +func (_e *Builder_Expecter) WithTopMargin(top interface{}) *Builder_WithTopMargin_Call { + return &Builder_WithTopMargin_Call{Call: _e.mock.On("WithTopMargin", top)} } -func (_c *Builder_Build_Call) Run(run func(cfg *entity.Config, _a1 cache.Cache)) *Builder_Build_Call { +func (_c *Builder_WithTopMargin_Call) Run(run func(top float64)) *Builder_WithTopMargin_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*entity.Config), args[1].(cache.Cache)) + run(args[0].(float64)) }) return _c } -func (_c *Builder_Build_Call) Return(_a0 *gofpdf.Dependencies) *Builder_Build_Call { +func (_c *Builder_WithTopMargin_Call) Return(_a0 config.Builder) *Builder_WithTopMargin_Call { _c.Call.Return(_a0) return _c } -func (_c *Builder_Build_Call) RunAndReturn(run func(*entity.Config, cache.Cache) *gofpdf.Dependencies) *Builder_Build_Call { +func (_c *Builder_WithTopMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithTopMargin_Call { _c.Call.Return(run) return _c } diff --git a/mocks/ProcessorProvider.go b/mocks/ProcessorProvider.go index a8cea020..31040da1 100644 --- a/mocks/ProcessorProvider.go +++ b/mocks/ProcessorProvider.go @@ -147,6 +147,69 @@ func (_c *ProcessorProvider_CreateMatrixCode_Call) RunAndReturn(run func(string, return _c } +// CreateQrCode provides a mock function with given fields: value, props +func (_m *ProcessorProvider) CreateQrCode(value string, props ...*propsmapper.Rect) processorprovider.PDFComponent { + _va := make([]interface{}, len(props)) + for _i := range props { + _va[_i] = props[_i] + } + var _ca []interface{} + _ca = append(_ca, value) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for CreateQrCode") + } + + var r0 processorprovider.PDFComponent + if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Rect) processorprovider.PDFComponent); ok { + r0 = rf(value, props...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(processorprovider.PDFComponent) + } + } + + return r0 +} + +// ProcessorProvider_CreateQrCode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateQrCode' +type ProcessorProvider_CreateQrCode_Call struct { + *mock.Call +} + +// CreateQrCode is a helper method to define mock.On call +// - value string +// - props ...*propsmapper.Rect +func (_e *ProcessorProvider_Expecter) CreateQrCode(value interface{}, props ...interface{}) *ProcessorProvider_CreateQrCode_Call { + return &ProcessorProvider_CreateQrCode_Call{Call: _e.mock.On("CreateQrCode", + append([]interface{}{value}, props...)...)} +} + +func (_c *ProcessorProvider_CreateQrCode_Call) Run(run func(value string, props ...*propsmapper.Rect)) *ProcessorProvider_CreateQrCode_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]*propsmapper.Rect, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(*propsmapper.Rect) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_CreateQrCode_Call) Return(_a0 processorprovider.PDFComponent) *ProcessorProvider_CreateQrCode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorProvider_CreateQrCode_Call) RunAndReturn(run func(string, ...*propsmapper.Rect) processorprovider.PDFComponent) *ProcessorProvider_CreateQrCode_Call { + _c.Call.Return(run) + return _c +} + // NewProcessorProvider creates a new instance of ProcessorProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewProcessorProvider(t interface { diff --git a/pkg/processor/mappers/components/codemapper/qrcode_test.go b/pkg/processor/mappers/components/codemapper/qrcode_test.go index 6a0b761e..30df87df 100644 --- a/pkg/processor/mappers/components/codemapper/qrcode_test.go +++ b/pkg/processor/mappers/components/codemapper/qrcode_test.go @@ -4,6 +4,7 @@ package codemapper_test import ( "testing" + "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/codemapper" "github.com/stretchr/testify/assert" ) @@ -99,3 +100,54 @@ func TestNewQrCode(t *testing.T) { assert.Equal(t, qrcode.Code, "code") }) } + +func TestQrCodeGenerate(t *testing.T) { + t.Run("if source key is not found, should return an error", func(t *testing.T) { + content := map[string]interface{}{} + provider := mocks.NewProcessorProvider(t) + + QrCode := codemapper.Qrcode{SourceKey: "code"} + component, err := QrCode.Generate(content, provider) + + assert.Nil(t, component) + assert.NotNil(t, err) + }) + t.Run("if source key content is not valid, should return an error", func(t *testing.T) { + content := map[string]interface{}{ + "code": 1, + } + provider := mocks.NewProcessorProvider(t) + + QrCode := codemapper.Qrcode{SourceKey: "code"} + component, err := QrCode.Generate(content, provider) + + assert.Nil(t, component) + assert.NotNil(t, err) + }) + t.Run("If the QrCode has no props, the props will not be sent", func(t *testing.T) { + content := map[string]interface{}{ + "code": "code", + } + + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateQrCode("code").Return(nil) + + QrCode := codemapper.Qrcode{SourceKey: "code"} + _, err := QrCode.Generate(content, provider) + + assert.Nil(t, err) + provider.AssertNumberOfCalls(t, "CreateQrCode", 1) + }) + t.Run("when valid code is sent, should generate QrCode", func(t *testing.T) { + content := map[string]interface{}{} + + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateQrCode("code").Return(nil) + + QrCode := codemapper.Qrcode{Code: "code"} + _, err := QrCode.Generate(content, provider) + + assert.Nil(t, err) + provider.AssertNumberOfCalls(t, "CreateQrCode", 1) + }) +} diff --git a/pkg/processor/processorprovider/Maroto_test.go b/pkg/processor/processorprovider/Maroto_test.go index a223bace..6639609e 100644 --- a/pkg/processor/processorprovider/Maroto_test.go +++ b/pkg/processor/processorprovider/Maroto_test.go @@ -35,3 +35,13 @@ func TestCreateMatrixCode(t *testing.T) { test.New(t).Assert(barcode.GetStructure()).Equals("processor/provider/matrixcode.json") }) } +func TestCreateQRCode(t *testing.T) { + t.Run("when CreateQrCode is called, should generate a qrcode", func(t *testing.T) { + m := processorprovider.NewMaroto() + barcode := m.CreateQrCode("code", + &propsmapper.Rect{Left: 10.0, Top: 10.0, Percent: 100.0, JustReferenceWidth: false, Center: false}, + ) + + test.New(t).Assert(barcode.GetStructure()).Equals("processor/provider/qrcode.json") + }) +} diff --git a/test/maroto/processor/provider/qrcode.json b/test/maroto/processor/provider/qrcode.json new file mode 100644 index 00000000..e293eb31 --- /dev/null +++ b/test/maroto/processor/provider/qrcode.json @@ -0,0 +1,9 @@ +{ + "value": "code", + "type": "qrcode", + "details": { + "prop_left": 10, + "prop_percent": 100, + "prop_top": 10 + } +} \ No newline at end of file From 814f13483d90980034c1be8713b67b4b63af49e7 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 30 Oct 2024 21:09:36 -0300 Subject: [PATCH 051/116] feat: create qrcode component --- .../mappers/components/codemapper/qrcode.go | 30 +++++++++++++++++-- pkg/processor/processorprovider/Maroto.go | 12 ++++++++ pkg/processor/processorprovider/provider.go | 1 + 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/pkg/processor/mappers/components/codemapper/qrcode.go b/pkg/processor/mappers/components/codemapper/qrcode.go index 035ad9a8..d74c893b 100644 --- a/pkg/processor/mappers/components/codemapper/qrcode.go +++ b/pkg/processor/mappers/components/codemapper/qrcode.go @@ -5,8 +5,8 @@ package codemapper import ( "fmt" - "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Qrcode struct { @@ -94,6 +94,30 @@ func (q *Qrcode) validateFields() error { return nil } -func (q *Qrcode) Generate(content map[string]interface{}) (components.PdfComponent, error) { - return nil, nil +func (q *Qrcode) getCode(content map[string]interface{}) (string, error) { + if q.Code != "" { + return q.Code, nil + } + codeFound, ok := content[q.SourceKey] + if !ok { + return "", fmt.Errorf("qrcode requires a source key named %s, but it was not found", q.SourceKey) + } + codeValid, ok := codeFound.(string) + if !ok { + return "", fmt.Errorf("unable to generate qrcode, invalid code. source key %s", q.SourceKey) + } + return codeValid, nil +} + +func (q *Qrcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { + code, err := q.getCode(content) + if err != nil { + return nil, err + } + q.Code = code + + if q.Props != nil { + return provider.CreateQrCode(q.Code, q.Props), nil + } + return provider.CreateQrCode(q.Code), nil } diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index abe28411..b2eb2b44 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -29,6 +29,18 @@ func (m *Maroto) CreateMatrixCode(codeValue string, codeProps ...*propsmapper.Re }) } +func (m *Maroto) CreateQrCode(codeValue string, codeProps ...*propsmapper.Rect) PDFComponent { + cProps := propsmapper.Rect{} + if len(codeProps) > 0 { + cProps = *codeProps[0] + } + + return code.NewQr(codeValue, props.Rect{ + Left: cProps.Left, Top: cProps.Top, Percent: cProps.Percent, + JustReferenceWidth: cProps.JustReferenceWidth, Center: cProps.Center, + }) +} + func (m *Maroto) CreateBarCode(codeValue string, codeProps ...*propsmapper.Barcode) PDFComponent { cProps := propsmapper.Barcode{} if len(codeProps) > 0 { diff --git a/pkg/processor/processorprovider/provider.go b/pkg/processor/processorprovider/provider.go index b2f70545..c5a11f2c 100644 --- a/pkg/processor/processorprovider/provider.go +++ b/pkg/processor/processorprovider/provider.go @@ -16,4 +16,5 @@ type PDFComponent interface { type ProcessorProvider interface { CreateBarCode(value string, props ...*propsmapper.Barcode) PDFComponent CreateMatrixCode(value string, props ...*propsmapper.Rect) PDFComponent + CreateQrCode(value string, props ...*propsmapper.Rect) PDFComponent } From 87ba0a0da47f4b0ecee77d69eaa6c9f6aefa4fbb Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 30 Oct 2024 22:32:22 -0300 Subject: [PATCH 052/116] test: validate image creation --- mocks/Builder.go | 1263 +---------------- mocks/ProcessorProvider.go | 64 + mocks/Repository.go | 65 + .../components/imagemapper/image_test.go | 107 +- .../processorprovider/Maroto_test.go | 13 + test/maroto/processor/provider/image.json | 11 + 6 files changed, 268 insertions(+), 1255 deletions(-) create mode 100644 test/maroto/processor/provider/image.json diff --git a/mocks/Builder.go b/mocks/Builder.go index 2cbe240a..883f7968 100644 --- a/mocks/Builder.go +++ b/mocks/Builder.go @@ -3,22 +3,12 @@ package mocks import ( - config "github.com/johnfercher/maroto/v2/pkg/config" + cache "github.com/johnfercher/maroto/v2/internal/cache" entity "github.com/johnfercher/maroto/v2/pkg/core/entity" - extension "github.com/johnfercher/maroto/v2/pkg/consts/extension" + gofpdf "github.com/johnfercher/maroto/v2/internal/providers/gofpdf" mock "github.com/stretchr/testify/mock" - - orientation "github.com/johnfercher/maroto/v2/pkg/consts/orientation" - - pagesize "github.com/johnfercher/maroto/v2/pkg/consts/pagesize" - - props "github.com/johnfercher/maroto/v2/pkg/props" - - protection "github.com/johnfercher/maroto/v2/pkg/consts/protection" - - time "time" ) // Builder is an autogenerated mock type for the Builder type @@ -34,20 +24,20 @@ func (_m *Builder) EXPECT() *Builder_Expecter { return &Builder_Expecter{mock: &_m.Mock} } -// Build provides a mock function with given fields: -func (_m *Builder) Build() *entity.Config { - ret := _m.Called() +// Build provides a mock function with given fields: cfg, _a1 +func (_m *Builder) Build(cfg *entity.Config, _a1 cache.Cache) *gofpdf.Dependencies { + ret := _m.Called(cfg, _a1) if len(ret) == 0 { panic("no return value specified for Build") } - var r0 *entity.Config - if rf, ok := ret.Get(0).(func() *entity.Config); ok { - r0 = rf() + var r0 *gofpdf.Dependencies + if rf, ok := ret.Get(0).(func(*entity.Config, cache.Cache) *gofpdf.Dependencies); ok { + r0 = rf(cfg, _a1) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*entity.Config) + r0 = ret.Get(0).(*gofpdf.Dependencies) } } @@ -60,1244 +50,25 @@ type Builder_Build_Call struct { } // Build is a helper method to define mock.On call -func (_e *Builder_Expecter) Build() *Builder_Build_Call { - return &Builder_Build_Call{Call: _e.mock.On("Build")} -} - -func (_c *Builder_Build_Call) Run(run func()) *Builder_Build_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *Builder_Build_Call) Return(_a0 *entity.Config) *Builder_Build_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_Build_Call) RunAndReturn(run func() *entity.Config) *Builder_Build_Call { - _c.Call.Return(run) - return _c -} - -// WithAuthor provides a mock function with given fields: author, isUTF8 -func (_m *Builder) WithAuthor(author string, isUTF8 bool) config.Builder { - ret := _m.Called(author, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithAuthor") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(author, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithAuthor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithAuthor' -type Builder_WithAuthor_Call struct { - *mock.Call -} - -// WithAuthor is a helper method to define mock.On call -// - author string -// - isUTF8 bool -func (_e *Builder_Expecter) WithAuthor(author interface{}, isUTF8 interface{}) *Builder_WithAuthor_Call { - return &Builder_WithAuthor_Call{Call: _e.mock.On("WithAuthor", author, isUTF8)} -} - -func (_c *Builder_WithAuthor_Call) Run(run func(author string, isUTF8 bool)) *Builder_WithAuthor_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithAuthor_Call) Return(_a0 config.Builder) *Builder_WithAuthor_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithAuthor_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithAuthor_Call { - _c.Call.Return(run) - return _c -} - -// WithBackgroundImage provides a mock function with given fields: _a0, _a1 -func (_m *Builder) WithBackgroundImage(_a0 []byte, _a1 extension.Type) config.Builder { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for WithBackgroundImage") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func([]byte, extension.Type) config.Builder); ok { - r0 = rf(_a0, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithBackgroundImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBackgroundImage' -type Builder_WithBackgroundImage_Call struct { - *mock.Call -} - -// WithBackgroundImage is a helper method to define mock.On call -// - _a0 []byte -// - _a1 extension.Type -func (_e *Builder_Expecter) WithBackgroundImage(_a0 interface{}, _a1 interface{}) *Builder_WithBackgroundImage_Call { - return &Builder_WithBackgroundImage_Call{Call: _e.mock.On("WithBackgroundImage", _a0, _a1)} -} - -func (_c *Builder_WithBackgroundImage_Call) Run(run func(_a0 []byte, _a1 extension.Type)) *Builder_WithBackgroundImage_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].([]byte), args[1].(extension.Type)) - }) - return _c -} - -func (_c *Builder_WithBackgroundImage_Call) Return(_a0 config.Builder) *Builder_WithBackgroundImage_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithBackgroundImage_Call) RunAndReturn(run func([]byte, extension.Type) config.Builder) *Builder_WithBackgroundImage_Call { - _c.Call.Return(run) - return _c -} - -// WithBottomMargin provides a mock function with given fields: bottom -func (_m *Builder) WithBottomMargin(bottom float64) config.Builder { - ret := _m.Called(bottom) - - if len(ret) == 0 { - panic("no return value specified for WithBottomMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(bottom) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithBottomMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBottomMargin' -type Builder_WithBottomMargin_Call struct { - *mock.Call -} - -// WithBottomMargin is a helper method to define mock.On call -// - bottom float64 -func (_e *Builder_Expecter) WithBottomMargin(bottom interface{}) *Builder_WithBottomMargin_Call { - return &Builder_WithBottomMargin_Call{Call: _e.mock.On("WithBottomMargin", bottom)} -} - -func (_c *Builder_WithBottomMargin_Call) Run(run func(bottom float64)) *Builder_WithBottomMargin_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) - }) - return _c -} - -func (_c *Builder_WithBottomMargin_Call) Return(_a0 config.Builder) *Builder_WithBottomMargin_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithBottomMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithBottomMargin_Call { - _c.Call.Return(run) - return _c -} - -// WithCompression provides a mock function with given fields: compression -func (_m *Builder) WithCompression(compression bool) config.Builder { - ret := _m.Called(compression) - - if len(ret) == 0 { - panic("no return value specified for WithCompression") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { - r0 = rf(compression) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCompression_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCompression' -type Builder_WithCompression_Call struct { - *mock.Call -} - -// WithCompression is a helper method to define mock.On call -// - compression bool -func (_e *Builder_Expecter) WithCompression(compression interface{}) *Builder_WithCompression_Call { - return &Builder_WithCompression_Call{Call: _e.mock.On("WithCompression", compression)} -} - -func (_c *Builder_WithCompression_Call) Run(run func(compression bool)) *Builder_WithCompression_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(bool)) - }) - return _c -} - -func (_c *Builder_WithCompression_Call) Return(_a0 config.Builder) *Builder_WithCompression_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCompression_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithCompression_Call { - _c.Call.Return(run) - return _c -} - -// WithConcurrentMode provides a mock function with given fields: chunkWorkers -func (_m *Builder) WithConcurrentMode(chunkWorkers int) config.Builder { - ret := _m.Called(chunkWorkers) - - if len(ret) == 0 { - panic("no return value specified for WithConcurrentMode") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(int) config.Builder); ok { - r0 = rf(chunkWorkers) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithConcurrentMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithConcurrentMode' -type Builder_WithConcurrentMode_Call struct { - *mock.Call -} - -// WithConcurrentMode is a helper method to define mock.On call -// - chunkWorkers int -func (_e *Builder_Expecter) WithConcurrentMode(chunkWorkers interface{}) *Builder_WithConcurrentMode_Call { - return &Builder_WithConcurrentMode_Call{Call: _e.mock.On("WithConcurrentMode", chunkWorkers)} -} - -func (_c *Builder_WithConcurrentMode_Call) Run(run func(chunkWorkers int)) *Builder_WithConcurrentMode_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(int)) - }) - return _c -} - -func (_c *Builder_WithConcurrentMode_Call) Return(_a0 config.Builder) *Builder_WithConcurrentMode_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithConcurrentMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithConcurrentMode_Call { - _c.Call.Return(run) - return _c -} - -// WithCreationDate provides a mock function with given fields: _a0 -func (_m *Builder) WithCreationDate(_a0 time.Time) config.Builder { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for WithCreationDate") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(time.Time) config.Builder); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCreationDate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreationDate' -type Builder_WithCreationDate_Call struct { - *mock.Call -} - -// WithCreationDate is a helper method to define mock.On call -// - _a0 time.Time -func (_e *Builder_Expecter) WithCreationDate(_a0 interface{}) *Builder_WithCreationDate_Call { - return &Builder_WithCreationDate_Call{Call: _e.mock.On("WithCreationDate", _a0)} -} - -func (_c *Builder_WithCreationDate_Call) Run(run func(_a0 time.Time)) *Builder_WithCreationDate_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(time.Time)) - }) - return _c -} - -func (_c *Builder_WithCreationDate_Call) Return(_a0 config.Builder) *Builder_WithCreationDate_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCreationDate_Call) RunAndReturn(run func(time.Time) config.Builder) *Builder_WithCreationDate_Call { - _c.Call.Return(run) - return _c -} - -// WithCreator provides a mock function with given fields: creator, isUTF8 -func (_m *Builder) WithCreator(creator string, isUTF8 bool) config.Builder { - ret := _m.Called(creator, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithCreator") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(creator, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCreator_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreator' -type Builder_WithCreator_Call struct { - *mock.Call -} - -// WithCreator is a helper method to define mock.On call -// - creator string -// - isUTF8 bool -func (_e *Builder_Expecter) WithCreator(creator interface{}, isUTF8 interface{}) *Builder_WithCreator_Call { - return &Builder_WithCreator_Call{Call: _e.mock.On("WithCreator", creator, isUTF8)} -} - -func (_c *Builder_WithCreator_Call) Run(run func(creator string, isUTF8 bool)) *Builder_WithCreator_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithCreator_Call) Return(_a0 config.Builder) *Builder_WithCreator_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCreator_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithCreator_Call { - _c.Call.Return(run) - return _c -} - -// WithCustomFonts provides a mock function with given fields: _a0 -func (_m *Builder) WithCustomFonts(_a0 []*entity.CustomFont) config.Builder { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for WithCustomFonts") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func([]*entity.CustomFont) config.Builder); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCustomFonts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCustomFonts' -type Builder_WithCustomFonts_Call struct { - *mock.Call -} - -// WithCustomFonts is a helper method to define mock.On call -// - _a0 []*entity.CustomFont -func (_e *Builder_Expecter) WithCustomFonts(_a0 interface{}) *Builder_WithCustomFonts_Call { - return &Builder_WithCustomFonts_Call{Call: _e.mock.On("WithCustomFonts", _a0)} -} - -func (_c *Builder_WithCustomFonts_Call) Run(run func(_a0 []*entity.CustomFont)) *Builder_WithCustomFonts_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].([]*entity.CustomFont)) - }) - return _c -} - -func (_c *Builder_WithCustomFonts_Call) Return(_a0 config.Builder) *Builder_WithCustomFonts_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCustomFonts_Call) RunAndReturn(run func([]*entity.CustomFont) config.Builder) *Builder_WithCustomFonts_Call { - _c.Call.Return(run) - return _c -} - -// WithDebug provides a mock function with given fields: on -func (_m *Builder) WithDebug(on bool) config.Builder { - ret := _m.Called(on) - - if len(ret) == 0 { - panic("no return value specified for WithDebug") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { - r0 = rf(on) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDebug_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDebug' -type Builder_WithDebug_Call struct { - *mock.Call -} - -// WithDebug is a helper method to define mock.On call -// - on bool -func (_e *Builder_Expecter) WithDebug(on interface{}) *Builder_WithDebug_Call { - return &Builder_WithDebug_Call{Call: _e.mock.On("WithDebug", on)} -} - -func (_c *Builder_WithDebug_Call) Run(run func(on bool)) *Builder_WithDebug_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(bool)) - }) - return _c -} - -func (_c *Builder_WithDebug_Call) Return(_a0 config.Builder) *Builder_WithDebug_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDebug_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDebug_Call { - _c.Call.Return(run) - return _c -} - -// WithDefaultFont provides a mock function with given fields: font -func (_m *Builder) WithDefaultFont(font *props.Font) config.Builder { - ret := _m.Called(font) - - if len(ret) == 0 { - panic("no return value specified for WithDefaultFont") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(*props.Font) config.Builder); ok { - r0 = rf(font) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDefaultFont_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDefaultFont' -type Builder_WithDefaultFont_Call struct { - *mock.Call -} - -// WithDefaultFont is a helper method to define mock.On call -// - font *props.Font -func (_e *Builder_Expecter) WithDefaultFont(font interface{}) *Builder_WithDefaultFont_Call { - return &Builder_WithDefaultFont_Call{Call: _e.mock.On("WithDefaultFont", font)} -} - -func (_c *Builder_WithDefaultFont_Call) Run(run func(font *props.Font)) *Builder_WithDefaultFont_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*props.Font)) - }) - return _c -} - -func (_c *Builder_WithDefaultFont_Call) Return(_a0 config.Builder) *Builder_WithDefaultFont_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDefaultFont_Call) RunAndReturn(run func(*props.Font) config.Builder) *Builder_WithDefaultFont_Call { - _c.Call.Return(run) - return _c -} - -// WithDimensions provides a mock function with given fields: width, height -func (_m *Builder) WithDimensions(width float64, height float64) config.Builder { - ret := _m.Called(width, height) - - if len(ret) == 0 { - panic("no return value specified for WithDimensions") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64, float64) config.Builder); ok { - r0 = rf(width, height) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDimensions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDimensions' -type Builder_WithDimensions_Call struct { - *mock.Call -} - -// WithDimensions is a helper method to define mock.On call -// - width float64 -// - height float64 -func (_e *Builder_Expecter) WithDimensions(width interface{}, height interface{}) *Builder_WithDimensions_Call { - return &Builder_WithDimensions_Call{Call: _e.mock.On("WithDimensions", width, height)} -} - -func (_c *Builder_WithDimensions_Call) Run(run func(width float64, height float64)) *Builder_WithDimensions_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64), args[1].(float64)) - }) - return _c -} - -func (_c *Builder_WithDimensions_Call) Return(_a0 config.Builder) *Builder_WithDimensions_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDimensions_Call) RunAndReturn(run func(float64, float64) config.Builder) *Builder_WithDimensions_Call { - _c.Call.Return(run) - return _c -} - -// WithDisableAutoPageBreak provides a mock function with given fields: disabled -func (_m *Builder) WithDisableAutoPageBreak(disabled bool) config.Builder { - ret := _m.Called(disabled) - - if len(ret) == 0 { - panic("no return value specified for WithDisableAutoPageBreak") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { - r0 = rf(disabled) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDisableAutoPageBreak_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDisableAutoPageBreak' -type Builder_WithDisableAutoPageBreak_Call struct { - *mock.Call -} - -// WithDisableAutoPageBreak is a helper method to define mock.On call -// - disabled bool -func (_e *Builder_Expecter) WithDisableAutoPageBreak(disabled interface{}) *Builder_WithDisableAutoPageBreak_Call { - return &Builder_WithDisableAutoPageBreak_Call{Call: _e.mock.On("WithDisableAutoPageBreak", disabled)} -} - -func (_c *Builder_WithDisableAutoPageBreak_Call) Run(run func(disabled bool)) *Builder_WithDisableAutoPageBreak_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(bool)) - }) - return _c -} - -func (_c *Builder_WithDisableAutoPageBreak_Call) Return(_a0 config.Builder) *Builder_WithDisableAutoPageBreak_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDisableAutoPageBreak_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDisableAutoPageBreak_Call { - _c.Call.Return(run) - return _c -} - -// WithKeywords provides a mock function with given fields: keywordsStr, isUTF8 -func (_m *Builder) WithKeywords(keywordsStr string, isUTF8 bool) config.Builder { - ret := _m.Called(keywordsStr, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithKeywords") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(keywordsStr, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithKeywords_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithKeywords' -type Builder_WithKeywords_Call struct { - *mock.Call -} - -// WithKeywords is a helper method to define mock.On call -// - keywordsStr string -// - isUTF8 bool -func (_e *Builder_Expecter) WithKeywords(keywordsStr interface{}, isUTF8 interface{}) *Builder_WithKeywords_Call { - return &Builder_WithKeywords_Call{Call: _e.mock.On("WithKeywords", keywordsStr, isUTF8)} -} - -func (_c *Builder_WithKeywords_Call) Run(run func(keywordsStr string, isUTF8 bool)) *Builder_WithKeywords_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithKeywords_Call) Return(_a0 config.Builder) *Builder_WithKeywords_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithKeywords_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithKeywords_Call { - _c.Call.Return(run) - return _c -} - -// WithLeftMargin provides a mock function with given fields: left -func (_m *Builder) WithLeftMargin(left float64) config.Builder { - ret := _m.Called(left) - - if len(ret) == 0 { - panic("no return value specified for WithLeftMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(left) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithLeftMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithLeftMargin' -type Builder_WithLeftMargin_Call struct { - *mock.Call -} - -// WithLeftMargin is a helper method to define mock.On call -// - left float64 -func (_e *Builder_Expecter) WithLeftMargin(left interface{}) *Builder_WithLeftMargin_Call { - return &Builder_WithLeftMargin_Call{Call: _e.mock.On("WithLeftMargin", left)} -} - -func (_c *Builder_WithLeftMargin_Call) Run(run func(left float64)) *Builder_WithLeftMargin_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) - }) - return _c -} - -func (_c *Builder_WithLeftMargin_Call) Return(_a0 config.Builder) *Builder_WithLeftMargin_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithLeftMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithLeftMargin_Call { - _c.Call.Return(run) - return _c -} - -// WithMaxGridSize provides a mock function with given fields: maxGridSize -func (_m *Builder) WithMaxGridSize(maxGridSize int) config.Builder { - ret := _m.Called(maxGridSize) - - if len(ret) == 0 { - panic("no return value specified for WithMaxGridSize") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(int) config.Builder); ok { - r0 = rf(maxGridSize) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithMaxGridSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithMaxGridSize' -type Builder_WithMaxGridSize_Call struct { - *mock.Call -} - -// WithMaxGridSize is a helper method to define mock.On call -// - maxGridSize int -func (_e *Builder_Expecter) WithMaxGridSize(maxGridSize interface{}) *Builder_WithMaxGridSize_Call { - return &Builder_WithMaxGridSize_Call{Call: _e.mock.On("WithMaxGridSize", maxGridSize)} -} - -func (_c *Builder_WithMaxGridSize_Call) Run(run func(maxGridSize int)) *Builder_WithMaxGridSize_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(int)) - }) - return _c -} - -func (_c *Builder_WithMaxGridSize_Call) Return(_a0 config.Builder) *Builder_WithMaxGridSize_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithMaxGridSize_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithMaxGridSize_Call { - _c.Call.Return(run) - return _c -} - -// WithOrientation provides a mock function with given fields: _a0 -func (_m *Builder) WithOrientation(_a0 orientation.Type) config.Builder { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for WithOrientation") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(orientation.Type) config.Builder); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithOrientation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithOrientation' -type Builder_WithOrientation_Call struct { - *mock.Call -} - -// WithOrientation is a helper method to define mock.On call -// - _a0 orientation.Type -func (_e *Builder_Expecter) WithOrientation(_a0 interface{}) *Builder_WithOrientation_Call { - return &Builder_WithOrientation_Call{Call: _e.mock.On("WithOrientation", _a0)} -} - -func (_c *Builder_WithOrientation_Call) Run(run func(_a0 orientation.Type)) *Builder_WithOrientation_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(orientation.Type)) - }) - return _c -} - -func (_c *Builder_WithOrientation_Call) Return(_a0 config.Builder) *Builder_WithOrientation_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithOrientation_Call) RunAndReturn(run func(orientation.Type) config.Builder) *Builder_WithOrientation_Call { - _c.Call.Return(run) - return _c -} - -// WithPageNumber provides a mock function with given fields: pageNumber -func (_m *Builder) WithPageNumber(pageNumber ...props.PageNumber) config.Builder { - _va := make([]interface{}, len(pageNumber)) - for _i := range pageNumber { - _va[_i] = pageNumber[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - if len(ret) == 0 { - panic("no return value specified for WithPageNumber") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(...props.PageNumber) config.Builder); ok { - r0 = rf(pageNumber...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithPageNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageNumber' -type Builder_WithPageNumber_Call struct { - *mock.Call -} - -// WithPageNumber is a helper method to define mock.On call -// - pageNumber ...props.PageNumber -func (_e *Builder_Expecter) WithPageNumber(pageNumber ...interface{}) *Builder_WithPageNumber_Call { - return &Builder_WithPageNumber_Call{Call: _e.mock.On("WithPageNumber", - append([]interface{}{}, pageNumber...)...)} -} - -func (_c *Builder_WithPageNumber_Call) Run(run func(pageNumber ...props.PageNumber)) *Builder_WithPageNumber_Call { - _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]props.PageNumber, len(args)-0) - for i, a := range args[0:] { - if a != nil { - variadicArgs[i] = a.(props.PageNumber) - } - } - run(variadicArgs...) - }) - return _c -} - -func (_c *Builder_WithPageNumber_Call) Return(_a0 config.Builder) *Builder_WithPageNumber_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithPageNumber_Call) RunAndReturn(run func(...props.PageNumber) config.Builder) *Builder_WithPageNumber_Call { - _c.Call.Return(run) - return _c -} - -// WithPageSize provides a mock function with given fields: size -func (_m *Builder) WithPageSize(size pagesize.Type) config.Builder { - ret := _m.Called(size) - - if len(ret) == 0 { - panic("no return value specified for WithPageSize") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(pagesize.Type) config.Builder); ok { - r0 = rf(size) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithPageSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageSize' -type Builder_WithPageSize_Call struct { - *mock.Call -} - -// WithPageSize is a helper method to define mock.On call -// - size pagesize.Type -func (_e *Builder_Expecter) WithPageSize(size interface{}) *Builder_WithPageSize_Call { - return &Builder_WithPageSize_Call{Call: _e.mock.On("WithPageSize", size)} -} - -func (_c *Builder_WithPageSize_Call) Run(run func(size pagesize.Type)) *Builder_WithPageSize_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(pagesize.Type)) - }) - return _c -} - -func (_c *Builder_WithPageSize_Call) Return(_a0 config.Builder) *Builder_WithPageSize_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithPageSize_Call) RunAndReturn(run func(pagesize.Type) config.Builder) *Builder_WithPageSize_Call { - _c.Call.Return(run) - return _c -} - -// WithProtection provides a mock function with given fields: protectionType, userPassword, ownerPassword -func (_m *Builder) WithProtection(protectionType protection.Type, userPassword string, ownerPassword string) config.Builder { - ret := _m.Called(protectionType, userPassword, ownerPassword) - - if len(ret) == 0 { - panic("no return value specified for WithProtection") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(protection.Type, string, string) config.Builder); ok { - r0 = rf(protectionType, userPassword, ownerPassword) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithProtection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithProtection' -type Builder_WithProtection_Call struct { - *mock.Call -} - -// WithProtection is a helper method to define mock.On call -// - protectionType protection.Type -// - userPassword string -// - ownerPassword string -func (_e *Builder_Expecter) WithProtection(protectionType interface{}, userPassword interface{}, ownerPassword interface{}) *Builder_WithProtection_Call { - return &Builder_WithProtection_Call{Call: _e.mock.On("WithProtection", protectionType, userPassword, ownerPassword)} -} - -func (_c *Builder_WithProtection_Call) Run(run func(protectionType protection.Type, userPassword string, ownerPassword string)) *Builder_WithProtection_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(protection.Type), args[1].(string), args[2].(string)) - }) - return _c -} - -func (_c *Builder_WithProtection_Call) Return(_a0 config.Builder) *Builder_WithProtection_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithProtection_Call) RunAndReturn(run func(protection.Type, string, string) config.Builder) *Builder_WithProtection_Call { - _c.Call.Return(run) - return _c -} - -// WithRightMargin provides a mock function with given fields: right -func (_m *Builder) WithRightMargin(right float64) config.Builder { - ret := _m.Called(right) - - if len(ret) == 0 { - panic("no return value specified for WithRightMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(right) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithRightMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithRightMargin' -type Builder_WithRightMargin_Call struct { - *mock.Call -} - -// WithRightMargin is a helper method to define mock.On call -// - right float64 -func (_e *Builder_Expecter) WithRightMargin(right interface{}) *Builder_WithRightMargin_Call { - return &Builder_WithRightMargin_Call{Call: _e.mock.On("WithRightMargin", right)} -} - -func (_c *Builder_WithRightMargin_Call) Run(run func(right float64)) *Builder_WithRightMargin_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) - }) - return _c -} - -func (_c *Builder_WithRightMargin_Call) Return(_a0 config.Builder) *Builder_WithRightMargin_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithRightMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithRightMargin_Call { - _c.Call.Return(run) - return _c -} - -// WithSequentialLowMemoryMode provides a mock function with given fields: chunkWorkers -func (_m *Builder) WithSequentialLowMemoryMode(chunkWorkers int) config.Builder { - ret := _m.Called(chunkWorkers) - - if len(ret) == 0 { - panic("no return value specified for WithSequentialLowMemoryMode") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(int) config.Builder); ok { - r0 = rf(chunkWorkers) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithSequentialLowMemoryMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialLowMemoryMode' -type Builder_WithSequentialLowMemoryMode_Call struct { - *mock.Call -} - -// WithSequentialLowMemoryMode is a helper method to define mock.On call -// - chunkWorkers int -func (_e *Builder_Expecter) WithSequentialLowMemoryMode(chunkWorkers interface{}) *Builder_WithSequentialLowMemoryMode_Call { - return &Builder_WithSequentialLowMemoryMode_Call{Call: _e.mock.On("WithSequentialLowMemoryMode", chunkWorkers)} -} - -func (_c *Builder_WithSequentialLowMemoryMode_Call) Run(run func(chunkWorkers int)) *Builder_WithSequentialLowMemoryMode_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(int)) - }) - return _c -} - -func (_c *Builder_WithSequentialLowMemoryMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialLowMemoryMode_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithSequentialLowMemoryMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithSequentialLowMemoryMode_Call { - _c.Call.Return(run) - return _c -} - -// WithSequentialMode provides a mock function with given fields: -func (_m *Builder) WithSequentialMode() config.Builder { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for WithSequentialMode") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func() config.Builder); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithSequentialMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialMode' -type Builder_WithSequentialMode_Call struct { - *mock.Call -} - -// WithSequentialMode is a helper method to define mock.On call -func (_e *Builder_Expecter) WithSequentialMode() *Builder_WithSequentialMode_Call { - return &Builder_WithSequentialMode_Call{Call: _e.mock.On("WithSequentialMode")} -} - -func (_c *Builder_WithSequentialMode_Call) Run(run func()) *Builder_WithSequentialMode_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *Builder_WithSequentialMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialMode_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithSequentialMode_Call) RunAndReturn(run func() config.Builder) *Builder_WithSequentialMode_Call { - _c.Call.Return(run) - return _c -} - -// WithSubject provides a mock function with given fields: subject, isUTF8 -func (_m *Builder) WithSubject(subject string, isUTF8 bool) config.Builder { - ret := _m.Called(subject, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithSubject") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(subject, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithSubject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSubject' -type Builder_WithSubject_Call struct { - *mock.Call -} - -// WithSubject is a helper method to define mock.On call -// - subject string -// - isUTF8 bool -func (_e *Builder_Expecter) WithSubject(subject interface{}, isUTF8 interface{}) *Builder_WithSubject_Call { - return &Builder_WithSubject_Call{Call: _e.mock.On("WithSubject", subject, isUTF8)} -} - -func (_c *Builder_WithSubject_Call) Run(run func(subject string, isUTF8 bool)) *Builder_WithSubject_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithSubject_Call) Return(_a0 config.Builder) *Builder_WithSubject_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithSubject_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithSubject_Call { - _c.Call.Return(run) - return _c -} - -// WithTitle provides a mock function with given fields: title, isUTF8 -func (_m *Builder) WithTitle(title string, isUTF8 bool) config.Builder { - ret := _m.Called(title, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithTitle") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(title, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithTitle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTitle' -type Builder_WithTitle_Call struct { - *mock.Call -} - -// WithTitle is a helper method to define mock.On call -// - title string -// - isUTF8 bool -func (_e *Builder_Expecter) WithTitle(title interface{}, isUTF8 interface{}) *Builder_WithTitle_Call { - return &Builder_WithTitle_Call{Call: _e.mock.On("WithTitle", title, isUTF8)} -} - -func (_c *Builder_WithTitle_Call) Run(run func(title string, isUTF8 bool)) *Builder_WithTitle_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithTitle_Call) Return(_a0 config.Builder) *Builder_WithTitle_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithTitle_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithTitle_Call { - _c.Call.Return(run) - return _c -} - -// WithTopMargin provides a mock function with given fields: top -func (_m *Builder) WithTopMargin(top float64) config.Builder { - ret := _m.Called(top) - - if len(ret) == 0 { - panic("no return value specified for WithTopMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(top) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithTopMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTopMargin' -type Builder_WithTopMargin_Call struct { - *mock.Call -} - -// WithTopMargin is a helper method to define mock.On call -// - top float64 -func (_e *Builder_Expecter) WithTopMargin(top interface{}) *Builder_WithTopMargin_Call { - return &Builder_WithTopMargin_Call{Call: _e.mock.On("WithTopMargin", top)} +// - cfg *entity.Config +// - _a1 cache.Cache +func (_e *Builder_Expecter) Build(cfg interface{}, _a1 interface{}) *Builder_Build_Call { + return &Builder_Build_Call{Call: _e.mock.On("Build", cfg, _a1)} } -func (_c *Builder_WithTopMargin_Call) Run(run func(top float64)) *Builder_WithTopMargin_Call { +func (_c *Builder_Build_Call) Run(run func(cfg *entity.Config, _a1 cache.Cache)) *Builder_Build_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) + run(args[0].(*entity.Config), args[1].(cache.Cache)) }) return _c } -func (_c *Builder_WithTopMargin_Call) Return(_a0 config.Builder) *Builder_WithTopMargin_Call { +func (_c *Builder_Build_Call) Return(_a0 *gofpdf.Dependencies) *Builder_Build_Call { _c.Call.Return(_a0) return _c } -func (_c *Builder_WithTopMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithTopMargin_Call { +func (_c *Builder_Build_Call) RunAndReturn(run func(*entity.Config, cache.Cache) *gofpdf.Dependencies) *Builder_Build_Call { _c.Call.Return(run) return _c } diff --git a/mocks/ProcessorProvider.go b/mocks/ProcessorProvider.go index 31040da1..456c406c 100644 --- a/mocks/ProcessorProvider.go +++ b/mocks/ProcessorProvider.go @@ -84,6 +84,70 @@ func (_c *ProcessorProvider_CreateBarCode_Call) RunAndReturn(run func(string, .. return _c } +// CreateImage provides a mock function with given fields: value, extension, props +func (_m *ProcessorProvider) CreateImage(value []byte, extension string, props ...*propsmapper.Rect) processorprovider.PDFComponent { + _va := make([]interface{}, len(props)) + for _i := range props { + _va[_i] = props[_i] + } + var _ca []interface{} + _ca = append(_ca, value, extension) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for CreateImage") + } + + var r0 processorprovider.PDFComponent + if rf, ok := ret.Get(0).(func([]byte, string, ...*propsmapper.Rect) processorprovider.PDFComponent); ok { + r0 = rf(value, extension, props...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(processorprovider.PDFComponent) + } + } + + return r0 +} + +// ProcessorProvider_CreateImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateImage' +type ProcessorProvider_CreateImage_Call struct { + *mock.Call +} + +// CreateImage is a helper method to define mock.On call +// - value []byte +// - extension string +// - props ...*propsmapper.Rect +func (_e *ProcessorProvider_Expecter) CreateImage(value interface{}, extension interface{}, props ...interface{}) *ProcessorProvider_CreateImage_Call { + return &ProcessorProvider_CreateImage_Call{Call: _e.mock.On("CreateImage", + append([]interface{}{value, extension}, props...)...)} +} + +func (_c *ProcessorProvider_CreateImage_Call) Run(run func(value []byte, extension string, props ...*propsmapper.Rect)) *ProcessorProvider_CreateImage_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]*propsmapper.Rect, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(*propsmapper.Rect) + } + } + run(args[0].([]byte), args[1].(string), variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_CreateImage_Call) Return(_a0 processorprovider.PDFComponent) *ProcessorProvider_CreateImage_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorProvider_CreateImage_Call) RunAndReturn(run func([]byte, string, ...*propsmapper.Rect) processorprovider.PDFComponent) *ProcessorProvider_CreateImage_Call { + _c.Call.Return(run) + return _c +} + // CreateMatrixCode provides a mock function with given fields: value, props func (_m *ProcessorProvider) CreateMatrixCode(value string, props ...*propsmapper.Rect) processorprovider.PDFComponent { _va := make([]interface{}, len(props)) diff --git a/mocks/Repository.go b/mocks/Repository.go index e5fec24e..9927b778 100644 --- a/mocks/Repository.go +++ b/mocks/Repository.go @@ -17,6 +17,71 @@ func (_m *Repository) EXPECT() *Repository_Expecter { return &Repository_Expecter{mock: &_m.Mock} } +// GetDocument provides a mock function with given fields: documentName +func (_m *Repository) GetDocument(documentName string) (string, []byte, error) { + ret := _m.Called(documentName) + + if len(ret) == 0 { + panic("no return value specified for GetDocument") + } + + var r0 string + var r1 []byte + var r2 error + if rf, ok := ret.Get(0).(func(string) (string, []byte, error)); ok { + return rf(documentName) + } + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(documentName) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(string) []byte); ok { + r1 = rf(documentName) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).([]byte) + } + } + + if rf, ok := ret.Get(2).(func(string) error); ok { + r2 = rf(documentName) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// Repository_GetDocument_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDocument' +type Repository_GetDocument_Call struct { + *mock.Call +} + +// GetDocument is a helper method to define mock.On call +// - documentName string +func (_e *Repository_Expecter) GetDocument(documentName interface{}) *Repository_GetDocument_Call { + return &Repository_GetDocument_Call{Call: _e.mock.On("GetDocument", documentName)} +} + +func (_c *Repository_GetDocument_Call) Run(run func(documentName string)) *Repository_GetDocument_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Repository_GetDocument_Call) Return(extension string, doc []byte, err error) *Repository_GetDocument_Call { + _c.Call.Return(extension, doc, err) + return _c +} + +func (_c *Repository_GetDocument_Call) RunAndReturn(run func(string) (string, []byte, error)) *Repository_GetDocument_Call { + _c.Call.Return(run) + return _c +} + // ReadTemplate provides a mock function with given fields: templateName func (_m *Repository) ReadTemplate(templateName string) (map[string]interface{}, error) { ret := _m.Called(templateName) diff --git a/pkg/processor/mappers/components/imagemapper/image_test.go b/pkg/processor/mappers/components/imagemapper/image_test.go index 0e8754d9..bce80f81 100644 --- a/pkg/processor/mappers/components/imagemapper/image_test.go +++ b/pkg/processor/mappers/components/imagemapper/image_test.go @@ -1,8 +1,10 @@ package imagemapper_test import ( + "fmt" "testing" + "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/imagemapper" "github.com/stretchr/testify/assert" ) @@ -10,18 +12,20 @@ import ( func TestNewImage(t *testing.T) { t.Run("when invalid image is sent, should return an error", func(t *testing.T) { imageTemplate := 1 + repository := mocks.NewRepository(t) - image, err := imagemapper.NewImage(imageTemplate) + image, err := imagemapper.NewImage(imageTemplate, repository) assert.Nil(t, image) assert.NotNil(t, err) }) t.Run("when props is not sent, image is created", func(t *testing.T) { imageTemplate := map[string]interface{}{ - "source_key": "source key", + "source_key": "image", } + repository := mocks.NewRepository(t) - image, err := imagemapper.NewImage(imageTemplate) + image, err := imagemapper.NewImage(imageTemplate, repository) assert.Nil(t, err) assert.NotNil(t, image) @@ -31,8 +35,9 @@ func TestNewImage(t *testing.T) { "props": 1, "source_key": "name", } + repository := mocks.NewRepository(t) - image, err := imagemapper.NewImage(imageTemplate) + image, err := imagemapper.NewImage(imageTemplate, repository) assert.Nil(t, image) assert.NotNil(t, err) @@ -42,16 +47,18 @@ func TestNewImage(t *testing.T) { "invalid_field": 1, "source_key": "name", } + repository := mocks.NewRepository(t) - image, err := imagemapper.NewImage(imageTemplate) + image, err := imagemapper.NewImage(imageTemplate, repository) assert.Nil(t, image) assert.NotNil(t, err) }) t.Run("when source_key is not sent, should return an error", func(t *testing.T) { imageTemplate := map[string]interface{}{} + repository := mocks.NewRepository(t) - image, err := imagemapper.NewImage(imageTemplate) + image, err := imagemapper.NewImage(imageTemplate, repository) assert.Nil(t, image) assert.NotNil(t, err) @@ -60,8 +67,18 @@ func TestNewImage(t *testing.T) { imageTemplate := map[string]interface{}{ "source_key": 123, } + repository := mocks.NewRepository(t) - image, err := imagemapper.NewImage(imageTemplate) + image, err := imagemapper.NewImage(imageTemplate, repository) + + assert.Nil(t, image) + assert.NotNil(t, err) + }) + t.Run("when source_key and path are not sent, should return an error", func(t *testing.T) { + imageTemplate := map[string]interface{}{} + repository := mocks.NewRepository(t) + + image, err := imagemapper.NewImage(imageTemplate, repository) assert.Nil(t, image) assert.NotNil(t, err) @@ -70,8 +87,9 @@ func TestNewImage(t *testing.T) { imageTemplate := map[string]interface{}{ "source_key": "icon", } + repository := mocks.NewRepository(t) - image, err := imagemapper.NewImage(imageTemplate) + image, err := imagemapper.NewImage(imageTemplate, repository) assert.Nil(t, err) assert.Equal(t, image.SourceKey, "icon") @@ -83,10 +101,81 @@ func TestNewImage(t *testing.T) { "left": 10.0, }, } + repository := mocks.NewRepository(t) - image, err := imagemapper.NewImage(imageTemplate) + image, err := imagemapper.NewImage(imageTemplate, repository) assert.Nil(t, err) assert.Equal(t, 10.0, image.Props.Left) }) } + +func TestImageGenerate(t *testing.T) { + t.Run("if image is not found, should return an error", func(t *testing.T) { + content := map[string]interface{}{} + provider := mocks.NewProcessorProvider(t) + repository := mocks.NewRepository(t) + + image := imagemapper.Image{SourceKey: "code", Repository: repository} + component, err := image.Generate(content, provider) + + assert.Nil(t, component) + assert.NotNil(t, err) + }) + t.Run("if image content is not valid, should return an error", func(t *testing.T) { + content := map[string]interface{}{ + "code": 1, + } + provider := mocks.NewProcessorProvider(t) + + image := imagemapper.Image{SourceKey: "code"} + component, err := image.Generate(content, provider) + + assert.Nil(t, component) + assert.NotNil(t, err) + }) + t.Run("If the image has no props, the props will not be sent", func(t *testing.T) { + content := map[string]interface{}{ + "Path": "path.png", + } + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateImage([]byte("image"), "png").Return(nil) + repository := mocks.NewRepository(t) + repository.EXPECT().GetDocument("path.png").Return("png", []byte("image"), nil) + + image := imagemapper.Image{SourceKey: "Path", Repository: repository} + _, err := image.Generate(content, provider) + + assert.Nil(t, err) + repository.AssertNumberOfCalls(t, "GetDocument", 1) + provider.AssertNumberOfCalls(t, "CreateImage", 1) + }) + t.Run("when it was not possible to load the image, it should return an error", func(t *testing.T) { + content := map[string]interface{}{} + + provider := mocks.NewProcessorProvider(t) + repository := mocks.NewRepository(t) + repository.EXPECT().GetDocument("path.png").Return("", nil, fmt.Errorf("any")) + + image := imagemapper.Image{Path: "path.png", Repository: repository} + _, err := image.Generate(content, provider) + + assert.NotNil(t, err) + repository.AssertNumberOfCalls(t, "GetDocument", 1) + }) + t.Run("when valid path is sent, should generate image", func(t *testing.T) { + content := map[string]interface{}{} + + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateImage([]byte("image"), "png").Return(nil) + repository := mocks.NewRepository(t) + repository.EXPECT().GetDocument("path.png").Return("png", []byte("image"), nil) + + image := imagemapper.Image{Path: "path.png", Repository: repository} + _, err := image.Generate(content, provider) + + assert.Nil(t, err) + repository.AssertNumberOfCalls(t, "GetDocument", 1) + provider.AssertNumberOfCalls(t, "CreateImage", 1) + }) +} diff --git a/pkg/processor/processorprovider/Maroto_test.go b/pkg/processor/processorprovider/Maroto_test.go index 6639609e..a1050977 100644 --- a/pkg/processor/processorprovider/Maroto_test.go +++ b/pkg/processor/processorprovider/Maroto_test.go @@ -25,6 +25,7 @@ func TestCreateBarCode(t *testing.T) { test.New(t).Assert(barcode.GetStructure()).Equals("processor/provider/barcode.json") }) } + func TestCreateMatrixCode(t *testing.T) { t.Run("when CreateMatrixCode is called, should generate a matrixcode", func(t *testing.T) { m := processorprovider.NewMaroto() @@ -35,6 +36,7 @@ func TestCreateMatrixCode(t *testing.T) { test.New(t).Assert(barcode.GetStructure()).Equals("processor/provider/matrixcode.json") }) } + func TestCreateQRCode(t *testing.T) { t.Run("when CreateQrCode is called, should generate a qrcode", func(t *testing.T) { m := processorprovider.NewMaroto() @@ -45,3 +47,14 @@ func TestCreateQRCode(t *testing.T) { test.New(t).Assert(barcode.GetStructure()).Equals("processor/provider/qrcode.json") }) } + +func TestCreateImage(t *testing.T) { + t.Run("when CreateImage is called, should generate a image", func(t *testing.T) { + m := processorprovider.NewMaroto() + image := m.CreateImage(make([]byte, 0), "png", + &propsmapper.Rect{Left: 10.0, Top: 10.0, Percent: 100.0, JustReferenceWidth: false, Center: false}, + ) + + test.New(t).Assert(image.GetStructure()).Equals("processor/provider/image.json") + }) +} diff --git a/test/maroto/processor/provider/image.json b/test/maroto/processor/provider/image.json new file mode 100644 index 00000000..d89c4ab0 --- /dev/null +++ b/test/maroto/processor/provider/image.json @@ -0,0 +1,11 @@ +{ + "value": "", + "type": "bytesImage", + "details": { + "bytes_size": 0, + "extension": "png", + "prop_left": 10, + "prop_percent": 100, + "prop_top": 10 + } +} \ No newline at end of file From fe56a3d8c1cf943b0e26d75ee53f6ab85e19baff Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 30 Oct 2024 22:33:41 -0300 Subject: [PATCH 053/116] feat: create image component add method to get document from repository add repository to image mapper --- pkg/processor/core/core.go | 1 + .../abstractfactory/abstractfactory.go | 11 ++-- .../mappers/components/imagemapper/image.go | 58 ++++++++++++++++--- pkg/processor/processor.go | 2 +- pkg/processor/processorprovider/Maroto.go | 14 +++++ pkg/processor/processorprovider/provider.go | 1 + pkg/processor/repository/memory_storage.go | 6 ++ 7 files changed, 79 insertions(+), 14 deletions(-) diff --git a/pkg/processor/core/core.go b/pkg/processor/core/core.go index 39f0f99c..9969d695 100644 --- a/pkg/processor/core/core.go +++ b/pkg/processor/core/core.go @@ -8,6 +8,7 @@ type Processor interface { type Repository interface { RegisterTemplate(templateName string, template map[string]any) error ReadTemplate(templateName string) (map[string]any, error) + GetDocument(documentName string) (extension string, doc []byte, err error) } type Deserializer interface { diff --git a/pkg/processor/mappers/abstractfactory/abstractfactory.go b/pkg/processor/mappers/abstractfactory/abstractfactory.go index 683bf1ba..44d81058 100644 --- a/pkg/processor/mappers/abstractfactory/abstractfactory.go +++ b/pkg/processor/mappers/abstractfactory/abstractfactory.go @@ -1,6 +1,7 @@ package abstractfactory import ( + "github.com/johnfercher/maroto/v2/pkg/processor/core" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/codemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/colmapper" @@ -13,11 +14,13 @@ import ( "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/textmapper" ) -type abstractFactoryMaps struct{} +type abstractFactoryMaps struct { + repository core.Repository +} // NewAbstractFactoryMaps is responsible for creating an object that encapsulates the creation of components -func NewAbstractFactoryMaps() *abstractFactoryMaps { - return &abstractFactoryMaps{} +func NewAbstractFactoryMaps(repository core.Repository) *abstractFactoryMaps { + return &abstractFactoryMaps{repository: repository} } // NewRow is responsible for wrapper the creation of a row @@ -59,7 +62,7 @@ func (f *abstractFactoryMaps) NewQrcode(document interface{}) (mappers.Component // NewImage is responsible for wrapper the creation of a image func (f *abstractFactoryMaps) NewImage(document interface{}) (mappers.Componentmapper, error) { - return imagemapper.NewImage(document) + return imagemapper.NewImage(document, f.repository) } // NewLine is responsible for wrapper the creation of a libe diff --git a/pkg/processor/mappers/components/imagemapper/image.go b/pkg/processor/mappers/components/imagemapper/image.go index a9f0a7c0..ba0e429b 100644 --- a/pkg/processor/mappers/components/imagemapper/image.go +++ b/pkg/processor/mappers/components/imagemapper/image.go @@ -4,31 +4,33 @@ package imagemapper import ( "fmt" - "github.com/johnfercher/maroto/v2/pkg/processor/components" + "github.com/johnfercher/maroto/v2/pkg/processor/core" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Image struct { - SourceKey string - Props *propsmapper.Rect + Path string + SourceKey string + Props *propsmapper.Rect + Repository core.Repository } -func NewImage(templateImage interface{}) (*Image, error) { +func NewImage(templateImage interface{}, repository core.Repository) (*Image, error) { imageMap, ok := templateImage.(map[string]interface{}) if !ok { return nil, fmt.Errorf("ensure image can be converted to map[string] interface{}") } - image := &Image{} + image := &Image{Repository: repository} if err := image.addFields(imageMap); err != nil { return nil, err } if image.SourceKey == "" { - return nil, fmt.Errorf("no value passed for image. Add the 'source_key'") + return nil, fmt.Errorf("no value passed for image. Add the 'source_key' or a path") } return image, nil - } // addFields is responsible for adding the barcode fields according to @@ -55,6 +57,7 @@ func (i *Image) getFieldMappers() map[string]func(interface{}) error { return map[string]func(interface{}) error{ "source_key": i.setSourceKey, "props": i.setProps, + "path": i.setPath, } } @@ -67,6 +70,15 @@ func (i *Image) setSourceKey(template interface{}) error { return nil } +func (i *Image) setPath(template interface{}) error { + path, ok := template.(string) + if !ok { + return fmt.Errorf("path cannot be converted to a string") + } + i.Path = path + return nil +} + func (b *Image) setProps(template interface{}) error { props, err := propsmapper.NewRect(template) if err != nil { @@ -76,6 +88,34 @@ func (b *Image) setProps(template interface{}) error { return nil } -func (b *Image) Generate(content map[string]interface{}) (components.PdfComponent, error) { - return nil, nil +func (i *Image) getImagePath(content map[string]interface{}) (string, error) { + if i.Path != "" { + return i.Path, nil + } + imageFound, ok := content[i.SourceKey] + if !ok { + return "", fmt.Errorf("image requires a source key named %s, but it was not found", i.SourceKey) + } + imageValid, ok := imageFound.(string) + if !ok { + return "", fmt.Errorf("unable to generate image, invalid path. source key %s", i.SourceKey) + } + return imageValid, nil +} + +func (i *Image) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { + path, err := i.getImagePath(content) + if err != nil { + return nil, err + } + i.Path = path + extension, img, err := i.Repository.GetDocument(i.Path) + if err != nil { + return nil, err + } + + if i.Props != nil { + return provider.CreateImage(img, extension, i.Props), nil + } + return provider.CreateImage(img, extension), nil } diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index 511ddd6b..c64b8fcd 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -44,7 +44,7 @@ func (p *processor) GenerateDocument(templateName string, content string) ([]byt return nil, err } - document, err := documentmapper.NewPdf(template, abstractfactory.NewAbstractFactoryMaps()) + document, err := documentmapper.NewPdf(template, abstractfactory.NewAbstractFactoryMaps(p.repository)) if err != nil { return nil, err } diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index b2eb2b44..28e1cd6f 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -2,7 +2,9 @@ package processorprovider import ( "github.com/johnfercher/maroto/v2/pkg/components/code" + "github.com/johnfercher/maroto/v2/pkg/components/image" "github.com/johnfercher/maroto/v2/pkg/consts/barcode" + "github.com/johnfercher/maroto/v2/pkg/consts/extension" "github.com/johnfercher/maroto/v2/pkg/core" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/props" @@ -17,6 +19,18 @@ func NewMaroto() *Maroto { return nil } +func (m *Maroto) CreateImage(img []byte, ext string, imgProps ...*propsmapper.Rect) PDFComponent { + cProps := propsmapper.Rect{} + if len(imgProps) > 0 { + cProps = *imgProps[0] + } + + return image.NewFromBytes(img, extension.Type(ext), props.Rect{ + Left: cProps.Left, Top: cProps.Top, Percent: cProps.Percent, + JustReferenceWidth: cProps.JustReferenceWidth, Center: cProps.Center, + }) +} + func (m *Maroto) CreateMatrixCode(codeValue string, codeProps ...*propsmapper.Rect) PDFComponent { cProps := propsmapper.Rect{} if len(codeProps) > 0 { diff --git a/pkg/processor/processorprovider/provider.go b/pkg/processor/processorprovider/provider.go index c5a11f2c..dc54e869 100644 --- a/pkg/processor/processorprovider/provider.go +++ b/pkg/processor/processorprovider/provider.go @@ -17,4 +17,5 @@ type ProcessorProvider interface { CreateBarCode(value string, props ...*propsmapper.Barcode) PDFComponent CreateMatrixCode(value string, props ...*propsmapper.Rect) PDFComponent CreateQrCode(value string, props ...*propsmapper.Rect) PDFComponent + CreateImage(value []byte, extension string, props ...*propsmapper.Rect) PDFComponent } diff --git a/pkg/processor/repository/memory_storage.go b/pkg/processor/repository/memory_storage.go index 2a4e4eec..c3211618 100644 --- a/pkg/processor/repository/memory_storage.go +++ b/pkg/processor/repository/memory_storage.go @@ -13,6 +13,12 @@ func NewMemoryStorage() *memoryStorage { } } +// GetDocument is responsible search and return the document according to the name sent +// - documentName is the name that the document references +func (m *memoryStorage) GetDocument(documentName string) (string, []byte, error) { + return "", nil, nil +} + // RegisterTemplate is responsible for register a template in memory // - name is the model identifier and is used to access it // - template is the template that will be stored From 321e55e0f539ab9f134630eb11d3e2566fdea071 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 30 Oct 2024 22:57:30 -0300 Subject: [PATCH 054/116] test: validate line creation --- mocks/ProcessorProvider.go | 48 +++++ mocks/Repository.go | 174 +++++++++--------- .../processorprovider/Maroto_test.go | 14 ++ test/maroto/processor/provider/line.json | 11 ++ 4 files changed, 157 insertions(+), 90 deletions(-) create mode 100644 test/maroto/processor/provider/line.json diff --git a/mocks/ProcessorProvider.go b/mocks/ProcessorProvider.go index 456c406c..b1805f57 100644 --- a/mocks/ProcessorProvider.go +++ b/mocks/ProcessorProvider.go @@ -148,6 +148,54 @@ func (_c *ProcessorProvider_CreateImage_Call) RunAndReturn(run func([]byte, stri return _c } +// CreateLine provides a mock function with given fields: props +func (_m *ProcessorProvider) CreateLine(props *propsmapper.Line) processorprovider.PDFComponent { + ret := _m.Called(props) + + if len(ret) == 0 { + panic("no return value specified for CreateLine") + } + + var r0 processorprovider.PDFComponent + if rf, ok := ret.Get(0).(func(*propsmapper.Line) processorprovider.PDFComponent); ok { + r0 = rf(props) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(processorprovider.PDFComponent) + } + } + + return r0 +} + +// ProcessorProvider_CreateLine_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateLine' +type ProcessorProvider_CreateLine_Call struct { + *mock.Call +} + +// CreateLine is a helper method to define mock.On call +// - props *propsmapper.Line +func (_e *ProcessorProvider_Expecter) CreateLine(props interface{}) *ProcessorProvider_CreateLine_Call { + return &ProcessorProvider_CreateLine_Call{Call: _e.mock.On("CreateLine", props)} +} + +func (_c *ProcessorProvider_CreateLine_Call) Run(run func(props *propsmapper.Line)) *ProcessorProvider_CreateLine_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*propsmapper.Line)) + }) + return _c +} + +func (_c *ProcessorProvider_CreateLine_Call) Return(_a0 processorprovider.PDFComponent) *ProcessorProvider_CreateLine_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorProvider_CreateLine_Call) RunAndReturn(run func(*propsmapper.Line) processorprovider.PDFComponent) *ProcessorProvider_CreateLine_Call { + _c.Call.Return(run) + return _c +} + // CreateMatrixCode provides a mock function with given fields: value, props func (_m *ProcessorProvider) CreateMatrixCode(value string, props ...*propsmapper.Rect) processorprovider.PDFComponent { _va := make([]interface{}, len(props)) diff --git a/mocks/Repository.go b/mocks/Repository.go index 9927b778..3977c94e 100644 --- a/mocks/Repository.go +++ b/mocks/Repository.go @@ -2,7 +2,14 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + fontstyle "github.com/johnfercher/maroto/v2/pkg/consts/fontstyle" + entity "github.com/johnfercher/maroto/v2/pkg/core/entity" + + mock "github.com/stretchr/testify/mock" + + repository "github.com/johnfercher/maroto/v2/pkg/repository" +) // Repository is an autogenerated mock type for the Repository type type Repository struct { @@ -17,172 +24,159 @@ func (_m *Repository) EXPECT() *Repository_Expecter { return &Repository_Expecter{mock: &_m.Mock} } -// GetDocument provides a mock function with given fields: documentName -func (_m *Repository) GetDocument(documentName string) (string, []byte, error) { - ret := _m.Called(documentName) +// AddUTF8Font provides a mock function with given fields: family, style, file +func (_m *Repository) AddUTF8Font(family string, style fontstyle.Type, file string) repository.Repository { + ret := _m.Called(family, style, file) if len(ret) == 0 { - panic("no return value specified for GetDocument") + panic("no return value specified for AddUTF8Font") } - var r0 string - var r1 []byte - var r2 error - if rf, ok := ret.Get(0).(func(string) (string, []byte, error)); ok { - return rf(documentName) - } - if rf, ok := ret.Get(0).(func(string) string); ok { - r0 = rf(documentName) + var r0 repository.Repository + if rf, ok := ret.Get(0).(func(string, fontstyle.Type, string) repository.Repository); ok { + r0 = rf(family, style, file) } else { - r0 = ret.Get(0).(string) - } - - if rf, ok := ret.Get(1).(func(string) []byte); ok { - r1 = rf(documentName) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).([]byte) + if ret.Get(0) != nil { + r0 = ret.Get(0).(repository.Repository) } } - if rf, ok := ret.Get(2).(func(string) error); ok { - r2 = rf(documentName) - } else { - r2 = ret.Error(2) - } - - return r0, r1, r2 + return r0 } -// Repository_GetDocument_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDocument' -type Repository_GetDocument_Call struct { +// Repository_AddUTF8Font_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddUTF8Font' +type Repository_AddUTF8Font_Call struct { *mock.Call } -// GetDocument is a helper method to define mock.On call -// - documentName string -func (_e *Repository_Expecter) GetDocument(documentName interface{}) *Repository_GetDocument_Call { - return &Repository_GetDocument_Call{Call: _e.mock.On("GetDocument", documentName)} +// AddUTF8Font is a helper method to define mock.On call +// - family string +// - style fontstyle.Type +// - file string +func (_e *Repository_Expecter) AddUTF8Font(family interface{}, style interface{}, file interface{}) *Repository_AddUTF8Font_Call { + return &Repository_AddUTF8Font_Call{Call: _e.mock.On("AddUTF8Font", family, style, file)} } -func (_c *Repository_GetDocument_Call) Run(run func(documentName string)) *Repository_GetDocument_Call { +func (_c *Repository_AddUTF8Font_Call) Run(run func(family string, style fontstyle.Type, file string)) *Repository_AddUTF8Font_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) + run(args[0].(string), args[1].(fontstyle.Type), args[2].(string)) }) return _c } -func (_c *Repository_GetDocument_Call) Return(extension string, doc []byte, err error) *Repository_GetDocument_Call { - _c.Call.Return(extension, doc, err) +func (_c *Repository_AddUTF8Font_Call) Return(_a0 repository.Repository) *Repository_AddUTF8Font_Call { + _c.Call.Return(_a0) return _c } -func (_c *Repository_GetDocument_Call) RunAndReturn(run func(string) (string, []byte, error)) *Repository_GetDocument_Call { +func (_c *Repository_AddUTF8Font_Call) RunAndReturn(run func(string, fontstyle.Type, string) repository.Repository) *Repository_AddUTF8Font_Call { _c.Call.Return(run) return _c } -// ReadTemplate provides a mock function with given fields: templateName -func (_m *Repository) ReadTemplate(templateName string) (map[string]interface{}, error) { - ret := _m.Called(templateName) +// AddUTF8FontFromBytes provides a mock function with given fields: family, style, bytes +func (_m *Repository) AddUTF8FontFromBytes(family string, style fontstyle.Type, bytes []byte) repository.Repository { + ret := _m.Called(family, style, bytes) if len(ret) == 0 { - panic("no return value specified for ReadTemplate") + panic("no return value specified for AddUTF8FontFromBytes") } - var r0 map[string]interface{} - var r1 error - if rf, ok := ret.Get(0).(func(string) (map[string]interface{}, error)); ok { - return rf(templateName) - } - if rf, ok := ret.Get(0).(func(string) map[string]interface{}); ok { - r0 = rf(templateName) + var r0 repository.Repository + if rf, ok := ret.Get(0).(func(string, fontstyle.Type, []byte) repository.Repository); ok { + r0 = rf(family, style, bytes) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(map[string]interface{}) + r0 = ret.Get(0).(repository.Repository) } } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(templateName) - } else { - r1 = ret.Error(1) - } - - return r0, r1 + return r0 } -// Repository_ReadTemplate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReadTemplate' -type Repository_ReadTemplate_Call struct { +// Repository_AddUTF8FontFromBytes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddUTF8FontFromBytes' +type Repository_AddUTF8FontFromBytes_Call struct { *mock.Call } -// ReadTemplate is a helper method to define mock.On call -// - templateName string -func (_e *Repository_Expecter) ReadTemplate(templateName interface{}) *Repository_ReadTemplate_Call { - return &Repository_ReadTemplate_Call{Call: _e.mock.On("ReadTemplate", templateName)} +// AddUTF8FontFromBytes is a helper method to define mock.On call +// - family string +// - style fontstyle.Type +// - bytes []byte +func (_e *Repository_Expecter) AddUTF8FontFromBytes(family interface{}, style interface{}, bytes interface{}) *Repository_AddUTF8FontFromBytes_Call { + return &Repository_AddUTF8FontFromBytes_Call{Call: _e.mock.On("AddUTF8FontFromBytes", family, style, bytes)} } -func (_c *Repository_ReadTemplate_Call) Run(run func(templateName string)) *Repository_ReadTemplate_Call { +func (_c *Repository_AddUTF8FontFromBytes_Call) Run(run func(family string, style fontstyle.Type, bytes []byte)) *Repository_AddUTF8FontFromBytes_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) + run(args[0].(string), args[1].(fontstyle.Type), args[2].([]byte)) }) return _c } -func (_c *Repository_ReadTemplate_Call) Return(_a0 map[string]interface{}, _a1 error) *Repository_ReadTemplate_Call { - _c.Call.Return(_a0, _a1) +func (_c *Repository_AddUTF8FontFromBytes_Call) Return(_a0 repository.Repository) *Repository_AddUTF8FontFromBytes_Call { + _c.Call.Return(_a0) return _c } -func (_c *Repository_ReadTemplate_Call) RunAndReturn(run func(string) (map[string]interface{}, error)) *Repository_ReadTemplate_Call { +func (_c *Repository_AddUTF8FontFromBytes_Call) RunAndReturn(run func(string, fontstyle.Type, []byte) repository.Repository) *Repository_AddUTF8FontFromBytes_Call { _c.Call.Return(run) return _c } -// RegisterTemplate provides a mock function with given fields: templateName, template -func (_m *Repository) RegisterTemplate(templateName string, template map[string]interface{}) error { - ret := _m.Called(templateName, template) +// Load provides a mock function with given fields: +func (_m *Repository) Load() ([]*entity.CustomFont, error) { + ret := _m.Called() if len(ret) == 0 { - panic("no return value specified for RegisterTemplate") + panic("no return value specified for Load") } - var r0 error - if rf, ok := ret.Get(0).(func(string, map[string]interface{}) error); ok { - r0 = rf(templateName, template) + var r0 []*entity.CustomFont + var r1 error + if rf, ok := ret.Get(0).(func() ([]*entity.CustomFont, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []*entity.CustomFont); ok { + r0 = rf() } else { - r0 = ret.Error(0) + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*entity.CustomFont) + } } - return r0 + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 } -// Repository_RegisterTemplate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterTemplate' -type Repository_RegisterTemplate_Call struct { +// Repository_Load_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Load' +type Repository_Load_Call struct { *mock.Call } -// RegisterTemplate is a helper method to define mock.On call -// - templateName string -// - template map[string]interface{} -func (_e *Repository_Expecter) RegisterTemplate(templateName interface{}, template interface{}) *Repository_RegisterTemplate_Call { - return &Repository_RegisterTemplate_Call{Call: _e.mock.On("RegisterTemplate", templateName, template)} +// Load is a helper method to define mock.On call +func (_e *Repository_Expecter) Load() *Repository_Load_Call { + return &Repository_Load_Call{Call: _e.mock.On("Load")} } -func (_c *Repository_RegisterTemplate_Call) Run(run func(templateName string, template map[string]interface{})) *Repository_RegisterTemplate_Call { +func (_c *Repository_Load_Call) Run(run func()) *Repository_Load_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(map[string]interface{})) + run() }) return _c } -func (_c *Repository_RegisterTemplate_Call) Return(_a0 error) *Repository_RegisterTemplate_Call { - _c.Call.Return(_a0) +func (_c *Repository_Load_Call) Return(_a0 []*entity.CustomFont, _a1 error) *Repository_Load_Call { + _c.Call.Return(_a0, _a1) return _c } -func (_c *Repository_RegisterTemplate_Call) RunAndReturn(run func(string, map[string]interface{}) error) *Repository_RegisterTemplate_Call { +func (_c *Repository_Load_Call) RunAndReturn(run func() ([]*entity.CustomFont, error)) *Repository_Load_Call { _c.Call.Return(run) return _c } diff --git a/pkg/processor/processorprovider/Maroto_test.go b/pkg/processor/processorprovider/Maroto_test.go index a1050977..366ed299 100644 --- a/pkg/processor/processorprovider/Maroto_test.go +++ b/pkg/processor/processorprovider/Maroto_test.go @@ -58,3 +58,17 @@ func TestCreateImage(t *testing.T) { test.New(t).Assert(image.GetStructure()).Equals("processor/provider/image.json") }) } + +func TestCreateLine(t *testing.T) { + t.Run("when CreateLine is called, should generate a line", func(t *testing.T) { + m := processorprovider.NewMaroto() + barcode := m.CreateLine( + &propsmapper.Line{ + Color: &propsmapper.Color{Red: 10, Green: 10, Blue: 10}, Style: "solid", Thickness: 10.0, + Orientation: "vertical", OffsetPercent: 50, SizePercent: 50, + }, + ) + + test.New(t).Assert(barcode.GetStructure()).Equals("processor/provider/line.json") + }) +} diff --git a/test/maroto/processor/provider/line.json b/test/maroto/processor/provider/line.json new file mode 100644 index 00000000..10301100 --- /dev/null +++ b/test/maroto/processor/provider/line.json @@ -0,0 +1,11 @@ +{ + "type": "line", + "details": { + "prop_color": "RGB(10, 10, 10)", + "prop_offset_percent": 50, + "prop_orientation": "vertical", + "prop_size_percent": 50, + "prop_style": "solid", + "prop_thickness": 10 + } +} \ No newline at end of file From dd53701ffcd7a84e879172b469846473d01c2694 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 30 Oct 2024 22:58:48 -0300 Subject: [PATCH 055/116] feat: create line component --- .../mappers/components/linemapper/line.go | 6 +++--- pkg/processor/processorprovider/Maroto.go | 15 +++++++++++++++ pkg/processor/processorprovider/provider.go | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pkg/processor/mappers/components/linemapper/line.go b/pkg/processor/mappers/components/linemapper/line.go index 01018150..af988060 100644 --- a/pkg/processor/mappers/components/linemapper/line.go +++ b/pkg/processor/mappers/components/linemapper/line.go @@ -4,8 +4,8 @@ package linemapper import ( "fmt" - "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Line struct { @@ -60,6 +60,6 @@ func (l *Line) setProps(templateProps interface{}) error { return nil } -func (l *Line) Generate(content map[string]interface{}) (components.PdfComponent, error) { - return nil, nil +func (l *Line) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { + return provider.CreateLine(l.Props), nil } diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index 28e1cd6f..93dd61d6 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -3,8 +3,11 @@ package processorprovider import ( "github.com/johnfercher/maroto/v2/pkg/components/code" "github.com/johnfercher/maroto/v2/pkg/components/image" + "github.com/johnfercher/maroto/v2/pkg/components/line" "github.com/johnfercher/maroto/v2/pkg/consts/barcode" "github.com/johnfercher/maroto/v2/pkg/consts/extension" + "github.com/johnfercher/maroto/v2/pkg/consts/linestyle" + "github.com/johnfercher/maroto/v2/pkg/consts/orientation" "github.com/johnfercher/maroto/v2/pkg/core" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/props" @@ -19,6 +22,18 @@ func NewMaroto() *Maroto { return nil } +func (m *Maroto) CreateLine(lineProps ...*propsmapper.Line) PDFComponent { + lProps := propsmapper.Line{} + if len(lineProps) > 0 { + lProps = *lineProps[0] + } + + return line.New(props.Line{ + Color: (*props.Color)(lProps.Color), Style: linestyle.Type(lProps.Style), Thickness: lProps.Thickness, + Orientation: orientation.Type(lProps.Orientation), OffsetPercent: lProps.OffsetPercent, SizePercent: lProps.SizePercent, + }) +} + func (m *Maroto) CreateImage(img []byte, ext string, imgProps ...*propsmapper.Rect) PDFComponent { cProps := propsmapper.Rect{} if len(imgProps) > 0 { diff --git a/pkg/processor/processorprovider/provider.go b/pkg/processor/processorprovider/provider.go index dc54e869..37800daf 100644 --- a/pkg/processor/processorprovider/provider.go +++ b/pkg/processor/processorprovider/provider.go @@ -18,4 +18,5 @@ type ProcessorProvider interface { CreateMatrixCode(value string, props ...*propsmapper.Rect) PDFComponent CreateQrCode(value string, props ...*propsmapper.Rect) PDFComponent CreateImage(value []byte, extension string, props ...*propsmapper.Rect) PDFComponent + CreateLine(props *propsmapper.Line) PDFComponent } From a3e75d8730bf467b63d13a06ac867b7c5eef8e48 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sat, 2 Nov 2024 14:42:09 -0300 Subject: [PATCH 056/116] test: validate creation of signature component --- mocks/Builder.go | 1263 ++++++++++++++++- mocks/ProcessorProvider.go | 63 + mocks/Repository.go | 174 +-- .../signaturemapper/signature_test.go | 52 + .../processorprovider/Maroto_test.go | 14 + test/maroto/processor/provider/signature.json | 13 + 6 files changed, 1478 insertions(+), 101 deletions(-) create mode 100644 test/maroto/processor/provider/signature.json diff --git a/mocks/Builder.go b/mocks/Builder.go index 883f7968..2cbe240a 100644 --- a/mocks/Builder.go +++ b/mocks/Builder.go @@ -3,12 +3,22 @@ package mocks import ( - cache "github.com/johnfercher/maroto/v2/internal/cache" + config "github.com/johnfercher/maroto/v2/pkg/config" entity "github.com/johnfercher/maroto/v2/pkg/core/entity" - gofpdf "github.com/johnfercher/maroto/v2/internal/providers/gofpdf" + extension "github.com/johnfercher/maroto/v2/pkg/consts/extension" mock "github.com/stretchr/testify/mock" + + orientation "github.com/johnfercher/maroto/v2/pkg/consts/orientation" + + pagesize "github.com/johnfercher/maroto/v2/pkg/consts/pagesize" + + props "github.com/johnfercher/maroto/v2/pkg/props" + + protection "github.com/johnfercher/maroto/v2/pkg/consts/protection" + + time "time" ) // Builder is an autogenerated mock type for the Builder type @@ -24,20 +34,20 @@ func (_m *Builder) EXPECT() *Builder_Expecter { return &Builder_Expecter{mock: &_m.Mock} } -// Build provides a mock function with given fields: cfg, _a1 -func (_m *Builder) Build(cfg *entity.Config, _a1 cache.Cache) *gofpdf.Dependencies { - ret := _m.Called(cfg, _a1) +// Build provides a mock function with given fields: +func (_m *Builder) Build() *entity.Config { + ret := _m.Called() if len(ret) == 0 { panic("no return value specified for Build") } - var r0 *gofpdf.Dependencies - if rf, ok := ret.Get(0).(func(*entity.Config, cache.Cache) *gofpdf.Dependencies); ok { - r0 = rf(cfg, _a1) + var r0 *entity.Config + if rf, ok := ret.Get(0).(func() *entity.Config); ok { + r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*gofpdf.Dependencies) + r0 = ret.Get(0).(*entity.Config) } } @@ -50,25 +60,1244 @@ type Builder_Build_Call struct { } // Build is a helper method to define mock.On call -// - cfg *entity.Config -// - _a1 cache.Cache -func (_e *Builder_Expecter) Build(cfg interface{}, _a1 interface{}) *Builder_Build_Call { - return &Builder_Build_Call{Call: _e.mock.On("Build", cfg, _a1)} +func (_e *Builder_Expecter) Build() *Builder_Build_Call { + return &Builder_Build_Call{Call: _e.mock.On("Build")} +} + +func (_c *Builder_Build_Call) Run(run func()) *Builder_Build_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Builder_Build_Call) Return(_a0 *entity.Config) *Builder_Build_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_Build_Call) RunAndReturn(run func() *entity.Config) *Builder_Build_Call { + _c.Call.Return(run) + return _c +} + +// WithAuthor provides a mock function with given fields: author, isUTF8 +func (_m *Builder) WithAuthor(author string, isUTF8 bool) config.Builder { + ret := _m.Called(author, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithAuthor") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(author, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithAuthor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithAuthor' +type Builder_WithAuthor_Call struct { + *mock.Call +} + +// WithAuthor is a helper method to define mock.On call +// - author string +// - isUTF8 bool +func (_e *Builder_Expecter) WithAuthor(author interface{}, isUTF8 interface{}) *Builder_WithAuthor_Call { + return &Builder_WithAuthor_Call{Call: _e.mock.On("WithAuthor", author, isUTF8)} +} + +func (_c *Builder_WithAuthor_Call) Run(run func(author string, isUTF8 bool)) *Builder_WithAuthor_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithAuthor_Call) Return(_a0 config.Builder) *Builder_WithAuthor_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithAuthor_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithAuthor_Call { + _c.Call.Return(run) + return _c +} + +// WithBackgroundImage provides a mock function with given fields: _a0, _a1 +func (_m *Builder) WithBackgroundImage(_a0 []byte, _a1 extension.Type) config.Builder { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for WithBackgroundImage") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func([]byte, extension.Type) config.Builder); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithBackgroundImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBackgroundImage' +type Builder_WithBackgroundImage_Call struct { + *mock.Call +} + +// WithBackgroundImage is a helper method to define mock.On call +// - _a0 []byte +// - _a1 extension.Type +func (_e *Builder_Expecter) WithBackgroundImage(_a0 interface{}, _a1 interface{}) *Builder_WithBackgroundImage_Call { + return &Builder_WithBackgroundImage_Call{Call: _e.mock.On("WithBackgroundImage", _a0, _a1)} +} + +func (_c *Builder_WithBackgroundImage_Call) Run(run func(_a0 []byte, _a1 extension.Type)) *Builder_WithBackgroundImage_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]byte), args[1].(extension.Type)) + }) + return _c +} + +func (_c *Builder_WithBackgroundImage_Call) Return(_a0 config.Builder) *Builder_WithBackgroundImage_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithBackgroundImage_Call) RunAndReturn(run func([]byte, extension.Type) config.Builder) *Builder_WithBackgroundImage_Call { + _c.Call.Return(run) + return _c +} + +// WithBottomMargin provides a mock function with given fields: bottom +func (_m *Builder) WithBottomMargin(bottom float64) config.Builder { + ret := _m.Called(bottom) + + if len(ret) == 0 { + panic("no return value specified for WithBottomMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(bottom) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithBottomMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBottomMargin' +type Builder_WithBottomMargin_Call struct { + *mock.Call +} + +// WithBottomMargin is a helper method to define mock.On call +// - bottom float64 +func (_e *Builder_Expecter) WithBottomMargin(bottom interface{}) *Builder_WithBottomMargin_Call { + return &Builder_WithBottomMargin_Call{Call: _e.mock.On("WithBottomMargin", bottom)} +} + +func (_c *Builder_WithBottomMargin_Call) Run(run func(bottom float64)) *Builder_WithBottomMargin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Builder_WithBottomMargin_Call) Return(_a0 config.Builder) *Builder_WithBottomMargin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithBottomMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithBottomMargin_Call { + _c.Call.Return(run) + return _c +} + +// WithCompression provides a mock function with given fields: compression +func (_m *Builder) WithCompression(compression bool) config.Builder { + ret := _m.Called(compression) + + if len(ret) == 0 { + panic("no return value specified for WithCompression") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { + r0 = rf(compression) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCompression_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCompression' +type Builder_WithCompression_Call struct { + *mock.Call +} + +// WithCompression is a helper method to define mock.On call +// - compression bool +func (_e *Builder_Expecter) WithCompression(compression interface{}) *Builder_WithCompression_Call { + return &Builder_WithCompression_Call{Call: _e.mock.On("WithCompression", compression)} +} + +func (_c *Builder_WithCompression_Call) Run(run func(compression bool)) *Builder_WithCompression_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Builder_WithCompression_Call) Return(_a0 config.Builder) *Builder_WithCompression_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCompression_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithCompression_Call { + _c.Call.Return(run) + return _c +} + +// WithConcurrentMode provides a mock function with given fields: chunkWorkers +func (_m *Builder) WithConcurrentMode(chunkWorkers int) config.Builder { + ret := _m.Called(chunkWorkers) + + if len(ret) == 0 { + panic("no return value specified for WithConcurrentMode") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(int) config.Builder); ok { + r0 = rf(chunkWorkers) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithConcurrentMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithConcurrentMode' +type Builder_WithConcurrentMode_Call struct { + *mock.Call +} + +// WithConcurrentMode is a helper method to define mock.On call +// - chunkWorkers int +func (_e *Builder_Expecter) WithConcurrentMode(chunkWorkers interface{}) *Builder_WithConcurrentMode_Call { + return &Builder_WithConcurrentMode_Call{Call: _e.mock.On("WithConcurrentMode", chunkWorkers)} +} + +func (_c *Builder_WithConcurrentMode_Call) Run(run func(chunkWorkers int)) *Builder_WithConcurrentMode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Builder_WithConcurrentMode_Call) Return(_a0 config.Builder) *Builder_WithConcurrentMode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithConcurrentMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithConcurrentMode_Call { + _c.Call.Return(run) + return _c +} + +// WithCreationDate provides a mock function with given fields: _a0 +func (_m *Builder) WithCreationDate(_a0 time.Time) config.Builder { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for WithCreationDate") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(time.Time) config.Builder); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCreationDate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreationDate' +type Builder_WithCreationDate_Call struct { + *mock.Call +} + +// WithCreationDate is a helper method to define mock.On call +// - _a0 time.Time +func (_e *Builder_Expecter) WithCreationDate(_a0 interface{}) *Builder_WithCreationDate_Call { + return &Builder_WithCreationDate_Call{Call: _e.mock.On("WithCreationDate", _a0)} +} + +func (_c *Builder_WithCreationDate_Call) Run(run func(_a0 time.Time)) *Builder_WithCreationDate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(time.Time)) + }) + return _c +} + +func (_c *Builder_WithCreationDate_Call) Return(_a0 config.Builder) *Builder_WithCreationDate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCreationDate_Call) RunAndReturn(run func(time.Time) config.Builder) *Builder_WithCreationDate_Call { + _c.Call.Return(run) + return _c +} + +// WithCreator provides a mock function with given fields: creator, isUTF8 +func (_m *Builder) WithCreator(creator string, isUTF8 bool) config.Builder { + ret := _m.Called(creator, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithCreator") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(creator, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCreator_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreator' +type Builder_WithCreator_Call struct { + *mock.Call +} + +// WithCreator is a helper method to define mock.On call +// - creator string +// - isUTF8 bool +func (_e *Builder_Expecter) WithCreator(creator interface{}, isUTF8 interface{}) *Builder_WithCreator_Call { + return &Builder_WithCreator_Call{Call: _e.mock.On("WithCreator", creator, isUTF8)} +} + +func (_c *Builder_WithCreator_Call) Run(run func(creator string, isUTF8 bool)) *Builder_WithCreator_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithCreator_Call) Return(_a0 config.Builder) *Builder_WithCreator_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCreator_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithCreator_Call { + _c.Call.Return(run) + return _c +} + +// WithCustomFonts provides a mock function with given fields: _a0 +func (_m *Builder) WithCustomFonts(_a0 []*entity.CustomFont) config.Builder { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for WithCustomFonts") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func([]*entity.CustomFont) config.Builder); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCustomFonts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCustomFonts' +type Builder_WithCustomFonts_Call struct { + *mock.Call +} + +// WithCustomFonts is a helper method to define mock.On call +// - _a0 []*entity.CustomFont +func (_e *Builder_Expecter) WithCustomFonts(_a0 interface{}) *Builder_WithCustomFonts_Call { + return &Builder_WithCustomFonts_Call{Call: _e.mock.On("WithCustomFonts", _a0)} +} + +func (_c *Builder_WithCustomFonts_Call) Run(run func(_a0 []*entity.CustomFont)) *Builder_WithCustomFonts_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]*entity.CustomFont)) + }) + return _c +} + +func (_c *Builder_WithCustomFonts_Call) Return(_a0 config.Builder) *Builder_WithCustomFonts_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCustomFonts_Call) RunAndReturn(run func([]*entity.CustomFont) config.Builder) *Builder_WithCustomFonts_Call { + _c.Call.Return(run) + return _c +} + +// WithDebug provides a mock function with given fields: on +func (_m *Builder) WithDebug(on bool) config.Builder { + ret := _m.Called(on) + + if len(ret) == 0 { + panic("no return value specified for WithDebug") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { + r0 = rf(on) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDebug_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDebug' +type Builder_WithDebug_Call struct { + *mock.Call +} + +// WithDebug is a helper method to define mock.On call +// - on bool +func (_e *Builder_Expecter) WithDebug(on interface{}) *Builder_WithDebug_Call { + return &Builder_WithDebug_Call{Call: _e.mock.On("WithDebug", on)} +} + +func (_c *Builder_WithDebug_Call) Run(run func(on bool)) *Builder_WithDebug_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Builder_WithDebug_Call) Return(_a0 config.Builder) *Builder_WithDebug_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDebug_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDebug_Call { + _c.Call.Return(run) + return _c +} + +// WithDefaultFont provides a mock function with given fields: font +func (_m *Builder) WithDefaultFont(font *props.Font) config.Builder { + ret := _m.Called(font) + + if len(ret) == 0 { + panic("no return value specified for WithDefaultFont") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(*props.Font) config.Builder); ok { + r0 = rf(font) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDefaultFont_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDefaultFont' +type Builder_WithDefaultFont_Call struct { + *mock.Call +} + +// WithDefaultFont is a helper method to define mock.On call +// - font *props.Font +func (_e *Builder_Expecter) WithDefaultFont(font interface{}) *Builder_WithDefaultFont_Call { + return &Builder_WithDefaultFont_Call{Call: _e.mock.On("WithDefaultFont", font)} +} + +func (_c *Builder_WithDefaultFont_Call) Run(run func(font *props.Font)) *Builder_WithDefaultFont_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*props.Font)) + }) + return _c +} + +func (_c *Builder_WithDefaultFont_Call) Return(_a0 config.Builder) *Builder_WithDefaultFont_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDefaultFont_Call) RunAndReturn(run func(*props.Font) config.Builder) *Builder_WithDefaultFont_Call { + _c.Call.Return(run) + return _c +} + +// WithDimensions provides a mock function with given fields: width, height +func (_m *Builder) WithDimensions(width float64, height float64) config.Builder { + ret := _m.Called(width, height) + + if len(ret) == 0 { + panic("no return value specified for WithDimensions") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64, float64) config.Builder); ok { + r0 = rf(width, height) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDimensions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDimensions' +type Builder_WithDimensions_Call struct { + *mock.Call +} + +// WithDimensions is a helper method to define mock.On call +// - width float64 +// - height float64 +func (_e *Builder_Expecter) WithDimensions(width interface{}, height interface{}) *Builder_WithDimensions_Call { + return &Builder_WithDimensions_Call{Call: _e.mock.On("WithDimensions", width, height)} +} + +func (_c *Builder_WithDimensions_Call) Run(run func(width float64, height float64)) *Builder_WithDimensions_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64), args[1].(float64)) + }) + return _c +} + +func (_c *Builder_WithDimensions_Call) Return(_a0 config.Builder) *Builder_WithDimensions_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDimensions_Call) RunAndReturn(run func(float64, float64) config.Builder) *Builder_WithDimensions_Call { + _c.Call.Return(run) + return _c +} + +// WithDisableAutoPageBreak provides a mock function with given fields: disabled +func (_m *Builder) WithDisableAutoPageBreak(disabled bool) config.Builder { + ret := _m.Called(disabled) + + if len(ret) == 0 { + panic("no return value specified for WithDisableAutoPageBreak") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { + r0 = rf(disabled) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDisableAutoPageBreak_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDisableAutoPageBreak' +type Builder_WithDisableAutoPageBreak_Call struct { + *mock.Call +} + +// WithDisableAutoPageBreak is a helper method to define mock.On call +// - disabled bool +func (_e *Builder_Expecter) WithDisableAutoPageBreak(disabled interface{}) *Builder_WithDisableAutoPageBreak_Call { + return &Builder_WithDisableAutoPageBreak_Call{Call: _e.mock.On("WithDisableAutoPageBreak", disabled)} +} + +func (_c *Builder_WithDisableAutoPageBreak_Call) Run(run func(disabled bool)) *Builder_WithDisableAutoPageBreak_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Builder_WithDisableAutoPageBreak_Call) Return(_a0 config.Builder) *Builder_WithDisableAutoPageBreak_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDisableAutoPageBreak_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDisableAutoPageBreak_Call { + _c.Call.Return(run) + return _c +} + +// WithKeywords provides a mock function with given fields: keywordsStr, isUTF8 +func (_m *Builder) WithKeywords(keywordsStr string, isUTF8 bool) config.Builder { + ret := _m.Called(keywordsStr, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithKeywords") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(keywordsStr, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithKeywords_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithKeywords' +type Builder_WithKeywords_Call struct { + *mock.Call +} + +// WithKeywords is a helper method to define mock.On call +// - keywordsStr string +// - isUTF8 bool +func (_e *Builder_Expecter) WithKeywords(keywordsStr interface{}, isUTF8 interface{}) *Builder_WithKeywords_Call { + return &Builder_WithKeywords_Call{Call: _e.mock.On("WithKeywords", keywordsStr, isUTF8)} +} + +func (_c *Builder_WithKeywords_Call) Run(run func(keywordsStr string, isUTF8 bool)) *Builder_WithKeywords_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithKeywords_Call) Return(_a0 config.Builder) *Builder_WithKeywords_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithKeywords_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithKeywords_Call { + _c.Call.Return(run) + return _c +} + +// WithLeftMargin provides a mock function with given fields: left +func (_m *Builder) WithLeftMargin(left float64) config.Builder { + ret := _m.Called(left) + + if len(ret) == 0 { + panic("no return value specified for WithLeftMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(left) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithLeftMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithLeftMargin' +type Builder_WithLeftMargin_Call struct { + *mock.Call +} + +// WithLeftMargin is a helper method to define mock.On call +// - left float64 +func (_e *Builder_Expecter) WithLeftMargin(left interface{}) *Builder_WithLeftMargin_Call { + return &Builder_WithLeftMargin_Call{Call: _e.mock.On("WithLeftMargin", left)} +} + +func (_c *Builder_WithLeftMargin_Call) Run(run func(left float64)) *Builder_WithLeftMargin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Builder_WithLeftMargin_Call) Return(_a0 config.Builder) *Builder_WithLeftMargin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithLeftMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithLeftMargin_Call { + _c.Call.Return(run) + return _c +} + +// WithMaxGridSize provides a mock function with given fields: maxGridSize +func (_m *Builder) WithMaxGridSize(maxGridSize int) config.Builder { + ret := _m.Called(maxGridSize) + + if len(ret) == 0 { + panic("no return value specified for WithMaxGridSize") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(int) config.Builder); ok { + r0 = rf(maxGridSize) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithMaxGridSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithMaxGridSize' +type Builder_WithMaxGridSize_Call struct { + *mock.Call +} + +// WithMaxGridSize is a helper method to define mock.On call +// - maxGridSize int +func (_e *Builder_Expecter) WithMaxGridSize(maxGridSize interface{}) *Builder_WithMaxGridSize_Call { + return &Builder_WithMaxGridSize_Call{Call: _e.mock.On("WithMaxGridSize", maxGridSize)} +} + +func (_c *Builder_WithMaxGridSize_Call) Run(run func(maxGridSize int)) *Builder_WithMaxGridSize_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Builder_WithMaxGridSize_Call) Return(_a0 config.Builder) *Builder_WithMaxGridSize_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithMaxGridSize_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithMaxGridSize_Call { + _c.Call.Return(run) + return _c +} + +// WithOrientation provides a mock function with given fields: _a0 +func (_m *Builder) WithOrientation(_a0 orientation.Type) config.Builder { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for WithOrientation") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(orientation.Type) config.Builder); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithOrientation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithOrientation' +type Builder_WithOrientation_Call struct { + *mock.Call +} + +// WithOrientation is a helper method to define mock.On call +// - _a0 orientation.Type +func (_e *Builder_Expecter) WithOrientation(_a0 interface{}) *Builder_WithOrientation_Call { + return &Builder_WithOrientation_Call{Call: _e.mock.On("WithOrientation", _a0)} +} + +func (_c *Builder_WithOrientation_Call) Run(run func(_a0 orientation.Type)) *Builder_WithOrientation_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(orientation.Type)) + }) + return _c +} + +func (_c *Builder_WithOrientation_Call) Return(_a0 config.Builder) *Builder_WithOrientation_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithOrientation_Call) RunAndReturn(run func(orientation.Type) config.Builder) *Builder_WithOrientation_Call { + _c.Call.Return(run) + return _c +} + +// WithPageNumber provides a mock function with given fields: pageNumber +func (_m *Builder) WithPageNumber(pageNumber ...props.PageNumber) config.Builder { + _va := make([]interface{}, len(pageNumber)) + for _i := range pageNumber { + _va[_i] = pageNumber[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for WithPageNumber") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(...props.PageNumber) config.Builder); ok { + r0 = rf(pageNumber...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithPageNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageNumber' +type Builder_WithPageNumber_Call struct { + *mock.Call +} + +// WithPageNumber is a helper method to define mock.On call +// - pageNumber ...props.PageNumber +func (_e *Builder_Expecter) WithPageNumber(pageNumber ...interface{}) *Builder_WithPageNumber_Call { + return &Builder_WithPageNumber_Call{Call: _e.mock.On("WithPageNumber", + append([]interface{}{}, pageNumber...)...)} +} + +func (_c *Builder_WithPageNumber_Call) Run(run func(pageNumber ...props.PageNumber)) *Builder_WithPageNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]props.PageNumber, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(props.PageNumber) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *Builder_WithPageNumber_Call) Return(_a0 config.Builder) *Builder_WithPageNumber_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithPageNumber_Call) RunAndReturn(run func(...props.PageNumber) config.Builder) *Builder_WithPageNumber_Call { + _c.Call.Return(run) + return _c +} + +// WithPageSize provides a mock function with given fields: size +func (_m *Builder) WithPageSize(size pagesize.Type) config.Builder { + ret := _m.Called(size) + + if len(ret) == 0 { + panic("no return value specified for WithPageSize") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(pagesize.Type) config.Builder); ok { + r0 = rf(size) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithPageSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageSize' +type Builder_WithPageSize_Call struct { + *mock.Call +} + +// WithPageSize is a helper method to define mock.On call +// - size pagesize.Type +func (_e *Builder_Expecter) WithPageSize(size interface{}) *Builder_WithPageSize_Call { + return &Builder_WithPageSize_Call{Call: _e.mock.On("WithPageSize", size)} +} + +func (_c *Builder_WithPageSize_Call) Run(run func(size pagesize.Type)) *Builder_WithPageSize_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(pagesize.Type)) + }) + return _c +} + +func (_c *Builder_WithPageSize_Call) Return(_a0 config.Builder) *Builder_WithPageSize_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithPageSize_Call) RunAndReturn(run func(pagesize.Type) config.Builder) *Builder_WithPageSize_Call { + _c.Call.Return(run) + return _c +} + +// WithProtection provides a mock function with given fields: protectionType, userPassword, ownerPassword +func (_m *Builder) WithProtection(protectionType protection.Type, userPassword string, ownerPassword string) config.Builder { + ret := _m.Called(protectionType, userPassword, ownerPassword) + + if len(ret) == 0 { + panic("no return value specified for WithProtection") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(protection.Type, string, string) config.Builder); ok { + r0 = rf(protectionType, userPassword, ownerPassword) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithProtection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithProtection' +type Builder_WithProtection_Call struct { + *mock.Call +} + +// WithProtection is a helper method to define mock.On call +// - protectionType protection.Type +// - userPassword string +// - ownerPassword string +func (_e *Builder_Expecter) WithProtection(protectionType interface{}, userPassword interface{}, ownerPassword interface{}) *Builder_WithProtection_Call { + return &Builder_WithProtection_Call{Call: _e.mock.On("WithProtection", protectionType, userPassword, ownerPassword)} +} + +func (_c *Builder_WithProtection_Call) Run(run func(protectionType protection.Type, userPassword string, ownerPassword string)) *Builder_WithProtection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(protection.Type), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *Builder_WithProtection_Call) Return(_a0 config.Builder) *Builder_WithProtection_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithProtection_Call) RunAndReturn(run func(protection.Type, string, string) config.Builder) *Builder_WithProtection_Call { + _c.Call.Return(run) + return _c +} + +// WithRightMargin provides a mock function with given fields: right +func (_m *Builder) WithRightMargin(right float64) config.Builder { + ret := _m.Called(right) + + if len(ret) == 0 { + panic("no return value specified for WithRightMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(right) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithRightMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithRightMargin' +type Builder_WithRightMargin_Call struct { + *mock.Call +} + +// WithRightMargin is a helper method to define mock.On call +// - right float64 +func (_e *Builder_Expecter) WithRightMargin(right interface{}) *Builder_WithRightMargin_Call { + return &Builder_WithRightMargin_Call{Call: _e.mock.On("WithRightMargin", right)} +} + +func (_c *Builder_WithRightMargin_Call) Run(run func(right float64)) *Builder_WithRightMargin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Builder_WithRightMargin_Call) Return(_a0 config.Builder) *Builder_WithRightMargin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithRightMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithRightMargin_Call { + _c.Call.Return(run) + return _c +} + +// WithSequentialLowMemoryMode provides a mock function with given fields: chunkWorkers +func (_m *Builder) WithSequentialLowMemoryMode(chunkWorkers int) config.Builder { + ret := _m.Called(chunkWorkers) + + if len(ret) == 0 { + panic("no return value specified for WithSequentialLowMemoryMode") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(int) config.Builder); ok { + r0 = rf(chunkWorkers) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithSequentialLowMemoryMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialLowMemoryMode' +type Builder_WithSequentialLowMemoryMode_Call struct { + *mock.Call +} + +// WithSequentialLowMemoryMode is a helper method to define mock.On call +// - chunkWorkers int +func (_e *Builder_Expecter) WithSequentialLowMemoryMode(chunkWorkers interface{}) *Builder_WithSequentialLowMemoryMode_Call { + return &Builder_WithSequentialLowMemoryMode_Call{Call: _e.mock.On("WithSequentialLowMemoryMode", chunkWorkers)} +} + +func (_c *Builder_WithSequentialLowMemoryMode_Call) Run(run func(chunkWorkers int)) *Builder_WithSequentialLowMemoryMode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Builder_WithSequentialLowMemoryMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialLowMemoryMode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithSequentialLowMemoryMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithSequentialLowMemoryMode_Call { + _c.Call.Return(run) + return _c +} + +// WithSequentialMode provides a mock function with given fields: +func (_m *Builder) WithSequentialMode() config.Builder { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for WithSequentialMode") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func() config.Builder); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithSequentialMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialMode' +type Builder_WithSequentialMode_Call struct { + *mock.Call +} + +// WithSequentialMode is a helper method to define mock.On call +func (_e *Builder_Expecter) WithSequentialMode() *Builder_WithSequentialMode_Call { + return &Builder_WithSequentialMode_Call{Call: _e.mock.On("WithSequentialMode")} +} + +func (_c *Builder_WithSequentialMode_Call) Run(run func()) *Builder_WithSequentialMode_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Builder_WithSequentialMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialMode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithSequentialMode_Call) RunAndReturn(run func() config.Builder) *Builder_WithSequentialMode_Call { + _c.Call.Return(run) + return _c +} + +// WithSubject provides a mock function with given fields: subject, isUTF8 +func (_m *Builder) WithSubject(subject string, isUTF8 bool) config.Builder { + ret := _m.Called(subject, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithSubject") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(subject, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithSubject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSubject' +type Builder_WithSubject_Call struct { + *mock.Call +} + +// WithSubject is a helper method to define mock.On call +// - subject string +// - isUTF8 bool +func (_e *Builder_Expecter) WithSubject(subject interface{}, isUTF8 interface{}) *Builder_WithSubject_Call { + return &Builder_WithSubject_Call{Call: _e.mock.On("WithSubject", subject, isUTF8)} +} + +func (_c *Builder_WithSubject_Call) Run(run func(subject string, isUTF8 bool)) *Builder_WithSubject_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithSubject_Call) Return(_a0 config.Builder) *Builder_WithSubject_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithSubject_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithSubject_Call { + _c.Call.Return(run) + return _c +} + +// WithTitle provides a mock function with given fields: title, isUTF8 +func (_m *Builder) WithTitle(title string, isUTF8 bool) config.Builder { + ret := _m.Called(title, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithTitle") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(title, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithTitle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTitle' +type Builder_WithTitle_Call struct { + *mock.Call +} + +// WithTitle is a helper method to define mock.On call +// - title string +// - isUTF8 bool +func (_e *Builder_Expecter) WithTitle(title interface{}, isUTF8 interface{}) *Builder_WithTitle_Call { + return &Builder_WithTitle_Call{Call: _e.mock.On("WithTitle", title, isUTF8)} +} + +func (_c *Builder_WithTitle_Call) Run(run func(title string, isUTF8 bool)) *Builder_WithTitle_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithTitle_Call) Return(_a0 config.Builder) *Builder_WithTitle_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithTitle_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithTitle_Call { + _c.Call.Return(run) + return _c +} + +// WithTopMargin provides a mock function with given fields: top +func (_m *Builder) WithTopMargin(top float64) config.Builder { + ret := _m.Called(top) + + if len(ret) == 0 { + panic("no return value specified for WithTopMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(top) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithTopMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTopMargin' +type Builder_WithTopMargin_Call struct { + *mock.Call +} + +// WithTopMargin is a helper method to define mock.On call +// - top float64 +func (_e *Builder_Expecter) WithTopMargin(top interface{}) *Builder_WithTopMargin_Call { + return &Builder_WithTopMargin_Call{Call: _e.mock.On("WithTopMargin", top)} } -func (_c *Builder_Build_Call) Run(run func(cfg *entity.Config, _a1 cache.Cache)) *Builder_Build_Call { +func (_c *Builder_WithTopMargin_Call) Run(run func(top float64)) *Builder_WithTopMargin_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*entity.Config), args[1].(cache.Cache)) + run(args[0].(float64)) }) return _c } -func (_c *Builder_Build_Call) Return(_a0 *gofpdf.Dependencies) *Builder_Build_Call { +func (_c *Builder_WithTopMargin_Call) Return(_a0 config.Builder) *Builder_WithTopMargin_Call { _c.Call.Return(_a0) return _c } -func (_c *Builder_Build_Call) RunAndReturn(run func(*entity.Config, cache.Cache) *gofpdf.Dependencies) *Builder_Build_Call { +func (_c *Builder_WithTopMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithTopMargin_Call { _c.Call.Return(run) return _c } diff --git a/mocks/ProcessorProvider.go b/mocks/ProcessorProvider.go index b1805f57..01223216 100644 --- a/mocks/ProcessorProvider.go +++ b/mocks/ProcessorProvider.go @@ -322,6 +322,69 @@ func (_c *ProcessorProvider_CreateQrCode_Call) RunAndReturn(run func(string, ... return _c } +// CreateSignature provides a mock function with given fields: value, props +func (_m *ProcessorProvider) CreateSignature(value string, props ...*propsmapper.Signature) processorprovider.PDFComponent { + _va := make([]interface{}, len(props)) + for _i := range props { + _va[_i] = props[_i] + } + var _ca []interface{} + _ca = append(_ca, value) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for CreateSignature") + } + + var r0 processorprovider.PDFComponent + if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Signature) processorprovider.PDFComponent); ok { + r0 = rf(value, props...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(processorprovider.PDFComponent) + } + } + + return r0 +} + +// ProcessorProvider_CreateSignature_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateSignature' +type ProcessorProvider_CreateSignature_Call struct { + *mock.Call +} + +// CreateSignature is a helper method to define mock.On call +// - value string +// - props ...*propsmapper.Signature +func (_e *ProcessorProvider_Expecter) CreateSignature(value interface{}, props ...interface{}) *ProcessorProvider_CreateSignature_Call { + return &ProcessorProvider_CreateSignature_Call{Call: _e.mock.On("CreateSignature", + append([]interface{}{value}, props...)...)} +} + +func (_c *ProcessorProvider_CreateSignature_Call) Run(run func(value string, props ...*propsmapper.Signature)) *ProcessorProvider_CreateSignature_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]*propsmapper.Signature, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(*propsmapper.Signature) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_CreateSignature_Call) Return(_a0 processorprovider.PDFComponent) *ProcessorProvider_CreateSignature_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorProvider_CreateSignature_Call) RunAndReturn(run func(string, ...*propsmapper.Signature) processorprovider.PDFComponent) *ProcessorProvider_CreateSignature_Call { + _c.Call.Return(run) + return _c +} + // NewProcessorProvider creates a new instance of ProcessorProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewProcessorProvider(t interface { diff --git a/mocks/Repository.go b/mocks/Repository.go index 3977c94e..9927b778 100644 --- a/mocks/Repository.go +++ b/mocks/Repository.go @@ -2,14 +2,7 @@ package mocks -import ( - fontstyle "github.com/johnfercher/maroto/v2/pkg/consts/fontstyle" - entity "github.com/johnfercher/maroto/v2/pkg/core/entity" - - mock "github.com/stretchr/testify/mock" - - repository "github.com/johnfercher/maroto/v2/pkg/repository" -) +import mock "github.com/stretchr/testify/mock" // Repository is an autogenerated mock type for the Repository type type Repository struct { @@ -24,159 +17,172 @@ func (_m *Repository) EXPECT() *Repository_Expecter { return &Repository_Expecter{mock: &_m.Mock} } -// AddUTF8Font provides a mock function with given fields: family, style, file -func (_m *Repository) AddUTF8Font(family string, style fontstyle.Type, file string) repository.Repository { - ret := _m.Called(family, style, file) +// GetDocument provides a mock function with given fields: documentName +func (_m *Repository) GetDocument(documentName string) (string, []byte, error) { + ret := _m.Called(documentName) if len(ret) == 0 { - panic("no return value specified for AddUTF8Font") + panic("no return value specified for GetDocument") } - var r0 repository.Repository - if rf, ok := ret.Get(0).(func(string, fontstyle.Type, string) repository.Repository); ok { - r0 = rf(family, style, file) + var r0 string + var r1 []byte + var r2 error + if rf, ok := ret.Get(0).(func(string) (string, []byte, error)); ok { + return rf(documentName) + } + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(documentName) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(repository.Repository) + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(string) []byte); ok { + r1 = rf(documentName) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).([]byte) } } - return r0 + if rf, ok := ret.Get(2).(func(string) error); ok { + r2 = rf(documentName) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 } -// Repository_AddUTF8Font_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddUTF8Font' -type Repository_AddUTF8Font_Call struct { +// Repository_GetDocument_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDocument' +type Repository_GetDocument_Call struct { *mock.Call } -// AddUTF8Font is a helper method to define mock.On call -// - family string -// - style fontstyle.Type -// - file string -func (_e *Repository_Expecter) AddUTF8Font(family interface{}, style interface{}, file interface{}) *Repository_AddUTF8Font_Call { - return &Repository_AddUTF8Font_Call{Call: _e.mock.On("AddUTF8Font", family, style, file)} +// GetDocument is a helper method to define mock.On call +// - documentName string +func (_e *Repository_Expecter) GetDocument(documentName interface{}) *Repository_GetDocument_Call { + return &Repository_GetDocument_Call{Call: _e.mock.On("GetDocument", documentName)} } -func (_c *Repository_AddUTF8Font_Call) Run(run func(family string, style fontstyle.Type, file string)) *Repository_AddUTF8Font_Call { +func (_c *Repository_GetDocument_Call) Run(run func(documentName string)) *Repository_GetDocument_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(fontstyle.Type), args[2].(string)) + run(args[0].(string)) }) return _c } -func (_c *Repository_AddUTF8Font_Call) Return(_a0 repository.Repository) *Repository_AddUTF8Font_Call { - _c.Call.Return(_a0) +func (_c *Repository_GetDocument_Call) Return(extension string, doc []byte, err error) *Repository_GetDocument_Call { + _c.Call.Return(extension, doc, err) return _c } -func (_c *Repository_AddUTF8Font_Call) RunAndReturn(run func(string, fontstyle.Type, string) repository.Repository) *Repository_AddUTF8Font_Call { +func (_c *Repository_GetDocument_Call) RunAndReturn(run func(string) (string, []byte, error)) *Repository_GetDocument_Call { _c.Call.Return(run) return _c } -// AddUTF8FontFromBytes provides a mock function with given fields: family, style, bytes -func (_m *Repository) AddUTF8FontFromBytes(family string, style fontstyle.Type, bytes []byte) repository.Repository { - ret := _m.Called(family, style, bytes) +// ReadTemplate provides a mock function with given fields: templateName +func (_m *Repository) ReadTemplate(templateName string) (map[string]interface{}, error) { + ret := _m.Called(templateName) if len(ret) == 0 { - panic("no return value specified for AddUTF8FontFromBytes") + panic("no return value specified for ReadTemplate") } - var r0 repository.Repository - if rf, ok := ret.Get(0).(func(string, fontstyle.Type, []byte) repository.Repository); ok { - r0 = rf(family, style, bytes) + var r0 map[string]interface{} + var r1 error + if rf, ok := ret.Get(0).(func(string) (map[string]interface{}, error)); ok { + return rf(templateName) + } + if rf, ok := ret.Get(0).(func(string) map[string]interface{}); ok { + r0 = rf(templateName) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(repository.Repository) + r0 = ret.Get(0).(map[string]interface{}) } } - return r0 + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(templateName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 } -// Repository_AddUTF8FontFromBytes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddUTF8FontFromBytes' -type Repository_AddUTF8FontFromBytes_Call struct { +// Repository_ReadTemplate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReadTemplate' +type Repository_ReadTemplate_Call struct { *mock.Call } -// AddUTF8FontFromBytes is a helper method to define mock.On call -// - family string -// - style fontstyle.Type -// - bytes []byte -func (_e *Repository_Expecter) AddUTF8FontFromBytes(family interface{}, style interface{}, bytes interface{}) *Repository_AddUTF8FontFromBytes_Call { - return &Repository_AddUTF8FontFromBytes_Call{Call: _e.mock.On("AddUTF8FontFromBytes", family, style, bytes)} +// ReadTemplate is a helper method to define mock.On call +// - templateName string +func (_e *Repository_Expecter) ReadTemplate(templateName interface{}) *Repository_ReadTemplate_Call { + return &Repository_ReadTemplate_Call{Call: _e.mock.On("ReadTemplate", templateName)} } -func (_c *Repository_AddUTF8FontFromBytes_Call) Run(run func(family string, style fontstyle.Type, bytes []byte)) *Repository_AddUTF8FontFromBytes_Call { +func (_c *Repository_ReadTemplate_Call) Run(run func(templateName string)) *Repository_ReadTemplate_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(fontstyle.Type), args[2].([]byte)) + run(args[0].(string)) }) return _c } -func (_c *Repository_AddUTF8FontFromBytes_Call) Return(_a0 repository.Repository) *Repository_AddUTF8FontFromBytes_Call { - _c.Call.Return(_a0) +func (_c *Repository_ReadTemplate_Call) Return(_a0 map[string]interface{}, _a1 error) *Repository_ReadTemplate_Call { + _c.Call.Return(_a0, _a1) return _c } -func (_c *Repository_AddUTF8FontFromBytes_Call) RunAndReturn(run func(string, fontstyle.Type, []byte) repository.Repository) *Repository_AddUTF8FontFromBytes_Call { +func (_c *Repository_ReadTemplate_Call) RunAndReturn(run func(string) (map[string]interface{}, error)) *Repository_ReadTemplate_Call { _c.Call.Return(run) return _c } -// Load provides a mock function with given fields: -func (_m *Repository) Load() ([]*entity.CustomFont, error) { - ret := _m.Called() +// RegisterTemplate provides a mock function with given fields: templateName, template +func (_m *Repository) RegisterTemplate(templateName string, template map[string]interface{}) error { + ret := _m.Called(templateName, template) if len(ret) == 0 { - panic("no return value specified for Load") + panic("no return value specified for RegisterTemplate") } - var r0 []*entity.CustomFont - var r1 error - if rf, ok := ret.Get(0).(func() ([]*entity.CustomFont, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() []*entity.CustomFont); ok { - r0 = rf() + var r0 error + if rf, ok := ret.Get(0).(func(string, map[string]interface{}) error); ok { + r0 = rf(templateName, template) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).([]*entity.CustomFont) - } + r0 = ret.Error(0) } - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 + return r0 } -// Repository_Load_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Load' -type Repository_Load_Call struct { +// Repository_RegisterTemplate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterTemplate' +type Repository_RegisterTemplate_Call struct { *mock.Call } -// Load is a helper method to define mock.On call -func (_e *Repository_Expecter) Load() *Repository_Load_Call { - return &Repository_Load_Call{Call: _e.mock.On("Load")} +// RegisterTemplate is a helper method to define mock.On call +// - templateName string +// - template map[string]interface{} +func (_e *Repository_Expecter) RegisterTemplate(templateName interface{}, template interface{}) *Repository_RegisterTemplate_Call { + return &Repository_RegisterTemplate_Call{Call: _e.mock.On("RegisterTemplate", templateName, template)} } -func (_c *Repository_Load_Call) Run(run func()) *Repository_Load_Call { +func (_c *Repository_RegisterTemplate_Call) Run(run func(templateName string, template map[string]interface{})) *Repository_RegisterTemplate_Call { _c.Call.Run(func(args mock.Arguments) { - run() + run(args[0].(string), args[1].(map[string]interface{})) }) return _c } -func (_c *Repository_Load_Call) Return(_a0 []*entity.CustomFont, _a1 error) *Repository_Load_Call { - _c.Call.Return(_a0, _a1) +func (_c *Repository_RegisterTemplate_Call) Return(_a0 error) *Repository_RegisterTemplate_Call { + _c.Call.Return(_a0) return _c } -func (_c *Repository_Load_Call) RunAndReturn(run func() ([]*entity.CustomFont, error)) *Repository_Load_Call { +func (_c *Repository_RegisterTemplate_Call) RunAndReturn(run func(string, map[string]interface{}) error) *Repository_RegisterTemplate_Call { _c.Call.Return(run) return _c } diff --git a/pkg/processor/mappers/components/signaturemapper/signature_test.go b/pkg/processor/mappers/components/signaturemapper/signature_test.go index 7938a783..98ee4708 100644 --- a/pkg/processor/mappers/components/signaturemapper/signature_test.go +++ b/pkg/processor/mappers/components/signaturemapper/signature_test.go @@ -3,6 +3,7 @@ package signaturemapper_test import ( "testing" + "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/signaturemapper" "github.com/stretchr/testify/assert" ) @@ -97,3 +98,54 @@ func TestNewSignature(t *testing.T) { assert.Equal(t, signature.Value, "value") }) } + +func TestGenerate(t *testing.T) { + t.Run("if source key is not found, should return an error", func(t *testing.T) { + content := map[string]interface{}{} + provider := mocks.NewProcessorProvider(t) + + signature := signaturemapper.Signature{SourceKey: "code"} + component, err := signature.Generate(content, provider) + + assert.Nil(t, component) + assert.NotNil(t, err) + }) + t.Run("if source key content is not valid, should return an error", func(t *testing.T) { + content := map[string]interface{}{ + "value": 1, + } + provider := mocks.NewProcessorProvider(t) + + signature := signaturemapper.Signature{SourceKey: "value"} + component, err := signature.Generate(content, provider) + + assert.Nil(t, component) + assert.NotNil(t, err) + }) + t.Run("If the signature has no props, the props will not be sent", func(t *testing.T) { + content := map[string]interface{}{ + "value": "signature", + } + + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateSignature("signature").Return(nil) + + signature := signaturemapper.Signature{SourceKey: "value"} + _, err := signature.Generate(content, provider) + + assert.Nil(t, err) + provider.AssertNumberOfCalls(t, "CreateSignature", 1) + }) + t.Run("when valid code is sent, should generate signature", func(t *testing.T) { + content := map[string]interface{}{} + + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateSignature("signature").Return(nil) + + signature := signaturemapper.Signature{Value: "signature"} + _, err := signature.Generate(content, provider) + + assert.Nil(t, err) + provider.AssertNumberOfCalls(t, "CreateSignature", 1) + }) +} diff --git a/pkg/processor/processorprovider/Maroto_test.go b/pkg/processor/processorprovider/Maroto_test.go index 366ed299..a3033abc 100644 --- a/pkg/processor/processorprovider/Maroto_test.go +++ b/pkg/processor/processorprovider/Maroto_test.go @@ -72,3 +72,17 @@ func TestCreateLine(t *testing.T) { test.New(t).Assert(barcode.GetStructure()).Equals("processor/provider/line.json") }) } + +func TestCreateSignature(t *testing.T) { + t.Run("when CreateSignature is called, should generate a signature", func(t *testing.T) { + m := processorprovider.NewMaroto() + barcode := m.CreateSignature("signature", + &propsmapper.Signature{ + FontFamily: "Arial", FontStyle: "bold", FontSize: 10.0, FontColor: &propsmapper.Color{Red: 10, Green: 10, Blue: 10}, + LineColor: &propsmapper.Color{Red: 10, Green: 10, Blue: 10}, LineStyle: "solid", LineThickness: 10.0, SafePadding: 10.0, + }, + ) + + test.New(t).Assert(barcode.GetStructure()).Equals("processor/provider/signature.json") + }) +} diff --git a/test/maroto/processor/provider/signature.json b/test/maroto/processor/provider/signature.json new file mode 100644 index 00000000..db4667fa --- /dev/null +++ b/test/maroto/processor/provider/signature.json @@ -0,0 +1,13 @@ +{ + "value": "signature", + "type": "signature", + "details": { + "prop_font_color": "RGB(10, 10, 10)", + "prop_font_family": "Arial", + "prop_font_size": 10, + "prop_font_style": "bold", + "prop_line_color": "RGB(10, 10, 10)", + "prop_line_style": "solid", + "prop_line_thickness": 10 + } +} \ No newline at end of file From 670093692caafb218735f8643d224dfbef6496af Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sat, 2 Nov 2024 14:43:00 -0300 Subject: [PATCH 057/116] feat: create signature component --- .../components/signaturemapper/signature.go | 30 +++++++++++++++++-- pkg/processor/processorprovider/Maroto.go | 16 ++++++++++ pkg/processor/processorprovider/provider.go | 1 + 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/pkg/processor/mappers/components/signaturemapper/signature.go b/pkg/processor/mappers/components/signaturemapper/signature.go index 0025f408..6e7864d0 100644 --- a/pkg/processor/mappers/components/signaturemapper/signature.go +++ b/pkg/processor/mappers/components/signaturemapper/signature.go @@ -4,8 +4,8 @@ package signaturemapper import ( "fmt" - "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Signature struct { @@ -93,6 +93,30 @@ func (s *Signature) validateFields() error { return nil } -func (s *Signature) Generate(content map[string]interface{}) (components.PdfComponent, error) { - return nil, nil +func (s *Signature) getSignature(content map[string]interface{}) (string, error) { + if s.Value != "" { + return s.Value, nil + } + signatureFound, ok := content[s.SourceKey] + if !ok { + return "", fmt.Errorf("signature requires a source key named %s, but it was not found", s.SourceKey) + } + signatureValid, ok := signatureFound.(string) + if !ok { + return "", fmt.Errorf("unable to generate signature, invalid value. source key %s", s.SourceKey) + } + return signatureValid, nil +} + +func (s *Signature) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { + signature, err := s.getSignature(content) + if err != nil { + return nil, err + } + s.Value = signature + + if s.Props != nil { + return provider.CreateSignature(s.Value, s.Props), nil + } + return provider.CreateSignature(s.Value), nil } diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index 93dd61d6..9f86564d 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -4,8 +4,10 @@ import ( "github.com/johnfercher/maroto/v2/pkg/components/code" "github.com/johnfercher/maroto/v2/pkg/components/image" "github.com/johnfercher/maroto/v2/pkg/components/line" + "github.com/johnfercher/maroto/v2/pkg/components/signature" "github.com/johnfercher/maroto/v2/pkg/consts/barcode" "github.com/johnfercher/maroto/v2/pkg/consts/extension" + "github.com/johnfercher/maroto/v2/pkg/consts/fontstyle" "github.com/johnfercher/maroto/v2/pkg/consts/linestyle" "github.com/johnfercher/maroto/v2/pkg/consts/orientation" "github.com/johnfercher/maroto/v2/pkg/core" @@ -22,6 +24,20 @@ func NewMaroto() *Maroto { return nil } +func (m *Maroto) CreateSignature(value string, signaturesProps ...*propsmapper.Signature) PDFComponent { + sProps := propsmapper.Signature{} + if len(signaturesProps) > 0 { + sProps = *signaturesProps[0] + } + + return signature.New(value, props.Signature{ + FontFamily: sProps.FontFamily, FontStyle: fontstyle.Type(sProps.FontStyle), FontSize: sProps.FontSize, + FontColor: (*props.Color)(sProps.FontColor), LineColor: (*props.Color)(sProps.LineColor), LineStyle: sProps.LineStyle, + LineThickness: sProps.LineThickness, SafePadding: sProps.SafePadding, + }) + +} + func (m *Maroto) CreateLine(lineProps ...*propsmapper.Line) PDFComponent { lProps := propsmapper.Line{} if len(lineProps) > 0 { diff --git a/pkg/processor/processorprovider/provider.go b/pkg/processor/processorprovider/provider.go index 37800daf..e7b54e7b 100644 --- a/pkg/processor/processorprovider/provider.go +++ b/pkg/processor/processorprovider/provider.go @@ -14,6 +14,7 @@ type PDFComponent interface { // ProcessorProvider provides an interface with all the methods that // Maroto provides for pdf builder type ProcessorProvider interface { + CreateSignature(value string, props ...*propsmapper.Signature) PDFComponent CreateBarCode(value string, props ...*propsmapper.Barcode) PDFComponent CreateMatrixCode(value string, props ...*propsmapper.Rect) PDFComponent CreateQrCode(value string, props ...*propsmapper.Rect) PDFComponent From b6e88d88f27c8bd84e42eab631119fc81f79d3a8 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sat, 2 Nov 2024 15:28:04 -0300 Subject: [PATCH 058/116] test: validate creation of text component --- mocks/Builder.go | 1263 +---------------- mocks/ProcessorProvider.go | 63 + mocks/Repository.go | 174 ++- .../components/textmapper/text_test.go | 52 + .../processorprovider/Maroto_test.go | 14 + test/maroto/processor/provider/text.json | 17 + 6 files changed, 247 insertions(+), 1336 deletions(-) create mode 100644 test/maroto/processor/provider/text.json diff --git a/mocks/Builder.go b/mocks/Builder.go index 2cbe240a..883f7968 100644 --- a/mocks/Builder.go +++ b/mocks/Builder.go @@ -3,22 +3,12 @@ package mocks import ( - config "github.com/johnfercher/maroto/v2/pkg/config" + cache "github.com/johnfercher/maroto/v2/internal/cache" entity "github.com/johnfercher/maroto/v2/pkg/core/entity" - extension "github.com/johnfercher/maroto/v2/pkg/consts/extension" + gofpdf "github.com/johnfercher/maroto/v2/internal/providers/gofpdf" mock "github.com/stretchr/testify/mock" - - orientation "github.com/johnfercher/maroto/v2/pkg/consts/orientation" - - pagesize "github.com/johnfercher/maroto/v2/pkg/consts/pagesize" - - props "github.com/johnfercher/maroto/v2/pkg/props" - - protection "github.com/johnfercher/maroto/v2/pkg/consts/protection" - - time "time" ) // Builder is an autogenerated mock type for the Builder type @@ -34,20 +24,20 @@ func (_m *Builder) EXPECT() *Builder_Expecter { return &Builder_Expecter{mock: &_m.Mock} } -// Build provides a mock function with given fields: -func (_m *Builder) Build() *entity.Config { - ret := _m.Called() +// Build provides a mock function with given fields: cfg, _a1 +func (_m *Builder) Build(cfg *entity.Config, _a1 cache.Cache) *gofpdf.Dependencies { + ret := _m.Called(cfg, _a1) if len(ret) == 0 { panic("no return value specified for Build") } - var r0 *entity.Config - if rf, ok := ret.Get(0).(func() *entity.Config); ok { - r0 = rf() + var r0 *gofpdf.Dependencies + if rf, ok := ret.Get(0).(func(*entity.Config, cache.Cache) *gofpdf.Dependencies); ok { + r0 = rf(cfg, _a1) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*entity.Config) + r0 = ret.Get(0).(*gofpdf.Dependencies) } } @@ -60,1244 +50,25 @@ type Builder_Build_Call struct { } // Build is a helper method to define mock.On call -func (_e *Builder_Expecter) Build() *Builder_Build_Call { - return &Builder_Build_Call{Call: _e.mock.On("Build")} -} - -func (_c *Builder_Build_Call) Run(run func()) *Builder_Build_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *Builder_Build_Call) Return(_a0 *entity.Config) *Builder_Build_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_Build_Call) RunAndReturn(run func() *entity.Config) *Builder_Build_Call { - _c.Call.Return(run) - return _c -} - -// WithAuthor provides a mock function with given fields: author, isUTF8 -func (_m *Builder) WithAuthor(author string, isUTF8 bool) config.Builder { - ret := _m.Called(author, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithAuthor") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(author, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithAuthor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithAuthor' -type Builder_WithAuthor_Call struct { - *mock.Call -} - -// WithAuthor is a helper method to define mock.On call -// - author string -// - isUTF8 bool -func (_e *Builder_Expecter) WithAuthor(author interface{}, isUTF8 interface{}) *Builder_WithAuthor_Call { - return &Builder_WithAuthor_Call{Call: _e.mock.On("WithAuthor", author, isUTF8)} -} - -func (_c *Builder_WithAuthor_Call) Run(run func(author string, isUTF8 bool)) *Builder_WithAuthor_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithAuthor_Call) Return(_a0 config.Builder) *Builder_WithAuthor_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithAuthor_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithAuthor_Call { - _c.Call.Return(run) - return _c -} - -// WithBackgroundImage provides a mock function with given fields: _a0, _a1 -func (_m *Builder) WithBackgroundImage(_a0 []byte, _a1 extension.Type) config.Builder { - ret := _m.Called(_a0, _a1) - - if len(ret) == 0 { - panic("no return value specified for WithBackgroundImage") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func([]byte, extension.Type) config.Builder); ok { - r0 = rf(_a0, _a1) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithBackgroundImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBackgroundImage' -type Builder_WithBackgroundImage_Call struct { - *mock.Call -} - -// WithBackgroundImage is a helper method to define mock.On call -// - _a0 []byte -// - _a1 extension.Type -func (_e *Builder_Expecter) WithBackgroundImage(_a0 interface{}, _a1 interface{}) *Builder_WithBackgroundImage_Call { - return &Builder_WithBackgroundImage_Call{Call: _e.mock.On("WithBackgroundImage", _a0, _a1)} -} - -func (_c *Builder_WithBackgroundImage_Call) Run(run func(_a0 []byte, _a1 extension.Type)) *Builder_WithBackgroundImage_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].([]byte), args[1].(extension.Type)) - }) - return _c -} - -func (_c *Builder_WithBackgroundImage_Call) Return(_a0 config.Builder) *Builder_WithBackgroundImage_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithBackgroundImage_Call) RunAndReturn(run func([]byte, extension.Type) config.Builder) *Builder_WithBackgroundImage_Call { - _c.Call.Return(run) - return _c -} - -// WithBottomMargin provides a mock function with given fields: bottom -func (_m *Builder) WithBottomMargin(bottom float64) config.Builder { - ret := _m.Called(bottom) - - if len(ret) == 0 { - panic("no return value specified for WithBottomMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(bottom) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithBottomMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBottomMargin' -type Builder_WithBottomMargin_Call struct { - *mock.Call -} - -// WithBottomMargin is a helper method to define mock.On call -// - bottom float64 -func (_e *Builder_Expecter) WithBottomMargin(bottom interface{}) *Builder_WithBottomMargin_Call { - return &Builder_WithBottomMargin_Call{Call: _e.mock.On("WithBottomMargin", bottom)} -} - -func (_c *Builder_WithBottomMargin_Call) Run(run func(bottom float64)) *Builder_WithBottomMargin_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) - }) - return _c -} - -func (_c *Builder_WithBottomMargin_Call) Return(_a0 config.Builder) *Builder_WithBottomMargin_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithBottomMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithBottomMargin_Call { - _c.Call.Return(run) - return _c -} - -// WithCompression provides a mock function with given fields: compression -func (_m *Builder) WithCompression(compression bool) config.Builder { - ret := _m.Called(compression) - - if len(ret) == 0 { - panic("no return value specified for WithCompression") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { - r0 = rf(compression) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCompression_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCompression' -type Builder_WithCompression_Call struct { - *mock.Call -} - -// WithCompression is a helper method to define mock.On call -// - compression bool -func (_e *Builder_Expecter) WithCompression(compression interface{}) *Builder_WithCompression_Call { - return &Builder_WithCompression_Call{Call: _e.mock.On("WithCompression", compression)} -} - -func (_c *Builder_WithCompression_Call) Run(run func(compression bool)) *Builder_WithCompression_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(bool)) - }) - return _c -} - -func (_c *Builder_WithCompression_Call) Return(_a0 config.Builder) *Builder_WithCompression_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCompression_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithCompression_Call { - _c.Call.Return(run) - return _c -} - -// WithConcurrentMode provides a mock function with given fields: chunkWorkers -func (_m *Builder) WithConcurrentMode(chunkWorkers int) config.Builder { - ret := _m.Called(chunkWorkers) - - if len(ret) == 0 { - panic("no return value specified for WithConcurrentMode") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(int) config.Builder); ok { - r0 = rf(chunkWorkers) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithConcurrentMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithConcurrentMode' -type Builder_WithConcurrentMode_Call struct { - *mock.Call -} - -// WithConcurrentMode is a helper method to define mock.On call -// - chunkWorkers int -func (_e *Builder_Expecter) WithConcurrentMode(chunkWorkers interface{}) *Builder_WithConcurrentMode_Call { - return &Builder_WithConcurrentMode_Call{Call: _e.mock.On("WithConcurrentMode", chunkWorkers)} -} - -func (_c *Builder_WithConcurrentMode_Call) Run(run func(chunkWorkers int)) *Builder_WithConcurrentMode_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(int)) - }) - return _c -} - -func (_c *Builder_WithConcurrentMode_Call) Return(_a0 config.Builder) *Builder_WithConcurrentMode_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithConcurrentMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithConcurrentMode_Call { - _c.Call.Return(run) - return _c -} - -// WithCreationDate provides a mock function with given fields: _a0 -func (_m *Builder) WithCreationDate(_a0 time.Time) config.Builder { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for WithCreationDate") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(time.Time) config.Builder); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCreationDate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreationDate' -type Builder_WithCreationDate_Call struct { - *mock.Call -} - -// WithCreationDate is a helper method to define mock.On call -// - _a0 time.Time -func (_e *Builder_Expecter) WithCreationDate(_a0 interface{}) *Builder_WithCreationDate_Call { - return &Builder_WithCreationDate_Call{Call: _e.mock.On("WithCreationDate", _a0)} -} - -func (_c *Builder_WithCreationDate_Call) Run(run func(_a0 time.Time)) *Builder_WithCreationDate_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(time.Time)) - }) - return _c -} - -func (_c *Builder_WithCreationDate_Call) Return(_a0 config.Builder) *Builder_WithCreationDate_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCreationDate_Call) RunAndReturn(run func(time.Time) config.Builder) *Builder_WithCreationDate_Call { - _c.Call.Return(run) - return _c -} - -// WithCreator provides a mock function with given fields: creator, isUTF8 -func (_m *Builder) WithCreator(creator string, isUTF8 bool) config.Builder { - ret := _m.Called(creator, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithCreator") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(creator, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCreator_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreator' -type Builder_WithCreator_Call struct { - *mock.Call -} - -// WithCreator is a helper method to define mock.On call -// - creator string -// - isUTF8 bool -func (_e *Builder_Expecter) WithCreator(creator interface{}, isUTF8 interface{}) *Builder_WithCreator_Call { - return &Builder_WithCreator_Call{Call: _e.mock.On("WithCreator", creator, isUTF8)} -} - -func (_c *Builder_WithCreator_Call) Run(run func(creator string, isUTF8 bool)) *Builder_WithCreator_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithCreator_Call) Return(_a0 config.Builder) *Builder_WithCreator_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCreator_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithCreator_Call { - _c.Call.Return(run) - return _c -} - -// WithCustomFonts provides a mock function with given fields: _a0 -func (_m *Builder) WithCustomFonts(_a0 []*entity.CustomFont) config.Builder { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for WithCustomFonts") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func([]*entity.CustomFont) config.Builder); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithCustomFonts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCustomFonts' -type Builder_WithCustomFonts_Call struct { - *mock.Call -} - -// WithCustomFonts is a helper method to define mock.On call -// - _a0 []*entity.CustomFont -func (_e *Builder_Expecter) WithCustomFonts(_a0 interface{}) *Builder_WithCustomFonts_Call { - return &Builder_WithCustomFonts_Call{Call: _e.mock.On("WithCustomFonts", _a0)} -} - -func (_c *Builder_WithCustomFonts_Call) Run(run func(_a0 []*entity.CustomFont)) *Builder_WithCustomFonts_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].([]*entity.CustomFont)) - }) - return _c -} - -func (_c *Builder_WithCustomFonts_Call) Return(_a0 config.Builder) *Builder_WithCustomFonts_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithCustomFonts_Call) RunAndReturn(run func([]*entity.CustomFont) config.Builder) *Builder_WithCustomFonts_Call { - _c.Call.Return(run) - return _c -} - -// WithDebug provides a mock function with given fields: on -func (_m *Builder) WithDebug(on bool) config.Builder { - ret := _m.Called(on) - - if len(ret) == 0 { - panic("no return value specified for WithDebug") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { - r0 = rf(on) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDebug_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDebug' -type Builder_WithDebug_Call struct { - *mock.Call -} - -// WithDebug is a helper method to define mock.On call -// - on bool -func (_e *Builder_Expecter) WithDebug(on interface{}) *Builder_WithDebug_Call { - return &Builder_WithDebug_Call{Call: _e.mock.On("WithDebug", on)} -} - -func (_c *Builder_WithDebug_Call) Run(run func(on bool)) *Builder_WithDebug_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(bool)) - }) - return _c -} - -func (_c *Builder_WithDebug_Call) Return(_a0 config.Builder) *Builder_WithDebug_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDebug_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDebug_Call { - _c.Call.Return(run) - return _c -} - -// WithDefaultFont provides a mock function with given fields: font -func (_m *Builder) WithDefaultFont(font *props.Font) config.Builder { - ret := _m.Called(font) - - if len(ret) == 0 { - panic("no return value specified for WithDefaultFont") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(*props.Font) config.Builder); ok { - r0 = rf(font) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDefaultFont_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDefaultFont' -type Builder_WithDefaultFont_Call struct { - *mock.Call -} - -// WithDefaultFont is a helper method to define mock.On call -// - font *props.Font -func (_e *Builder_Expecter) WithDefaultFont(font interface{}) *Builder_WithDefaultFont_Call { - return &Builder_WithDefaultFont_Call{Call: _e.mock.On("WithDefaultFont", font)} -} - -func (_c *Builder_WithDefaultFont_Call) Run(run func(font *props.Font)) *Builder_WithDefaultFont_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*props.Font)) - }) - return _c -} - -func (_c *Builder_WithDefaultFont_Call) Return(_a0 config.Builder) *Builder_WithDefaultFont_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDefaultFont_Call) RunAndReturn(run func(*props.Font) config.Builder) *Builder_WithDefaultFont_Call { - _c.Call.Return(run) - return _c -} - -// WithDimensions provides a mock function with given fields: width, height -func (_m *Builder) WithDimensions(width float64, height float64) config.Builder { - ret := _m.Called(width, height) - - if len(ret) == 0 { - panic("no return value specified for WithDimensions") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64, float64) config.Builder); ok { - r0 = rf(width, height) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDimensions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDimensions' -type Builder_WithDimensions_Call struct { - *mock.Call -} - -// WithDimensions is a helper method to define mock.On call -// - width float64 -// - height float64 -func (_e *Builder_Expecter) WithDimensions(width interface{}, height interface{}) *Builder_WithDimensions_Call { - return &Builder_WithDimensions_Call{Call: _e.mock.On("WithDimensions", width, height)} -} - -func (_c *Builder_WithDimensions_Call) Run(run func(width float64, height float64)) *Builder_WithDimensions_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64), args[1].(float64)) - }) - return _c -} - -func (_c *Builder_WithDimensions_Call) Return(_a0 config.Builder) *Builder_WithDimensions_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDimensions_Call) RunAndReturn(run func(float64, float64) config.Builder) *Builder_WithDimensions_Call { - _c.Call.Return(run) - return _c -} - -// WithDisableAutoPageBreak provides a mock function with given fields: disabled -func (_m *Builder) WithDisableAutoPageBreak(disabled bool) config.Builder { - ret := _m.Called(disabled) - - if len(ret) == 0 { - panic("no return value specified for WithDisableAutoPageBreak") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { - r0 = rf(disabled) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithDisableAutoPageBreak_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDisableAutoPageBreak' -type Builder_WithDisableAutoPageBreak_Call struct { - *mock.Call -} - -// WithDisableAutoPageBreak is a helper method to define mock.On call -// - disabled bool -func (_e *Builder_Expecter) WithDisableAutoPageBreak(disabled interface{}) *Builder_WithDisableAutoPageBreak_Call { - return &Builder_WithDisableAutoPageBreak_Call{Call: _e.mock.On("WithDisableAutoPageBreak", disabled)} -} - -func (_c *Builder_WithDisableAutoPageBreak_Call) Run(run func(disabled bool)) *Builder_WithDisableAutoPageBreak_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(bool)) - }) - return _c -} - -func (_c *Builder_WithDisableAutoPageBreak_Call) Return(_a0 config.Builder) *Builder_WithDisableAutoPageBreak_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithDisableAutoPageBreak_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDisableAutoPageBreak_Call { - _c.Call.Return(run) - return _c -} - -// WithKeywords provides a mock function with given fields: keywordsStr, isUTF8 -func (_m *Builder) WithKeywords(keywordsStr string, isUTF8 bool) config.Builder { - ret := _m.Called(keywordsStr, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithKeywords") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(keywordsStr, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithKeywords_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithKeywords' -type Builder_WithKeywords_Call struct { - *mock.Call -} - -// WithKeywords is a helper method to define mock.On call -// - keywordsStr string -// - isUTF8 bool -func (_e *Builder_Expecter) WithKeywords(keywordsStr interface{}, isUTF8 interface{}) *Builder_WithKeywords_Call { - return &Builder_WithKeywords_Call{Call: _e.mock.On("WithKeywords", keywordsStr, isUTF8)} -} - -func (_c *Builder_WithKeywords_Call) Run(run func(keywordsStr string, isUTF8 bool)) *Builder_WithKeywords_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithKeywords_Call) Return(_a0 config.Builder) *Builder_WithKeywords_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithKeywords_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithKeywords_Call { - _c.Call.Return(run) - return _c -} - -// WithLeftMargin provides a mock function with given fields: left -func (_m *Builder) WithLeftMargin(left float64) config.Builder { - ret := _m.Called(left) - - if len(ret) == 0 { - panic("no return value specified for WithLeftMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(left) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithLeftMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithLeftMargin' -type Builder_WithLeftMargin_Call struct { - *mock.Call -} - -// WithLeftMargin is a helper method to define mock.On call -// - left float64 -func (_e *Builder_Expecter) WithLeftMargin(left interface{}) *Builder_WithLeftMargin_Call { - return &Builder_WithLeftMargin_Call{Call: _e.mock.On("WithLeftMargin", left)} -} - -func (_c *Builder_WithLeftMargin_Call) Run(run func(left float64)) *Builder_WithLeftMargin_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) - }) - return _c -} - -func (_c *Builder_WithLeftMargin_Call) Return(_a0 config.Builder) *Builder_WithLeftMargin_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithLeftMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithLeftMargin_Call { - _c.Call.Return(run) - return _c -} - -// WithMaxGridSize provides a mock function with given fields: maxGridSize -func (_m *Builder) WithMaxGridSize(maxGridSize int) config.Builder { - ret := _m.Called(maxGridSize) - - if len(ret) == 0 { - panic("no return value specified for WithMaxGridSize") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(int) config.Builder); ok { - r0 = rf(maxGridSize) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithMaxGridSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithMaxGridSize' -type Builder_WithMaxGridSize_Call struct { - *mock.Call -} - -// WithMaxGridSize is a helper method to define mock.On call -// - maxGridSize int -func (_e *Builder_Expecter) WithMaxGridSize(maxGridSize interface{}) *Builder_WithMaxGridSize_Call { - return &Builder_WithMaxGridSize_Call{Call: _e.mock.On("WithMaxGridSize", maxGridSize)} -} - -func (_c *Builder_WithMaxGridSize_Call) Run(run func(maxGridSize int)) *Builder_WithMaxGridSize_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(int)) - }) - return _c -} - -func (_c *Builder_WithMaxGridSize_Call) Return(_a0 config.Builder) *Builder_WithMaxGridSize_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithMaxGridSize_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithMaxGridSize_Call { - _c.Call.Return(run) - return _c -} - -// WithOrientation provides a mock function with given fields: _a0 -func (_m *Builder) WithOrientation(_a0 orientation.Type) config.Builder { - ret := _m.Called(_a0) - - if len(ret) == 0 { - panic("no return value specified for WithOrientation") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(orientation.Type) config.Builder); ok { - r0 = rf(_a0) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithOrientation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithOrientation' -type Builder_WithOrientation_Call struct { - *mock.Call -} - -// WithOrientation is a helper method to define mock.On call -// - _a0 orientation.Type -func (_e *Builder_Expecter) WithOrientation(_a0 interface{}) *Builder_WithOrientation_Call { - return &Builder_WithOrientation_Call{Call: _e.mock.On("WithOrientation", _a0)} -} - -func (_c *Builder_WithOrientation_Call) Run(run func(_a0 orientation.Type)) *Builder_WithOrientation_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(orientation.Type)) - }) - return _c -} - -func (_c *Builder_WithOrientation_Call) Return(_a0 config.Builder) *Builder_WithOrientation_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithOrientation_Call) RunAndReturn(run func(orientation.Type) config.Builder) *Builder_WithOrientation_Call { - _c.Call.Return(run) - return _c -} - -// WithPageNumber provides a mock function with given fields: pageNumber -func (_m *Builder) WithPageNumber(pageNumber ...props.PageNumber) config.Builder { - _va := make([]interface{}, len(pageNumber)) - for _i := range pageNumber { - _va[_i] = pageNumber[_i] - } - var _ca []interface{} - _ca = append(_ca, _va...) - ret := _m.Called(_ca...) - - if len(ret) == 0 { - panic("no return value specified for WithPageNumber") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(...props.PageNumber) config.Builder); ok { - r0 = rf(pageNumber...) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithPageNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageNumber' -type Builder_WithPageNumber_Call struct { - *mock.Call -} - -// WithPageNumber is a helper method to define mock.On call -// - pageNumber ...props.PageNumber -func (_e *Builder_Expecter) WithPageNumber(pageNumber ...interface{}) *Builder_WithPageNumber_Call { - return &Builder_WithPageNumber_Call{Call: _e.mock.On("WithPageNumber", - append([]interface{}{}, pageNumber...)...)} -} - -func (_c *Builder_WithPageNumber_Call) Run(run func(pageNumber ...props.PageNumber)) *Builder_WithPageNumber_Call { - _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]props.PageNumber, len(args)-0) - for i, a := range args[0:] { - if a != nil { - variadicArgs[i] = a.(props.PageNumber) - } - } - run(variadicArgs...) - }) - return _c -} - -func (_c *Builder_WithPageNumber_Call) Return(_a0 config.Builder) *Builder_WithPageNumber_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithPageNumber_Call) RunAndReturn(run func(...props.PageNumber) config.Builder) *Builder_WithPageNumber_Call { - _c.Call.Return(run) - return _c -} - -// WithPageSize provides a mock function with given fields: size -func (_m *Builder) WithPageSize(size pagesize.Type) config.Builder { - ret := _m.Called(size) - - if len(ret) == 0 { - panic("no return value specified for WithPageSize") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(pagesize.Type) config.Builder); ok { - r0 = rf(size) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithPageSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageSize' -type Builder_WithPageSize_Call struct { - *mock.Call -} - -// WithPageSize is a helper method to define mock.On call -// - size pagesize.Type -func (_e *Builder_Expecter) WithPageSize(size interface{}) *Builder_WithPageSize_Call { - return &Builder_WithPageSize_Call{Call: _e.mock.On("WithPageSize", size)} -} - -func (_c *Builder_WithPageSize_Call) Run(run func(size pagesize.Type)) *Builder_WithPageSize_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(pagesize.Type)) - }) - return _c -} - -func (_c *Builder_WithPageSize_Call) Return(_a0 config.Builder) *Builder_WithPageSize_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithPageSize_Call) RunAndReturn(run func(pagesize.Type) config.Builder) *Builder_WithPageSize_Call { - _c.Call.Return(run) - return _c -} - -// WithProtection provides a mock function with given fields: protectionType, userPassword, ownerPassword -func (_m *Builder) WithProtection(protectionType protection.Type, userPassword string, ownerPassword string) config.Builder { - ret := _m.Called(protectionType, userPassword, ownerPassword) - - if len(ret) == 0 { - panic("no return value specified for WithProtection") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(protection.Type, string, string) config.Builder); ok { - r0 = rf(protectionType, userPassword, ownerPassword) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithProtection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithProtection' -type Builder_WithProtection_Call struct { - *mock.Call -} - -// WithProtection is a helper method to define mock.On call -// - protectionType protection.Type -// - userPassword string -// - ownerPassword string -func (_e *Builder_Expecter) WithProtection(protectionType interface{}, userPassword interface{}, ownerPassword interface{}) *Builder_WithProtection_Call { - return &Builder_WithProtection_Call{Call: _e.mock.On("WithProtection", protectionType, userPassword, ownerPassword)} -} - -func (_c *Builder_WithProtection_Call) Run(run func(protectionType protection.Type, userPassword string, ownerPassword string)) *Builder_WithProtection_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(protection.Type), args[1].(string), args[2].(string)) - }) - return _c -} - -func (_c *Builder_WithProtection_Call) Return(_a0 config.Builder) *Builder_WithProtection_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithProtection_Call) RunAndReturn(run func(protection.Type, string, string) config.Builder) *Builder_WithProtection_Call { - _c.Call.Return(run) - return _c -} - -// WithRightMargin provides a mock function with given fields: right -func (_m *Builder) WithRightMargin(right float64) config.Builder { - ret := _m.Called(right) - - if len(ret) == 0 { - panic("no return value specified for WithRightMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(right) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithRightMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithRightMargin' -type Builder_WithRightMargin_Call struct { - *mock.Call -} - -// WithRightMargin is a helper method to define mock.On call -// - right float64 -func (_e *Builder_Expecter) WithRightMargin(right interface{}) *Builder_WithRightMargin_Call { - return &Builder_WithRightMargin_Call{Call: _e.mock.On("WithRightMargin", right)} -} - -func (_c *Builder_WithRightMargin_Call) Run(run func(right float64)) *Builder_WithRightMargin_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) - }) - return _c -} - -func (_c *Builder_WithRightMargin_Call) Return(_a0 config.Builder) *Builder_WithRightMargin_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithRightMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithRightMargin_Call { - _c.Call.Return(run) - return _c -} - -// WithSequentialLowMemoryMode provides a mock function with given fields: chunkWorkers -func (_m *Builder) WithSequentialLowMemoryMode(chunkWorkers int) config.Builder { - ret := _m.Called(chunkWorkers) - - if len(ret) == 0 { - panic("no return value specified for WithSequentialLowMemoryMode") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(int) config.Builder); ok { - r0 = rf(chunkWorkers) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithSequentialLowMemoryMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialLowMemoryMode' -type Builder_WithSequentialLowMemoryMode_Call struct { - *mock.Call -} - -// WithSequentialLowMemoryMode is a helper method to define mock.On call -// - chunkWorkers int -func (_e *Builder_Expecter) WithSequentialLowMemoryMode(chunkWorkers interface{}) *Builder_WithSequentialLowMemoryMode_Call { - return &Builder_WithSequentialLowMemoryMode_Call{Call: _e.mock.On("WithSequentialLowMemoryMode", chunkWorkers)} -} - -func (_c *Builder_WithSequentialLowMemoryMode_Call) Run(run func(chunkWorkers int)) *Builder_WithSequentialLowMemoryMode_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(int)) - }) - return _c -} - -func (_c *Builder_WithSequentialLowMemoryMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialLowMemoryMode_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithSequentialLowMemoryMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithSequentialLowMemoryMode_Call { - _c.Call.Return(run) - return _c -} - -// WithSequentialMode provides a mock function with given fields: -func (_m *Builder) WithSequentialMode() config.Builder { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for WithSequentialMode") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func() config.Builder); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithSequentialMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialMode' -type Builder_WithSequentialMode_Call struct { - *mock.Call -} - -// WithSequentialMode is a helper method to define mock.On call -func (_e *Builder_Expecter) WithSequentialMode() *Builder_WithSequentialMode_Call { - return &Builder_WithSequentialMode_Call{Call: _e.mock.On("WithSequentialMode")} -} - -func (_c *Builder_WithSequentialMode_Call) Run(run func()) *Builder_WithSequentialMode_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *Builder_WithSequentialMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialMode_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithSequentialMode_Call) RunAndReturn(run func() config.Builder) *Builder_WithSequentialMode_Call { - _c.Call.Return(run) - return _c -} - -// WithSubject provides a mock function with given fields: subject, isUTF8 -func (_m *Builder) WithSubject(subject string, isUTF8 bool) config.Builder { - ret := _m.Called(subject, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithSubject") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(subject, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithSubject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSubject' -type Builder_WithSubject_Call struct { - *mock.Call -} - -// WithSubject is a helper method to define mock.On call -// - subject string -// - isUTF8 bool -func (_e *Builder_Expecter) WithSubject(subject interface{}, isUTF8 interface{}) *Builder_WithSubject_Call { - return &Builder_WithSubject_Call{Call: _e.mock.On("WithSubject", subject, isUTF8)} -} - -func (_c *Builder_WithSubject_Call) Run(run func(subject string, isUTF8 bool)) *Builder_WithSubject_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithSubject_Call) Return(_a0 config.Builder) *Builder_WithSubject_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithSubject_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithSubject_Call { - _c.Call.Return(run) - return _c -} - -// WithTitle provides a mock function with given fields: title, isUTF8 -func (_m *Builder) WithTitle(title string, isUTF8 bool) config.Builder { - ret := _m.Called(title, isUTF8) - - if len(ret) == 0 { - panic("no return value specified for WithTitle") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { - r0 = rf(title, isUTF8) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithTitle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTitle' -type Builder_WithTitle_Call struct { - *mock.Call -} - -// WithTitle is a helper method to define mock.On call -// - title string -// - isUTF8 bool -func (_e *Builder_Expecter) WithTitle(title interface{}, isUTF8 interface{}) *Builder_WithTitle_Call { - return &Builder_WithTitle_Call{Call: _e.mock.On("WithTitle", title, isUTF8)} -} - -func (_c *Builder_WithTitle_Call) Run(run func(title string, isUTF8 bool)) *Builder_WithTitle_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(bool)) - }) - return _c -} - -func (_c *Builder_WithTitle_Call) Return(_a0 config.Builder) *Builder_WithTitle_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *Builder_WithTitle_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithTitle_Call { - _c.Call.Return(run) - return _c -} - -// WithTopMargin provides a mock function with given fields: top -func (_m *Builder) WithTopMargin(top float64) config.Builder { - ret := _m.Called(top) - - if len(ret) == 0 { - panic("no return value specified for WithTopMargin") - } - - var r0 config.Builder - if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { - r0 = rf(top) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(config.Builder) - } - } - - return r0 -} - -// Builder_WithTopMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTopMargin' -type Builder_WithTopMargin_Call struct { - *mock.Call -} - -// WithTopMargin is a helper method to define mock.On call -// - top float64 -func (_e *Builder_Expecter) WithTopMargin(top interface{}) *Builder_WithTopMargin_Call { - return &Builder_WithTopMargin_Call{Call: _e.mock.On("WithTopMargin", top)} +// - cfg *entity.Config +// - _a1 cache.Cache +func (_e *Builder_Expecter) Build(cfg interface{}, _a1 interface{}) *Builder_Build_Call { + return &Builder_Build_Call{Call: _e.mock.On("Build", cfg, _a1)} } -func (_c *Builder_WithTopMargin_Call) Run(run func(top float64)) *Builder_WithTopMargin_Call { +func (_c *Builder_Build_Call) Run(run func(cfg *entity.Config, _a1 cache.Cache)) *Builder_Build_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(float64)) + run(args[0].(*entity.Config), args[1].(cache.Cache)) }) return _c } -func (_c *Builder_WithTopMargin_Call) Return(_a0 config.Builder) *Builder_WithTopMargin_Call { +func (_c *Builder_Build_Call) Return(_a0 *gofpdf.Dependencies) *Builder_Build_Call { _c.Call.Return(_a0) return _c } -func (_c *Builder_WithTopMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithTopMargin_Call { +func (_c *Builder_Build_Call) RunAndReturn(run func(*entity.Config, cache.Cache) *gofpdf.Dependencies) *Builder_Build_Call { _c.Call.Return(run) return _c } diff --git a/mocks/ProcessorProvider.go b/mocks/ProcessorProvider.go index 01223216..f082532b 100644 --- a/mocks/ProcessorProvider.go +++ b/mocks/ProcessorProvider.go @@ -385,6 +385,69 @@ func (_c *ProcessorProvider_CreateSignature_Call) RunAndReturn(run func(string, return _c } +// CreateText provides a mock function with given fields: value, props +func (_m *ProcessorProvider) CreateText(value string, props ...*propsmapper.Text) processorprovider.PDFComponent { + _va := make([]interface{}, len(props)) + for _i := range props { + _va[_i] = props[_i] + } + var _ca []interface{} + _ca = append(_ca, value) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for CreateText") + } + + var r0 processorprovider.PDFComponent + if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Text) processorprovider.PDFComponent); ok { + r0 = rf(value, props...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(processorprovider.PDFComponent) + } + } + + return r0 +} + +// ProcessorProvider_CreateText_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateText' +type ProcessorProvider_CreateText_Call struct { + *mock.Call +} + +// CreateText is a helper method to define mock.On call +// - value string +// - props ...*propsmapper.Text +func (_e *ProcessorProvider_Expecter) CreateText(value interface{}, props ...interface{}) *ProcessorProvider_CreateText_Call { + return &ProcessorProvider_CreateText_Call{Call: _e.mock.On("CreateText", + append([]interface{}{value}, props...)...)} +} + +func (_c *ProcessorProvider_CreateText_Call) Run(run func(value string, props ...*propsmapper.Text)) *ProcessorProvider_CreateText_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]*propsmapper.Text, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(*propsmapper.Text) + } + } + run(args[0].(string), variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_CreateText_Call) Return(_a0 processorprovider.PDFComponent) *ProcessorProvider_CreateText_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorProvider_CreateText_Call) RunAndReturn(run func(string, ...*propsmapper.Text) processorprovider.PDFComponent) *ProcessorProvider_CreateText_Call { + _c.Call.Return(run) + return _c +} + // NewProcessorProvider creates a new instance of ProcessorProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewProcessorProvider(t interface { diff --git a/mocks/Repository.go b/mocks/Repository.go index 9927b778..3977c94e 100644 --- a/mocks/Repository.go +++ b/mocks/Repository.go @@ -2,7 +2,14 @@ package mocks -import mock "github.com/stretchr/testify/mock" +import ( + fontstyle "github.com/johnfercher/maroto/v2/pkg/consts/fontstyle" + entity "github.com/johnfercher/maroto/v2/pkg/core/entity" + + mock "github.com/stretchr/testify/mock" + + repository "github.com/johnfercher/maroto/v2/pkg/repository" +) // Repository is an autogenerated mock type for the Repository type type Repository struct { @@ -17,172 +24,159 @@ func (_m *Repository) EXPECT() *Repository_Expecter { return &Repository_Expecter{mock: &_m.Mock} } -// GetDocument provides a mock function with given fields: documentName -func (_m *Repository) GetDocument(documentName string) (string, []byte, error) { - ret := _m.Called(documentName) +// AddUTF8Font provides a mock function with given fields: family, style, file +func (_m *Repository) AddUTF8Font(family string, style fontstyle.Type, file string) repository.Repository { + ret := _m.Called(family, style, file) if len(ret) == 0 { - panic("no return value specified for GetDocument") + panic("no return value specified for AddUTF8Font") } - var r0 string - var r1 []byte - var r2 error - if rf, ok := ret.Get(0).(func(string) (string, []byte, error)); ok { - return rf(documentName) - } - if rf, ok := ret.Get(0).(func(string) string); ok { - r0 = rf(documentName) + var r0 repository.Repository + if rf, ok := ret.Get(0).(func(string, fontstyle.Type, string) repository.Repository); ok { + r0 = rf(family, style, file) } else { - r0 = ret.Get(0).(string) - } - - if rf, ok := ret.Get(1).(func(string) []byte); ok { - r1 = rf(documentName) - } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).([]byte) + if ret.Get(0) != nil { + r0 = ret.Get(0).(repository.Repository) } } - if rf, ok := ret.Get(2).(func(string) error); ok { - r2 = rf(documentName) - } else { - r2 = ret.Error(2) - } - - return r0, r1, r2 + return r0 } -// Repository_GetDocument_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDocument' -type Repository_GetDocument_Call struct { +// Repository_AddUTF8Font_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddUTF8Font' +type Repository_AddUTF8Font_Call struct { *mock.Call } -// GetDocument is a helper method to define mock.On call -// - documentName string -func (_e *Repository_Expecter) GetDocument(documentName interface{}) *Repository_GetDocument_Call { - return &Repository_GetDocument_Call{Call: _e.mock.On("GetDocument", documentName)} +// AddUTF8Font is a helper method to define mock.On call +// - family string +// - style fontstyle.Type +// - file string +func (_e *Repository_Expecter) AddUTF8Font(family interface{}, style interface{}, file interface{}) *Repository_AddUTF8Font_Call { + return &Repository_AddUTF8Font_Call{Call: _e.mock.On("AddUTF8Font", family, style, file)} } -func (_c *Repository_GetDocument_Call) Run(run func(documentName string)) *Repository_GetDocument_Call { +func (_c *Repository_AddUTF8Font_Call) Run(run func(family string, style fontstyle.Type, file string)) *Repository_AddUTF8Font_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) + run(args[0].(string), args[1].(fontstyle.Type), args[2].(string)) }) return _c } -func (_c *Repository_GetDocument_Call) Return(extension string, doc []byte, err error) *Repository_GetDocument_Call { - _c.Call.Return(extension, doc, err) +func (_c *Repository_AddUTF8Font_Call) Return(_a0 repository.Repository) *Repository_AddUTF8Font_Call { + _c.Call.Return(_a0) return _c } -func (_c *Repository_GetDocument_Call) RunAndReturn(run func(string) (string, []byte, error)) *Repository_GetDocument_Call { +func (_c *Repository_AddUTF8Font_Call) RunAndReturn(run func(string, fontstyle.Type, string) repository.Repository) *Repository_AddUTF8Font_Call { _c.Call.Return(run) return _c } -// ReadTemplate provides a mock function with given fields: templateName -func (_m *Repository) ReadTemplate(templateName string) (map[string]interface{}, error) { - ret := _m.Called(templateName) +// AddUTF8FontFromBytes provides a mock function with given fields: family, style, bytes +func (_m *Repository) AddUTF8FontFromBytes(family string, style fontstyle.Type, bytes []byte) repository.Repository { + ret := _m.Called(family, style, bytes) if len(ret) == 0 { - panic("no return value specified for ReadTemplate") + panic("no return value specified for AddUTF8FontFromBytes") } - var r0 map[string]interface{} - var r1 error - if rf, ok := ret.Get(0).(func(string) (map[string]interface{}, error)); ok { - return rf(templateName) - } - if rf, ok := ret.Get(0).(func(string) map[string]interface{}); ok { - r0 = rf(templateName) + var r0 repository.Repository + if rf, ok := ret.Get(0).(func(string, fontstyle.Type, []byte) repository.Repository); ok { + r0 = rf(family, style, bytes) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(map[string]interface{}) + r0 = ret.Get(0).(repository.Repository) } } - if rf, ok := ret.Get(1).(func(string) error); ok { - r1 = rf(templateName) - } else { - r1 = ret.Error(1) - } - - return r0, r1 + return r0 } -// Repository_ReadTemplate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReadTemplate' -type Repository_ReadTemplate_Call struct { +// Repository_AddUTF8FontFromBytes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddUTF8FontFromBytes' +type Repository_AddUTF8FontFromBytes_Call struct { *mock.Call } -// ReadTemplate is a helper method to define mock.On call -// - templateName string -func (_e *Repository_Expecter) ReadTemplate(templateName interface{}) *Repository_ReadTemplate_Call { - return &Repository_ReadTemplate_Call{Call: _e.mock.On("ReadTemplate", templateName)} +// AddUTF8FontFromBytes is a helper method to define mock.On call +// - family string +// - style fontstyle.Type +// - bytes []byte +func (_e *Repository_Expecter) AddUTF8FontFromBytes(family interface{}, style interface{}, bytes interface{}) *Repository_AddUTF8FontFromBytes_Call { + return &Repository_AddUTF8FontFromBytes_Call{Call: _e.mock.On("AddUTF8FontFromBytes", family, style, bytes)} } -func (_c *Repository_ReadTemplate_Call) Run(run func(templateName string)) *Repository_ReadTemplate_Call { +func (_c *Repository_AddUTF8FontFromBytes_Call) Run(run func(family string, style fontstyle.Type, bytes []byte)) *Repository_AddUTF8FontFromBytes_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) + run(args[0].(string), args[1].(fontstyle.Type), args[2].([]byte)) }) return _c } -func (_c *Repository_ReadTemplate_Call) Return(_a0 map[string]interface{}, _a1 error) *Repository_ReadTemplate_Call { - _c.Call.Return(_a0, _a1) +func (_c *Repository_AddUTF8FontFromBytes_Call) Return(_a0 repository.Repository) *Repository_AddUTF8FontFromBytes_Call { + _c.Call.Return(_a0) return _c } -func (_c *Repository_ReadTemplate_Call) RunAndReturn(run func(string) (map[string]interface{}, error)) *Repository_ReadTemplate_Call { +func (_c *Repository_AddUTF8FontFromBytes_Call) RunAndReturn(run func(string, fontstyle.Type, []byte) repository.Repository) *Repository_AddUTF8FontFromBytes_Call { _c.Call.Return(run) return _c } -// RegisterTemplate provides a mock function with given fields: templateName, template -func (_m *Repository) RegisterTemplate(templateName string, template map[string]interface{}) error { - ret := _m.Called(templateName, template) +// Load provides a mock function with given fields: +func (_m *Repository) Load() ([]*entity.CustomFont, error) { + ret := _m.Called() if len(ret) == 0 { - panic("no return value specified for RegisterTemplate") + panic("no return value specified for Load") } - var r0 error - if rf, ok := ret.Get(0).(func(string, map[string]interface{}) error); ok { - r0 = rf(templateName, template) + var r0 []*entity.CustomFont + var r1 error + if rf, ok := ret.Get(0).(func() ([]*entity.CustomFont, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []*entity.CustomFont); ok { + r0 = rf() } else { - r0 = ret.Error(0) + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*entity.CustomFont) + } } - return r0 + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 } -// Repository_RegisterTemplate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterTemplate' -type Repository_RegisterTemplate_Call struct { +// Repository_Load_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Load' +type Repository_Load_Call struct { *mock.Call } -// RegisterTemplate is a helper method to define mock.On call -// - templateName string -// - template map[string]interface{} -func (_e *Repository_Expecter) RegisterTemplate(templateName interface{}, template interface{}) *Repository_RegisterTemplate_Call { - return &Repository_RegisterTemplate_Call{Call: _e.mock.On("RegisterTemplate", templateName, template)} +// Load is a helper method to define mock.On call +func (_e *Repository_Expecter) Load() *Repository_Load_Call { + return &Repository_Load_Call{Call: _e.mock.On("Load")} } -func (_c *Repository_RegisterTemplate_Call) Run(run func(templateName string, template map[string]interface{})) *Repository_RegisterTemplate_Call { +func (_c *Repository_Load_Call) Run(run func()) *Repository_Load_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(map[string]interface{})) + run() }) return _c } -func (_c *Repository_RegisterTemplate_Call) Return(_a0 error) *Repository_RegisterTemplate_Call { - _c.Call.Return(_a0) +func (_c *Repository_Load_Call) Return(_a0 []*entity.CustomFont, _a1 error) *Repository_Load_Call { + _c.Call.Return(_a0, _a1) return _c } -func (_c *Repository_RegisterTemplate_Call) RunAndReturn(run func(string, map[string]interface{}) error) *Repository_RegisterTemplate_Call { +func (_c *Repository_Load_Call) RunAndReturn(run func() ([]*entity.CustomFont, error)) *Repository_Load_Call { _c.Call.Return(run) return _c } diff --git a/pkg/processor/mappers/components/textmapper/text_test.go b/pkg/processor/mappers/components/textmapper/text_test.go index 99f5c698..a7cfb2cd 100644 --- a/pkg/processor/mappers/components/textmapper/text_test.go +++ b/pkg/processor/mappers/components/textmapper/text_test.go @@ -3,6 +3,7 @@ package textmapper_test import ( "testing" + "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/textmapper" "github.com/stretchr/testify/assert" ) @@ -98,3 +99,54 @@ func TestNewText(t *testing.T) { assert.Equal(t, text.Value, "value") }) } + +func TestGenerate(t *testing.T) { + t.Run("if source key is not found, should return an error", func(t *testing.T) { + content := map[string]interface{}{} + provider := mocks.NewProcessorProvider(t) + + text := textmapper.Text{SourceKey: "text"} + component, err := text.Generate(content, provider) + + assert.Nil(t, component) + assert.NotNil(t, err) + }) + t.Run("if source key content is not valid, should return an error", func(t *testing.T) { + content := map[string]interface{}{ + "value": 1, + } + provider := mocks.NewProcessorProvider(t) + + text := textmapper.Text{SourceKey: "value"} + component, err := text.Generate(content, provider) + + assert.Nil(t, component) + assert.NotNil(t, err) + }) + t.Run("If the text has no props, the props will not be sent", func(t *testing.T) { + content := map[string]interface{}{ + "value": "text", + } + + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateText("text").Return(nil) + + text := textmapper.Text{SourceKey: "value"} + _, err := text.Generate(content, provider) + + assert.Nil(t, err) + provider.AssertNumberOfCalls(t, "CreateText", 1) + }) + t.Run("when valid text is sent, should generate text", func(t *testing.T) { + content := map[string]interface{}{} + + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateText("text").Return(nil) + + text := textmapper.Text{Value: "text"} + _, err := text.Generate(content, provider) + + assert.Nil(t, err) + provider.AssertNumberOfCalls(t, "CreateText", 1) + }) +} diff --git a/pkg/processor/processorprovider/Maroto_test.go b/pkg/processor/processorprovider/Maroto_test.go index a3033abc..b672135d 100644 --- a/pkg/processor/processorprovider/Maroto_test.go +++ b/pkg/processor/processorprovider/Maroto_test.go @@ -86,3 +86,17 @@ func TestCreateSignature(t *testing.T) { test.New(t).Assert(barcode.GetStructure()).Equals("processor/provider/signature.json") }) } + +func TestCreateText(t *testing.T) { + t.Run("when CreateText is called, should generate a text", func(t *testing.T) { + m := processorprovider.NewMaroto() + barcode := m.CreateText("text", + &propsmapper.Text{ + Top: 10.0, Left: 10.0, Right: 10.0, Family: "Arial", Style: "bold", Size: 10.0, Align: "center", BreakLineStrategy: "dash_strategy", + VerticalPadding: 10.0, Color: &propsmapper.Color{Red: 10, Green: 10, Blue: 10}, Hyperlink: "test", + }, + ) + + test.New(t).Assert(barcode.GetStructure()).Equals("processor/provider/text.json") + }) +} diff --git a/test/maroto/processor/provider/text.json b/test/maroto/processor/provider/text.json new file mode 100644 index 00000000..876ddbbf --- /dev/null +++ b/test/maroto/processor/provider/text.json @@ -0,0 +1,17 @@ +{ + "value": "text", + "type": "text", + "details": { + "prop_align": "center", + "prop_breakline_strategy": "dash_strategy", + "prop_color": "RGB(10, 10, 10)", + "prop_font_family": "Arial", + "prop_font_size": 10, + "prop_font_style": "bold", + "prop_hyperlink": "test", + "prop_left": 10, + "prop_right": 10, + "prop_top": 10, + "prop_vertical_padding": 10 + } +} \ No newline at end of file From b7a1fc8feebcbca9bdd488be7d6c90acb8566cb3 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sat, 2 Nov 2024 15:28:48 -0300 Subject: [PATCH 059/116] feat: create text component --- .../components/codemapper/barcode_test.go | 1 - .../mappers/components/textmapper/text.go | 30 +++++++++++++++++-- pkg/processor/processorprovider/Maroto.go | 16 +++++++++- pkg/processor/processorprovider/provider.go | 1 + 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/pkg/processor/mappers/components/codemapper/barcode_test.go b/pkg/processor/mappers/components/codemapper/barcode_test.go index ad4e3617..a04ae62a 100644 --- a/pkg/processor/mappers/components/codemapper/barcode_test.go +++ b/pkg/processor/mappers/components/codemapper/barcode_test.go @@ -150,5 +150,4 @@ func TestGenerate(t *testing.T) { assert.Nil(t, err) provider.AssertNumberOfCalls(t, "CreateBarCode", 1) }) - } diff --git a/pkg/processor/mappers/components/textmapper/text.go b/pkg/processor/mappers/components/textmapper/text.go index 9b07fb68..f79837d4 100644 --- a/pkg/processor/mappers/components/textmapper/text.go +++ b/pkg/processor/mappers/components/textmapper/text.go @@ -3,8 +3,8 @@ package textmapper import ( "fmt" - "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Text struct { @@ -92,6 +92,30 @@ func (t *Text) validateFields() error { return nil } -func (t *Text) Generate(content map[string]interface{}) (components.PdfComponent, error) { - return nil, nil +func (t *Text) getValue(content map[string]interface{}) (string, error) { + if t.Value != "" { + return t.Value, nil + } + textFound, ok := content[t.SourceKey] + if !ok { + return "", fmt.Errorf("text requires a source key named %s, but it was not found", t.SourceKey) + } + textValid, ok := textFound.(string) + if !ok { + return "", fmt.Errorf("unable to generate text, invalid value. source key %s", t.SourceKey) + } + return textValid, nil +} + +func (t *Text) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { + signature, err := t.getValue(content) + if err != nil { + return nil, err + } + t.Value = signature + + if t.Props != nil { + return provider.CreateText(t.Value, t.Props), nil + } + return provider.CreateText(t.Value), nil } diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index 9f86564d..64580465 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -5,7 +5,10 @@ import ( "github.com/johnfercher/maroto/v2/pkg/components/image" "github.com/johnfercher/maroto/v2/pkg/components/line" "github.com/johnfercher/maroto/v2/pkg/components/signature" + "github.com/johnfercher/maroto/v2/pkg/components/text" + "github.com/johnfercher/maroto/v2/pkg/consts/align" "github.com/johnfercher/maroto/v2/pkg/consts/barcode" + "github.com/johnfercher/maroto/v2/pkg/consts/breakline" "github.com/johnfercher/maroto/v2/pkg/consts/extension" "github.com/johnfercher/maroto/v2/pkg/consts/fontstyle" "github.com/johnfercher/maroto/v2/pkg/consts/linestyle" @@ -24,6 +27,18 @@ func NewMaroto() *Maroto { return nil } +func (m *Maroto) CreateText(value string, textsProps ...*propsmapper.Text) PDFComponent { + tProps := propsmapper.Text{} + if len(textsProps) > 0 { + tProps = *textsProps[0] + } + + return text.New(value, props.Text{Top: tProps.Top, Left: tProps.Left, Right: tProps.Right, Family: tProps.Family, + Style: fontstyle.Type(tProps.Style), Size: tProps.Size, Align: align.Type(tProps.Align), BreakLineStrategy: breakline.Strategy(tProps.BreakLineStrategy), + VerticalPadding: tProps.VerticalPadding, Color: (*props.Color)(tProps.Color), Hyperlink: &tProps.Hyperlink, + }) +} + func (m *Maroto) CreateSignature(value string, signaturesProps ...*propsmapper.Signature) PDFComponent { sProps := propsmapper.Signature{} if len(signaturesProps) > 0 { @@ -35,7 +50,6 @@ func (m *Maroto) CreateSignature(value string, signaturesProps ...*propsmapper.S FontColor: (*props.Color)(sProps.FontColor), LineColor: (*props.Color)(sProps.LineColor), LineStyle: sProps.LineStyle, LineThickness: sProps.LineThickness, SafePadding: sProps.SafePadding, }) - } func (m *Maroto) CreateLine(lineProps ...*propsmapper.Line) PDFComponent { diff --git a/pkg/processor/processorprovider/provider.go b/pkg/processor/processorprovider/provider.go index e7b54e7b..c51c9e93 100644 --- a/pkg/processor/processorprovider/provider.go +++ b/pkg/processor/processorprovider/provider.go @@ -14,6 +14,7 @@ type PDFComponent interface { // ProcessorProvider provides an interface with all the methods that // Maroto provides for pdf builder type ProcessorProvider interface { + CreateText(value string, props ...*propsmapper.Text) PDFComponent CreateSignature(value string, props ...*propsmapper.Signature) PDFComponent CreateBarCode(value string, props ...*propsmapper.Barcode) PDFComponent CreateMatrixCode(value string, props ...*propsmapper.Rect) PDFComponent From 6587e5425995fab4709d067a33c6a1ccc378b29c Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Mon, 4 Nov 2024 22:30:38 -0300 Subject: [PATCH 060/116] refactor: Update interfaces create an interface that represents all the components of Maroto rename interface repository --- mocks/Componentmapper.go | 14 +- mocks/PDFComponent.go | 201 ------------ mocks/ProcessorProvider.go | 301 +++++++++++++++--- mocks/ProcessorRepository.go | 203 ++++++++++++ mocks/ProviderComponent.go | 120 +++++++ pkg/processor/core/core.go | 2 +- .../abstractfactory/abstractfactory.go | 4 +- pkg/processor/mappers/component_mapper.go | 12 +- .../mappers/components/codemapper/barcode.go | 6 +- .../components/codemapper/matrixcode.go | 6 +- .../mappers/components/codemapper/qrcode.go | 6 +- .../mappers/components/imagemapper/image.go | 12 +- .../components/imagemapper/image_test.go | 26 +- .../mappers/components/linemapper/line.go | 4 +- .../components/signaturemapper/signature.go | 6 +- .../mappers/components/textmapper/text.go | 6 +- .../mappers/documentmapper/document.go | 4 +- pkg/processor/processor.go | 2 +- pkg/processor/processorprovider/provider.go | 23 +- 19 files changed, 653 insertions(+), 305 deletions(-) delete mode 100644 mocks/PDFComponent.go create mode 100644 mocks/ProcessorRepository.go create mode 100644 mocks/ProviderComponent.go diff --git a/mocks/Componentmapper.go b/mocks/Componentmapper.go index b7e91bb4..b6f4c978 100644 --- a/mocks/Componentmapper.go +++ b/mocks/Componentmapper.go @@ -21,23 +21,23 @@ func (_m *Componentmapper) EXPECT() *Componentmapper_Expecter { } // Generate provides a mock function with given fields: content, provider -func (_m *Componentmapper) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { +func (_m *Componentmapper) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { ret := _m.Called(content, provider) if len(ret) == 0 { panic("no return value specified for Generate") } - var r0 processorprovider.PDFComponent + var r0 []processorprovider.ProviderComponent var r1 error - if rf, ok := ret.Get(0).(func(map[string]interface{}, processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error)); ok { + if rf, ok := ret.Get(0).(func(map[string]interface{}, processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error)); ok { return rf(content, provider) } - if rf, ok := ret.Get(0).(func(map[string]interface{}, processorprovider.ProcessorProvider) processorprovider.PDFComponent); ok { + if rf, ok := ret.Get(0).(func(map[string]interface{}, processorprovider.ProcessorProvider) []processorprovider.ProviderComponent); ok { r0 = rf(content, provider) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(processorprovider.PDFComponent) + r0 = ret.Get(0).([]processorprovider.ProviderComponent) } } @@ -69,12 +69,12 @@ func (_c *Componentmapper_Generate_Call) Run(run func(content map[string]interfa return _c } -func (_c *Componentmapper_Generate_Call) Return(_a0 processorprovider.PDFComponent, _a1 error) *Componentmapper_Generate_Call { +func (_c *Componentmapper_Generate_Call) Return(_a0 []processorprovider.ProviderComponent, _a1 error) *Componentmapper_Generate_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *Componentmapper_Generate_Call) RunAndReturn(run func(map[string]interface{}, processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error)) *Componentmapper_Generate_Call { +func (_c *Componentmapper_Generate_Call) RunAndReturn(run func(map[string]interface{}, processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error)) *Componentmapper_Generate_Call { _c.Call.Return(run) return _c } diff --git a/mocks/PDFComponent.go b/mocks/PDFComponent.go deleted file mode 100644 index 880dbbb5..00000000 --- a/mocks/PDFComponent.go +++ /dev/null @@ -1,201 +0,0 @@ -// Code generated by mockery v2.42.0. DO NOT EDIT. - -package mocks - -import ( - core "github.com/johnfercher/maroto/v2/pkg/core" - entity "github.com/johnfercher/maroto/v2/pkg/core/entity" - - mock "github.com/stretchr/testify/mock" - - node "github.com/johnfercher/go-tree/node" -) - -// PDFComponent is an autogenerated mock type for the PDFComponent type -type PDFComponent struct { - mock.Mock -} - -type PDFComponent_Expecter struct { - mock *mock.Mock -} - -func (_m *PDFComponent) EXPECT() *PDFComponent_Expecter { - return &PDFComponent_Expecter{mock: &_m.Mock} -} - -// GetHeight provides a mock function with given fields: provider, cell -func (_m *PDFComponent) GetHeight(provider core.Provider, cell *entity.Cell) float64 { - ret := _m.Called(provider, cell) - - if len(ret) == 0 { - panic("no return value specified for GetHeight") - } - - var r0 float64 - if rf, ok := ret.Get(0).(func(core.Provider, *entity.Cell) float64); ok { - r0 = rf(provider, cell) - } else { - r0 = ret.Get(0).(float64) - } - - return r0 -} - -// PDFComponent_GetHeight_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetHeight' -type PDFComponent_GetHeight_Call struct { - *mock.Call -} - -// GetHeight is a helper method to define mock.On call -// - provider core.Provider -// - cell *entity.Cell -func (_e *PDFComponent_Expecter) GetHeight(provider interface{}, cell interface{}) *PDFComponent_GetHeight_Call { - return &PDFComponent_GetHeight_Call{Call: _e.mock.On("GetHeight", provider, cell)} -} - -func (_c *PDFComponent_GetHeight_Call) Run(run func(provider core.Provider, cell *entity.Cell)) *PDFComponent_GetHeight_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(core.Provider), args[1].(*entity.Cell)) - }) - return _c -} - -func (_c *PDFComponent_GetHeight_Call) Return(_a0 float64) *PDFComponent_GetHeight_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *PDFComponent_GetHeight_Call) RunAndReturn(run func(core.Provider, *entity.Cell) float64) *PDFComponent_GetHeight_Call { - _c.Call.Return(run) - return _c -} - -// GetStructure provides a mock function with given fields: -func (_m *PDFComponent) GetStructure() *node.Node[core.Structure] { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for GetStructure") - } - - var r0 *node.Node[core.Structure] - if rf, ok := ret.Get(0).(func() *node.Node[core.Structure]); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*node.Node[core.Structure]) - } - } - - return r0 -} - -// PDFComponent_GetStructure_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetStructure' -type PDFComponent_GetStructure_Call struct { - *mock.Call -} - -// GetStructure is a helper method to define mock.On call -func (_e *PDFComponent_Expecter) GetStructure() *PDFComponent_GetStructure_Call { - return &PDFComponent_GetStructure_Call{Call: _e.mock.On("GetStructure")} -} - -func (_c *PDFComponent_GetStructure_Call) Run(run func()) *PDFComponent_GetStructure_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *PDFComponent_GetStructure_Call) Return(_a0 *node.Node[core.Structure]) *PDFComponent_GetStructure_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *PDFComponent_GetStructure_Call) RunAndReturn(run func() *node.Node[core.Structure]) *PDFComponent_GetStructure_Call { - _c.Call.Return(run) - return _c -} - -// Render provides a mock function with given fields: provider, cell -func (_m *PDFComponent) Render(provider core.Provider, cell *entity.Cell) { - _m.Called(provider, cell) -} - -// PDFComponent_Render_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Render' -type PDFComponent_Render_Call struct { - *mock.Call -} - -// Render is a helper method to define mock.On call -// - provider core.Provider -// - cell *entity.Cell -func (_e *PDFComponent_Expecter) Render(provider interface{}, cell interface{}) *PDFComponent_Render_Call { - return &PDFComponent_Render_Call{Call: _e.mock.On("Render", provider, cell)} -} - -func (_c *PDFComponent_Render_Call) Run(run func(provider core.Provider, cell *entity.Cell)) *PDFComponent_Render_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(core.Provider), args[1].(*entity.Cell)) - }) - return _c -} - -func (_c *PDFComponent_Render_Call) Return() *PDFComponent_Render_Call { - _c.Call.Return() - return _c -} - -func (_c *PDFComponent_Render_Call) RunAndReturn(run func(core.Provider, *entity.Cell)) *PDFComponent_Render_Call { - _c.Call.Return(run) - return _c -} - -// SetConfig provides a mock function with given fields: config -func (_m *PDFComponent) SetConfig(config *entity.Config) { - _m.Called(config) -} - -// PDFComponent_SetConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetConfig' -type PDFComponent_SetConfig_Call struct { - *mock.Call -} - -// SetConfig is a helper method to define mock.On call -// - config *entity.Config -func (_e *PDFComponent_Expecter) SetConfig(config interface{}) *PDFComponent_SetConfig_Call { - return &PDFComponent_SetConfig_Call{Call: _e.mock.On("SetConfig", config)} -} - -func (_c *PDFComponent_SetConfig_Call) Run(run func(config *entity.Config)) *PDFComponent_SetConfig_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*entity.Config)) - }) - return _c -} - -func (_c *PDFComponent_SetConfig_Call) Return() *PDFComponent_SetConfig_Call { - _c.Call.Return() - return _c -} - -func (_c *PDFComponent_SetConfig_Call) RunAndReturn(run func(*entity.Config)) *PDFComponent_SetConfig_Call { - _c.Call.Return(run) - return _c -} - -// NewPDFComponent creates a new instance of PDFComponent. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewPDFComponent(t interface { - mock.TestingT - Cleanup(func()) -}, -) *PDFComponent { - mock := &PDFComponent{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/mocks/ProcessorProvider.go b/mocks/ProcessorProvider.go index f082532b..89e0fb26 100644 --- a/mocks/ProcessorProvider.go +++ b/mocks/ProcessorProvider.go @@ -22,7 +22,7 @@ func (_m *ProcessorProvider) EXPECT() *ProcessorProvider_Expecter { } // CreateBarCode provides a mock function with given fields: value, props -func (_m *ProcessorProvider) CreateBarCode(value string, props ...*propsmapper.Barcode) processorprovider.PDFComponent { +func (_m *ProcessorProvider) CreateBarCode(value string, props ...*propsmapper.Barcode) processorprovider.ProviderComponent { _va := make([]interface{}, len(props)) for _i := range props { _va[_i] = props[_i] @@ -36,12 +36,12 @@ func (_m *ProcessorProvider) CreateBarCode(value string, props ...*propsmapper.B panic("no return value specified for CreateBarCode") } - var r0 processorprovider.PDFComponent - if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Barcode) processorprovider.PDFComponent); ok { + var r0 processorprovider.ProviderComponent + if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Barcode) processorprovider.ProviderComponent); ok { r0 = rf(value, props...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(processorprovider.PDFComponent) + r0 = ret.Get(0).(processorprovider.ProviderComponent) } } @@ -74,18 +74,91 @@ func (_c *ProcessorProvider_CreateBarCode_Call) Run(run func(value string, props return _c } -func (_c *ProcessorProvider_CreateBarCode_Call) Return(_a0 processorprovider.PDFComponent) *ProcessorProvider_CreateBarCode_Call { +func (_c *ProcessorProvider_CreateBarCode_Call) Return(_a0 processorprovider.ProviderComponent) *ProcessorProvider_CreateBarCode_Call { _c.Call.Return(_a0) return _c } -func (_c *ProcessorProvider_CreateBarCode_Call) RunAndReturn(run func(string, ...*propsmapper.Barcode) processorprovider.PDFComponent) *ProcessorProvider_CreateBarCode_Call { +func (_c *ProcessorProvider_CreateBarCode_Call) RunAndReturn(run func(string, ...*propsmapper.Barcode) processorprovider.ProviderComponent) *ProcessorProvider_CreateBarCode_Call { + _c.Call.Return(run) + return _c +} + +// CreateCol provides a mock function with given fields: size, components +func (_m *ProcessorProvider) CreateCol(size int, components ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error) { + _va := make([]interface{}, len(components)) + for _i := range components { + _va[_i] = components[_i] + } + var _ca []interface{} + _ca = append(_ca, size) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for CreateCol") + } + + var r0 processorprovider.ProviderComponent + var r1 error + if rf, ok := ret.Get(0).(func(int, ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error)); ok { + return rf(size, components...) + } + if rf, ok := ret.Get(0).(func(int, ...processorprovider.ProviderComponent) processorprovider.ProviderComponent); ok { + r0 = rf(size, components...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(processorprovider.ProviderComponent) + } + } + + if rf, ok := ret.Get(1).(func(int, ...processorprovider.ProviderComponent) error); ok { + r1 = rf(size, components...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProcessorProvider_CreateCol_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateCol' +type ProcessorProvider_CreateCol_Call struct { + *mock.Call +} + +// CreateCol is a helper method to define mock.On call +// - size int +// - components ...processorprovider.ProviderComponent +func (_e *ProcessorProvider_Expecter) CreateCol(size interface{}, components ...interface{}) *ProcessorProvider_CreateCol_Call { + return &ProcessorProvider_CreateCol_Call{Call: _e.mock.On("CreateCol", + append([]interface{}{size}, components...)...)} +} + +func (_c *ProcessorProvider_CreateCol_Call) Run(run func(size int, components ...processorprovider.ProviderComponent)) *ProcessorProvider_CreateCol_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]processorprovider.ProviderComponent, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(processorprovider.ProviderComponent) + } + } + run(args[0].(int), variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_CreateCol_Call) Return(_a0 processorprovider.ProviderComponent, _a1 error) *ProcessorProvider_CreateCol_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ProcessorProvider_CreateCol_Call) RunAndReturn(run func(int, ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error)) *ProcessorProvider_CreateCol_Call { _c.Call.Return(run) return _c } // CreateImage provides a mock function with given fields: value, extension, props -func (_m *ProcessorProvider) CreateImage(value []byte, extension string, props ...*propsmapper.Rect) processorprovider.PDFComponent { +func (_m *ProcessorProvider) CreateImage(value []byte, extension string, props ...*propsmapper.Rect) processorprovider.ProviderComponent { _va := make([]interface{}, len(props)) for _i := range props { _va[_i] = props[_i] @@ -99,12 +172,12 @@ func (_m *ProcessorProvider) CreateImage(value []byte, extension string, props . panic("no return value specified for CreateImage") } - var r0 processorprovider.PDFComponent - if rf, ok := ret.Get(0).(func([]byte, string, ...*propsmapper.Rect) processorprovider.PDFComponent); ok { + var r0 processorprovider.ProviderComponent + if rf, ok := ret.Get(0).(func([]byte, string, ...*propsmapper.Rect) processorprovider.ProviderComponent); ok { r0 = rf(value, extension, props...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(processorprovider.PDFComponent) + r0 = ret.Get(0).(processorprovider.ProviderComponent) } } @@ -138,30 +211,30 @@ func (_c *ProcessorProvider_CreateImage_Call) Run(run func(value []byte, extensi return _c } -func (_c *ProcessorProvider_CreateImage_Call) Return(_a0 processorprovider.PDFComponent) *ProcessorProvider_CreateImage_Call { +func (_c *ProcessorProvider_CreateImage_Call) Return(_a0 processorprovider.ProviderComponent) *ProcessorProvider_CreateImage_Call { _c.Call.Return(_a0) return _c } -func (_c *ProcessorProvider_CreateImage_Call) RunAndReturn(run func([]byte, string, ...*propsmapper.Rect) processorprovider.PDFComponent) *ProcessorProvider_CreateImage_Call { +func (_c *ProcessorProvider_CreateImage_Call) RunAndReturn(run func([]byte, string, ...*propsmapper.Rect) processorprovider.ProviderComponent) *ProcessorProvider_CreateImage_Call { _c.Call.Return(run) return _c } // CreateLine provides a mock function with given fields: props -func (_m *ProcessorProvider) CreateLine(props *propsmapper.Line) processorprovider.PDFComponent { +func (_m *ProcessorProvider) CreateLine(props *propsmapper.Line) processorprovider.ProviderComponent { ret := _m.Called(props) if len(ret) == 0 { panic("no return value specified for CreateLine") } - var r0 processorprovider.PDFComponent - if rf, ok := ret.Get(0).(func(*propsmapper.Line) processorprovider.PDFComponent); ok { + var r0 processorprovider.ProviderComponent + if rf, ok := ret.Get(0).(func(*propsmapper.Line) processorprovider.ProviderComponent); ok { r0 = rf(props) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(processorprovider.PDFComponent) + r0 = ret.Get(0).(processorprovider.ProviderComponent) } } @@ -186,18 +259,18 @@ func (_c *ProcessorProvider_CreateLine_Call) Run(run func(props *propsmapper.Lin return _c } -func (_c *ProcessorProvider_CreateLine_Call) Return(_a0 processorprovider.PDFComponent) *ProcessorProvider_CreateLine_Call { +func (_c *ProcessorProvider_CreateLine_Call) Return(_a0 processorprovider.ProviderComponent) *ProcessorProvider_CreateLine_Call { _c.Call.Return(_a0) return _c } -func (_c *ProcessorProvider_CreateLine_Call) RunAndReturn(run func(*propsmapper.Line) processorprovider.PDFComponent) *ProcessorProvider_CreateLine_Call { +func (_c *ProcessorProvider_CreateLine_Call) RunAndReturn(run func(*propsmapper.Line) processorprovider.ProviderComponent) *ProcessorProvider_CreateLine_Call { _c.Call.Return(run) return _c } // CreateMatrixCode provides a mock function with given fields: value, props -func (_m *ProcessorProvider) CreateMatrixCode(value string, props ...*propsmapper.Rect) processorprovider.PDFComponent { +func (_m *ProcessorProvider) CreateMatrixCode(value string, props ...*propsmapper.Rect) processorprovider.ProviderComponent { _va := make([]interface{}, len(props)) for _i := range props { _va[_i] = props[_i] @@ -211,12 +284,12 @@ func (_m *ProcessorProvider) CreateMatrixCode(value string, props ...*propsmappe panic("no return value specified for CreateMatrixCode") } - var r0 processorprovider.PDFComponent - if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Rect) processorprovider.PDFComponent); ok { + var r0 processorprovider.ProviderComponent + if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Rect) processorprovider.ProviderComponent); ok { r0 = rf(value, props...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(processorprovider.PDFComponent) + r0 = ret.Get(0).(processorprovider.ProviderComponent) } } @@ -249,18 +322,89 @@ func (_c *ProcessorProvider_CreateMatrixCode_Call) Run(run func(value string, pr return _c } -func (_c *ProcessorProvider_CreateMatrixCode_Call) Return(_a0 processorprovider.PDFComponent) *ProcessorProvider_CreateMatrixCode_Call { +func (_c *ProcessorProvider_CreateMatrixCode_Call) Return(_a0 processorprovider.ProviderComponent) *ProcessorProvider_CreateMatrixCode_Call { _c.Call.Return(_a0) return _c } -func (_c *ProcessorProvider_CreateMatrixCode_Call) RunAndReturn(run func(string, ...*propsmapper.Rect) processorprovider.PDFComponent) *ProcessorProvider_CreateMatrixCode_Call { +func (_c *ProcessorProvider_CreateMatrixCode_Call) RunAndReturn(run func(string, ...*propsmapper.Rect) processorprovider.ProviderComponent) *ProcessorProvider_CreateMatrixCode_Call { + _c.Call.Return(run) + return _c +} + +// CreatePage provides a mock function with given fields: components +func (_m *ProcessorProvider) CreatePage(components ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error) { + _va := make([]interface{}, len(components)) + for _i := range components { + _va[_i] = components[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for CreatePage") + } + + var r0 processorprovider.ProviderComponent + var r1 error + if rf, ok := ret.Get(0).(func(...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error)); ok { + return rf(components...) + } + if rf, ok := ret.Get(0).(func(...processorprovider.ProviderComponent) processorprovider.ProviderComponent); ok { + r0 = rf(components...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(processorprovider.ProviderComponent) + } + } + + if rf, ok := ret.Get(1).(func(...processorprovider.ProviderComponent) error); ok { + r1 = rf(components...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProcessorProvider_CreatePage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreatePage' +type ProcessorProvider_CreatePage_Call struct { + *mock.Call +} + +// CreatePage is a helper method to define mock.On call +// - components ...processorprovider.ProviderComponent +func (_e *ProcessorProvider_Expecter) CreatePage(components ...interface{}) *ProcessorProvider_CreatePage_Call { + return &ProcessorProvider_CreatePage_Call{Call: _e.mock.On("CreatePage", + append([]interface{}{}, components...)...)} +} + +func (_c *ProcessorProvider_CreatePage_Call) Run(run func(components ...processorprovider.ProviderComponent)) *ProcessorProvider_CreatePage_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]processorprovider.ProviderComponent, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(processorprovider.ProviderComponent) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_CreatePage_Call) Return(_a0 processorprovider.ProviderComponent, _a1 error) *ProcessorProvider_CreatePage_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ProcessorProvider_CreatePage_Call) RunAndReturn(run func(...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error)) *ProcessorProvider_CreatePage_Call { _c.Call.Return(run) return _c } // CreateQrCode provides a mock function with given fields: value, props -func (_m *ProcessorProvider) CreateQrCode(value string, props ...*propsmapper.Rect) processorprovider.PDFComponent { +func (_m *ProcessorProvider) CreateQrCode(value string, props ...*propsmapper.Rect) processorprovider.ProviderComponent { _va := make([]interface{}, len(props)) for _i := range props { _va[_i] = props[_i] @@ -274,12 +418,12 @@ func (_m *ProcessorProvider) CreateQrCode(value string, props ...*propsmapper.Re panic("no return value specified for CreateQrCode") } - var r0 processorprovider.PDFComponent - if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Rect) processorprovider.PDFComponent); ok { + var r0 processorprovider.ProviderComponent + if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Rect) processorprovider.ProviderComponent); ok { r0 = rf(value, props...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(processorprovider.PDFComponent) + r0 = ret.Get(0).(processorprovider.ProviderComponent) } } @@ -312,18 +456,91 @@ func (_c *ProcessorProvider_CreateQrCode_Call) Run(run func(value string, props return _c } -func (_c *ProcessorProvider_CreateQrCode_Call) Return(_a0 processorprovider.PDFComponent) *ProcessorProvider_CreateQrCode_Call { +func (_c *ProcessorProvider_CreateQrCode_Call) Return(_a0 processorprovider.ProviderComponent) *ProcessorProvider_CreateQrCode_Call { _c.Call.Return(_a0) return _c } -func (_c *ProcessorProvider_CreateQrCode_Call) RunAndReturn(run func(string, ...*propsmapper.Rect) processorprovider.PDFComponent) *ProcessorProvider_CreateQrCode_Call { +func (_c *ProcessorProvider_CreateQrCode_Call) RunAndReturn(run func(string, ...*propsmapper.Rect) processorprovider.ProviderComponent) *ProcessorProvider_CreateQrCode_Call { + _c.Call.Return(run) + return _c +} + +// CreateRow provides a mock function with given fields: height, components +func (_m *ProcessorProvider) CreateRow(height float64, components ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error) { + _va := make([]interface{}, len(components)) + for _i := range components { + _va[_i] = components[_i] + } + var _ca []interface{} + _ca = append(_ca, height) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for CreateRow") + } + + var r0 processorprovider.ProviderComponent + var r1 error + if rf, ok := ret.Get(0).(func(float64, ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error)); ok { + return rf(height, components...) + } + if rf, ok := ret.Get(0).(func(float64, ...processorprovider.ProviderComponent) processorprovider.ProviderComponent); ok { + r0 = rf(height, components...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(processorprovider.ProviderComponent) + } + } + + if rf, ok := ret.Get(1).(func(float64, ...processorprovider.ProviderComponent) error); ok { + r1 = rf(height, components...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProcessorProvider_CreateRow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateRow' +type ProcessorProvider_CreateRow_Call struct { + *mock.Call +} + +// CreateRow is a helper method to define mock.On call +// - height float64 +// - components ...processorprovider.ProviderComponent +func (_e *ProcessorProvider_Expecter) CreateRow(height interface{}, components ...interface{}) *ProcessorProvider_CreateRow_Call { + return &ProcessorProvider_CreateRow_Call{Call: _e.mock.On("CreateRow", + append([]interface{}{height}, components...)...)} +} + +func (_c *ProcessorProvider_CreateRow_Call) Run(run func(height float64, components ...processorprovider.ProviderComponent)) *ProcessorProvider_CreateRow_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]processorprovider.ProviderComponent, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(processorprovider.ProviderComponent) + } + } + run(args[0].(float64), variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_CreateRow_Call) Return(_a0 processorprovider.ProviderComponent, _a1 error) *ProcessorProvider_CreateRow_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ProcessorProvider_CreateRow_Call) RunAndReturn(run func(float64, ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error)) *ProcessorProvider_CreateRow_Call { _c.Call.Return(run) return _c } // CreateSignature provides a mock function with given fields: value, props -func (_m *ProcessorProvider) CreateSignature(value string, props ...*propsmapper.Signature) processorprovider.PDFComponent { +func (_m *ProcessorProvider) CreateSignature(value string, props ...*propsmapper.Signature) processorprovider.ProviderComponent { _va := make([]interface{}, len(props)) for _i := range props { _va[_i] = props[_i] @@ -337,12 +554,12 @@ func (_m *ProcessorProvider) CreateSignature(value string, props ...*propsmapper panic("no return value specified for CreateSignature") } - var r0 processorprovider.PDFComponent - if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Signature) processorprovider.PDFComponent); ok { + var r0 processorprovider.ProviderComponent + if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Signature) processorprovider.ProviderComponent); ok { r0 = rf(value, props...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(processorprovider.PDFComponent) + r0 = ret.Get(0).(processorprovider.ProviderComponent) } } @@ -375,18 +592,18 @@ func (_c *ProcessorProvider_CreateSignature_Call) Run(run func(value string, pro return _c } -func (_c *ProcessorProvider_CreateSignature_Call) Return(_a0 processorprovider.PDFComponent) *ProcessorProvider_CreateSignature_Call { +func (_c *ProcessorProvider_CreateSignature_Call) Return(_a0 processorprovider.ProviderComponent) *ProcessorProvider_CreateSignature_Call { _c.Call.Return(_a0) return _c } -func (_c *ProcessorProvider_CreateSignature_Call) RunAndReturn(run func(string, ...*propsmapper.Signature) processorprovider.PDFComponent) *ProcessorProvider_CreateSignature_Call { +func (_c *ProcessorProvider_CreateSignature_Call) RunAndReturn(run func(string, ...*propsmapper.Signature) processorprovider.ProviderComponent) *ProcessorProvider_CreateSignature_Call { _c.Call.Return(run) return _c } // CreateText provides a mock function with given fields: value, props -func (_m *ProcessorProvider) CreateText(value string, props ...*propsmapper.Text) processorprovider.PDFComponent { +func (_m *ProcessorProvider) CreateText(value string, props ...*propsmapper.Text) processorprovider.ProviderComponent { _va := make([]interface{}, len(props)) for _i := range props { _va[_i] = props[_i] @@ -400,12 +617,12 @@ func (_m *ProcessorProvider) CreateText(value string, props ...*propsmapper.Text panic("no return value specified for CreateText") } - var r0 processorprovider.PDFComponent - if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Text) processorprovider.PDFComponent); ok { + var r0 processorprovider.ProviderComponent + if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Text) processorprovider.ProviderComponent); ok { r0 = rf(value, props...) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(processorprovider.PDFComponent) + r0 = ret.Get(0).(processorprovider.ProviderComponent) } } @@ -438,12 +655,12 @@ func (_c *ProcessorProvider_CreateText_Call) Run(run func(value string, props .. return _c } -func (_c *ProcessorProvider_CreateText_Call) Return(_a0 processorprovider.PDFComponent) *ProcessorProvider_CreateText_Call { +func (_c *ProcessorProvider_CreateText_Call) Return(_a0 processorprovider.ProviderComponent) *ProcessorProvider_CreateText_Call { _c.Call.Return(_a0) return _c } -func (_c *ProcessorProvider_CreateText_Call) RunAndReturn(run func(string, ...*propsmapper.Text) processorprovider.PDFComponent) *ProcessorProvider_CreateText_Call { +func (_c *ProcessorProvider_CreateText_Call) RunAndReturn(run func(string, ...*propsmapper.Text) processorprovider.ProviderComponent) *ProcessorProvider_CreateText_Call { _c.Call.Return(run) return _c } diff --git a/mocks/ProcessorRepository.go b/mocks/ProcessorRepository.go new file mode 100644 index 00000000..e1fe28c2 --- /dev/null +++ b/mocks/ProcessorRepository.go @@ -0,0 +1,203 @@ +// Code generated by mockery v2.42.0. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// ProcessorRepository is an autogenerated mock type for the ProcessorRepository type +type ProcessorRepository struct { + mock.Mock +} + +type ProcessorRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *ProcessorRepository) EXPECT() *ProcessorRepository_Expecter { + return &ProcessorRepository_Expecter{mock: &_m.Mock} +} + +// GetDocument provides a mock function with given fields: documentName +func (_m *ProcessorRepository) GetDocument(documentName string) (string, []byte, error) { + ret := _m.Called(documentName) + + if len(ret) == 0 { + panic("no return value specified for GetDocument") + } + + var r0 string + var r1 []byte + var r2 error + if rf, ok := ret.Get(0).(func(string) (string, []byte, error)); ok { + return rf(documentName) + } + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(documentName) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(string) []byte); ok { + r1 = rf(documentName) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).([]byte) + } + } + + if rf, ok := ret.Get(2).(func(string) error); ok { + r2 = rf(documentName) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// ProcessorRepository_GetDocument_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDocument' +type ProcessorRepository_GetDocument_Call struct { + *mock.Call +} + +// GetDocument is a helper method to define mock.On call +// - documentName string +func (_e *ProcessorRepository_Expecter) GetDocument(documentName interface{}) *ProcessorRepository_GetDocument_Call { + return &ProcessorRepository_GetDocument_Call{Call: _e.mock.On("GetDocument", documentName)} +} + +func (_c *ProcessorRepository_GetDocument_Call) Run(run func(documentName string)) *ProcessorRepository_GetDocument_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *ProcessorRepository_GetDocument_Call) Return(extension string, doc []byte, err error) *ProcessorRepository_GetDocument_Call { + _c.Call.Return(extension, doc, err) + return _c +} + +func (_c *ProcessorRepository_GetDocument_Call) RunAndReturn(run func(string) (string, []byte, error)) *ProcessorRepository_GetDocument_Call { + _c.Call.Return(run) + return _c +} + +// ReadTemplate provides a mock function with given fields: templateName +func (_m *ProcessorRepository) ReadTemplate(templateName string) (map[string]interface{}, error) { + ret := _m.Called(templateName) + + if len(ret) == 0 { + panic("no return value specified for ReadTemplate") + } + + var r0 map[string]interface{} + var r1 error + if rf, ok := ret.Get(0).(func(string) (map[string]interface{}, error)); ok { + return rf(templateName) + } + if rf, ok := ret.Get(0).(func(string) map[string]interface{}); ok { + r0 = rf(templateName) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[string]interface{}) + } + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(templateName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProcessorRepository_ReadTemplate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReadTemplate' +type ProcessorRepository_ReadTemplate_Call struct { + *mock.Call +} + +// ReadTemplate is a helper method to define mock.On call +// - templateName string +func (_e *ProcessorRepository_Expecter) ReadTemplate(templateName interface{}) *ProcessorRepository_ReadTemplate_Call { + return &ProcessorRepository_ReadTemplate_Call{Call: _e.mock.On("ReadTemplate", templateName)} +} + +func (_c *ProcessorRepository_ReadTemplate_Call) Run(run func(templateName string)) *ProcessorRepository_ReadTemplate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *ProcessorRepository_ReadTemplate_Call) Return(_a0 map[string]interface{}, _a1 error) *ProcessorRepository_ReadTemplate_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ProcessorRepository_ReadTemplate_Call) RunAndReturn(run func(string) (map[string]interface{}, error)) *ProcessorRepository_ReadTemplate_Call { + _c.Call.Return(run) + return _c +} + +// RegisterTemplate provides a mock function with given fields: templateName, template +func (_m *ProcessorRepository) RegisterTemplate(templateName string, template map[string]interface{}) error { + ret := _m.Called(templateName, template) + + if len(ret) == 0 { + panic("no return value specified for RegisterTemplate") + } + + var r0 error + if rf, ok := ret.Get(0).(func(string, map[string]interface{}) error); ok { + r0 = rf(templateName, template) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ProcessorRepository_RegisterTemplate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterTemplate' +type ProcessorRepository_RegisterTemplate_Call struct { + *mock.Call +} + +// RegisterTemplate is a helper method to define mock.On call +// - templateName string +// - template map[string]interface{} +func (_e *ProcessorRepository_Expecter) RegisterTemplate(templateName interface{}, template interface{}) *ProcessorRepository_RegisterTemplate_Call { + return &ProcessorRepository_RegisterTemplate_Call{Call: _e.mock.On("RegisterTemplate", templateName, template)} +} + +func (_c *ProcessorRepository_RegisterTemplate_Call) Run(run func(templateName string, template map[string]interface{})) *ProcessorRepository_RegisterTemplate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(map[string]interface{})) + }) + return _c +} + +func (_c *ProcessorRepository_RegisterTemplate_Call) Return(_a0 error) *ProcessorRepository_RegisterTemplate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorRepository_RegisterTemplate_Call) RunAndReturn(run func(string, map[string]interface{}) error) *ProcessorRepository_RegisterTemplate_Call { + _c.Call.Return(run) + return _c +} + +// NewProcessorRepository creates a new instance of ProcessorRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewProcessorRepository(t interface { + mock.TestingT + Cleanup(func()) +}, +) *ProcessorRepository { + mock := &ProcessorRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/ProviderComponent.go b/mocks/ProviderComponent.go new file mode 100644 index 00000000..6dd0acc9 --- /dev/null +++ b/mocks/ProviderComponent.go @@ -0,0 +1,120 @@ +// Code generated by mockery v2.42.0. DO NOT EDIT. + +package mocks + +import ( + core "github.com/johnfercher/maroto/v2/pkg/core" + entity "github.com/johnfercher/maroto/v2/pkg/core/entity" + + mock "github.com/stretchr/testify/mock" + + node "github.com/johnfercher/go-tree/node" +) + +// ProviderComponent is an autogenerated mock type for the ProviderComponent type +type ProviderComponent struct { + mock.Mock +} + +type ProviderComponent_Expecter struct { + mock *mock.Mock +} + +func (_m *ProviderComponent) EXPECT() *ProviderComponent_Expecter { + return &ProviderComponent_Expecter{mock: &_m.Mock} +} + +// GetStructure provides a mock function with given fields: +func (_m *ProviderComponent) GetStructure() *node.Node[core.Structure] { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetStructure") + } + + var r0 *node.Node[core.Structure] + if rf, ok := ret.Get(0).(func() *node.Node[core.Structure]); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*node.Node[core.Structure]) + } + } + + return r0 +} + +// ProviderComponent_GetStructure_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetStructure' +type ProviderComponent_GetStructure_Call struct { + *mock.Call +} + +// GetStructure is a helper method to define mock.On call +func (_e *ProviderComponent_Expecter) GetStructure() *ProviderComponent_GetStructure_Call { + return &ProviderComponent_GetStructure_Call{Call: _e.mock.On("GetStructure")} +} + +func (_c *ProviderComponent_GetStructure_Call) Run(run func()) *ProviderComponent_GetStructure_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ProviderComponent_GetStructure_Call) Return(_a0 *node.Node[core.Structure]) *ProviderComponent_GetStructure_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProviderComponent_GetStructure_Call) RunAndReturn(run func() *node.Node[core.Structure]) *ProviderComponent_GetStructure_Call { + _c.Call.Return(run) + return _c +} + +// SetConfig provides a mock function with given fields: config +func (_m *ProviderComponent) SetConfig(config *entity.Config) { + _m.Called(config) +} + +// ProviderComponent_SetConfig_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetConfig' +type ProviderComponent_SetConfig_Call struct { + *mock.Call +} + +// SetConfig is a helper method to define mock.On call +// - config *entity.Config +func (_e *ProviderComponent_Expecter) SetConfig(config interface{}) *ProviderComponent_SetConfig_Call { + return &ProviderComponent_SetConfig_Call{Call: _e.mock.On("SetConfig", config)} +} + +func (_c *ProviderComponent_SetConfig_Call) Run(run func(config *entity.Config)) *ProviderComponent_SetConfig_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*entity.Config)) + }) + return _c +} + +func (_c *ProviderComponent_SetConfig_Call) Return() *ProviderComponent_SetConfig_Call { + _c.Call.Return() + return _c +} + +func (_c *ProviderComponent_SetConfig_Call) RunAndReturn(run func(*entity.Config)) *ProviderComponent_SetConfig_Call { + _c.Call.Return(run) + return _c +} + +// NewProviderComponent creates a new instance of ProviderComponent. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewProviderComponent(t interface { + mock.TestingT + Cleanup(func()) +}, +) *ProviderComponent { + mock := &ProviderComponent{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/processor/core/core.go b/pkg/processor/core/core.go index 9969d695..106cd76f 100644 --- a/pkg/processor/core/core.go +++ b/pkg/processor/core/core.go @@ -5,7 +5,7 @@ type Processor interface { GenerateDocument(templateName string, content string) []byte } -type Repository interface { +type ProcessorRepository interface { RegisterTemplate(templateName string, template map[string]any) error ReadTemplate(templateName string) (map[string]any, error) GetDocument(documentName string) (extension string, doc []byte, err error) diff --git a/pkg/processor/mappers/abstractfactory/abstractfactory.go b/pkg/processor/mappers/abstractfactory/abstractfactory.go index 44d81058..60dbfc23 100644 --- a/pkg/processor/mappers/abstractfactory/abstractfactory.go +++ b/pkg/processor/mappers/abstractfactory/abstractfactory.go @@ -15,11 +15,11 @@ import ( ) type abstractFactoryMaps struct { - repository core.Repository + repository core.ProcessorRepository } // NewAbstractFactoryMaps is responsible for creating an object that encapsulates the creation of components -func NewAbstractFactoryMaps(repository core.Repository) *abstractFactoryMaps { +func NewAbstractFactoryMaps(repository core.ProcessorRepository) *abstractFactoryMaps { return &abstractFactoryMaps{repository: repository} } diff --git a/pkg/processor/mappers/component_mapper.go b/pkg/processor/mappers/component_mapper.go index 2a0e41c9..ae8993cc 100644 --- a/pkg/processor/mappers/component_mapper.go +++ b/pkg/processor/mappers/component_mapper.go @@ -1,13 +1,21 @@ package mappers -import "github.com/johnfercher/maroto/v2/pkg/processor/components" +import ( + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" +) +// GenerateComponent defines the signature of a factory method, it is used +// to make it possible to send a factory method to another object type GenerateComponent func(document interface{}, sourceKey string) (Componentmapper, error) +// The Component Mapper Interface defines the mapper component, the mapper component is responsible for +// transforming the structured document into the pdf components type Componentmapper interface { - Generate(content map[string]interface{}) (components.PdfComponent, error) + Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) } +// The AbstractFactoryMaps interface defines the object responsible for wrapping the creation of components +// it is used to ensure decoupling between components type AbstractFactoryMaps interface { NewRow(document interface{}, sourceKey string) (Componentmapper, error) NewPage(document interface{}, sourceKey string) (Componentmapper, error) diff --git a/pkg/processor/mappers/components/codemapper/barcode.go b/pkg/processor/mappers/components/codemapper/barcode.go index 73bf3301..780df5dc 100644 --- a/pkg/processor/mappers/components/codemapper/barcode.go +++ b/pkg/processor/mappers/components/codemapper/barcode.go @@ -109,7 +109,7 @@ func (b *Barcode) getCode(content map[string]interface{}) (string, error) { return codeValid, nil } -func (b *Barcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { +func (b *Barcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { code, err := b.getCode(content) if err != nil { return nil, err @@ -117,7 +117,7 @@ func (b *Barcode) Generate(content map[string]interface{}, provider processorpro b.Code = code if b.Props != nil { - return provider.CreateBarCode(b.Code, b.Props), nil + return []processorprovider.ProviderComponent{provider.CreateBarCode(b.Code, b.Props)}, nil } - return provider.CreateBarCode(b.Code), nil + return []processorprovider.ProviderComponent{provider.CreateBarCode(b.Code)}, nil } diff --git a/pkg/processor/mappers/components/codemapper/matrixcode.go b/pkg/processor/mappers/components/codemapper/matrixcode.go index 9b584aa8..34abb60f 100644 --- a/pkg/processor/mappers/components/codemapper/matrixcode.go +++ b/pkg/processor/mappers/components/codemapper/matrixcode.go @@ -109,7 +109,7 @@ func (m *Matrixcode) getCode(content map[string]interface{}) (string, error) { return codeValid, nil } -func (m *Matrixcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { +func (m *Matrixcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { code, err := m.getCode(content) if err != nil { return nil, err @@ -117,7 +117,7 @@ func (m *Matrixcode) Generate(content map[string]interface{}, provider processor m.Code = code if m.Props != nil { - return provider.CreateMatrixCode(m.Code, m.Props), nil + return []processorprovider.ProviderComponent{provider.CreateMatrixCode(m.Code, m.Props)}, nil } - return provider.CreateMatrixCode(m.Code), nil + return []processorprovider.ProviderComponent{provider.CreateMatrixCode(m.Code)}, nil } diff --git a/pkg/processor/mappers/components/codemapper/qrcode.go b/pkg/processor/mappers/components/codemapper/qrcode.go index d74c893b..19e87e90 100644 --- a/pkg/processor/mappers/components/codemapper/qrcode.go +++ b/pkg/processor/mappers/components/codemapper/qrcode.go @@ -109,7 +109,7 @@ func (q *Qrcode) getCode(content map[string]interface{}) (string, error) { return codeValid, nil } -func (q *Qrcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { +func (q *Qrcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { code, err := q.getCode(content) if err != nil { return nil, err @@ -117,7 +117,7 @@ func (q *Qrcode) Generate(content map[string]interface{}, provider processorprov q.Code = code if q.Props != nil { - return provider.CreateQrCode(q.Code, q.Props), nil + return []processorprovider.ProviderComponent{provider.CreateQrCode(q.Code, q.Props)}, nil } - return provider.CreateQrCode(q.Code), nil + return []processorprovider.ProviderComponent{provider.CreateQrCode(q.Code)}, nil } diff --git a/pkg/processor/mappers/components/imagemapper/image.go b/pkg/processor/mappers/components/imagemapper/image.go index ba0e429b..6768093c 100644 --- a/pkg/processor/mappers/components/imagemapper/image.go +++ b/pkg/processor/mappers/components/imagemapper/image.go @@ -4,7 +4,7 @@ package imagemapper import ( "fmt" - "github.com/johnfercher/maroto/v2/pkg/processor/core" + processorcore "github.com/johnfercher/maroto/v2/pkg/processor/core" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) @@ -13,10 +13,10 @@ type Image struct { Path string SourceKey string Props *propsmapper.Rect - Repository core.Repository + Repository processorcore.ProcessorRepository } -func NewImage(templateImage interface{}, repository core.Repository) (*Image, error) { +func NewImage(templateImage interface{}, repository processorcore.ProcessorRepository) (*Image, error) { imageMap, ok := templateImage.(map[string]interface{}) if !ok { return nil, fmt.Errorf("ensure image can be converted to map[string] interface{}") @@ -103,7 +103,7 @@ func (i *Image) getImagePath(content map[string]interface{}) (string, error) { return imageValid, nil } -func (i *Image) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { +func (i *Image) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { path, err := i.getImagePath(content) if err != nil { return nil, err @@ -115,7 +115,7 @@ func (i *Image) Generate(content map[string]interface{}, provider processorprovi } if i.Props != nil { - return provider.CreateImage(img, extension, i.Props), nil + return []processorprovider.ProviderComponent{provider.CreateImage(img, extension, i.Props)}, nil } - return provider.CreateImage(img, extension), nil + return []processorprovider.ProviderComponent{provider.CreateImage(img, extension)}, nil } diff --git a/pkg/processor/mappers/components/imagemapper/image_test.go b/pkg/processor/mappers/components/imagemapper/image_test.go index bce80f81..acf7e10c 100644 --- a/pkg/processor/mappers/components/imagemapper/image_test.go +++ b/pkg/processor/mappers/components/imagemapper/image_test.go @@ -12,7 +12,7 @@ import ( func TestNewImage(t *testing.T) { t.Run("when invalid image is sent, should return an error", func(t *testing.T) { imageTemplate := 1 - repository := mocks.NewRepository(t) + repository := mocks.NewProcessorRepository(t) image, err := imagemapper.NewImage(imageTemplate, repository) @@ -23,7 +23,7 @@ func TestNewImage(t *testing.T) { imageTemplate := map[string]interface{}{ "source_key": "image", } - repository := mocks.NewRepository(t) + repository := mocks.NewProcessorRepository(t) image, err := imagemapper.NewImage(imageTemplate, repository) @@ -35,7 +35,7 @@ func TestNewImage(t *testing.T) { "props": 1, "source_key": "name", } - repository := mocks.NewRepository(t) + repository := mocks.NewProcessorRepository(t) image, err := imagemapper.NewImage(imageTemplate, repository) @@ -47,7 +47,7 @@ func TestNewImage(t *testing.T) { "invalid_field": 1, "source_key": "name", } - repository := mocks.NewRepository(t) + repository := mocks.NewProcessorRepository(t) image, err := imagemapper.NewImage(imageTemplate, repository) @@ -56,7 +56,7 @@ func TestNewImage(t *testing.T) { }) t.Run("when source_key is not sent, should return an error", func(t *testing.T) { imageTemplate := map[string]interface{}{} - repository := mocks.NewRepository(t) + repository := mocks.NewProcessorRepository(t) image, err := imagemapper.NewImage(imageTemplate, repository) @@ -67,7 +67,7 @@ func TestNewImage(t *testing.T) { imageTemplate := map[string]interface{}{ "source_key": 123, } - repository := mocks.NewRepository(t) + repository := mocks.NewProcessorRepository(t) image, err := imagemapper.NewImage(imageTemplate, repository) @@ -76,7 +76,7 @@ func TestNewImage(t *testing.T) { }) t.Run("when source_key and path are not sent, should return an error", func(t *testing.T) { imageTemplate := map[string]interface{}{} - repository := mocks.NewRepository(t) + repository := mocks.NewProcessorRepository(t) image, err := imagemapper.NewImage(imageTemplate, repository) @@ -87,7 +87,7 @@ func TestNewImage(t *testing.T) { imageTemplate := map[string]interface{}{ "source_key": "icon", } - repository := mocks.NewRepository(t) + repository := mocks.NewProcessorRepository(t) image, err := imagemapper.NewImage(imageTemplate, repository) @@ -101,7 +101,7 @@ func TestNewImage(t *testing.T) { "left": 10.0, }, } - repository := mocks.NewRepository(t) + repository := mocks.NewProcessorRepository(t) image, err := imagemapper.NewImage(imageTemplate, repository) @@ -114,7 +114,7 @@ func TestImageGenerate(t *testing.T) { t.Run("if image is not found, should return an error", func(t *testing.T) { content := map[string]interface{}{} provider := mocks.NewProcessorProvider(t) - repository := mocks.NewRepository(t) + repository := mocks.NewProcessorRepository(t) image := imagemapper.Image{SourceKey: "code", Repository: repository} component, err := image.Generate(content, provider) @@ -140,7 +140,7 @@ func TestImageGenerate(t *testing.T) { } provider := mocks.NewProcessorProvider(t) provider.EXPECT().CreateImage([]byte("image"), "png").Return(nil) - repository := mocks.NewRepository(t) + repository := mocks.NewProcessorRepository(t) repository.EXPECT().GetDocument("path.png").Return("png", []byte("image"), nil) image := imagemapper.Image{SourceKey: "Path", Repository: repository} @@ -154,7 +154,7 @@ func TestImageGenerate(t *testing.T) { content := map[string]interface{}{} provider := mocks.NewProcessorProvider(t) - repository := mocks.NewRepository(t) + repository := mocks.NewProcessorRepository(t) repository.EXPECT().GetDocument("path.png").Return("", nil, fmt.Errorf("any")) image := imagemapper.Image{Path: "path.png", Repository: repository} @@ -168,7 +168,7 @@ func TestImageGenerate(t *testing.T) { provider := mocks.NewProcessorProvider(t) provider.EXPECT().CreateImage([]byte("image"), "png").Return(nil) - repository := mocks.NewRepository(t) + repository := mocks.NewProcessorRepository(t) repository.EXPECT().GetDocument("path.png").Return("png", []byte("image"), nil) image := imagemapper.Image{Path: "path.png", Repository: repository} diff --git a/pkg/processor/mappers/components/linemapper/line.go b/pkg/processor/mappers/components/linemapper/line.go index af988060..584f6045 100644 --- a/pkg/processor/mappers/components/linemapper/line.go +++ b/pkg/processor/mappers/components/linemapper/line.go @@ -60,6 +60,6 @@ func (l *Line) setProps(templateProps interface{}) error { return nil } -func (l *Line) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { - return provider.CreateLine(l.Props), nil +func (l *Line) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { + return []processorprovider.ProviderComponent{provider.CreateLine(l.Props)}, nil } diff --git a/pkg/processor/mappers/components/signaturemapper/signature.go b/pkg/processor/mappers/components/signaturemapper/signature.go index 6e7864d0..38c19770 100644 --- a/pkg/processor/mappers/components/signaturemapper/signature.go +++ b/pkg/processor/mappers/components/signaturemapper/signature.go @@ -108,7 +108,7 @@ func (s *Signature) getSignature(content map[string]interface{}) (string, error) return signatureValid, nil } -func (s *Signature) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { +func (s *Signature) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { signature, err := s.getSignature(content) if err != nil { return nil, err @@ -116,7 +116,7 @@ func (s *Signature) Generate(content map[string]interface{}, provider processorp s.Value = signature if s.Props != nil { - return provider.CreateSignature(s.Value, s.Props), nil + return []processorprovider.ProviderComponent{provider.CreateSignature(s.Value, s.Props)}, nil } - return provider.CreateSignature(s.Value), nil + return []processorprovider.ProviderComponent{provider.CreateSignature(s.Value)}, nil } diff --git a/pkg/processor/mappers/components/textmapper/text.go b/pkg/processor/mappers/components/textmapper/text.go index f79837d4..98c2499a 100644 --- a/pkg/processor/mappers/components/textmapper/text.go +++ b/pkg/processor/mappers/components/textmapper/text.go @@ -107,7 +107,7 @@ func (t *Text) getValue(content map[string]interface{}) (string, error) { return textValid, nil } -func (t *Text) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (processorprovider.PDFComponent, error) { +func (t *Text) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { signature, err := t.getValue(content) if err != nil { return nil, err @@ -115,7 +115,7 @@ func (t *Text) Generate(content map[string]interface{}, provider processorprovid t.Value = signature if t.Props != nil { - return provider.CreateText(t.Value, t.Props), nil + return []processorprovider.ProviderComponent{provider.CreateText(t.Value, t.Props)}, nil } - return provider.CreateText(t.Value), nil + return []processorprovider.ProviderComponent{provider.CreateText(t.Value)}, nil } diff --git a/pkg/processor/mappers/documentmapper/document.go b/pkg/processor/mappers/documentmapper/document.go index d895c63f..0157ecb8 100644 --- a/pkg/processor/mappers/documentmapper/document.go +++ b/pkg/processor/mappers/documentmapper/document.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - "github.com/johnfercher/maroto/v2/pkg/processor/components/pdf" + "github.com/johnfercher/maroto/v2/pkg/core" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/buildermapper" ) @@ -135,6 +135,6 @@ func (p *Document) setPages(pagesDoc interface{}) error { } // generate is responsible for the builder pdf according to the submitted content -func (p *Document) Generate(content map[string]interface{}) (*pdf.Pdf, error) { +func (p *Document) Generate(content map[string]interface{}) (*core.Component, error) { return nil, nil } diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index c64b8fcd..50ebf5f4 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -11,7 +11,7 @@ import ( ) type processor struct { - repository core.Repository + repository core.ProcessorRepository deserializer core.Deserializer loader core.Loader } diff --git a/pkg/processor/processorprovider/provider.go b/pkg/processor/processorprovider/provider.go index c51c9e93..fb168e55 100644 --- a/pkg/processor/processorprovider/provider.go +++ b/pkg/processor/processorprovider/provider.go @@ -5,20 +5,21 @@ import ( "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" ) -// PDFComponent provides the interface of the components that -// will be generated by the provider (Maroto) -type PDFComponent interface { - core.Component +type ProviderComponent interface { + core.Node } // ProcessorProvider provides an interface with all the methods that // Maroto provides for pdf builder type ProcessorProvider interface { - CreateText(value string, props ...*propsmapper.Text) PDFComponent - CreateSignature(value string, props ...*propsmapper.Signature) PDFComponent - CreateBarCode(value string, props ...*propsmapper.Barcode) PDFComponent - CreateMatrixCode(value string, props ...*propsmapper.Rect) PDFComponent - CreateQrCode(value string, props ...*propsmapper.Rect) PDFComponent - CreateImage(value []byte, extension string, props ...*propsmapper.Rect) PDFComponent - CreateLine(props *propsmapper.Line) PDFComponent + CreatePage(components ...ProviderComponent) (ProviderComponent, error) + CreateRow(height float64, components ...ProviderComponent) (ProviderComponent, error) + CreateCol(size int, components ...ProviderComponent) (ProviderComponent, error) + CreateText(value string, props ...*propsmapper.Text) ProviderComponent + CreateSignature(value string, props ...*propsmapper.Signature) ProviderComponent + CreateBarCode(value string, props ...*propsmapper.Barcode) ProviderComponent + CreateMatrixCode(value string, props ...*propsmapper.Rect) ProviderComponent + CreateQrCode(value string, props ...*propsmapper.Rect) ProviderComponent + CreateImage(value []byte, extension string, props ...*propsmapper.Rect) ProviderComponent + CreateLine(props *propsmapper.Line) ProviderComponent } From b66d83e83732f89e15861a55b0f36ce09357c9d8 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Mon, 4 Nov 2024 22:31:12 -0300 Subject: [PATCH 061/116] test: validate row creation --- .../mappers/components/rowmapper/row_test.go | 51 ++++++++++++++++ .../processorprovider/Maroto_test.go | 59 +++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/pkg/processor/mappers/components/rowmapper/row_test.go b/pkg/processor/mappers/components/rowmapper/row_test.go index b279a2de..9192cfa6 100644 --- a/pkg/processor/mappers/components/rowmapper/row_test.go +++ b/pkg/processor/mappers/components/rowmapper/row_test.go @@ -1,11 +1,14 @@ package rowmapper_test import ( + "fmt" "testing" "github.com/johnfercher/maroto/v2/mocks" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/rowmapper" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" ) func TestNewRow(t *testing.T) { @@ -61,3 +64,51 @@ func TestNewRow(t *testing.T) { assert.NotNil(t, err) }) } + +func TestGenerate(t *testing.T) { + t.Run("when content no has source_key, should return an error", func(t *testing.T) { + content := map[string]interface{}{} + factory := mocks.NewAbstractFactoryMaps(t) + provider := mocks.NewProcessorProvider(t) + + row := rowmapper.Row{Height: 10, Cols: make([]mappers.Componentmapper, 0), Factory: factory, SourceKey: "test"} + newRow, err := row.Generate(content, provider) + + assert.NotNil(t, err) + assert.Nil(t, newRow) + }) + t.Run("when row no has row, it should no sent row", func(t *testing.T) { + content := map[string]interface{}{"content": map[string]interface{}{"text": "value"}} + factory := mocks.NewAbstractFactoryMaps(t) + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateRow(10.0).Return(nil, nil) + + row := rowmapper.Row{Height: 10.0, Cols: make([]mappers.Componentmapper, 0), Factory: factory, SourceKey: "content"} + _, err := row.Generate(content, provider) + + assert.Nil(t, err) + }) + t.Run("when is not possible generate components, should return an error", func(t *testing.T) { + content := map[string]interface{}{"content": map[string]interface{}{"text": "value"}} + factory := mocks.NewAbstractFactoryMaps(t) + provider := mocks.NewProcessorProvider(t) + component := mocks.NewComponentmapper(t) + component.EXPECT().Generate(mock.Anything, provider).Return(nil, fmt.Errorf("any")) + + row := rowmapper.Row{Height: 10.0, Cols: []mappers.Componentmapper{component}, Factory: factory, SourceKey: "content"} + _, err := row.Generate(content, provider) + + assert.NotNil(t, err) + }) + t.Run("when is not possible generate row, should return an error", func(t *testing.T) { + content := map[string]interface{}{"content": map[string]interface{}{"text": "value"}} + factory := mocks.NewAbstractFactoryMaps(t) + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateRow(10.0).Return(nil, fmt.Errorf("any")) + + row := rowmapper.Row{Height: 10.0, Cols: make([]mappers.Componentmapper, 0), Factory: factory, SourceKey: "content"} + _, err := row.Generate(content, provider) + + assert.NotNil(t, err) + }) +} diff --git a/pkg/processor/processorprovider/Maroto_test.go b/pkg/processor/processorprovider/Maroto_test.go index b672135d..768aa124 100644 --- a/pkg/processor/processorprovider/Maroto_test.go +++ b/pkg/processor/processorprovider/Maroto_test.go @@ -4,6 +4,8 @@ import ( "testing" "github.com/johnfercher/maroto/v2/pkg/components/code" + "github.com/johnfercher/maroto/v2/pkg/components/row" + "github.com/johnfercher/maroto/v2/pkg/components/text" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" "github.com/johnfercher/maroto/v2/pkg/test" @@ -100,3 +102,60 @@ func TestCreateText(t *testing.T) { test.New(t).Assert(barcode.GetStructure()).Equals("processor/provider/text.json") }) } + +func TestCreateCol(t *testing.T) { + t.Run("when CreateCol is called, should generate a col", func(t *testing.T) { + m := processorprovider.NewMaroto() + text := text.New("test") + + col, err := m.CreateCol(10, text) + + assert.Nil(t, err) + assert.NotNil(t, col) + }) + + t.Run("when invalid components are sent, should return an error", func(t *testing.T) { + m := processorprovider.NewMaroto() + page, err := m.CreatePage(text.NewCol(10, "10")) + + assert.Nil(t, page) + assert.NotNil(t, err) + }) +} + +func TestCreateRow(t *testing.T) { + t.Run("when CreateRow is called, should generate a row", func(t *testing.T) { + m := processorprovider.NewMaroto() + text := text.NewCol(12, "test") + + col, err := m.CreateRow(10, text) + + assert.Nil(t, err) + assert.NotNil(t, col) + }) + + t.Run("when invalid components are sent, should return an error", func(t *testing.T) { + m := processorprovider.NewMaroto() + page, err := m.CreatePage(text.New("10")) + + assert.Nil(t, page) + assert.NotNil(t, err) + }) +} + +func TestCreatePage(t *testing.T) { + t.Run("when CreatePage is called, should generate a page", func(t *testing.T) { + m := processorprovider.NewMaroto() + page, err := m.CreatePage(row.New(10)) + + assert.Nil(t, err) + assert.NotNil(t, page) + }) + t.Run("when invalid components are sent, should return an error", func(t *testing.T) { + m := processorprovider.NewMaroto() + page, err := m.CreatePage(text.New("10")) + + assert.Nil(t, page) + assert.NotNil(t, err) + }) +} From f041d5c35fbb447ea4a2eff07397b5662f8a17c8 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Mon, 4 Nov 2024 22:31:30 -0300 Subject: [PATCH 062/116] feat: create row component --- .../mappers/components/rowmapper/row.go | 51 +++++++++++++--- pkg/processor/processorprovider/Maroto.go | 61 ++++++++++++++++--- 2 files changed, 94 insertions(+), 18 deletions(-) diff --git a/pkg/processor/mappers/components/rowmapper/row.go b/pkg/processor/mappers/components/rowmapper/row.go index a6850829..f53abc48 100644 --- a/pkg/processor/mappers/components/rowmapper/row.go +++ b/pkg/processor/mappers/components/rowmapper/row.go @@ -4,14 +4,15 @@ package rowmapper import ( "fmt" - "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Row struct { - Height float64 - Cols []mappers.Componentmapper - factory mappers.AbstractFactoryMaps + Height float64 + Cols []mappers.Componentmapper + Factory mappers.AbstractFactoryMaps + SourceKey string } func NewRow(templateRows interface{}, sourceKey string, factory mappers.AbstractFactoryMaps) (*Row, error) { @@ -20,9 +21,10 @@ func NewRow(templateRows interface{}, sourceKey string, factory mappers.Abstract return nil, fmt.Errorf("ensure that rows can be converted to map[string] interface{}") } row := &Row{ - Height: 0, - Cols: make([]mappers.Componentmapper, 0), - factory: factory, + Height: 0, + Cols: make([]mappers.Componentmapper, 0), + Factory: factory, + SourceKey: sourceKey, } err := row.addComponents(mapRows) @@ -67,7 +69,7 @@ func (r *Row) setCols(template interface{}) error { r.Cols = make([]mappers.Componentmapper, len(cols)) for i, col := range cols { - newCol, err := r.factory.NewCol(col) + newCol, err := r.Factory.NewCol(col) if err != nil { return err } @@ -86,6 +88,35 @@ func (r *Row) getFieldMappers() map[string]func(interface{}) error { } } -func (r *Row) Generate(content map[string]interface{}) (components.PdfComponent, error) { - return nil, nil +func (r *Row) getRowContent(content map[string]interface{}) (map[string]interface{}, error) { + rowContent, ok := content[r.SourceKey] + if !ok { + return nil, fmt.Errorf("the row needs the source key \"%s\", but it was not found", r.SourceKey) + } + if mapRow, ok := rowContent.(map[string]interface{}); ok { + return mapRow, nil + } + return nil, fmt.Errorf("ensure that the contents of the row \"%s\" can be converted to map[string]interface{}", r.SourceKey) +} + +func (r *Row) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { + rowContent, err := r.getRowContent(content) + if err != nil { + return nil, err + } + + cols := make([]processorprovider.ProviderComponent, 0, len(r.Cols)) + for _, col := range r.Cols { + newCol, err := col.Generate(rowContent, provider) + if err != nil { + return nil, err + } + cols = append(cols, newCol...) + } + + row, err := provider.CreateRow(r.Height, cols...) + if err != nil { + return nil, err + } + return []processorprovider.ProviderComponent{row}, nil } diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index 64580465..20f2768d 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -1,9 +1,14 @@ package processorprovider import ( + "fmt" + "github.com/johnfercher/maroto/v2/pkg/components/code" + "github.com/johnfercher/maroto/v2/pkg/components/col" "github.com/johnfercher/maroto/v2/pkg/components/image" "github.com/johnfercher/maroto/v2/pkg/components/line" + "github.com/johnfercher/maroto/v2/pkg/components/page" + "github.com/johnfercher/maroto/v2/pkg/components/row" "github.com/johnfercher/maroto/v2/pkg/components/signature" "github.com/johnfercher/maroto/v2/pkg/components/text" "github.com/johnfercher/maroto/v2/pkg/consts/align" @@ -27,19 +32,59 @@ func NewMaroto() *Maroto { return nil } -func (m *Maroto) CreateText(value string, textsProps ...*propsmapper.Text) PDFComponent { +func convertComponentType[T any](components ...ProviderComponent) ([]T, error) { + newComponents := make([]T, len(components)) + for i, component := range components { + validComponent, ok := component.(T) + if !ok { + return nil, fmt.Errorf("could not convert pdf components to a valid type") + } + newComponents[i] = validComponent + } + return newComponents, nil +} + +func (m *Maroto) CreatePage(components ...ProviderComponent) (ProviderComponent, error) { + newComponents, err := convertComponentType[core.Row](components...) + if err != nil { + return nil, err + } + + return page.New().Add(newComponents...), nil +} + +func (m *Maroto) CreateRow(height float64, components ...ProviderComponent) (ProviderComponent, error) { + newComponents, err := convertComponentType[core.Col](components...) + if err != nil { + return nil, err + } + + return row.New(height).Add(newComponents...), nil +} + +func (m *Maroto) CreateCol(size int, components ...ProviderComponent) (ProviderComponent, error) { + newComponents, err := convertComponentType[core.Component](components...) + if err != nil { + return nil, err + } + + return col.New(size).Add(newComponents...), nil +} + +func (m *Maroto) CreateText(value string, textsProps ...*propsmapper.Text) ProviderComponent { tProps := propsmapper.Text{} if len(textsProps) > 0 { tProps = *textsProps[0] } - return text.New(value, props.Text{Top: tProps.Top, Left: tProps.Left, Right: tProps.Right, Family: tProps.Family, + return text.New(value, props.Text{ + Top: tProps.Top, Left: tProps.Left, Right: tProps.Right, Family: tProps.Family, Style: fontstyle.Type(tProps.Style), Size: tProps.Size, Align: align.Type(tProps.Align), BreakLineStrategy: breakline.Strategy(tProps.BreakLineStrategy), VerticalPadding: tProps.VerticalPadding, Color: (*props.Color)(tProps.Color), Hyperlink: &tProps.Hyperlink, }) } -func (m *Maroto) CreateSignature(value string, signaturesProps ...*propsmapper.Signature) PDFComponent { +func (m *Maroto) CreateSignature(value string, signaturesProps ...*propsmapper.Signature) ProviderComponent { sProps := propsmapper.Signature{} if len(signaturesProps) > 0 { sProps = *signaturesProps[0] @@ -52,7 +97,7 @@ func (m *Maroto) CreateSignature(value string, signaturesProps ...*propsmapper.S }) } -func (m *Maroto) CreateLine(lineProps ...*propsmapper.Line) PDFComponent { +func (m *Maroto) CreateLine(lineProps ...*propsmapper.Line) ProviderComponent { lProps := propsmapper.Line{} if len(lineProps) > 0 { lProps = *lineProps[0] @@ -64,7 +109,7 @@ func (m *Maroto) CreateLine(lineProps ...*propsmapper.Line) PDFComponent { }) } -func (m *Maroto) CreateImage(img []byte, ext string, imgProps ...*propsmapper.Rect) PDFComponent { +func (m *Maroto) CreateImage(img []byte, ext string, imgProps ...*propsmapper.Rect) ProviderComponent { cProps := propsmapper.Rect{} if len(imgProps) > 0 { cProps = *imgProps[0] @@ -76,7 +121,7 @@ func (m *Maroto) CreateImage(img []byte, ext string, imgProps ...*propsmapper.Re }) } -func (m *Maroto) CreateMatrixCode(codeValue string, codeProps ...*propsmapper.Rect) PDFComponent { +func (m *Maroto) CreateMatrixCode(codeValue string, codeProps ...*propsmapper.Rect) ProviderComponent { cProps := propsmapper.Rect{} if len(codeProps) > 0 { cProps = *codeProps[0] @@ -88,7 +133,7 @@ func (m *Maroto) CreateMatrixCode(codeValue string, codeProps ...*propsmapper.Re }) } -func (m *Maroto) CreateQrCode(codeValue string, codeProps ...*propsmapper.Rect) PDFComponent { +func (m *Maroto) CreateQrCode(codeValue string, codeProps ...*propsmapper.Rect) ProviderComponent { cProps := propsmapper.Rect{} if len(codeProps) > 0 { cProps = *codeProps[0] @@ -100,7 +145,7 @@ func (m *Maroto) CreateQrCode(codeValue string, codeProps ...*propsmapper.Rect) }) } -func (m *Maroto) CreateBarCode(codeValue string, codeProps ...*propsmapper.Barcode) PDFComponent { +func (m *Maroto) CreateBarCode(codeValue string, codeProps ...*propsmapper.Barcode) ProviderComponent { cProps := propsmapper.Barcode{} if len(codeProps) > 0 { cProps = *codeProps[0] From 6613097d04cb27262fe982004171fdd0caeabbd1 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Mon, 4 Nov 2024 22:32:01 -0300 Subject: [PATCH 063/116] test: validate page creation --- .../components/pagemapper/page_test.go | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/pkg/processor/mappers/components/pagemapper/page_test.go b/pkg/processor/mappers/components/pagemapper/page_test.go index 5dbe0bcf..b71a4722 100644 --- a/pkg/processor/mappers/components/pagemapper/page_test.go +++ b/pkg/processor/mappers/components/pagemapper/page_test.go @@ -1,10 +1,12 @@ package pagemapper_test import ( + "fmt" "testing" "github.com/johnfercher/maroto/v2/internal/fixture" "github.com/johnfercher/maroto/v2/mocks" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/listmapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/pagemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/rowmapper" @@ -57,3 +59,51 @@ func TestNewPage(t *testing.T) { assert.IsType(t, &listmapper.List{}, doc.Rows[0]) }) } + +func TestGenerate(t *testing.T) { + t.Run("when content no has source_key, should return an error", func(t *testing.T) { + content := map[string]interface{}{} + factory := mocks.NewAbstractFactoryMaps(t) + provider := mocks.NewProcessorProvider(t) + + page := pagemapper.Page{Rows: make([]mappers.Componentmapper, 0), Factory: factory, SourceKey: "test"} + newPage, err := page.Generate(content, provider) + + assert.NotNil(t, err) + assert.Nil(t, newPage) + }) + t.Run("when page no has rows, it should no sent rows", func(t *testing.T) { + content := map[string]interface{}{"content": map[string]interface{}{"row_1": "any"}} + factory := mocks.NewAbstractFactoryMaps(t) + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreatePage().Return(nil, nil) + + page := pagemapper.Page{Rows: make([]mappers.Componentmapper, 0), Factory: factory, SourceKey: "content"} + _, err := page.Generate(content, provider) + + assert.Nil(t, err) + }) + t.Run("when is not possible generate components, should return an error", func(t *testing.T) { + content := map[string]interface{}{"content": map[string]interface{}{"text": "value"}} + factory := mocks.NewAbstractFactoryMaps(t) + provider := mocks.NewProcessorProvider(t) + component := mocks.NewComponentmapper(t) + component.EXPECT().Generate(mock.Anything, provider).Return(nil, fmt.Errorf("any")) + + page := pagemapper.Page{Rows: []mappers.Componentmapper{component}, Factory: factory, SourceKey: "content"} + _, err := page.Generate(content, provider) + + assert.NotNil(t, err) + }) + t.Run("when is not possible generate page, should return an error", func(t *testing.T) { + content := map[string]interface{}{"content": map[string]interface{}{"text": "value"}} + factory := mocks.NewAbstractFactoryMaps(t) + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreatePage().Return(nil, fmt.Errorf("any")) + + page := pagemapper.Page{Rows: make([]mappers.Componentmapper, 0), Factory: factory, SourceKey: "content"} + _, err := page.Generate(content, provider) + + assert.NotNil(t, err) + }) +} From bcd5a451090c192770c9b771a4c278ab82f6dccd Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Mon, 4 Nov 2024 22:32:19 -0300 Subject: [PATCH 064/116] feat: create page component --- .../mappers/components/pagemapper/page.go | 43 ++++++++++++++++--- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/pkg/processor/mappers/components/pagemapper/page.go b/pkg/processor/mappers/components/pagemapper/page.go index 3e3ddce6..c5c4fa9f 100644 --- a/pkg/processor/mappers/components/pagemapper/page.go +++ b/pkg/processor/mappers/components/pagemapper/page.go @@ -5,20 +5,20 @@ import ( "fmt" "strings" - "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Page struct { SourceKey string Rows []mappers.Componentmapper - factory mappers.AbstractFactoryMaps + Factory mappers.AbstractFactoryMaps } func NewPage(rows interface{}, sourceKey string, factory mappers.AbstractFactoryMaps) (*Page, error) { newPage := &Page{ SourceKey: sourceKey, - factory: factory, + Factory: factory, } if err := newPage.setRows(rows); err != nil { return nil, err @@ -40,9 +40,9 @@ func (p *Page) setRows(rowsDoc interface{}) error { var err error if strings.HasPrefix(templateName, "list") { - rows, err = p.factory.NewList(template, templateName, p.factory.NewRow) + rows, err = p.Factory.NewList(template, templateName, p.Factory.NewRow) } else { - rows, err = p.factory.NewRow(template, templateName) + rows, err = p.Factory.NewRow(template, templateName) } if err != nil { @@ -54,6 +54,35 @@ func (p *Page) setRows(rowsDoc interface{}) error { return nil } -func (p *Page) Generate(content map[string]interface{}) (components.PdfComponent, error) { - return nil, nil +func (p *Page) getPageContent(content map[string]interface{}) (map[string]interface{}, error) { + pageContent, ok := content[p.SourceKey] + if !ok { + return nil, fmt.Errorf("the page needs the source key \"%s\", but it was not found", p.SourceKey) + } + if mapPage, ok := pageContent.(map[string]interface{}); ok { + return mapPage, nil + } + return nil, fmt.Errorf("ensure that the contents of the page \"%s\" can be converted to map[string]interface{}", p.SourceKey) +} + +func (p *Page) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { + pageContent, err := p.getPageContent(content) + if err != nil { + return nil, err + } + + rows := make([]processorprovider.ProviderComponent, 0, len(p.Rows)) + for _, row := range p.Rows { + newRow, err := row.Generate(pageContent, provider) + if err != nil { + return nil, err + } + rows = append(rows, newRow...) + } + + page, err := provider.CreatePage(rows...) + if err != nil { + return nil, err + } + return []processorprovider.ProviderComponent{page}, nil } From 42c6f58ffe6cf0c5ea70042a141d68832209c5de Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Mon, 4 Nov 2024 22:32:46 -0300 Subject: [PATCH 065/116] test: validate col creation --- .../mappers/components/colmapper/col_test.go | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pkg/processor/mappers/components/colmapper/col_test.go b/pkg/processor/mappers/components/colmapper/col_test.go index 0473caca..a98d4683 100644 --- a/pkg/processor/mappers/components/colmapper/col_test.go +++ b/pkg/processor/mappers/components/colmapper/col_test.go @@ -6,12 +6,15 @@ import ( "github.com/johnfercher/maroto/v2/internal/fixture" "github.com/johnfercher/maroto/v2/mocks" + "github.com/johnfercher/maroto/v2/pkg/components/text" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/codemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/colmapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/imagemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/linemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/signaturemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/textmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -166,3 +169,45 @@ func TestNewCol(t *testing.T) { assert.Equal(t, doc.Size, 6) }) } + +func TestGenerate(t *testing.T) { + t.Run("when col has no components, it should not send components", func(t *testing.T) { + content := map[string]interface{}{} + col := colmapper.Col{Size: 10, Components: make([]mappers.Componentmapper, 0)} + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateCol(10).Return(nil, nil) + + _, err := col.Generate(content, provider) + + assert.Nil(t, err) + provider.AssertNumberOfCalls(t, "CreateCol", 1) + }) + t.Run("when col has two components, it should add two components", func(t *testing.T) { + content := map[string]interface{}{"text1": "test", "text2": "test"} + provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateCol(10, text.New("test"), text.New("test")).Return(nil, nil) + + component := mocks.NewComponentmapper(t) + component.EXPECT().Generate(content, provider).Return([]processorprovider.ProviderComponent{text.New("test")}, nil) + col := colmapper.Col{Size: 10, Components: []mappers.Componentmapper{component, component}} + + _, err := col.Generate(content, provider) + + assert.Nil(t, err) + provider.AssertNumberOfCalls(t, "CreateCol", 1) + component.AssertNumberOfCalls(t, "Generate", 2) + }) + t.Run("when it is not possible to generate the component, an error should be returned", func(t *testing.T) { + content := map[string]interface{}{"text1": "test"} + provider := mocks.NewProcessorProvider(t) + + component := mocks.NewComponentmapper(t) + component.EXPECT().Generate(content, provider).Return(nil, errors.New("any")) + col := colmapper.Col{Size: 10, Components: []mappers.Componentmapper{component}} + + _, err := col.Generate(content, provider) + + component.AssertNumberOfCalls(t, "Generate", 1) + assert.NotNil(t, err) + }) +} From 103eb470c8d8040de72ac29ccb519c70b940a632 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Mon, 4 Nov 2024 22:33:14 -0300 Subject: [PATCH 066/116] feat: create col component --- .../mappers/components/colmapper/col.go | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/pkg/processor/mappers/components/colmapper/col.go b/pkg/processor/mappers/components/colmapper/col.go index a9c84db7..bec0af45 100644 --- a/pkg/processor/mappers/components/colmapper/col.go +++ b/pkg/processor/mappers/components/colmapper/col.go @@ -3,8 +3,8 @@ package colmapper import ( "fmt" - "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Col struct { @@ -31,10 +31,6 @@ func NewCol(templateCols interface{}, factory mappers.AbstractFactoryMaps) (*Col return col, nil } -func (c *Col) Generate(content map[string]interface{}) (components.PdfComponent, error) { - return nil, nil -} - func (c *Col) addComponents(mapComponents map[string]interface{}) error { fieldMappers := c.getFieldMappers() @@ -78,3 +74,22 @@ func (c *Col) getFieldMappers() map[string]func(interface{}) (mappers.Componentm "text": c.factory.NewText, } } + +// Generate is responsible for generating the col component, it will generate all the internal components and add them to the col +// - The content is a map with the properties of the col components +func (c *Col) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { + components := make([]processorprovider.ProviderComponent, 0, len(c.Components)) + for _, component := range c.Components { + newComponent, err := component.Generate(content, provider) + if err != nil { + return nil, err + } + components = append(components, newComponent...) + } + + col, err := provider.CreateCol(c.Size, components...) + if err != nil { + return nil, err + } + return []processorprovider.ProviderComponent{col}, nil +} From 9471b8968cf54203dd43c6d25ab3145285643f11 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Mon, 4 Nov 2024 23:16:09 -0300 Subject: [PATCH 067/116] test: Validate component list creation --- .../components/listmapper/list_test.go | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/pkg/processor/mappers/components/listmapper/list_test.go b/pkg/processor/mappers/components/listmapper/list_test.go index 5c86b802..fb6ed4f8 100644 --- a/pkg/processor/mappers/components/listmapper/list_test.go +++ b/pkg/processor/mappers/components/listmapper/list_test.go @@ -2,11 +2,14 @@ package listmapper_test import ( "errors" + "fmt" "testing" "github.com/johnfercher/maroto/v2/internal/fixture" "github.com/johnfercher/maroto/v2/mocks" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/listmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -52,3 +55,58 @@ func TestNewList(t *testing.T) { assert.Equal(t, len(doc.Templates), 2) }) } + +func TestGenerate(t *testing.T) { + t.Run("when source_key is not found, should return an error", func(t *testing.T) { + provider := mocks.NewProcessorProvider(t) + content := map[string]interface{}{} + list := listmapper.List{SourceKey: "list", Templates: make([]mappers.Componentmapper, 0)} + + components, err := list.Generate(content, provider) + + assert.Nil(t, components) + assert.NotNil(t, err) + }) + t.Run("when invalid content is sent, should return an error", func(t *testing.T) { + provider := mocks.NewProcessorProvider(t) + content := map[string]interface{}{"list": 1} + list := listmapper.List{SourceKey: "list", Templates: make([]mappers.Componentmapper, 0)} + + components, err := list.Generate(content, provider) + + assert.Nil(t, components) + assert.NotNil(t, err) + }) + + t.Run("when componentes is not generate, should return an error", func(t *testing.T) { + contentRow1 := map[string]interface{}{"row_1": nil} + listContent := map[string]interface{}{"list": []map[string]interface{}{contentRow1}} + provider := mocks.NewProcessorProvider(t) + component := mocks.NewComponentmapper(t) + component.EXPECT().Generate(mock.Anything, provider).Return(nil, fmt.Errorf("any")) + + list := listmapper.List{SourceKey: "list", Templates: []mappers.Componentmapper{component}} + components, err := list.Generate(listContent, provider) + + assert.Nil(t, components) + assert.NotNil(t, err) + }) + + t.Run("when 2 templates are added, it should generate 4 components", func(t *testing.T) { + content1 := map[string]interface{}{"row_1": nil, "row_2": nil} + content2 := map[string]interface{}{"row_1": nil, "row_2": nil} + listContent := map[string]interface{}{"list": []map[string]interface{}{content1, content2}} + provider := mocks.NewProcessorProvider(t) + providerComponent := mocks.NewProviderComponent(t) + component := mocks.NewComponentmapper(t) + component.EXPECT().Generate(mock.Anything, provider).Return([]processorprovider.ProviderComponent{providerComponent}, nil) + + list := listmapper.List{SourceKey: "list", Templates: []mappers.Componentmapper{component, component}} + components, err := list.Generate(listContent, provider) + + assert.NotNil(t, components) + assert.Nil(t, err) + component.AssertNumberOfCalls(t, "Generate", 4) + assert.Len(t, components, 4) + }) +} From cc099dd3a48f74c9667f87ae6398f8367c3096e3 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Mon, 4 Nov 2024 23:16:46 -0300 Subject: [PATCH 068/116] feat: implement component list generation --- .../mappers/components/listmapper/list.go | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/pkg/processor/mappers/components/listmapper/list.go b/pkg/processor/mappers/components/listmapper/list.go index fdfdddcf..137f4e42 100644 --- a/pkg/processor/mappers/components/listmapper/list.go +++ b/pkg/processor/mappers/components/listmapper/list.go @@ -4,10 +4,12 @@ package listmapper import ( "fmt" - "github.com/johnfercher/maroto/v2/pkg/processor/components" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) +// The List component is responsible for adding a list behavior to a component. +// It will repeat a component for each content sent in the generate method type List struct { SourceKey string Templates []mappers.Componentmapper @@ -43,6 +45,43 @@ func createComponents(listMapper map[string]interface{}, generate mappers.Genera return components, nil } -func (r *List) Generate(content map[string]interface{}) (components.PdfComponent, error) { - return nil, nil +func (l *List) getListContent(content map[string]interface{}) ([]map[string]interface{}, error) { + listContent, ok := content[l.SourceKey] + if !ok { + return nil, fmt.Errorf("the list needs the source key \"%s\", but it was not found", l.SourceKey) + } + if contents, ok := listContent.([]map[string]interface{}); ok { + return contents, nil + } + return nil, fmt.Errorf("ensure that the contents of the list \"%s\" can be converted to []map[string]interface{}", l.SourceKey) +} + +func (l *List) generateTemplates(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { + components := make([]processorprovider.ProviderComponent, 0, len(l.Templates)) + for _, template := range l.Templates { + component, err := template.Generate(content, provider) + if err != nil { + return nil, err + } + components = append(components, component...) + } + return components, nil +} + +func (l *List) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { + listContent, err := l.getListContent(content) + if err != nil { + return nil, err + } + newComponents := make([]processorprovider.ProviderComponent, 0, len(l.Templates)*len(listContent)) + + for _, content := range listContent { + components, err := l.generateTemplates(content, provider) + if err != nil { + return nil, err + } + newComponents = append(newComponents, components...) + } + + return newComponents, nil } From 8ea21e9aecabfe1421b48bdbc7eb3aceaeef6c11 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 13 Nov 2024 21:31:33 -0300 Subject: [PATCH 069/116] test: validate provider builder props definition --- internal/fixture/processorfixture.go | 12 + mocks/Builder.go | 1263 ++++++++++++++++- .../mappers/buildermapper/bulder_test.go | 26 +- .../mappers/documentmapper/document_test.go | 4 +- .../processorprovider/builder_maroto_test.go | 621 ++++++++ test/maroto/processor/all_builder_pros.json | 21 +- 6 files changed, 1922 insertions(+), 25 deletions(-) create mode 100644 pkg/processor/processorprovider/builder_maroto_test.go diff --git a/internal/fixture/processorfixture.go b/internal/fixture/processorfixture.go index 47206a2e..f598cd42 100644 --- a/internal/fixture/processorfixture.go +++ b/internal/fixture/processorfixture.go @@ -1,6 +1,8 @@ package fixture import ( + "time" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/codemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/imagemapper" @@ -10,6 +12,7 @@ import ( "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/rowmapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/signaturemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/textmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" ) func MapperRow() *rowmapper.Row { @@ -57,3 +60,12 @@ func Signature() *signaturemapper.Signature { func Text() *textmapper.Text { return &textmapper.Text{} } + +func Metadata() *propsmapper.Metadata { + creation := time.Now() + return &propsmapper.Metadata{ + Author: &propsmapper.Utf8Text{Text: "Author", UTF8: true}, Creator: &propsmapper.Utf8Text{Text: "Creator", UTF8: true}, + Subject: &propsmapper.Utf8Text{Text: "Subject", UTF8: true}, Title: &propsmapper.Utf8Text{Text: "Title", UTF8: true}, + CreationDate: &creation, KeywordsStr: &propsmapper.Utf8Text{Text: "KeywordsStr", UTF8: true}, + } +} diff --git a/mocks/Builder.go b/mocks/Builder.go index 883f7968..2cbe240a 100644 --- a/mocks/Builder.go +++ b/mocks/Builder.go @@ -3,12 +3,22 @@ package mocks import ( - cache "github.com/johnfercher/maroto/v2/internal/cache" + config "github.com/johnfercher/maroto/v2/pkg/config" entity "github.com/johnfercher/maroto/v2/pkg/core/entity" - gofpdf "github.com/johnfercher/maroto/v2/internal/providers/gofpdf" + extension "github.com/johnfercher/maroto/v2/pkg/consts/extension" mock "github.com/stretchr/testify/mock" + + orientation "github.com/johnfercher/maroto/v2/pkg/consts/orientation" + + pagesize "github.com/johnfercher/maroto/v2/pkg/consts/pagesize" + + props "github.com/johnfercher/maroto/v2/pkg/props" + + protection "github.com/johnfercher/maroto/v2/pkg/consts/protection" + + time "time" ) // Builder is an autogenerated mock type for the Builder type @@ -24,20 +34,20 @@ func (_m *Builder) EXPECT() *Builder_Expecter { return &Builder_Expecter{mock: &_m.Mock} } -// Build provides a mock function with given fields: cfg, _a1 -func (_m *Builder) Build(cfg *entity.Config, _a1 cache.Cache) *gofpdf.Dependencies { - ret := _m.Called(cfg, _a1) +// Build provides a mock function with given fields: +func (_m *Builder) Build() *entity.Config { + ret := _m.Called() if len(ret) == 0 { panic("no return value specified for Build") } - var r0 *gofpdf.Dependencies - if rf, ok := ret.Get(0).(func(*entity.Config, cache.Cache) *gofpdf.Dependencies); ok { - r0 = rf(cfg, _a1) + var r0 *entity.Config + if rf, ok := ret.Get(0).(func() *entity.Config); ok { + r0 = rf() } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*gofpdf.Dependencies) + r0 = ret.Get(0).(*entity.Config) } } @@ -50,25 +60,1244 @@ type Builder_Build_Call struct { } // Build is a helper method to define mock.On call -// - cfg *entity.Config -// - _a1 cache.Cache -func (_e *Builder_Expecter) Build(cfg interface{}, _a1 interface{}) *Builder_Build_Call { - return &Builder_Build_Call{Call: _e.mock.On("Build", cfg, _a1)} +func (_e *Builder_Expecter) Build() *Builder_Build_Call { + return &Builder_Build_Call{Call: _e.mock.On("Build")} +} + +func (_c *Builder_Build_Call) Run(run func()) *Builder_Build_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Builder_Build_Call) Return(_a0 *entity.Config) *Builder_Build_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_Build_Call) RunAndReturn(run func() *entity.Config) *Builder_Build_Call { + _c.Call.Return(run) + return _c +} + +// WithAuthor provides a mock function with given fields: author, isUTF8 +func (_m *Builder) WithAuthor(author string, isUTF8 bool) config.Builder { + ret := _m.Called(author, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithAuthor") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(author, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithAuthor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithAuthor' +type Builder_WithAuthor_Call struct { + *mock.Call +} + +// WithAuthor is a helper method to define mock.On call +// - author string +// - isUTF8 bool +func (_e *Builder_Expecter) WithAuthor(author interface{}, isUTF8 interface{}) *Builder_WithAuthor_Call { + return &Builder_WithAuthor_Call{Call: _e.mock.On("WithAuthor", author, isUTF8)} +} + +func (_c *Builder_WithAuthor_Call) Run(run func(author string, isUTF8 bool)) *Builder_WithAuthor_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithAuthor_Call) Return(_a0 config.Builder) *Builder_WithAuthor_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithAuthor_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithAuthor_Call { + _c.Call.Return(run) + return _c +} + +// WithBackgroundImage provides a mock function with given fields: _a0, _a1 +func (_m *Builder) WithBackgroundImage(_a0 []byte, _a1 extension.Type) config.Builder { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for WithBackgroundImage") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func([]byte, extension.Type) config.Builder); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithBackgroundImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBackgroundImage' +type Builder_WithBackgroundImage_Call struct { + *mock.Call +} + +// WithBackgroundImage is a helper method to define mock.On call +// - _a0 []byte +// - _a1 extension.Type +func (_e *Builder_Expecter) WithBackgroundImage(_a0 interface{}, _a1 interface{}) *Builder_WithBackgroundImage_Call { + return &Builder_WithBackgroundImage_Call{Call: _e.mock.On("WithBackgroundImage", _a0, _a1)} +} + +func (_c *Builder_WithBackgroundImage_Call) Run(run func(_a0 []byte, _a1 extension.Type)) *Builder_WithBackgroundImage_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]byte), args[1].(extension.Type)) + }) + return _c +} + +func (_c *Builder_WithBackgroundImage_Call) Return(_a0 config.Builder) *Builder_WithBackgroundImage_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithBackgroundImage_Call) RunAndReturn(run func([]byte, extension.Type) config.Builder) *Builder_WithBackgroundImage_Call { + _c.Call.Return(run) + return _c +} + +// WithBottomMargin provides a mock function with given fields: bottom +func (_m *Builder) WithBottomMargin(bottom float64) config.Builder { + ret := _m.Called(bottom) + + if len(ret) == 0 { + panic("no return value specified for WithBottomMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(bottom) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithBottomMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithBottomMargin' +type Builder_WithBottomMargin_Call struct { + *mock.Call +} + +// WithBottomMargin is a helper method to define mock.On call +// - bottom float64 +func (_e *Builder_Expecter) WithBottomMargin(bottom interface{}) *Builder_WithBottomMargin_Call { + return &Builder_WithBottomMargin_Call{Call: _e.mock.On("WithBottomMargin", bottom)} +} + +func (_c *Builder_WithBottomMargin_Call) Run(run func(bottom float64)) *Builder_WithBottomMargin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Builder_WithBottomMargin_Call) Return(_a0 config.Builder) *Builder_WithBottomMargin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithBottomMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithBottomMargin_Call { + _c.Call.Return(run) + return _c +} + +// WithCompression provides a mock function with given fields: compression +func (_m *Builder) WithCompression(compression bool) config.Builder { + ret := _m.Called(compression) + + if len(ret) == 0 { + panic("no return value specified for WithCompression") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { + r0 = rf(compression) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCompression_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCompression' +type Builder_WithCompression_Call struct { + *mock.Call +} + +// WithCompression is a helper method to define mock.On call +// - compression bool +func (_e *Builder_Expecter) WithCompression(compression interface{}) *Builder_WithCompression_Call { + return &Builder_WithCompression_Call{Call: _e.mock.On("WithCompression", compression)} +} + +func (_c *Builder_WithCompression_Call) Run(run func(compression bool)) *Builder_WithCompression_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Builder_WithCompression_Call) Return(_a0 config.Builder) *Builder_WithCompression_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCompression_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithCompression_Call { + _c.Call.Return(run) + return _c +} + +// WithConcurrentMode provides a mock function with given fields: chunkWorkers +func (_m *Builder) WithConcurrentMode(chunkWorkers int) config.Builder { + ret := _m.Called(chunkWorkers) + + if len(ret) == 0 { + panic("no return value specified for WithConcurrentMode") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(int) config.Builder); ok { + r0 = rf(chunkWorkers) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithConcurrentMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithConcurrentMode' +type Builder_WithConcurrentMode_Call struct { + *mock.Call +} + +// WithConcurrentMode is a helper method to define mock.On call +// - chunkWorkers int +func (_e *Builder_Expecter) WithConcurrentMode(chunkWorkers interface{}) *Builder_WithConcurrentMode_Call { + return &Builder_WithConcurrentMode_Call{Call: _e.mock.On("WithConcurrentMode", chunkWorkers)} +} + +func (_c *Builder_WithConcurrentMode_Call) Run(run func(chunkWorkers int)) *Builder_WithConcurrentMode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Builder_WithConcurrentMode_Call) Return(_a0 config.Builder) *Builder_WithConcurrentMode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithConcurrentMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithConcurrentMode_Call { + _c.Call.Return(run) + return _c +} + +// WithCreationDate provides a mock function with given fields: _a0 +func (_m *Builder) WithCreationDate(_a0 time.Time) config.Builder { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for WithCreationDate") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(time.Time) config.Builder); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCreationDate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreationDate' +type Builder_WithCreationDate_Call struct { + *mock.Call +} + +// WithCreationDate is a helper method to define mock.On call +// - _a0 time.Time +func (_e *Builder_Expecter) WithCreationDate(_a0 interface{}) *Builder_WithCreationDate_Call { + return &Builder_WithCreationDate_Call{Call: _e.mock.On("WithCreationDate", _a0)} +} + +func (_c *Builder_WithCreationDate_Call) Run(run func(_a0 time.Time)) *Builder_WithCreationDate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(time.Time)) + }) + return _c +} + +func (_c *Builder_WithCreationDate_Call) Return(_a0 config.Builder) *Builder_WithCreationDate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCreationDate_Call) RunAndReturn(run func(time.Time) config.Builder) *Builder_WithCreationDate_Call { + _c.Call.Return(run) + return _c +} + +// WithCreator provides a mock function with given fields: creator, isUTF8 +func (_m *Builder) WithCreator(creator string, isUTF8 bool) config.Builder { + ret := _m.Called(creator, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithCreator") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(creator, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCreator_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCreator' +type Builder_WithCreator_Call struct { + *mock.Call +} + +// WithCreator is a helper method to define mock.On call +// - creator string +// - isUTF8 bool +func (_e *Builder_Expecter) WithCreator(creator interface{}, isUTF8 interface{}) *Builder_WithCreator_Call { + return &Builder_WithCreator_Call{Call: _e.mock.On("WithCreator", creator, isUTF8)} +} + +func (_c *Builder_WithCreator_Call) Run(run func(creator string, isUTF8 bool)) *Builder_WithCreator_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithCreator_Call) Return(_a0 config.Builder) *Builder_WithCreator_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCreator_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithCreator_Call { + _c.Call.Return(run) + return _c +} + +// WithCustomFonts provides a mock function with given fields: _a0 +func (_m *Builder) WithCustomFonts(_a0 []*entity.CustomFont) config.Builder { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for WithCustomFonts") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func([]*entity.CustomFont) config.Builder); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithCustomFonts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithCustomFonts' +type Builder_WithCustomFonts_Call struct { + *mock.Call +} + +// WithCustomFonts is a helper method to define mock.On call +// - _a0 []*entity.CustomFont +func (_e *Builder_Expecter) WithCustomFonts(_a0 interface{}) *Builder_WithCustomFonts_Call { + return &Builder_WithCustomFonts_Call{Call: _e.mock.On("WithCustomFonts", _a0)} +} + +func (_c *Builder_WithCustomFonts_Call) Run(run func(_a0 []*entity.CustomFont)) *Builder_WithCustomFonts_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]*entity.CustomFont)) + }) + return _c +} + +func (_c *Builder_WithCustomFonts_Call) Return(_a0 config.Builder) *Builder_WithCustomFonts_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithCustomFonts_Call) RunAndReturn(run func([]*entity.CustomFont) config.Builder) *Builder_WithCustomFonts_Call { + _c.Call.Return(run) + return _c +} + +// WithDebug provides a mock function with given fields: on +func (_m *Builder) WithDebug(on bool) config.Builder { + ret := _m.Called(on) + + if len(ret) == 0 { + panic("no return value specified for WithDebug") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { + r0 = rf(on) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDebug_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDebug' +type Builder_WithDebug_Call struct { + *mock.Call +} + +// WithDebug is a helper method to define mock.On call +// - on bool +func (_e *Builder_Expecter) WithDebug(on interface{}) *Builder_WithDebug_Call { + return &Builder_WithDebug_Call{Call: _e.mock.On("WithDebug", on)} +} + +func (_c *Builder_WithDebug_Call) Run(run func(on bool)) *Builder_WithDebug_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Builder_WithDebug_Call) Return(_a0 config.Builder) *Builder_WithDebug_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDebug_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDebug_Call { + _c.Call.Return(run) + return _c +} + +// WithDefaultFont provides a mock function with given fields: font +func (_m *Builder) WithDefaultFont(font *props.Font) config.Builder { + ret := _m.Called(font) + + if len(ret) == 0 { + panic("no return value specified for WithDefaultFont") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(*props.Font) config.Builder); ok { + r0 = rf(font) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDefaultFont_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDefaultFont' +type Builder_WithDefaultFont_Call struct { + *mock.Call +} + +// WithDefaultFont is a helper method to define mock.On call +// - font *props.Font +func (_e *Builder_Expecter) WithDefaultFont(font interface{}) *Builder_WithDefaultFont_Call { + return &Builder_WithDefaultFont_Call{Call: _e.mock.On("WithDefaultFont", font)} +} + +func (_c *Builder_WithDefaultFont_Call) Run(run func(font *props.Font)) *Builder_WithDefaultFont_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*props.Font)) + }) + return _c +} + +func (_c *Builder_WithDefaultFont_Call) Return(_a0 config.Builder) *Builder_WithDefaultFont_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDefaultFont_Call) RunAndReturn(run func(*props.Font) config.Builder) *Builder_WithDefaultFont_Call { + _c.Call.Return(run) + return _c +} + +// WithDimensions provides a mock function with given fields: width, height +func (_m *Builder) WithDimensions(width float64, height float64) config.Builder { + ret := _m.Called(width, height) + + if len(ret) == 0 { + panic("no return value specified for WithDimensions") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64, float64) config.Builder); ok { + r0 = rf(width, height) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDimensions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDimensions' +type Builder_WithDimensions_Call struct { + *mock.Call +} + +// WithDimensions is a helper method to define mock.On call +// - width float64 +// - height float64 +func (_e *Builder_Expecter) WithDimensions(width interface{}, height interface{}) *Builder_WithDimensions_Call { + return &Builder_WithDimensions_Call{Call: _e.mock.On("WithDimensions", width, height)} +} + +func (_c *Builder_WithDimensions_Call) Run(run func(width float64, height float64)) *Builder_WithDimensions_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64), args[1].(float64)) + }) + return _c +} + +func (_c *Builder_WithDimensions_Call) Return(_a0 config.Builder) *Builder_WithDimensions_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDimensions_Call) RunAndReturn(run func(float64, float64) config.Builder) *Builder_WithDimensions_Call { + _c.Call.Return(run) + return _c +} + +// WithDisableAutoPageBreak provides a mock function with given fields: disabled +func (_m *Builder) WithDisableAutoPageBreak(disabled bool) config.Builder { + ret := _m.Called(disabled) + + if len(ret) == 0 { + panic("no return value specified for WithDisableAutoPageBreak") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(bool) config.Builder); ok { + r0 = rf(disabled) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithDisableAutoPageBreak_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithDisableAutoPageBreak' +type Builder_WithDisableAutoPageBreak_Call struct { + *mock.Call +} + +// WithDisableAutoPageBreak is a helper method to define mock.On call +// - disabled bool +func (_e *Builder_Expecter) WithDisableAutoPageBreak(disabled interface{}) *Builder_WithDisableAutoPageBreak_Call { + return &Builder_WithDisableAutoPageBreak_Call{Call: _e.mock.On("WithDisableAutoPageBreak", disabled)} +} + +func (_c *Builder_WithDisableAutoPageBreak_Call) Run(run func(disabled bool)) *Builder_WithDisableAutoPageBreak_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *Builder_WithDisableAutoPageBreak_Call) Return(_a0 config.Builder) *Builder_WithDisableAutoPageBreak_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithDisableAutoPageBreak_Call) RunAndReturn(run func(bool) config.Builder) *Builder_WithDisableAutoPageBreak_Call { + _c.Call.Return(run) + return _c +} + +// WithKeywords provides a mock function with given fields: keywordsStr, isUTF8 +func (_m *Builder) WithKeywords(keywordsStr string, isUTF8 bool) config.Builder { + ret := _m.Called(keywordsStr, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithKeywords") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(keywordsStr, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithKeywords_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithKeywords' +type Builder_WithKeywords_Call struct { + *mock.Call +} + +// WithKeywords is a helper method to define mock.On call +// - keywordsStr string +// - isUTF8 bool +func (_e *Builder_Expecter) WithKeywords(keywordsStr interface{}, isUTF8 interface{}) *Builder_WithKeywords_Call { + return &Builder_WithKeywords_Call{Call: _e.mock.On("WithKeywords", keywordsStr, isUTF8)} +} + +func (_c *Builder_WithKeywords_Call) Run(run func(keywordsStr string, isUTF8 bool)) *Builder_WithKeywords_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithKeywords_Call) Return(_a0 config.Builder) *Builder_WithKeywords_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithKeywords_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithKeywords_Call { + _c.Call.Return(run) + return _c +} + +// WithLeftMargin provides a mock function with given fields: left +func (_m *Builder) WithLeftMargin(left float64) config.Builder { + ret := _m.Called(left) + + if len(ret) == 0 { + panic("no return value specified for WithLeftMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(left) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithLeftMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithLeftMargin' +type Builder_WithLeftMargin_Call struct { + *mock.Call +} + +// WithLeftMargin is a helper method to define mock.On call +// - left float64 +func (_e *Builder_Expecter) WithLeftMargin(left interface{}) *Builder_WithLeftMargin_Call { + return &Builder_WithLeftMargin_Call{Call: _e.mock.On("WithLeftMargin", left)} +} + +func (_c *Builder_WithLeftMargin_Call) Run(run func(left float64)) *Builder_WithLeftMargin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Builder_WithLeftMargin_Call) Return(_a0 config.Builder) *Builder_WithLeftMargin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithLeftMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithLeftMargin_Call { + _c.Call.Return(run) + return _c +} + +// WithMaxGridSize provides a mock function with given fields: maxGridSize +func (_m *Builder) WithMaxGridSize(maxGridSize int) config.Builder { + ret := _m.Called(maxGridSize) + + if len(ret) == 0 { + panic("no return value specified for WithMaxGridSize") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(int) config.Builder); ok { + r0 = rf(maxGridSize) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithMaxGridSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithMaxGridSize' +type Builder_WithMaxGridSize_Call struct { + *mock.Call +} + +// WithMaxGridSize is a helper method to define mock.On call +// - maxGridSize int +func (_e *Builder_Expecter) WithMaxGridSize(maxGridSize interface{}) *Builder_WithMaxGridSize_Call { + return &Builder_WithMaxGridSize_Call{Call: _e.mock.On("WithMaxGridSize", maxGridSize)} +} + +func (_c *Builder_WithMaxGridSize_Call) Run(run func(maxGridSize int)) *Builder_WithMaxGridSize_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Builder_WithMaxGridSize_Call) Return(_a0 config.Builder) *Builder_WithMaxGridSize_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithMaxGridSize_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithMaxGridSize_Call { + _c.Call.Return(run) + return _c +} + +// WithOrientation provides a mock function with given fields: _a0 +func (_m *Builder) WithOrientation(_a0 orientation.Type) config.Builder { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for WithOrientation") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(orientation.Type) config.Builder); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithOrientation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithOrientation' +type Builder_WithOrientation_Call struct { + *mock.Call +} + +// WithOrientation is a helper method to define mock.On call +// - _a0 orientation.Type +func (_e *Builder_Expecter) WithOrientation(_a0 interface{}) *Builder_WithOrientation_Call { + return &Builder_WithOrientation_Call{Call: _e.mock.On("WithOrientation", _a0)} +} + +func (_c *Builder_WithOrientation_Call) Run(run func(_a0 orientation.Type)) *Builder_WithOrientation_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(orientation.Type)) + }) + return _c +} + +func (_c *Builder_WithOrientation_Call) Return(_a0 config.Builder) *Builder_WithOrientation_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithOrientation_Call) RunAndReturn(run func(orientation.Type) config.Builder) *Builder_WithOrientation_Call { + _c.Call.Return(run) + return _c +} + +// WithPageNumber provides a mock function with given fields: pageNumber +func (_m *Builder) WithPageNumber(pageNumber ...props.PageNumber) config.Builder { + _va := make([]interface{}, len(pageNumber)) + for _i := range pageNumber { + _va[_i] = pageNumber[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for WithPageNumber") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(...props.PageNumber) config.Builder); ok { + r0 = rf(pageNumber...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithPageNumber_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageNumber' +type Builder_WithPageNumber_Call struct { + *mock.Call +} + +// WithPageNumber is a helper method to define mock.On call +// - pageNumber ...props.PageNumber +func (_e *Builder_Expecter) WithPageNumber(pageNumber ...interface{}) *Builder_WithPageNumber_Call { + return &Builder_WithPageNumber_Call{Call: _e.mock.On("WithPageNumber", + append([]interface{}{}, pageNumber...)...)} +} + +func (_c *Builder_WithPageNumber_Call) Run(run func(pageNumber ...props.PageNumber)) *Builder_WithPageNumber_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]props.PageNumber, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(props.PageNumber) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *Builder_WithPageNumber_Call) Return(_a0 config.Builder) *Builder_WithPageNumber_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithPageNumber_Call) RunAndReturn(run func(...props.PageNumber) config.Builder) *Builder_WithPageNumber_Call { + _c.Call.Return(run) + return _c +} + +// WithPageSize provides a mock function with given fields: size +func (_m *Builder) WithPageSize(size pagesize.Type) config.Builder { + ret := _m.Called(size) + + if len(ret) == 0 { + panic("no return value specified for WithPageSize") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(pagesize.Type) config.Builder); ok { + r0 = rf(size) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithPageSize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithPageSize' +type Builder_WithPageSize_Call struct { + *mock.Call +} + +// WithPageSize is a helper method to define mock.On call +// - size pagesize.Type +func (_e *Builder_Expecter) WithPageSize(size interface{}) *Builder_WithPageSize_Call { + return &Builder_WithPageSize_Call{Call: _e.mock.On("WithPageSize", size)} +} + +func (_c *Builder_WithPageSize_Call) Run(run func(size pagesize.Type)) *Builder_WithPageSize_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(pagesize.Type)) + }) + return _c +} + +func (_c *Builder_WithPageSize_Call) Return(_a0 config.Builder) *Builder_WithPageSize_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithPageSize_Call) RunAndReturn(run func(pagesize.Type) config.Builder) *Builder_WithPageSize_Call { + _c.Call.Return(run) + return _c +} + +// WithProtection provides a mock function with given fields: protectionType, userPassword, ownerPassword +func (_m *Builder) WithProtection(protectionType protection.Type, userPassword string, ownerPassword string) config.Builder { + ret := _m.Called(protectionType, userPassword, ownerPassword) + + if len(ret) == 0 { + panic("no return value specified for WithProtection") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(protection.Type, string, string) config.Builder); ok { + r0 = rf(protectionType, userPassword, ownerPassword) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithProtection_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithProtection' +type Builder_WithProtection_Call struct { + *mock.Call +} + +// WithProtection is a helper method to define mock.On call +// - protectionType protection.Type +// - userPassword string +// - ownerPassword string +func (_e *Builder_Expecter) WithProtection(protectionType interface{}, userPassword interface{}, ownerPassword interface{}) *Builder_WithProtection_Call { + return &Builder_WithProtection_Call{Call: _e.mock.On("WithProtection", protectionType, userPassword, ownerPassword)} +} + +func (_c *Builder_WithProtection_Call) Run(run func(protectionType protection.Type, userPassword string, ownerPassword string)) *Builder_WithProtection_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(protection.Type), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *Builder_WithProtection_Call) Return(_a0 config.Builder) *Builder_WithProtection_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithProtection_Call) RunAndReturn(run func(protection.Type, string, string) config.Builder) *Builder_WithProtection_Call { + _c.Call.Return(run) + return _c +} + +// WithRightMargin provides a mock function with given fields: right +func (_m *Builder) WithRightMargin(right float64) config.Builder { + ret := _m.Called(right) + + if len(ret) == 0 { + panic("no return value specified for WithRightMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(right) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithRightMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithRightMargin' +type Builder_WithRightMargin_Call struct { + *mock.Call +} + +// WithRightMargin is a helper method to define mock.On call +// - right float64 +func (_e *Builder_Expecter) WithRightMargin(right interface{}) *Builder_WithRightMargin_Call { + return &Builder_WithRightMargin_Call{Call: _e.mock.On("WithRightMargin", right)} +} + +func (_c *Builder_WithRightMargin_Call) Run(run func(right float64)) *Builder_WithRightMargin_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64)) + }) + return _c +} + +func (_c *Builder_WithRightMargin_Call) Return(_a0 config.Builder) *Builder_WithRightMargin_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithRightMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithRightMargin_Call { + _c.Call.Return(run) + return _c +} + +// WithSequentialLowMemoryMode provides a mock function with given fields: chunkWorkers +func (_m *Builder) WithSequentialLowMemoryMode(chunkWorkers int) config.Builder { + ret := _m.Called(chunkWorkers) + + if len(ret) == 0 { + panic("no return value specified for WithSequentialLowMemoryMode") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(int) config.Builder); ok { + r0 = rf(chunkWorkers) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithSequentialLowMemoryMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialLowMemoryMode' +type Builder_WithSequentialLowMemoryMode_Call struct { + *mock.Call +} + +// WithSequentialLowMemoryMode is a helper method to define mock.On call +// - chunkWorkers int +func (_e *Builder_Expecter) WithSequentialLowMemoryMode(chunkWorkers interface{}) *Builder_WithSequentialLowMemoryMode_Call { + return &Builder_WithSequentialLowMemoryMode_Call{Call: _e.mock.On("WithSequentialLowMemoryMode", chunkWorkers)} +} + +func (_c *Builder_WithSequentialLowMemoryMode_Call) Run(run func(chunkWorkers int)) *Builder_WithSequentialLowMemoryMode_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int)) + }) + return _c +} + +func (_c *Builder_WithSequentialLowMemoryMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialLowMemoryMode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithSequentialLowMemoryMode_Call) RunAndReturn(run func(int) config.Builder) *Builder_WithSequentialLowMemoryMode_Call { + _c.Call.Return(run) + return _c +} + +// WithSequentialMode provides a mock function with given fields: +func (_m *Builder) WithSequentialMode() config.Builder { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for WithSequentialMode") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func() config.Builder); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithSequentialMode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSequentialMode' +type Builder_WithSequentialMode_Call struct { + *mock.Call +} + +// WithSequentialMode is a helper method to define mock.On call +func (_e *Builder_Expecter) WithSequentialMode() *Builder_WithSequentialMode_Call { + return &Builder_WithSequentialMode_Call{Call: _e.mock.On("WithSequentialMode")} +} + +func (_c *Builder_WithSequentialMode_Call) Run(run func()) *Builder_WithSequentialMode_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Builder_WithSequentialMode_Call) Return(_a0 config.Builder) *Builder_WithSequentialMode_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithSequentialMode_Call) RunAndReturn(run func() config.Builder) *Builder_WithSequentialMode_Call { + _c.Call.Return(run) + return _c +} + +// WithSubject provides a mock function with given fields: subject, isUTF8 +func (_m *Builder) WithSubject(subject string, isUTF8 bool) config.Builder { + ret := _m.Called(subject, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithSubject") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(subject, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithSubject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithSubject' +type Builder_WithSubject_Call struct { + *mock.Call +} + +// WithSubject is a helper method to define mock.On call +// - subject string +// - isUTF8 bool +func (_e *Builder_Expecter) WithSubject(subject interface{}, isUTF8 interface{}) *Builder_WithSubject_Call { + return &Builder_WithSubject_Call{Call: _e.mock.On("WithSubject", subject, isUTF8)} +} + +func (_c *Builder_WithSubject_Call) Run(run func(subject string, isUTF8 bool)) *Builder_WithSubject_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithSubject_Call) Return(_a0 config.Builder) *Builder_WithSubject_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithSubject_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithSubject_Call { + _c.Call.Return(run) + return _c +} + +// WithTitle provides a mock function with given fields: title, isUTF8 +func (_m *Builder) WithTitle(title string, isUTF8 bool) config.Builder { + ret := _m.Called(title, isUTF8) + + if len(ret) == 0 { + panic("no return value specified for WithTitle") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(string, bool) config.Builder); ok { + r0 = rf(title, isUTF8) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithTitle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTitle' +type Builder_WithTitle_Call struct { + *mock.Call +} + +// WithTitle is a helper method to define mock.On call +// - title string +// - isUTF8 bool +func (_e *Builder_Expecter) WithTitle(title interface{}, isUTF8 interface{}) *Builder_WithTitle_Call { + return &Builder_WithTitle_Call{Call: _e.mock.On("WithTitle", title, isUTF8)} +} + +func (_c *Builder_WithTitle_Call) Run(run func(title string, isUTF8 bool)) *Builder_WithTitle_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(bool)) + }) + return _c +} + +func (_c *Builder_WithTitle_Call) Return(_a0 config.Builder) *Builder_WithTitle_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Builder_WithTitle_Call) RunAndReturn(run func(string, bool) config.Builder) *Builder_WithTitle_Call { + _c.Call.Return(run) + return _c +} + +// WithTopMargin provides a mock function with given fields: top +func (_m *Builder) WithTopMargin(top float64) config.Builder { + ret := _m.Called(top) + + if len(ret) == 0 { + panic("no return value specified for WithTopMargin") + } + + var r0 config.Builder + if rf, ok := ret.Get(0).(func(float64) config.Builder); ok { + r0 = rf(top) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(config.Builder) + } + } + + return r0 +} + +// Builder_WithTopMargin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WithTopMargin' +type Builder_WithTopMargin_Call struct { + *mock.Call +} + +// WithTopMargin is a helper method to define mock.On call +// - top float64 +func (_e *Builder_Expecter) WithTopMargin(top interface{}) *Builder_WithTopMargin_Call { + return &Builder_WithTopMargin_Call{Call: _e.mock.On("WithTopMargin", top)} } -func (_c *Builder_Build_Call) Run(run func(cfg *entity.Config, _a1 cache.Cache)) *Builder_Build_Call { +func (_c *Builder_WithTopMargin_Call) Run(run func(top float64)) *Builder_WithTopMargin_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*entity.Config), args[1].(cache.Cache)) + run(args[0].(float64)) }) return _c } -func (_c *Builder_Build_Call) Return(_a0 *gofpdf.Dependencies) *Builder_Build_Call { +func (_c *Builder_WithTopMargin_Call) Return(_a0 config.Builder) *Builder_WithTopMargin_Call { _c.Call.Return(_a0) return _c } -func (_c *Builder_Build_Call) RunAndReturn(run func(*entity.Config, cache.Cache) *gofpdf.Dependencies) *Builder_Build_Call { +func (_c *Builder_WithTopMargin_Call) RunAndReturn(run func(float64) config.Builder) *Builder_WithTopMargin_Call { _c.Call.Return(run) return _c } diff --git a/pkg/processor/mappers/buildermapper/bulder_test.go b/pkg/processor/mappers/buildermapper/bulder_test.go index e74cb242..6269befd 100644 --- a/pkg/processor/mappers/buildermapper/bulder_test.go +++ b/pkg/processor/mappers/buildermapper/bulder_test.go @@ -23,9 +23,11 @@ func DefaultBuilderMap() *Builder { Top: 10.0, Bottom: 10.0, }, - ChunkWorkers: 10, - Debug: true, - MaxGridSize: 10, + SequentialMode: false, + ConcurrentMode: 10, + SequentialLowMemoryMode: -1, + Debug: true, + MaxGridSize: 10, DefaultFont: &propsmapper.Font{ Family: "Arial", Style: "bold", @@ -36,6 +38,22 @@ func DefaultBuilderMap() *Builder { Blue: 150, }, }, + PageNumber: &propsmapper.PageNumber{ + Pattern: "pattern_test", + Place: "place_test", + Family: "family_test", + Style: "style_test", + Size: 10.0, + Color: &propsmapper.Color{ + Red: 10, + Green: 100, + Blue: 150, + }, + }, + CustomFonts: []*propsmapper.CustomFont{ + {Family: "family_test", Style: "style_test", File: "file_test"}, + {Family: "family_test2", Style: "style_test2", File: "file_test2"}, + }, Protection: &propsmapper.Protection{ Type: 4, UserPassword: "senha123", @@ -43,7 +61,7 @@ func DefaultBuilderMap() *Builder { }, Compression: true, PageSize: "T", - Orientation: "portrait", + Orientation: "vertical", Metadata: &propsmapper.Metadata{ Author: &propsmapper.Utf8Text{Text: "user_test", UTF8: true}, Creator: &propsmapper.Utf8Text{Text: "user_test", UTF8: true}, diff --git a/pkg/processor/mappers/documentmapper/document_test.go b/pkg/processor/mappers/documentmapper/document_test.go index def6301e..7c9b2591 100644 --- a/pkg/processor/mappers/documentmapper/document_test.go +++ b/pkg/processor/mappers/documentmapper/document_test.go @@ -16,7 +16,7 @@ func TestNewPdf(t *testing.T) { t.Run("when builder is sent, should set builder", func(t *testing.T) { builderDocument := ` { - "builder": {"chunk_workers": 10} + "builder": {"concurrent_mode": 10} } ` factory := mocks.NewAbstractFactoryMaps(t) @@ -26,7 +26,7 @@ func TestNewPdf(t *testing.T) { doc, err := NewPdf(template, factory) assert.Nil(t, err) - assert.Equal(t, doc.Builder.ChunkWorkers, 10) + assert.Equal(t, doc.Builder.ConcurrentMode, 10) }) t.Run("when an invalid builder is passed, should return an error", func(t *testing.T) { diff --git a/pkg/processor/processorprovider/builder_maroto_test.go b/pkg/processor/processorprovider/builder_maroto_test.go new file mode 100644 index 00000000..f8493452 --- /dev/null +++ b/pkg/processor/processorprovider/builder_maroto_test.go @@ -0,0 +1,621 @@ +package processorprovider_test + +import ( + "fmt" + "testing" + + "github.com/johnfercher/maroto/v2/internal/fixture" + "github.com/johnfercher/maroto/v2/mocks" + "github.com/johnfercher/maroto/v2/pkg/config" + "github.com/johnfercher/maroto/v2/pkg/consts/extension" + "github.com/johnfercher/maroto/v2/pkg/consts/orientation" + "github.com/johnfercher/maroto/v2/pkg/consts/pagesize" + "github.com/johnfercher/maroto/v2/pkg/consts/protection" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +func TestWithPageSize(t *testing.T) { + t.Run("when page size is null, should not set page size", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithPageSize("") + + assert.NotNil(t, cfg) + }) + t.Run("when page size is sent, should set page size", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithPageSize(pagesize.A1).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithPageSize("a1") + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithPageSize", 1) + }) +} + +func TestWithDimensions(t *testing.T) { + t.Run("when dimensions is nil, should not set dimensions", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithDimensions(nil) + + assert.NotNil(t, cfg) + }) + t.Run("when dimensions is sent, should set dimensions", func(t *testing.T) { + fixDimensions := propsmapper.Dimensions{Width: 10.0, Height: 10.0} + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithDimensions(fixDimensions.Width, fixDimensions.Height).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithDimensions(&fixDimensions) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithDimensions", 1) + }) +} + +func TestWithMargins(t *testing.T) { + t.Run("when only left margin is sent, should set only left margin", func(t *testing.T) { + fixMargins := propsmapper.Margins{Left: 10, Right: -1, Top: -1, Bottom: -1} + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithLeftMargin(fixMargins.Left).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithMargin(&fixMargins) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithLeftMargin", 1) + }) + t.Run("when only right margin is sent, should set only right margin", func(t *testing.T) { + fixMargins := propsmapper.Margins{Left: -1, Right: 10, Top: -1, Bottom: -1} + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithRightMargin(fixMargins.Right).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithMargin(&fixMargins) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithRightMargin", 1) + }) + t.Run("when only bottom margin is sent, should set only bottom margin", func(t *testing.T) { + fixMargins := propsmapper.Margins{Left: -1, Right: -1, Top: 10, Bottom: -1} + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithTopMargin(fixMargins.Top).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithMargin(&fixMargins) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithTopMargin", 1) + }) + t.Run("when only top margin is sent, should set only top margin", func(t *testing.T) { + fixMargins := propsmapper.Margins{Left: -1, Right: -1, Top: -1, Bottom: 10} + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithBottomMargin(fixMargins.Bottom).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithMargin(&fixMargins) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithBottomMargin", 1) + }) + t.Run("When margins is not set, should no set margin", func(t *testing.T) { + fixMargins := propsmapper.Margins{Left: 10, Right: 11, Top: 12, Bottom: 13} + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithBottomMargin(fixMargins.Bottom).Return(config.NewBuilder()) + build.EXPECT().WithTopMargin(fixMargins.Top).Return(config.NewBuilder()) + build.EXPECT().WithLeftMargin(fixMargins.Left).Return(config.NewBuilder()) + build.EXPECT().WithRightMargin(fixMargins.Right).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithMargin(&fixMargins) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithBottomMargin", 1) + build.AssertNumberOfCalls(t, "WithTopMargin", 1) + build.AssertNumberOfCalls(t, "WithLeftMargin", 1) + build.AssertNumberOfCalls(t, "WithRightMargin", 1) + }) +} + +func TestWithConcurrentMode(t *testing.T) { + t.Run("when 0 works is sent, should not set concurrent Mode", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithConcurrentMode(0) + + assert.NotNil(t, cfg) + }) + t.Run("when 2 works are sent, should set concurrent mode", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithConcurrentMode(2).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithConcurrentMode(2) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithConcurrentMode", 1) + }) +} + +func TestWithSequentialMode(t *testing.T) { + t.Run("when sequential mode is true, should set sequential mode", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithSequentialMode().Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithSequentialMode(true) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithSequentialMode", 1) + }) + t.Run("when sequential mode is false, should not set sequential mode", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithSequentialMode().Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithSequentialMode(false) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithSequentialMode", 1) + }) +} + +func TestWithSequentialLowMemoryMode(t *testing.T) { + t.Run("when sequential low memory mode is 0, should not set sequential low memory", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithSequentialLowMemoryMode(0) + + assert.NotNil(t, cfg) + }) + + t.Run("when sequential low memory mode is 2, should set sequential low memory", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithSequentialLowMemoryMode(2).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithSequentialLowMemoryMode(2) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithSequentialLowMemoryMode", 1) + }) +} + +func TestWithDebug(t *testing.T) { + t.Run("when debug is true, should set debug", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithDebug(true).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithDebug(true) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithDebug", 1) + }) + t.Run("when debug is false, should not set debug", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithDebug(false).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithDebug(false) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithDebug", 1) + }) +} + +func TestWithMaxGridSize(t *testing.T) { + t.Run("when max grid size is 0, should not set max grid size", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithMaxGridSize(0) + + assert.NotNil(t, cfg) + }) + + t.Run("when max grid size is 2, should set max grid size with 2", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithMaxGridSize(2).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithMaxGridSize(2) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithMaxGridSize", 1) + }) +} + +func TestWithDefaultFont(t *testing.T) { + t.Run("when font is nil, should not set font", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithDefaultFont(nil) + + assert.NotNil(t, cfg) + }) + t.Run("when invalid style is call, should set font", func(t *testing.T) { + fixFont := fixture.FontProp() + fixFont.Style = "invalid" + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithDefaultFont(&fixFont).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithDefaultFont(&propsmapper.Font{ + Family: fixFont.Family, + Style: string(fixFont.Style), Size: fixFont.Size, Color: (*propsmapper.Color)(fixFont.Color), + }) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithDefaultFont", 1) + }) + t.Run("when font is sent, should set font", func(t *testing.T) { + fixFont := fixture.FontProp() + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithDefaultFont(&fixFont).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithDefaultFont(&propsmapper.Font{ + Family: fixFont.Family, + Style: string(fixFont.Style), Size: fixFont.Size, Color: (*propsmapper.Color)(fixFont.Color), + }) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithDefaultFont", 1) + }) +} + +func TestWithPageNumber(t *testing.T) { + t.Run("when page number is nil, should not set page number", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithPageNumber(nil) + + assert.NotNil(t, cfg) + }) + t.Run("when page number is sent, should set page number", func(t *testing.T) { + fixPageNumber := fixture.PageProp() + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithPageNumber(fixPageNumber).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithPageNumber(&propsmapper.PageNumber{ + Pattern: fixPageNumber.Pattern, Place: string(fixPageNumber.Place), Family: fixPageNumber.Family, + Style: string(fixPageNumber.Style), Size: fixPageNumber.Size, Color: (*propsmapper.Color)(fixPageNumber.Color), + }) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithPageNumber", 1) + }) +} + +func TestWithProtection(t *testing.T) { + t.Run("when protection is nil, should not set protection", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithProtection(nil) + + assert.NotNil(t, cfg) + }) + + t.Run("when protection is sent, should set protection", func(t *testing.T) { + fixProtection := propsmapper.Protection{Type: 0, UserPassword: "user.password", OwnerPassword: "pass"} + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithProtection(protection.Type(fixProtection.Type), fixProtection.UserPassword, + fixProtection.OwnerPassword).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithProtection(&fixProtection) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithProtection", 1) + }) +} + +func TestWithCompression(t *testing.T) { + t.Run("when compression is true, should set compression", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithCompression(true).Return(config.NewBuilder()) + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithCompression(true) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithCompression", 1) + }) +} + +func TestWithOrientation(t *testing.T) { + t.Run("when orientation is null, should not set orientation", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithOrientation("") + + assert.NotNil(t, cfg) + }) + t.Run("when orientation is sent, should set orientation", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithOrientation(orientation.Vertical).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithOrientation("vertical") + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithOrientation", 1) + }) +} + +func TestWithMetadata(t *testing.T) { + t.Run("when metadata is nil, should not set any metadata", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithMetadata(nil) + + assert.NotNil(t, cfg) + }) + t.Run("when only author is sent, should set only author", func(t *testing.T) { + fixMetadata := fixture.Metadata() + fixMetadata.CreationDate = nil + fixMetadata.Creator = nil + fixMetadata.Subject = nil + fixMetadata.KeywordsStr = nil + fixMetadata.Title = nil + + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithAuthor(fixMetadata.Author.Text, fixMetadata.Author.UTF8).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithMetadata(fixMetadata) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithAuthor", 1) + }) + t.Run("when creation date is nil, should not set creation date", func(t *testing.T) { + fixMetadata := fixture.Metadata() + fixMetadata.Author = nil + fixMetadata.Creator = nil + fixMetadata.Subject = nil + fixMetadata.KeywordsStr = nil + fixMetadata.Title = nil + + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithCreationDate(*fixMetadata.CreationDate).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithMetadata(fixMetadata) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithCreationDate", 1) + }) + t.Run("when creator is nil, should not set creator", func(t *testing.T) { + fixMetadata := fixture.Metadata() + fixMetadata.Author = nil + fixMetadata.CreationDate = nil + fixMetadata.Subject = nil + fixMetadata.KeywordsStr = nil + fixMetadata.Title = nil + + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithCreator(fixMetadata.Creator.Text, fixMetadata.Creator.UTF8).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithMetadata(fixMetadata) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithCreator", 1) + }) + t.Run("when keywords is nil, should not set keywords", func(t *testing.T) { + fixMetadata := fixture.Metadata() + fixMetadata.Author = nil + fixMetadata.CreationDate = nil + fixMetadata.Subject = nil + fixMetadata.Creator = nil + fixMetadata.Title = nil + + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithKeywords(fixMetadata.KeywordsStr.Text, fixMetadata.KeywordsStr.UTF8).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithMetadata(fixMetadata) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithKeywords", 1) + }) + t.Run("when subject is nil, should not set subject", func(t *testing.T) { + fixMetadata := fixture.Metadata() + fixMetadata.Author = nil + fixMetadata.CreationDate = nil + fixMetadata.KeywordsStr = nil + fixMetadata.Creator = nil + fixMetadata.Title = nil + + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithSubject(fixMetadata.Subject.Text, fixMetadata.Subject.UTF8).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithMetadata(fixMetadata) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithSubject", 1) + }) + t.Run("when title is nil, should not set title", func(t *testing.T) { + fixMetadata := fixture.Metadata() + fixMetadata.Author = nil + fixMetadata.CreationDate = nil + fixMetadata.KeywordsStr = nil + fixMetadata.Creator = nil + fixMetadata.Subject = nil + + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithTitle(fixMetadata.Title.Text, fixMetadata.Title.UTF8).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithMetadata(fixMetadata) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithTitle", 1) + }) + t.Run("when all metadatas is sent, should set all metadatas", func(t *testing.T) { + fixMetadata := fixture.Metadata() + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithAuthor(fixMetadata.Author.Text, fixMetadata.Author.UTF8).Return(config.NewBuilder()) + build.EXPECT().WithCreationDate(*fixMetadata.CreationDate).Return(config.NewBuilder()) + build.EXPECT().WithCreator(fixMetadata.Creator.Text, fixMetadata.Creator.UTF8).Return(config.NewBuilder()) + build.EXPECT().WithKeywords(fixMetadata.KeywordsStr.Text, fixMetadata.KeywordsStr.UTF8).Return(config.NewBuilder()) + build.EXPECT().WithSubject(fixMetadata.Subject.Text, fixMetadata.Subject.UTF8).Return(config.NewBuilder()) + build.EXPECT().WithTitle(fixMetadata.Title.Text, fixMetadata.Title.UTF8).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithMetadata(fixMetadata) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithAuthor", 1) + build.AssertNumberOfCalls(t, "WithCreationDate", 1) + build.AssertNumberOfCalls(t, "WithCreator", 1) + build.AssertNumberOfCalls(t, "WithKeywords", 1) + build.AssertNumberOfCalls(t, "WithSubject", 1) + build.AssertNumberOfCalls(t, "WithTitle", 1) + }) +} + +func TestWithCustomFonts(t *testing.T) { + t.Run("when fonts is not sent, should not set fonts", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg, err := builder.WithCustomFonts(nil) + + assert.Nil(t, err) + assert.NotNil(t, cfg) + }) + t.Run("when is not possible load font file, should return an error", func(t *testing.T) { + fixCustomFont := propsmapper.CustomFont{Family: "family", Style: "bold", File: "file"} + repository := mocks.NewProcessorRepository(t) + repository.EXPECT().GetDocument(fixCustomFont.File).Return("", nil, fmt.Errorf("any")) + build := mocks.NewBuilder(t) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg, err := builder.WithCustomFonts([]*propsmapper.CustomFont{&fixCustomFont}) + + assert.NotNil(t, err) + assert.Nil(t, cfg) + }) + t.Run("when 2 fonts is sent, should set 2 fonts", func(t *testing.T) { + fixCustomFont := propsmapper.CustomFont{Family: "family", Style: "bold", File: "file"} + repository := mocks.NewProcessorRepository(t) + repository.EXPECT().GetDocument(fixCustomFont.File).Return(".ttt", []byte{}, nil) + build := mocks.NewBuilder(t) + build.EXPECT().WithCustomFonts(mock.Anything).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg, err := builder.WithCustomFonts([]*propsmapper.CustomFont{&fixCustomFont, &fixCustomFont}) + + assert.Nil(t, err) + assert.NotNil(t, cfg) + repository.AssertNumberOfCalls(t, "GetDocument", 2) + build.AssertNumberOfCalls(t, "WithCustomFonts", 1) + }) +} + +func TestWithBackgroundImage(t *testing.T) { + t.Run("when background image is not sent, should not set background image", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg, err := builder.WithCustomFonts(nil) + + assert.Nil(t, err) + assert.NotNil(t, cfg) + }) + t.Run("when is not possible load image, should return an error", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + repository.EXPECT().GetDocument("img").Return("", nil, fmt.Errorf("any")) + build := mocks.NewBuilder(t) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg, err := builder.WithBackgroundImage("img") + + assert.NotNil(t, err) + assert.Nil(t, cfg) + }) + t.Run("when backgroun image is sent, should set background", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + repository.EXPECT().GetDocument("img").Return(string(extension.Png), []byte{123}, nil) + build := mocks.NewBuilder(t) + build.EXPECT().WithBackgroundImage([]byte{123}, extension.Png).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg, err := builder.WithBackgroundImage("img") + + assert.Nil(t, err) + assert.NotNil(t, cfg) + repository.AssertNumberOfCalls(t, "GetDocument", 1) + build.AssertNumberOfCalls(t, "WithBackgroundImage", 1) + }) +} + +func TestWithDisableAutoPageBreak(t *testing.T) { + t.Run("when disable auto page break is true, should disable auto page break", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + build := mocks.NewBuilder(t) + build.EXPECT().WithDisableAutoPageBreak(true).Return(config.NewBuilder()) + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg := builder.WithDisableAutoPageBreak(true) + + assert.NotNil(t, cfg) + build.AssertNumberOfCalls(t, "WithDisableAutoPageBreak", 1) + }) +} diff --git a/test/maroto/processor/all_builder_pros.json b/test/maroto/processor/all_builder_pros.json index a282c876..1dad8398 100644 --- a/test/maroto/processor/all_builder_pros.json +++ b/test/maroto/processor/all_builder_pros.json @@ -9,7 +9,8 @@ "top": 10, "bottom": 10 }, - "chunk_workers": 10, + "concurrent_mode": 10, + "sequential_mode": false, "debug": true, "max_grid_size": 10, "default_font": { @@ -22,6 +23,22 @@ "blue": 150 } }, + "page_number":{ + "pattern": "pattern_test", + "place": "place_test", + "family": "family_test", + "style": "style_test", + "size": 10, + "color": { + "red": 10, + "green": 100, + "blue": 150 + } + }, + "custom_font": [ + {"family": "family_test", "style": "style_test", "file_path": "file_test"}, + {"family": "family_test2", "style": "style_test2", "file_path": "file_test2"} + ], "protection": { "type": "Print", "user_password": "senha123", @@ -29,7 +46,7 @@ }, "compression": true, "page_size": "T", - "orientation": "portrait", + "orientation": "vertical", "metadata": { "author": {"text": "user_test", "utf8": true}, "creator": {"text": "user_test", "utf8": true}, From a0e4fe1a0f29d6f78cdea04eaec268ddab6882d8 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 13 Nov 2024 21:33:52 -0300 Subject: [PATCH 070/116] feat: set provider builder props create methods to transform buldermapper into builder provider add builder properties to buidermapper --- .../mappers/buildermapper/builder.go | 64 +++--- .../processorprovider/builder_maroto.go | 188 ++++++++++++++++++ 2 files changed, 224 insertions(+), 28 deletions(-) create mode 100644 pkg/processor/processorprovider/builder_maroto.go diff --git a/pkg/processor/mappers/buildermapper/builder.go b/pkg/processor/mappers/buildermapper/builder.go index 317447b4..44003d57 100644 --- a/pkg/processor/mappers/buildermapper/builder.go +++ b/pkg/processor/mappers/buildermapper/builder.go @@ -7,21 +7,24 @@ import ( ) type Builder struct { - Dimensions *propsmapper.Dimensions - Margins *propsmapper.Margins - ChunkWorkers int - Debug bool - MaxGridSize int - DefaultFont *propsmapper.Font - CustomFonts []*propsmapper.CustomFont - PageNumber *propsmapper.PageNumber - Protection *propsmapper.Protection - Compression bool - PageSize string - Orientation string - Metadata *propsmapper.Metadata - DisableAutoPageBreak bool - GenerationMode string + PageSize string + Dimensions *propsmapper.Dimensions + Margins *propsmapper.Margins + ConcurrentMode int + SequentialMode bool + SequentialLowMemoryMode int + Debug bool + MaxGridSize int + DefaultFont *propsmapper.Font + CustomFonts []*propsmapper.CustomFont + PageNumber *propsmapper.PageNumber + Protection *propsmapper.Protection + Compression bool + Orientation string + Metadata *propsmapper.Metadata + DisableAutoPageBreak bool + GenerationMode string + BackgroundImage string } // NewBuilder is responsible for creating Builder properties. If an invalid property is provided, a default value will be assigned. @@ -32,19 +35,24 @@ func NewBuilder(builder interface{}) (*Builder, error) { } return &Builder{ - Dimensions: propsmapper.NewDimensions(builderMap["dimensions"]), - Margins: propsmapper.NewMargins(builderMap["margins"]), - ChunkWorkers: int(factoryField(builderMap["chunk_workers"], -1.0)), - Debug: factoryField(builderMap["debug"], false), - MaxGridSize: int(factoryField(builderMap["max_grid_size"], -1.0)), - DefaultFont: propsmapper.NewFont(builderMap["default_font"]), - Protection: propsmapper.NewProtection(builderMap["protection"]), - Compression: factoryField(builderMap["compression"], false), - PageSize: factoryField(builderMap["page_size"], ""), - Orientation: factoryField(builderMap["orientation"], ""), - Metadata: propsmapper.NewMetadata(builderMap["metadata"]), - DisableAutoPageBreak: factoryField(builderMap["disable_auto_page_break"], false), - GenerationMode: factoryField(builderMap["generation_mode"], ""), + PageSize: factoryField(builderMap["page_size"], ""), + Dimensions: propsmapper.NewDimensions(builderMap["dimensions"]), + Margins: propsmapper.NewMargins(builderMap["margins"]), + ConcurrentMode: int(factoryField(builderMap["concurrent_mode"], -1.0)), + SequentialMode: factoryField(builderMap["sequential_mode"], false), + SequentialLowMemoryMode: int(factoryField(builderMap["sequential_low_memory_mode"], -1.0)), + Debug: factoryField(builderMap["debug"], false), + MaxGridSize: int(factoryField(builderMap["max_grid_size"], -1.0)), + DefaultFont: propsmapper.NewFont(builderMap["default_font"]), + CustomFonts: propsmapper.NewCustomFonts(builderMap["custom_font"]), + PageNumber: propsmapper.NewPageNumber(builderMap["page_number"]), + Protection: propsmapper.NewProtection(builderMap["protection"]), + Compression: factoryField(builderMap["compression"], false), + Orientation: propsmapper.NewOrientation(factoryField(builderMap["orientation"], "")), + Metadata: propsmapper.NewMetadata(builderMap["metadata"]), + DisableAutoPageBreak: factoryField(builderMap["disable_auto_page_break"], false), + GenerationMode: factoryField(builderMap["generation_mode"], ""), + BackgroundImage: factoryField(builderMap["background_image"], ""), }, nil } diff --git a/pkg/processor/processorprovider/builder_maroto.go b/pkg/processor/processorprovider/builder_maroto.go new file mode 100644 index 00000000..30e1ee94 --- /dev/null +++ b/pkg/processor/processorprovider/builder_maroto.go @@ -0,0 +1,188 @@ +package processorprovider + +import ( + "github.com/johnfercher/maroto/v2/pkg/config" + "github.com/johnfercher/maroto/v2/pkg/consts/extension" + "github.com/johnfercher/maroto/v2/pkg/consts/fontstyle" + "github.com/johnfercher/maroto/v2/pkg/consts/orientation" + "github.com/johnfercher/maroto/v2/pkg/consts/pagesize" + "github.com/johnfercher/maroto/v2/pkg/consts/protection" + "github.com/johnfercher/maroto/v2/pkg/core/entity" + "github.com/johnfercher/maroto/v2/pkg/processor/core" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" + "github.com/johnfercher/maroto/v2/pkg/props" + "github.com/johnfercher/maroto/v2/pkg/repository" +) + +type MarotoBuilder struct { + cfg config.Builder + repository core.ProcessorRepository +} + +func NewMarotoBuilder(repository core.ProcessorRepository, cfg config.Builder) *MarotoBuilder { + return &MarotoBuilder{ + repository: repository, + cfg: cfg, + } +} + +func (m *MarotoBuilder) WithPageSize(size string) config.Builder { + validAndRun(func() { m.cfg.WithPageSize(pagesize.Type(size)) }, size != "") + return m.cfg +} + +// WithDimensions defines custom page dimensions, this overrides page size. +func (m *MarotoBuilder) WithDimensions(dimensions *propsmapper.Dimensions) config.Builder { + validAndRun(func() { m.cfg.WithDimensions(dimensions.Width, dimensions.Height) }, dimensions != nil) + return m.cfg +} + +// WithLeftMargin customize margin. +func (m *MarotoBuilder) WithMargin(margin *propsmapper.Margins) config.Builder { + validAndRun(func() { m.cfg.WithBottomMargin(margin.Bottom) }, margin.Bottom >= 0) + validAndRun(func() { m.cfg.WithTopMargin(margin.Top) }, margin.Top >= 0) + validAndRun(func() { m.cfg.WithLeftMargin(margin.Left) }, margin.Left >= 0) + validAndRun(func() { m.cfg.WithRightMargin(margin.Right) }, margin.Right >= 0) + return m.cfg +} + +// WithConcurrentMode defines concurrent generation, chunk workers define how mano chuncks +// will be executed concurrently. +func (m *MarotoBuilder) WithConcurrentMode(chunkWorkers int) config.Builder { + validAndRun(func() { m.cfg.WithConcurrentMode(chunkWorkers) }, chunkWorkers > 0) + return m.cfg +} + +// WithSequentialMode defines that maroto will run in default mode. +func (m *MarotoBuilder) WithSequentialMode(on bool) config.Builder { + m.cfg.WithSequentialMode() + return m.cfg +} + +// WithSequentialLowMemoryMode defines that maroto will run focusing in reduce memory consumption, +// chunk workers define how many divisions the work will have. +func (m *MarotoBuilder) WithSequentialLowMemoryMode(chunkWorkers int) config.Builder { + validAndRun(func() { m.cfg.WithSequentialLowMemoryMode(chunkWorkers) }, chunkWorkers > 0) + return m.cfg +} + +// WithDebug defines a debug behaviour where maroto will draw borders in everything. +func (m *MarotoBuilder) WithDebug(on bool) config.Builder { + m.cfg.WithDebug(on) + return m.cfg +} + +// WithMaxGridSize defines a custom max grid sum which it will change the sum of column sizes. +func (m *MarotoBuilder) WithMaxGridSize(maxGridSize int) config.Builder { + validAndRun(func() { m.cfg.WithMaxGridSize(maxGridSize) }, maxGridSize > 0) + return m.cfg +} + +// WithDefaultFont defines a custom font, other than arial. This can be used to define a custom font as default. +func (m *MarotoBuilder) WithDefaultFont(font *propsmapper.Font) config.Builder { + validAndRun(func() { + m.cfg.WithDefaultFont(&props.Font{ + Family: font.Family, Style: fontstyle.Type(font.Style), + Size: font.Size, Color: (*props.Color)(font.Color), + }) + }, font != nil) + return m.cfg +} + +// WithPageNumber defines a string pattern to write the current page and total. +func (m *MarotoBuilder) WithPageNumber(pageNumber *propsmapper.PageNumber) config.Builder { + validAndRun(func() { + m.cfg.WithPageNumber(props.PageNumber{ + Pattern: pageNumber.Pattern, Place: props.Place(pageNumber.Place), Family: pageNumber.Family, + Style: fontstyle.Type(pageNumber.Style), Size: pageNumber.Size, + Color: &props.Color{Red: pageNumber.Color.Red, Green: pageNumber.Color.Green, Blue: pageNumber.Color.Blue}, + }) + }, pageNumber != nil) + return m.cfg +} + +// WithProtection defines protection types to the PDF document. +func (m *MarotoBuilder) WithProtection(protectionmapper *propsmapper.Protection) config.Builder { + validAndRun(func() { + m.cfg.WithProtection(protection.Type(protectionmapper.Type), protectionmapper.UserPassword, protectionmapper.OwnerPassword) + }, protectionmapper != nil) + return m.cfg +} + +// WithCompression defines compression. +func (m *MarotoBuilder) WithCompression(compression bool) config.Builder { + m.cfg.WithCompression(compression) + return m.cfg +} + +// WithOrientation defines the page orientation. The default orientation is vertical, +// if horizontal is defined width and height will be flipped. +func (m *MarotoBuilder) WithOrientation(orientationMapper string) config.Builder { + validAndRun(func() { m.cfg.WithOrientation(orientation.Type(orientationMapper)) }, orientationMapper != "") + return m.cfg +} + +// WithAuthor defines the author name metadata. +func (m *MarotoBuilder) WithMetadata(metadata *propsmapper.Metadata) config.Builder { + if metadata != nil { + validAndRun(func() { m.cfg.WithAuthor(metadata.Author.Text, metadata.Author.UTF8) }, metadata.Author != nil) + validAndRun(func() { m.cfg.WithCreationDate(*metadata.CreationDate) }, metadata.CreationDate != nil) + validAndRun(func() { m.cfg.WithCreator(metadata.Creator.Text, metadata.Creator.UTF8) }, metadata.Creator != nil) + validAndRun(func() { m.cfg.WithKeywords(metadata.KeywordsStr.Text, metadata.KeywordsStr.UTF8) }, metadata.KeywordsStr != nil) + validAndRun(func() { m.cfg.WithSubject(metadata.Subject.Text, metadata.Subject.UTF8) }, metadata.Subject != nil) + validAndRun(func() { m.cfg.WithTitle(metadata.Title.Text, metadata.Title.UTF8) }, metadata.Title != nil) + } + return m.cfg +} + +// WithCustomFonts add custom fonts. +func (m *MarotoBuilder) WithCustomFonts(customFonts []*propsmapper.CustomFont) (config.Builder, error) { + if len(customFonts) == 0 { + return m.cfg, nil + } + newFonts, err := m.loadFonts(customFonts) + if err != nil { + return nil, err + } + m.cfg.WithCustomFonts(newFonts) + return m.cfg, nil +} + +// WithBackgroundImage defines the background image that will be applied in every page. +func (m *MarotoBuilder) WithBackgroundImage(backgroundImage string) (config.Builder, error) { + if backgroundImage == "" { + return m.cfg, nil + } + + ext, imageBytes, err := m.repository.GetDocument(backgroundImage) + if err != nil { + return nil, err + } + m.cfg.WithBackgroundImage(imageBytes, extension.Type(ext)) + return m.cfg, nil +} + +// WithDisableAutoPageBreak defines the option to disable automatic page breaks. +func (m *MarotoBuilder) WithDisableAutoPageBreak(disabled bool) config.Builder { + m.cfg.WithDisableAutoPageBreak(disabled) + return m.cfg +} + +func validAndRun(setParam func(), parameter bool) { + if parameter { + setParam() + } +} + +func (m *MarotoBuilder) loadFonts(customFonts []*propsmapper.CustomFont) ([]*entity.CustomFont, error) { + fontRepository := repository.New() + + for _, customFont := range customFonts { + _, fontBytes, err := m.repository.GetDocument(customFont.File) + if err != nil { + return nil, err + } + fontRepository.AddUTF8FontFromBytes(customFont.Family, fontstyle.Type(customFont.Style), fontBytes) + } + return fontRepository.Load() +} From 7bd595b54a9d9e7d457998d19e5388fb01014b01 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 13 Nov 2024 21:35:38 -0300 Subject: [PATCH 071/116] style: implement golint suggestions --- .../mappers/components/codemapper/barcode.go | 4 ++- .../components/codemapper/matrixcode.go | 4 ++- .../mappers/components/codemapper/qrcode.go | 4 ++- .../mappers/components/colmapper/col.go | 4 ++- .../mappers/components/imagemapper/image.go | 8 +++-- .../mappers/components/linemapper/line.go | 4 ++- .../mappers/components/listmapper/list.go | 8 +++-- .../components/listmapper/list_test.go | 2 +- .../mappers/components/pagemapper/page.go | 4 ++- .../mappers/components/rowmapper/row.go | 4 ++- .../components/signaturemapper/signature.go | 4 ++- .../mappers/components/textmapper/text.go | 4 ++- .../mappers/propsmapper/customfont.go | 35 +++++++++++++------ .../mappers/propsmapper/pagenumber.go | 22 ++++++------ pkg/processor/processorprovider/Maroto.go | 4 +-- 15 files changed, 77 insertions(+), 38 deletions(-) diff --git a/pkg/processor/mappers/components/codemapper/barcode.go b/pkg/processor/mappers/components/codemapper/barcode.go index 780df5dc..59e1ded6 100644 --- a/pkg/processor/mappers/components/codemapper/barcode.go +++ b/pkg/processor/mappers/components/codemapper/barcode.go @@ -109,7 +109,9 @@ func (b *Barcode) getCode(content map[string]interface{}) (string, error) { return codeValid, nil } -func (b *Barcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { +func (b *Barcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( + []processorprovider.ProviderComponent, error, +) { code, err := b.getCode(content) if err != nil { return nil, err diff --git a/pkg/processor/mappers/components/codemapper/matrixcode.go b/pkg/processor/mappers/components/codemapper/matrixcode.go index 34abb60f..745357c9 100644 --- a/pkg/processor/mappers/components/codemapper/matrixcode.go +++ b/pkg/processor/mappers/components/codemapper/matrixcode.go @@ -109,7 +109,9 @@ func (m *Matrixcode) getCode(content map[string]interface{}) (string, error) { return codeValid, nil } -func (m *Matrixcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { +func (m *Matrixcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( + []processorprovider.ProviderComponent, error, +) { code, err := m.getCode(content) if err != nil { return nil, err diff --git a/pkg/processor/mappers/components/codemapper/qrcode.go b/pkg/processor/mappers/components/codemapper/qrcode.go index 19e87e90..21a1f820 100644 --- a/pkg/processor/mappers/components/codemapper/qrcode.go +++ b/pkg/processor/mappers/components/codemapper/qrcode.go @@ -109,7 +109,9 @@ func (q *Qrcode) getCode(content map[string]interface{}) (string, error) { return codeValid, nil } -func (q *Qrcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { +func (q *Qrcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( + []processorprovider.ProviderComponent, error, +) { code, err := q.getCode(content) if err != nil { return nil, err diff --git a/pkg/processor/mappers/components/colmapper/col.go b/pkg/processor/mappers/components/colmapper/col.go index bec0af45..6f667d1d 100644 --- a/pkg/processor/mappers/components/colmapper/col.go +++ b/pkg/processor/mappers/components/colmapper/col.go @@ -77,7 +77,9 @@ func (c *Col) getFieldMappers() map[string]func(interface{}) (mappers.Componentm // Generate is responsible for generating the col component, it will generate all the internal components and add them to the col // - The content is a map with the properties of the col components -func (c *Col) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { +func (c *Col) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( + []processorprovider.ProviderComponent, error, +) { components := make([]processorprovider.ProviderComponent, 0, len(c.Components)) for _, component := range c.Components { newComponent, err := component.Generate(content, provider) diff --git a/pkg/processor/mappers/components/imagemapper/image.go b/pkg/processor/mappers/components/imagemapper/image.go index 6768093c..497d7411 100644 --- a/pkg/processor/mappers/components/imagemapper/image.go +++ b/pkg/processor/mappers/components/imagemapper/image.go @@ -79,12 +79,12 @@ func (i *Image) setPath(template interface{}) error { return nil } -func (b *Image) setProps(template interface{}) error { +func (i *Image) setProps(template interface{}) error { props, err := propsmapper.NewRect(template) if err != nil { return err } - b.Props = props + i.Props = props return nil } @@ -103,7 +103,9 @@ func (i *Image) getImagePath(content map[string]interface{}) (string, error) { return imageValid, nil } -func (i *Image) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { +func (i *Image) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( + []processorprovider.ProviderComponent, error, +) { path, err := i.getImagePath(content) if err != nil { return nil, err diff --git a/pkg/processor/mappers/components/linemapper/line.go b/pkg/processor/mappers/components/linemapper/line.go index 584f6045..d93bdcd3 100644 --- a/pkg/processor/mappers/components/linemapper/line.go +++ b/pkg/processor/mappers/components/linemapper/line.go @@ -60,6 +60,8 @@ func (l *Line) setProps(templateProps interface{}) error { return nil } -func (l *Line) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { +func (l *Line) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( + []processorprovider.ProviderComponent, error, +) { return []processorprovider.ProviderComponent{provider.CreateLine(l.Props)}, nil } diff --git a/pkg/processor/mappers/components/listmapper/list.go b/pkg/processor/mappers/components/listmapper/list.go index 137f4e42..30a39af7 100644 --- a/pkg/processor/mappers/components/listmapper/list.go +++ b/pkg/processor/mappers/components/listmapper/list.go @@ -56,7 +56,9 @@ func (l *List) getListContent(content map[string]interface{}) ([]map[string]inte return nil, fmt.Errorf("ensure that the contents of the list \"%s\" can be converted to []map[string]interface{}", l.SourceKey) } -func (l *List) generateTemplates(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { +func (l *List) generateTemplates(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( + []processorprovider.ProviderComponent, error, +) { components := make([]processorprovider.ProviderComponent, 0, len(l.Templates)) for _, template := range l.Templates { component, err := template.Generate(content, provider) @@ -68,7 +70,9 @@ func (l *List) generateTemplates(content map[string]interface{}, provider proces return components, nil } -func (l *List) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { +func (l *List) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( + []processorprovider.ProviderComponent, error, +) { listContent, err := l.getListContent(content) if err != nil { return nil, err diff --git a/pkg/processor/mappers/components/listmapper/list_test.go b/pkg/processor/mappers/components/listmapper/list_test.go index fb6ed4f8..b4bf50a5 100644 --- a/pkg/processor/mappers/components/listmapper/list_test.go +++ b/pkg/processor/mappers/components/listmapper/list_test.go @@ -78,7 +78,7 @@ func TestGenerate(t *testing.T) { assert.NotNil(t, err) }) - t.Run("when componentes is not generate, should return an error", func(t *testing.T) { + t.Run("when components is not generate, should return an error", func(t *testing.T) { contentRow1 := map[string]interface{}{"row_1": nil} listContent := map[string]interface{}{"list": []map[string]interface{}{contentRow1}} provider := mocks.NewProcessorProvider(t) diff --git a/pkg/processor/mappers/components/pagemapper/page.go b/pkg/processor/mappers/components/pagemapper/page.go index c5c4fa9f..6b704724 100644 --- a/pkg/processor/mappers/components/pagemapper/page.go +++ b/pkg/processor/mappers/components/pagemapper/page.go @@ -65,7 +65,9 @@ func (p *Page) getPageContent(content map[string]interface{}) (map[string]interf return nil, fmt.Errorf("ensure that the contents of the page \"%s\" can be converted to map[string]interface{}", p.SourceKey) } -func (p *Page) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { +func (p *Page) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( + []processorprovider.ProviderComponent, error, +) { pageContent, err := p.getPageContent(content) if err != nil { return nil, err diff --git a/pkg/processor/mappers/components/rowmapper/row.go b/pkg/processor/mappers/components/rowmapper/row.go index f53abc48..6a793602 100644 --- a/pkg/processor/mappers/components/rowmapper/row.go +++ b/pkg/processor/mappers/components/rowmapper/row.go @@ -99,7 +99,9 @@ func (r *Row) getRowContent(content map[string]interface{}) (map[string]interfac return nil, fmt.Errorf("ensure that the contents of the row \"%s\" can be converted to map[string]interface{}", r.SourceKey) } -func (r *Row) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { +func (r *Row) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( + []processorprovider.ProviderComponent, error, +) { rowContent, err := r.getRowContent(content) if err != nil { return nil, err diff --git a/pkg/processor/mappers/components/signaturemapper/signature.go b/pkg/processor/mappers/components/signaturemapper/signature.go index 38c19770..25d64dc4 100644 --- a/pkg/processor/mappers/components/signaturemapper/signature.go +++ b/pkg/processor/mappers/components/signaturemapper/signature.go @@ -108,7 +108,9 @@ func (s *Signature) getSignature(content map[string]interface{}) (string, error) return signatureValid, nil } -func (s *Signature) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { +func (s *Signature) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( + []processorprovider.ProviderComponent, error, +) { signature, err := s.getSignature(content) if err != nil { return nil, err diff --git a/pkg/processor/mappers/components/textmapper/text.go b/pkg/processor/mappers/components/textmapper/text.go index 98c2499a..9ac232ee 100644 --- a/pkg/processor/mappers/components/textmapper/text.go +++ b/pkg/processor/mappers/components/textmapper/text.go @@ -107,7 +107,9 @@ func (t *Text) getValue(content map[string]interface{}) (string, error) { return textValid, nil } -func (t *Text) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { +func (t *Text) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( + []processorprovider.ProviderComponent, error, +) { signature, err := t.getValue(content) if err != nil { return nil, err diff --git a/pkg/processor/mappers/propsmapper/customfont.go b/pkg/processor/mappers/propsmapper/customfont.go index 6649054f..250475f4 100644 --- a/pkg/processor/mappers/propsmapper/customfont.go +++ b/pkg/processor/mappers/propsmapper/customfont.go @@ -1,24 +1,39 @@ package propsmapper type CustomFont struct { - Family *string - Style *string - File *string - Bytes []*byte + Family string + Style string + File string } -// NewCustomFont is responsible for creating the CustomFont, if the CustomFont fields cannot be +// newCustomFont is responsible for creating the CustomFont, if the CustomFont fields cannot be // converted, an invalid value is set. -func NewCustomFont(font interface{}) *CustomFont { +func newCustomFont(font interface{}) *CustomFont { fontMap, ok := font.(map[string]interface{}) if !ok { return nil } return &CustomFont{ - Family: convertFields(fontMap["family"], ""), - Style: convertFields(fontMap["style"], ""), - File: convertFields(fontMap["file"], ""), - // Bytes: NewColor(fontMap["bytes"]), + Family: *convertFields(fontMap["family"], ""), + Style: *convertFields(fontMap["style"], ""), + File: *convertFields(fontMap["file_path"], ""), } } + +// NewCustomFont is responsible for creating a CustomFont list +func NewCustomFonts(interfaceFonts interface{}) []*CustomFont { + fonts, ok := interfaceFonts.([]interface{}) + if !ok { + return nil + } + customFonts := make([]*CustomFont, 0, len(fonts)) + + for _, font := range fonts { + if newFont := newCustomFont(font); newFont != nil { + customFonts = append(customFonts, newCustomFont(font)) + } + } + + return customFonts +} diff --git a/pkg/processor/mappers/propsmapper/pagenumber.go b/pkg/processor/mappers/propsmapper/pagenumber.go index b34dbb55..6526e25b 100644 --- a/pkg/processor/mappers/propsmapper/pagenumber.go +++ b/pkg/processor/mappers/propsmapper/pagenumber.go @@ -3,15 +3,15 @@ package propsmapper // PageNumber have attributes of page number type PageNumber struct { // Pattern is the string pattern which will be used to apply the page count component. - Pattern *string + Pattern string // Place defines where the page count component will be placed. - Place *string + Place string // Family defines which font family will be applied to page count. - Family *string + Family string // Style defines which font style will be applied to page count. - Style *string + Style string // Size defines which font size will be applied to page count. - Size *float64 + Size float64 // Color defines which will be applied to page count. Color *Color } @@ -21,15 +21,15 @@ type PageNumber struct { func NewPageNumber(pageNumber interface{}) *PageNumber { pageNumberMap, ok := pageNumber.(map[string]interface{}) if !ok { - return nil + return &PageNumber{} } return &PageNumber{ - Pattern: convertFields(pageNumberMap["pattern"], ""), - Place: convertFields(pageNumberMap["place"], ""), - Family: convertFields(pageNumberMap["family"], ""), - Style: convertFields(pageNumberMap["style"], ""), - Size: convertFields(pageNumberMap["size"], 0.0), + Pattern: *convertFields(pageNumberMap["pattern"], ""), + Place: *convertFields(pageNumberMap["place"], ""), + Family: *convertFields(pageNumberMap["family"], ""), + Style: *convertFields(pageNumberMap["style"], ""), + Size: *convertFields(pageNumberMap["size"], 0.0), Color: NewColor(pageNumberMap["color"]), } } diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index 20f2768d..f32169fe 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -78,8 +78,8 @@ func (m *Maroto) CreateText(value string, textsProps ...*propsmapper.Text) Provi } return text.New(value, props.Text{ - Top: tProps.Top, Left: tProps.Left, Right: tProps.Right, Family: tProps.Family, - Style: fontstyle.Type(tProps.Style), Size: tProps.Size, Align: align.Type(tProps.Align), BreakLineStrategy: breakline.Strategy(tProps.BreakLineStrategy), + Top: tProps.Top, Left: tProps.Left, Right: tProps.Right, Family: tProps.Family, Style: fontstyle.Type(tProps.Style), + Size: tProps.Size, Align: align.Type(tProps.Align), BreakLineStrategy: breakline.Strategy(tProps.BreakLineStrategy), VerticalPadding: tProps.VerticalPadding, Color: (*props.Color)(tProps.Color), Hyperlink: &tProps.Hyperlink, }) } From 983385d99d331ab21660ef1c40b06795feba73d9 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Fri, 15 Nov 2024 12:39:06 -0300 Subject: [PATCH 072/116] fix: avoid cyclic import between processor and Maroto --- metricsdecorator_test.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/metricsdecorator_test.go b/metricsdecorator_test.go index ee66d78b..f2116b83 100644 --- a/metricsdecorator_test.go +++ b/metricsdecorator_test.go @@ -1,9 +1,10 @@ -package maroto +package maroto_test import ( "fmt" "testing" + "github.com/johnfercher/maroto/v2" "github.com/johnfercher/maroto/v2/pkg/core/entity" "github.com/johnfercher/maroto/v2/pkg/components/text" @@ -20,7 +21,7 @@ import ( func TestNewMetricsDecorator(t *testing.T) { // Act - sut := NewMetricsDecorator(nil) + sut := maroto.NewMetricsDecorator(nil) // Assert assert.NotNil(t, sut) @@ -37,7 +38,7 @@ func TestMetricsDecorator_AddPages(t *testing.T) { inner.EXPECT().AddPages(pg) inner.EXPECT().Generate().Return(docToReturn, nil) - sut := NewMetricsDecorator(inner) + sut := maroto.NewMetricsDecorator(inner) // Act sut.AddPages(pg) @@ -67,7 +68,7 @@ func TestMetricsDecorator_AddRow(t *testing.T) { inner.EXPECT().AddRow(10.0, col).Return(nil) inner.EXPECT().Generate().Return(docToReturn, nil) - sut := NewMetricsDecorator(inner) + sut := maroto.NewMetricsDecorator(inner) // Act sut.AddRow(10, col) @@ -97,7 +98,7 @@ func TestMetricsDecorator_AddRows(t *testing.T) { inner.EXPECT().AddRows(row) inner.EXPECT().Generate().Return(docToReturn, nil) - sut := NewMetricsDecorator(inner) + sut := maroto.NewMetricsDecorator(inner) // Act sut.AddRows(row) @@ -128,7 +129,7 @@ func TestMetricsDecorator_GetStructure(t *testing.T) { inner.EXPECT().GetStructure().Return(&node.Node[core.Structure]{}) inner.EXPECT().Generate().Return(docToReturn, nil) - sut := NewMetricsDecorator(inner) + sut := maroto.NewMetricsDecorator(inner) sut.AddRows(row) // Act @@ -156,7 +157,7 @@ func TestMetricsDecorator_FitlnCurrentPage(t *testing.T) { inner.EXPECT().FitlnCurrentPage(10.0).Return(true) inner.EXPECT().FitlnCurrentPage(20.0).Return(false) - sut := NewMetricsDecorator(inner) + sut := maroto.NewMetricsDecorator(inner) // Act & Assert assert.True(t, sut.FitlnCurrentPage(10)) @@ -171,7 +172,7 @@ func TestMetricsDecorator_GetCurrentConfig(t *testing.T) { inner := mocks.NewMaroto(t) inner.EXPECT().GetCurrentConfig().Return(cfgToReturn) - sut := NewMetricsDecorator(inner) + sut := maroto.NewMetricsDecorator(inner) // Act cfg := sut.GetCurrentConfig() @@ -188,7 +189,7 @@ func TestMetricsDecorator_RegisterHeader(t *testing.T) { inner.EXPECT().RegisterHeader(row).Return(nil) inner.EXPECT().Generate().Return(&core.Pdf{}, nil) - sut := NewMetricsDecorator(inner) + sut := maroto.NewMetricsDecorator(inner) // Act err := sut.RegisterHeader(row) @@ -214,7 +215,7 @@ func TestMetricsDecorator_RegisterFooter(t *testing.T) { inner.EXPECT().RegisterFooter(row).Return(nil) inner.EXPECT().Generate().Return(&core.Pdf{}, nil) - sut := NewMetricsDecorator(inner) + sut := maroto.NewMetricsDecorator(inner) // Act err := sut.RegisterFooter(row) From 7b2783fea91be7d2f20a92b79ac7cddf816e732e Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sat, 16 Nov 2024 17:43:19 -0300 Subject: [PATCH 073/116] test: validate document generation --- internal/fixture/processorfixture.go | 98 ++++++ mocks/ProcessorProvider.go | 302 +++++++++++++++++- .../mappers/documentmapper/document_test.go | 197 +++++++++++- .../processorprovider/Maroto_test.go | 164 +++++++++- .../processorprovider/builder_maroto_test.go | 70 ++++ .../provider/document_with_footer.json | 61 ++++ .../provider/document_with_header.json | 61 ++++ .../provider/document_with_page.json | 48 +++ 8 files changed, 962 insertions(+), 39 deletions(-) create mode 100644 test/maroto/processor/provider/document_with_footer.json create mode 100644 test/maroto/processor/provider/document_with_header.json create mode 100644 test/maroto/processor/provider/document_with_page.json diff --git a/internal/fixture/processorfixture.go b/internal/fixture/processorfixture.go index f598cd42..6e9d3199 100644 --- a/internal/fixture/processorfixture.go +++ b/internal/fixture/processorfixture.go @@ -4,7 +4,9 @@ import ( "time" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/buildermapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/codemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/colmapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/imagemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/linemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/listmapper" @@ -69,3 +71,99 @@ func Metadata() *propsmapper.Metadata { CreationDate: &creation, KeywordsStr: &propsmapper.Utf8Text{Text: "KeywordsStr", UTF8: true}, } } + +func BuilderProps() *buildermapper.Builder { + time, _ := time.Parse("2006-01-02 15:04:05", "2024-10-09 14:30:00") + return &buildermapper.Builder{ + Dimensions: &propsmapper.Dimensions{ + Width: 10.0, + Height: 10.0, + }, + Margins: &propsmapper.Margins{ + Left: 10.0, + Right: 10.0, + Top: 10.0, + Bottom: 10.0, + }, + SequentialMode: false, + ConcurrentMode: 10, + SequentialLowMemoryMode: -1, + Debug: true, + MaxGridSize: 10, + DefaultFont: &propsmapper.Font{ + Family: "Arial", + Style: "bold", + Size: 10, + Color: &propsmapper.Color{ + Red: 10, + Green: 100, + Blue: 150, + }, + }, + PageNumber: &propsmapper.PageNumber{ + Pattern: "pattern_test", + Place: "place_test", + Family: "family_test", + Style: "style_test", + Size: 10.0, + Color: &propsmapper.Color{ + Red: 10, + Green: 100, + Blue: 150, + }, + }, + CustomFonts: []*propsmapper.CustomFont{ + {Family: "family_test", Style: "style_test", File: "file_test"}, + {Family: "family_test2", Style: "style_test2", File: "file_test2"}, + }, + Protection: &propsmapper.Protection{ + Type: 4, + UserPassword: "senha123", + OwnerPassword: "senha123", + }, + Compression: true, + PageSize: "T", + Orientation: "vertical", + Metadata: &propsmapper.Metadata{ + Author: &propsmapper.Utf8Text{Text: "user_test", UTF8: true}, + Creator: &propsmapper.Utf8Text{Text: "user_test", UTF8: true}, + Subject: &propsmapper.Utf8Text{Text: "test", UTF8: true}, + Title: &propsmapper.Utf8Text{Text: "report", UTF8: true}, + CreationDate: &time, + KeywordsStr: &propsmapper.Utf8Text{Text: "test", UTF8: true}, + }, + DisableAutoPageBreak: true, + GenerationMode: "concurrent", + } +} + +func Row(sourceKeyRow, sourceKeyText string) *rowmapper.Row { + col := colmapper.Col{ + Size: 12, + Components: []mappers.Componentmapper{&textmapper.Text{SourceKey: sourceKeyText}}, + } + + return &rowmapper.Row{ + Height: 10, + SourceKey: sourceKeyRow, + Cols: []mappers.Componentmapper{&col}, + } +} + +func Page(sourceKeyPage, sourceKeyRow, sourceKeyText string) *pagemapper.Page { + col := colmapper.Col{ + Size: 12, + Components: []mappers.Componentmapper{&textmapper.Text{SourceKey: sourceKeyText}}, + } + + return &pagemapper.Page{ + SourceKey: sourceKeyPage, + Rows: []mappers.Componentmapper{ + &rowmapper.Row{ + Height: 10, + SourceKey: sourceKeyRow, + Cols: []mappers.Componentmapper{&col}, + }, + }, + } +} diff --git a/mocks/ProcessorProvider.go b/mocks/ProcessorProvider.go index 89e0fb26..e2095962 100644 --- a/mocks/ProcessorProvider.go +++ b/mocks/ProcessorProvider.go @@ -3,9 +3,14 @@ package mocks import ( - propsmapper "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" - processorprovider "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" + core "github.com/johnfercher/maroto/v2/pkg/core" mock "github.com/stretchr/testify/mock" + + node "github.com/johnfercher/go-tree/node" + + processorprovider "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" + + propsmapper "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" ) // ProcessorProvider is an autogenerated mock type for the ProcessorProvider type @@ -21,6 +26,219 @@ func (_m *ProcessorProvider) EXPECT() *ProcessorProvider_Expecter { return &ProcessorProvider_Expecter{mock: &_m.Mock} } +// AddFooter provides a mock function with given fields: footer +func (_m *ProcessorProvider) AddFooter(footer ...processorprovider.ProviderComponent) (processorprovider.ProcessorProvider, error) { + _va := make([]interface{}, len(footer)) + for _i := range footer { + _va[_i] = footer[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for AddFooter") + } + + var r0 processorprovider.ProcessorProvider + var r1 error + if rf, ok := ret.Get(0).(func(...processorprovider.ProviderComponent) (processorprovider.ProcessorProvider, error)); ok { + return rf(footer...) + } + if rf, ok := ret.Get(0).(func(...processorprovider.ProviderComponent) processorprovider.ProcessorProvider); ok { + r0 = rf(footer...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(processorprovider.ProcessorProvider) + } + } + + if rf, ok := ret.Get(1).(func(...processorprovider.ProviderComponent) error); ok { + r1 = rf(footer...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProcessorProvider_AddFooter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddFooter' +type ProcessorProvider_AddFooter_Call struct { + *mock.Call +} + +// AddFooter is a helper method to define mock.On call +// - footer ...processorprovider.ProviderComponent +func (_e *ProcessorProvider_Expecter) AddFooter(footer ...interface{}) *ProcessorProvider_AddFooter_Call { + return &ProcessorProvider_AddFooter_Call{Call: _e.mock.On("AddFooter", + append([]interface{}{}, footer...)...)} +} + +func (_c *ProcessorProvider_AddFooter_Call) Run(run func(footer ...processorprovider.ProviderComponent)) *ProcessorProvider_AddFooter_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]processorprovider.ProviderComponent, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(processorprovider.ProviderComponent) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_AddFooter_Call) Return(_a0 processorprovider.ProcessorProvider, _a1 error) *ProcessorProvider_AddFooter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ProcessorProvider_AddFooter_Call) RunAndReturn(run func(...processorprovider.ProviderComponent) (processorprovider.ProcessorProvider, error)) *ProcessorProvider_AddFooter_Call { + _c.Call.Return(run) + return _c +} + +// AddHeader provides a mock function with given fields: header +func (_m *ProcessorProvider) AddHeader(header ...processorprovider.ProviderComponent) (processorprovider.ProcessorProvider, error) { + _va := make([]interface{}, len(header)) + for _i := range header { + _va[_i] = header[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for AddHeader") + } + + var r0 processorprovider.ProcessorProvider + var r1 error + if rf, ok := ret.Get(0).(func(...processorprovider.ProviderComponent) (processorprovider.ProcessorProvider, error)); ok { + return rf(header...) + } + if rf, ok := ret.Get(0).(func(...processorprovider.ProviderComponent) processorprovider.ProcessorProvider); ok { + r0 = rf(header...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(processorprovider.ProcessorProvider) + } + } + + if rf, ok := ret.Get(1).(func(...processorprovider.ProviderComponent) error); ok { + r1 = rf(header...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProcessorProvider_AddHeader_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddHeader' +type ProcessorProvider_AddHeader_Call struct { + *mock.Call +} + +// AddHeader is a helper method to define mock.On call +// - header ...processorprovider.ProviderComponent +func (_e *ProcessorProvider_Expecter) AddHeader(header ...interface{}) *ProcessorProvider_AddHeader_Call { + return &ProcessorProvider_AddHeader_Call{Call: _e.mock.On("AddHeader", + append([]interface{}{}, header...)...)} +} + +func (_c *ProcessorProvider_AddHeader_Call) Run(run func(header ...processorprovider.ProviderComponent)) *ProcessorProvider_AddHeader_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]processorprovider.ProviderComponent, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(processorprovider.ProviderComponent) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_AddHeader_Call) Return(_a0 processorprovider.ProcessorProvider, _a1 error) *ProcessorProvider_AddHeader_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ProcessorProvider_AddHeader_Call) RunAndReturn(run func(...processorprovider.ProviderComponent) (processorprovider.ProcessorProvider, error)) *ProcessorProvider_AddHeader_Call { + _c.Call.Return(run) + return _c +} + +// AddPages provides a mock function with given fields: pages +func (_m *ProcessorProvider) AddPages(pages ...processorprovider.ProviderComponent) (processorprovider.ProcessorProvider, error) { + _va := make([]interface{}, len(pages)) + for _i := range pages { + _va[_i] = pages[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for AddPages") + } + + var r0 processorprovider.ProcessorProvider + var r1 error + if rf, ok := ret.Get(0).(func(...processorprovider.ProviderComponent) (processorprovider.ProcessorProvider, error)); ok { + return rf(pages...) + } + if rf, ok := ret.Get(0).(func(...processorprovider.ProviderComponent) processorprovider.ProcessorProvider); ok { + r0 = rf(pages...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(processorprovider.ProcessorProvider) + } + } + + if rf, ok := ret.Get(1).(func(...processorprovider.ProviderComponent) error); ok { + r1 = rf(pages...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProcessorProvider_AddPages_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddPages' +type ProcessorProvider_AddPages_Call struct { + *mock.Call +} + +// AddPages is a helper method to define mock.On call +// - pages ...processorprovider.ProviderComponent +func (_e *ProcessorProvider_Expecter) AddPages(pages ...interface{}) *ProcessorProvider_AddPages_Call { + return &ProcessorProvider_AddPages_Call{Call: _e.mock.On("AddPages", + append([]interface{}{}, pages...)...)} +} + +func (_c *ProcessorProvider_AddPages_Call) Run(run func(pages ...processorprovider.ProviderComponent)) *ProcessorProvider_AddPages_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]processorprovider.ProviderComponent, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(processorprovider.ProviderComponent) + } + } + run(variadicArgs...) + }) + return _c +} + +func (_c *ProcessorProvider_AddPages_Call) Return(_a0 processorprovider.ProcessorProvider, _a1 error) *ProcessorProvider_AddPages_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ProcessorProvider_AddPages_Call) RunAndReturn(run func(...processorprovider.ProviderComponent) (processorprovider.ProcessorProvider, error)) *ProcessorProvider_AddPages_Call { + _c.Call.Return(run) + return _c +} + // CreateBarCode provides a mock function with given fields: value, props func (_m *ProcessorProvider) CreateBarCode(value string, props ...*propsmapper.Barcode) processorprovider.ProviderComponent { _va := make([]interface{}, len(props)) @@ -222,16 +440,22 @@ func (_c *ProcessorProvider_CreateImage_Call) RunAndReturn(run func([]byte, stri } // CreateLine provides a mock function with given fields: props -func (_m *ProcessorProvider) CreateLine(props *propsmapper.Line) processorprovider.ProviderComponent { - ret := _m.Called(props) +func (_m *ProcessorProvider) CreateLine(props ...*propsmapper.Line) processorprovider.ProviderComponent { + _va := make([]interface{}, len(props)) + for _i := range props { + _va[_i] = props[_i] + } + var _ca []interface{} + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) if len(ret) == 0 { panic("no return value specified for CreateLine") } var r0 processorprovider.ProviderComponent - if rf, ok := ret.Get(0).(func(*propsmapper.Line) processorprovider.ProviderComponent); ok { - r0 = rf(props) + if rf, ok := ret.Get(0).(func(...*propsmapper.Line) processorprovider.ProviderComponent); ok { + r0 = rf(props...) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(processorprovider.ProviderComponent) @@ -247,14 +471,21 @@ type ProcessorProvider_CreateLine_Call struct { } // CreateLine is a helper method to define mock.On call -// - props *propsmapper.Line -func (_e *ProcessorProvider_Expecter) CreateLine(props interface{}) *ProcessorProvider_CreateLine_Call { - return &ProcessorProvider_CreateLine_Call{Call: _e.mock.On("CreateLine", props)} +// - props ...*propsmapper.Line +func (_e *ProcessorProvider_Expecter) CreateLine(props ...interface{}) *ProcessorProvider_CreateLine_Call { + return &ProcessorProvider_CreateLine_Call{Call: _e.mock.On("CreateLine", + append([]interface{}{}, props...)...)} } -func (_c *ProcessorProvider_CreateLine_Call) Run(run func(props *propsmapper.Line)) *ProcessorProvider_CreateLine_Call { +func (_c *ProcessorProvider_CreateLine_Call) Run(run func(props ...*propsmapper.Line)) *ProcessorProvider_CreateLine_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*propsmapper.Line)) + variadicArgs := make([]*propsmapper.Line, len(args)-0) + for i, a := range args[0:] { + if a != nil { + variadicArgs[i] = a.(*propsmapper.Line) + } + } + run(variadicArgs...) }) return _c } @@ -264,7 +495,7 @@ func (_c *ProcessorProvider_CreateLine_Call) Return(_a0 processorprovider.Provid return _c } -func (_c *ProcessorProvider_CreateLine_Call) RunAndReturn(run func(*propsmapper.Line) processorprovider.ProviderComponent) *ProcessorProvider_CreateLine_Call { +func (_c *ProcessorProvider_CreateLine_Call) RunAndReturn(run func(...*propsmapper.Line) processorprovider.ProviderComponent) *ProcessorProvider_CreateLine_Call { _c.Call.Return(run) return _c } @@ -665,6 +896,53 @@ func (_c *ProcessorProvider_CreateText_Call) RunAndReturn(run func(string, ...*p return _c } +// GetStructure provides a mock function with given fields: +func (_m *ProcessorProvider) GetStructure() *node.Node[core.Structure] { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetStructure") + } + + var r0 *node.Node[core.Structure] + if rf, ok := ret.Get(0).(func() *node.Node[core.Structure]); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*node.Node[core.Structure]) + } + } + + return r0 +} + +// ProcessorProvider_GetStructure_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetStructure' +type ProcessorProvider_GetStructure_Call struct { + *mock.Call +} + +// GetStructure is a helper method to define mock.On call +func (_e *ProcessorProvider_Expecter) GetStructure() *ProcessorProvider_GetStructure_Call { + return &ProcessorProvider_GetStructure_Call{Call: _e.mock.On("GetStructure")} +} + +func (_c *ProcessorProvider_GetStructure_Call) Run(run func()) *ProcessorProvider_GetStructure_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ProcessorProvider_GetStructure_Call) Return(_a0 *node.Node[core.Structure]) *ProcessorProvider_GetStructure_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProcessorProvider_GetStructure_Call) RunAndReturn(run func() *node.Node[core.Structure]) *ProcessorProvider_GetStructure_Call { + _c.Call.Return(run) + return _c +} + // NewProcessorProvider creates a new instance of ProcessorProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewProcessorProvider(t interface { diff --git a/pkg/processor/mappers/documentmapper/document_test.go b/pkg/processor/mappers/documentmapper/document_test.go index 7c9b2591..e86d6006 100644 --- a/pkg/processor/mappers/documentmapper/document_test.go +++ b/pkg/processor/mappers/documentmapper/document_test.go @@ -1,13 +1,17 @@ -package documentmapper +package documentmapper_test import ( + "fmt" "testing" "github.com/johnfercher/maroto/v2/internal/fixture" "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/processor/deserializer" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/listmapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/pagemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/documentmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -24,7 +28,7 @@ func TestNewPdf(t *testing.T) { template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) - doc, err := NewPdf(template, factory) + doc, err := documentmapper.NewPdf(template, factory) assert.Nil(t, err) assert.Equal(t, doc.Builder.ConcurrentMode, 10) }) @@ -36,7 +40,7 @@ func TestNewPdf(t *testing.T) { template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) - doc, err := NewPdf(template, factory) + doc, err := documentmapper.NewPdf(template, factory) assert.NotNil(t, err) assert.Nil(t, doc) @@ -56,7 +60,7 @@ func TestNewPdf(t *testing.T) { template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) - doc, err := NewPdf(template, factory) + doc, err := documentmapper.NewPdf(template, factory) assert.Nil(t, err) assert.Equal(t, 2, len(doc.Header)) @@ -69,7 +73,7 @@ func TestNewPdf(t *testing.T) { template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) - _, err = NewPdf(template, factory) + _, err = documentmapper.NewPdf(template, factory) assert.NotNil(t, err) }) @@ -87,7 +91,7 @@ func TestNewPdf(t *testing.T) { template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) - doc, err := NewPdf(template, factory) + doc, err := documentmapper.NewPdf(template, factory) assert.Nil(t, err) assert.Equal(t, 2, len(doc.Footer)) @@ -100,7 +104,7 @@ func TestNewPdf(t *testing.T) { template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) - _, err = NewPdf(template, factory) + _, err = documentmapper.NewPdf(template, factory) assert.NotNil(t, err) }) @@ -120,11 +124,11 @@ func TestNewPdf(t *testing.T) { template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) - doc, err := NewPdf(template, factory) + doc, err := documentmapper.NewPdf(template, factory) assert.Nil(t, err) - assert.Equal(t, len(doc.pages), 2) - assert.IsType(t, &pagemapper.Page{}, doc.pages[0]) + assert.Equal(t, len(doc.Pages), 2) + assert.IsType(t, &pagemapper.Page{}, doc.Pages[0]) }) t.Run("when 1 list is sent, it should add 1 list to the document", func(t *testing.T) { @@ -140,11 +144,11 @@ func TestNewPdf(t *testing.T) { template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) - doc, err := NewPdf(template, factory) + doc, err := documentmapper.NewPdf(template, factory) assert.Nil(t, err) - assert.Equal(t, len(doc.pages), 1) - assert.IsType(t, &listmapper.List{}, doc.pages[0]) + assert.Equal(t, len(doc.Pages), 1) + assert.IsType(t, &listmapper.List{}, doc.Pages[0]) }) t.Run("when an invalid page is sent, it should return an error", func(t *testing.T) { @@ -154,7 +158,172 @@ func TestNewPdf(t *testing.T) { template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) - _, err = NewPdf(template, factory) + _, err = documentmapper.NewPdf(template, factory) assert.NotNil(t, err) }) } + +func TestGenerate(t *testing.T) { + t.Run("when document have no template, should not set template ", func(t *testing.T) { + fixContent := make(map[string]interface{}) + mockProvider := mocks.NewProcessorProvider(t) + + doc := documentmapper.Document{ + Pages: make([]mappers.Componentmapper, 0), Header: make([]mappers.Componentmapper, 0), + Footer: make([]mappers.Componentmapper, 0), + } + provider, err := doc.Generate(fixContent, mockProvider) + + assert.Nil(t, err) + assert.NotNil(t, provider) + }) + t.Run("when templates have no content, should generate templates with empty content", func(t *testing.T) { + fixContent := map[string]interface{}{"test": "any"} + + mockProviderComponents := []processorprovider.ProviderComponent{mocks.NewProviderComponent(t)} + mockComponent := mocks.NewComponentmapper(t) + mockComponent.EXPECT().Generate(map[string]interface{}{}, mock.Anything).Return(mockProviderComponents, nil) + mockProvider := mocks.NewProcessorProvider(t) + mockProvider.EXPECT().AddPages(mockProviderComponents[0]).Return(mockProvider, nil) + mockProvider.EXPECT().AddHeader(mockProviderComponents[0]).Return(mockProvider, nil) + mockProvider.EXPECT().AddFooter(mockProviderComponents[0]).Return(mockProvider, nil) + + doc := documentmapper.Document{ + Pages: []mappers.Componentmapper{mockComponent}, Header: []mappers.Componentmapper{mockComponent}, + Footer: []mappers.Componentmapper{mockComponent}, + } + provider, err := doc.Generate(fixContent, mockProvider) + + assert.Nil(t, err) + assert.NotNil(t, provider) + }) + t.Run("when it is not possible to generate the page, it should return an error", func(t *testing.T) { + fixContent := map[string]interface{}{} + + mockComponent := mocks.NewComponentmapper(t) + mockComponent.EXPECT().Generate(map[string]interface{}{}, mock.Anything).Return(nil, fmt.Errorf("any")) + mockProvider := mocks.NewProcessorProvider(t) + + doc := documentmapper.Document{ + Pages: []mappers.Componentmapper{mockComponent}, Header: []mappers.Componentmapper{}, + Footer: []mappers.Componentmapper{}, + } + provider, err := doc.Generate(fixContent, mockProvider) + + assert.Nil(t, provider) + assert.NotNil(t, err) + }) + t.Run("when it is not possible to generate the header, it should return an error", func(t *testing.T) { + fixContent := map[string]interface{}{} + + mockComponent := mocks.NewComponentmapper(t) + mockComponent.EXPECT().Generate(map[string]interface{}{}, mock.Anything).Return(nil, fmt.Errorf("any")) + mockProvider := mocks.NewProcessorProvider(t) + + doc := documentmapper.Document{ + Pages: []mappers.Componentmapper{}, Header: []mappers.Componentmapper{mockComponent}, + Footer: []mappers.Componentmapper{}, + } + provider, err := doc.Generate(fixContent, mockProvider) + + assert.Nil(t, provider) + assert.NotNil(t, err) + }) + t.Run("when it is not possible to generate the footer, it should return an error", func(t *testing.T) { + fixContent := map[string]interface{}{} + + mockComponent := mocks.NewComponentmapper(t) + mockComponent.EXPECT().Generate(map[string]interface{}{}, mock.Anything).Return(nil, fmt.Errorf("any")) + mockProvider := mocks.NewProcessorProvider(t) + + doc := documentmapper.Document{ + Pages: []mappers.Componentmapper{}, Header: []mappers.Componentmapper{}, + Footer: []mappers.Componentmapper{mockComponent}, + } + provider, err := doc.Generate(fixContent, mockProvider) + + assert.Nil(t, provider) + assert.NotNil(t, err) + }) + t.Run("when it is not possible add the page to the document, it should return an error", func(t *testing.T) { + fixContent := map[string]interface{}{} + + mockProviderComponents := []processorprovider.ProviderComponent{mocks.NewProviderComponent(t)} + mockComponent := mocks.NewComponentmapper(t) + mockComponent.EXPECT().Generate(map[string]interface{}{}, mock.Anything).Return(mockProviderComponents, nil) + mockProvider := mocks.NewProcessorProvider(t) + mockProvider.EXPECT().AddPages(mockProviderComponents[0]).Return(nil, fmt.Errorf("any")) + + doc := documentmapper.Document{ + Pages: []mappers.Componentmapper{mockComponent}, Header: []mappers.Componentmapper{}, + Footer: []mappers.Componentmapper{}, + } + provider, err := doc.Generate(fixContent, mockProvider) + + assert.Nil(t, provider) + assert.NotNil(t, err) + }) + t.Run("when it is not possible add the header to the document, it should return an error", func(t *testing.T) { + fixContent := map[string]interface{}{} + + mockProviderComponents := []processorprovider.ProviderComponent{mocks.NewProviderComponent(t)} + mockComponent := mocks.NewComponentmapper(t) + mockComponent.EXPECT().Generate(map[string]interface{}{}, mock.Anything).Return(mockProviderComponents, nil) + mockProvider := mocks.NewProcessorProvider(t) + mockProvider.EXPECT().AddHeader(mockProviderComponents[0]).Return(nil, fmt.Errorf("any")) + + doc := documentmapper.Document{ + Pages: []mappers.Componentmapper{}, Header: []mappers.Componentmapper{mockComponent}, + Footer: []mappers.Componentmapper{}, + } + provider, err := doc.Generate(fixContent, mockProvider) + + assert.Nil(t, provider) + assert.NotNil(t, err) + }) + t.Run("when it is not possible add the footer to the document, it should return an error", func(t *testing.T) { + fixContent := map[string]interface{}{} + + mockProviderComponents := []processorprovider.ProviderComponent{mocks.NewProviderComponent(t)} + mockComponent := mocks.NewComponentmapper(t) + mockComponent.EXPECT().Generate(map[string]interface{}{}, mock.Anything).Return(mockProviderComponents, nil) + mockProvider := mocks.NewProcessorProvider(t) + mockProvider.EXPECT().AddFooter(mockProviderComponents[0]).Return(nil, fmt.Errorf("any")) + + doc := documentmapper.Document{ + Pages: []mappers.Componentmapper{}, Header: []mappers.Componentmapper{}, + Footer: []mappers.Componentmapper{mockComponent}, + } + provider, err := doc.Generate(fixContent, mockProvider) + + assert.Nil(t, provider) + assert.NotNil(t, err) + }) + t.Run("when document with page, header and footer is call, should generate document", func(t *testing.T) { + fixContent := map[string]interface{}{ + "header": map[string]interface{}{"row_header": "test"}, + "footer": map[string]interface{}{"row_footer": "test"}, + "pages": map[string]interface{}{"template_page_1": "test"}, + } + + mockProviderComponents := []processorprovider.ProviderComponent{mocks.NewProviderComponent(t)} + mockComponent := mocks.NewComponentmapper(t) + mockComponent.EXPECT().Generate(fixContent["header"], mock.Anything).Return(mockProviderComponents, nil) + mockComponent.EXPECT().Generate(fixContent["footer"], mock.Anything).Return(mockProviderComponents, nil) + mockComponent.EXPECT().Generate(fixContent["pages"], mock.Anything).Return(mockProviderComponents, nil) + mockProvider := mocks.NewProcessorProvider(t) + mockProvider.EXPECT().AddPages(mockProviderComponents[0]).Return(mockProvider, nil) + mockProvider.EXPECT().AddHeader(mockProviderComponents[0]).Return(mockProvider, nil) + mockProvider.EXPECT().AddFooter(mockProviderComponents[0]).Return(mockProvider, nil) + + doc := documentmapper.Document{ + Pages: []mappers.Componentmapper{mockComponent}, Header: []mappers.Componentmapper{mockComponent}, + Footer: []mappers.Componentmapper{mockComponent}, + } + provider, err := doc.Generate(fixContent, mockProvider) + + assert.Nil(t, err) + assert.NotNil(t, provider) + mockComponent.AssertNumberOfCalls(t, "Generate", 3) + }) +} diff --git a/pkg/processor/processorprovider/Maroto_test.go b/pkg/processor/processorprovider/Maroto_test.go index 768aa124..1fe81946 100644 --- a/pkg/processor/processorprovider/Maroto_test.go +++ b/pkg/processor/processorprovider/Maroto_test.go @@ -1,20 +1,158 @@ package processorprovider_test import ( + "fmt" "testing" + "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/components/code" + "github.com/johnfercher/maroto/v2/pkg/components/page" "github.com/johnfercher/maroto/v2/pkg/components/row" "github.com/johnfercher/maroto/v2/pkg/components/text" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/buildermapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" + "github.com/johnfercher/maroto/v2/pkg/processor/repository" "github.com/johnfercher/maroto/v2/pkg/test" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" ) +func TestAddPages(t *testing.T) { + t.Run("when page is not sent, should not add header", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + provider, _ := processorprovider.NewMaroto(repository) + + provider, err := provider.AddPages() + + assert.Nil(t, err) + assert.NotNil(t, provider) + }) + + t.Run("when invalid component is sent, should return an error", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + provider, _ := processorprovider.NewMaroto(repository) + + provider, err := provider.AddPages(text.New("123")) + + assert.NotNil(t, err) + assert.Nil(t, provider) + }) + + t.Run("when page is sent, should add page", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + provider, _ := processorprovider.NewMaroto(repository) + + provider, err := provider.AddPages(page.New().Add(row.New(10))) + + assert.NotNil(t, provider) + assert.Nil(t, err) + test.New(t).Assert(provider.GetStructure()).Equals("processor/provider/document_with_page.json") + }) +} + +// nolint: dupl +func TestAddFooter(t *testing.T) { + t.Run("when footer is not sent, should not add footer", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + provider, _ := processorprovider.NewMaroto(repository) + + provider, err := provider.AddFooter() + + assert.Nil(t, err) + assert.NotNil(t, provider) + }) + + t.Run("when invalid component is sent, should return an error", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + provider, _ := processorprovider.NewMaroto(repository) + + provider, err := provider.AddFooter(page.New()) + + assert.NotNil(t, err) + assert.Nil(t, provider) + }) + + t.Run("when footer is sent, should add footer", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + provider, _ := processorprovider.NewMaroto(repository) + + provider, err := provider.AddFooter(text.NewAutoRow("footer")) + + assert.NotNil(t, provider) + assert.Nil(t, err) + test.New(t).Assert(provider.GetStructure()).Equals("processor/provider/document_with_footer.json") + }) +} + +// nolint: dupl +func TestAddHeader(t *testing.T) { + t.Run("when header is not sent, should not add header", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + provider, _ := processorprovider.NewMaroto(repository) + + provider, err := provider.AddHeader() + + assert.Nil(t, err) + assert.NotNil(t, provider) + }) + + t.Run("when invalid component is sent, should return an error", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + provider, _ := processorprovider.NewMaroto(repository) + + provider, err := provider.AddHeader(page.New()) + + assert.NotNil(t, err) + assert.Nil(t, provider) + }) + + t.Run("when header is sent, should add header", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + provider, _ := processorprovider.NewMaroto(repository) + + provider, err := provider.AddHeader(text.NewAutoRow("header")) + + assert.NotNil(t, provider) + assert.Nil(t, err) + test.New(t).Assert(provider.GetStructure()).Equals("processor/provider/document_with_header.json") + }) +} + +func TestNewMaroto(t *testing.T) { + t.Run("when builder is not sent, should not create Maroto builder", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + + provider, err := processorprovider.NewMaroto(repository) + + assert.NotNil(t, provider) + assert.Nil(t, err) + }) + t.Run("when is not possible create Maroto builder, should return an error", func(t *testing.T) { + mapperFix := buildermapper.Builder{BackgroundImage: "file"} + repository := mocks.NewProcessorRepository(t) + repository.EXPECT().GetDocument(mock.Anything).Return("", nil, fmt.Errorf("any")) + + provider, err := processorprovider.NewMaroto(repository, mapperFix) + + assert.NotNil(t, err) + assert.Nil(t, provider) + }) + t.Run("when builder is sent, should create Maroto builder", func(t *testing.T) { + mapperFix := buildermapper.Builder{BackgroundImage: "file"} + repository := mocks.NewProcessorRepository(t) + repository.EXPECT().GetDocument(mock.Anything).Return("", []byte{123}, nil) + + provider, err := processorprovider.NewMaroto(repository, mapperFix) + + assert.NotNil(t, provider) + assert.Nil(t, err) + }) +} + func TestCreateBarCode(t *testing.T) { t.Run("when CreateBarCode is called, should generate a barcode", func(t *testing.T) { - m := processorprovider.NewMaroto() + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) barcode := m.CreateBarCode("code", &propsmapper.Barcode{ Left: 10.0, Top: 10.0, Percent: 100.0, @@ -30,7 +168,7 @@ func TestCreateBarCode(t *testing.T) { func TestCreateMatrixCode(t *testing.T) { t.Run("when CreateMatrixCode is called, should generate a matrixcode", func(t *testing.T) { - m := processorprovider.NewMaroto() + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) barcode := m.CreateMatrixCode("code", &propsmapper.Rect{Left: 10.0, Top: 10.0, Percent: 100.0, JustReferenceWidth: false, Center: false}, ) @@ -41,7 +179,7 @@ func TestCreateMatrixCode(t *testing.T) { func TestCreateQRCode(t *testing.T) { t.Run("when CreateQrCode is called, should generate a qrcode", func(t *testing.T) { - m := processorprovider.NewMaroto() + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) barcode := m.CreateQrCode("code", &propsmapper.Rect{Left: 10.0, Top: 10.0, Percent: 100.0, JustReferenceWidth: false, Center: false}, ) @@ -52,7 +190,7 @@ func TestCreateQRCode(t *testing.T) { func TestCreateImage(t *testing.T) { t.Run("when CreateImage is called, should generate a image", func(t *testing.T) { - m := processorprovider.NewMaroto() + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) image := m.CreateImage(make([]byte, 0), "png", &propsmapper.Rect{Left: 10.0, Top: 10.0, Percent: 100.0, JustReferenceWidth: false, Center: false}, ) @@ -63,7 +201,7 @@ func TestCreateImage(t *testing.T) { func TestCreateLine(t *testing.T) { t.Run("when CreateLine is called, should generate a line", func(t *testing.T) { - m := processorprovider.NewMaroto() + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) barcode := m.CreateLine( &propsmapper.Line{ Color: &propsmapper.Color{Red: 10, Green: 10, Blue: 10}, Style: "solid", Thickness: 10.0, @@ -77,7 +215,7 @@ func TestCreateLine(t *testing.T) { func TestCreateSignature(t *testing.T) { t.Run("when CreateSignature is called, should generate a signature", func(t *testing.T) { - m := processorprovider.NewMaroto() + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) barcode := m.CreateSignature("signature", &propsmapper.Signature{ FontFamily: "Arial", FontStyle: "bold", FontSize: 10.0, FontColor: &propsmapper.Color{Red: 10, Green: 10, Blue: 10}, @@ -91,7 +229,7 @@ func TestCreateSignature(t *testing.T) { func TestCreateText(t *testing.T) { t.Run("when CreateText is called, should generate a text", func(t *testing.T) { - m := processorprovider.NewMaroto() + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) barcode := m.CreateText("text", &propsmapper.Text{ Top: 10.0, Left: 10.0, Right: 10.0, Family: "Arial", Style: "bold", Size: 10.0, Align: "center", BreakLineStrategy: "dash_strategy", @@ -105,7 +243,7 @@ func TestCreateText(t *testing.T) { func TestCreateCol(t *testing.T) { t.Run("when CreateCol is called, should generate a col", func(t *testing.T) { - m := processorprovider.NewMaroto() + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) text := text.New("test") col, err := m.CreateCol(10, text) @@ -115,7 +253,7 @@ func TestCreateCol(t *testing.T) { }) t.Run("when invalid components are sent, should return an error", func(t *testing.T) { - m := processorprovider.NewMaroto() + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) page, err := m.CreatePage(text.NewCol(10, "10")) assert.Nil(t, page) @@ -125,7 +263,7 @@ func TestCreateCol(t *testing.T) { func TestCreateRow(t *testing.T) { t.Run("when CreateRow is called, should generate a row", func(t *testing.T) { - m := processorprovider.NewMaroto() + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) text := text.NewCol(12, "test") col, err := m.CreateRow(10, text) @@ -135,7 +273,7 @@ func TestCreateRow(t *testing.T) { }) t.Run("when invalid components are sent, should return an error", func(t *testing.T) { - m := processorprovider.NewMaroto() + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) page, err := m.CreatePage(text.New("10")) assert.Nil(t, page) @@ -145,14 +283,14 @@ func TestCreateRow(t *testing.T) { func TestCreatePage(t *testing.T) { t.Run("when CreatePage is called, should generate a page", func(t *testing.T) { - m := processorprovider.NewMaroto() + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) page, err := m.CreatePage(row.New(10)) assert.Nil(t, err) assert.NotNil(t, page) }) t.Run("when invalid components are sent, should return an error", func(t *testing.T) { - m := processorprovider.NewMaroto() + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) page, err := m.CreatePage(text.New("10")) assert.Nil(t, page) diff --git a/pkg/processor/processorprovider/builder_maroto_test.go b/pkg/processor/processorprovider/builder_maroto_test.go index f8493452..cba8a072 100644 --- a/pkg/processor/processorprovider/builder_maroto_test.go +++ b/pkg/processor/processorprovider/builder_maroto_test.go @@ -17,6 +17,76 @@ import ( "github.com/stretchr/testify/mock" ) +func createBuilderMocks(t *testing.T) *mocks.Builder { + build := mocks.NewBuilder(t) + build.EXPECT().WithPageSize(mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithDimensions(mock.Anything, mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithTopMargin(mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithBottomMargin(mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithLeftMargin(mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithRightMargin(mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithConcurrentMode(mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithSequentialMode().Return(config.NewBuilder()) + build.EXPECT().WithDebug(mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithMaxGridSize(mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithDefaultFont(mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithPageNumber(mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithProtection(mock.Anything, mock.Anything, mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithCompression(mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithOrientation(mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithAuthor(mock.Anything, mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithCreationDate(mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithCreator(mock.Anything, mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithKeywords(mock.Anything, mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithSubject(mock.Anything, mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithTitle(mock.Anything, mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithDisableAutoPageBreak(mock.Anything).Return(config.NewBuilder()) + build.EXPECT().WithCustomFonts(mock.Anything).Return(config.NewBuilder()) + return build +} + +func validateCallOfAllMethods(t *testing.T, builder *mocks.Builder) { + builder.AssertNumberOfCalls(t, "WithPageSize", 1) + builder.AssertNumberOfCalls(t, "WithDimensions", 1) + builder.AssertNumberOfCalls(t, "WithTopMargin", 1) + builder.AssertNumberOfCalls(t, "WithBottomMargin", 1) + builder.AssertNumberOfCalls(t, "WithLeftMargin", 1) + builder.AssertNumberOfCalls(t, "WithRightMargin", 1) + builder.AssertNumberOfCalls(t, "WithConcurrentMode", 1) + builder.AssertNumberOfCalls(t, "WithSequentialMode", 1) + builder.AssertNumberOfCalls(t, "WithDebug", 1) + builder.AssertNumberOfCalls(t, "WithMaxGridSize", 1) + builder.AssertNumberOfCalls(t, "WithDefaultFont", 1) + builder.AssertNumberOfCalls(t, "WithPageNumber", 1) + builder.AssertNumberOfCalls(t, "WithProtection", 1) + builder.AssertNumberOfCalls(t, "WithCompression", 1) + builder.AssertNumberOfCalls(t, "WithOrientation", 1) + builder.AssertNumberOfCalls(t, "WithAuthor", 1) + builder.AssertNumberOfCalls(t, "WithCreationDate", 1) + builder.AssertNumberOfCalls(t, "WithCreator", 1) + builder.AssertNumberOfCalls(t, "WithKeywords", 1) + builder.AssertNumberOfCalls(t, "WithSubject", 1) + builder.AssertNumberOfCalls(t, "WithTitle", 1) + builder.AssertNumberOfCalls(t, "WithDisableAutoPageBreak", 1) + builder.AssertNumberOfCalls(t, "WithCustomFonts", 1) +} + +func TestCreateMarotoBuilder(t *testing.T) { + t.Run("when all props are sent, should add all props", func(t *testing.T) { + repository := mocks.NewProcessorRepository(t) + repository.EXPECT().GetDocument(mock.Anything).Return(string(extension.Png), []byte{123}, nil) + build := createBuilderMocks(t) + fixProps := fixture.BuilderProps() + + builder := processorprovider.NewMarotoBuilder(repository, build) + cfg, err := builder.CreateMarotoBuilder(fixProps) + + assert.Nil(t, err) + assert.NotNil(t, cfg) + validateCallOfAllMethods(t, build) + }) +} + func TestWithPageSize(t *testing.T) { t.Run("when page size is null, should not set page size", func(t *testing.T) { repository := mocks.NewProcessorRepository(t) diff --git a/test/maroto/processor/provider/document_with_footer.json b/test/maroto/processor/provider/document_with_footer.json new file mode 100644 index 00000000..e219b167 --- /dev/null +++ b/test/maroto/processor/provider/document_with_footer.json @@ -0,0 +1,61 @@ +{ + "type": "maroto", + "details": { + "chunk_workers": 1, + "config_margin_bottom": 20.0025, + "config_margin_left": 10, + "config_margin_right": 10, + "config_margin_top": 10, + "config_max_grid_sum": 12, + "config_provider_type": "gofpdf", + "generation_mode": "sequential", + "maroto_dimension_height": 297, + "maroto_dimension_width": 210, + "prop_font_color": "RGB(0, 0, 0)", + "prop_font_family": "arial", + "prop_font_size": 10 + }, + "nodes": [ + { + "type": "page", + "nodes": [ + { + "value": 263.46972222222223, + "type": "row", + "nodes": [ + { + "value": 12, + "type": "col" + } + ] + }, + { + "value": 3.527777777777778, + "type": "row", + "nodes": [ + { + "value": 0, + "type": "col", + "details": { + "is_max": true + }, + "nodes": [ + { + "value": "footer", + "type": "text", + "details": { + "prop_align": "L", + "prop_breakline_strategy": "empty_space_strategy", + "prop_color": "RGB(0, 0, 0)", + "prop_font_family": "arial", + "prop_font_size": 10 + } + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/maroto/processor/provider/document_with_header.json b/test/maroto/processor/provider/document_with_header.json new file mode 100644 index 00000000..1b40d055 --- /dev/null +++ b/test/maroto/processor/provider/document_with_header.json @@ -0,0 +1,61 @@ +{ + "type": "maroto", + "details": { + "chunk_workers": 1, + "config_margin_bottom": 20.0025, + "config_margin_left": 10, + "config_margin_right": 10, + "config_margin_top": 10, + "config_max_grid_sum": 12, + "config_provider_type": "gofpdf", + "generation_mode": "sequential", + "maroto_dimension_height": 297, + "maroto_dimension_width": 210, + "prop_font_color": "RGB(0, 0, 0)", + "prop_font_family": "arial", + "prop_font_size": 10 + }, + "nodes": [ + { + "type": "page", + "nodes": [ + { + "value": 3.527777777777778, + "type": "row", + "nodes": [ + { + "value": 0, + "type": "col", + "details": { + "is_max": true + }, + "nodes": [ + { + "value": "header", + "type": "text", + "details": { + "prop_align": "L", + "prop_breakline_strategy": "empty_space_strategy", + "prop_color": "RGB(0, 0, 0)", + "prop_font_family": "arial", + "prop_font_size": 10 + } + } + ] + } + ] + }, + { + "value": 263.46972222222223, + "type": "row", + "nodes": [ + { + "value": 12, + "type": "col" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/test/maroto/processor/provider/document_with_page.json b/test/maroto/processor/provider/document_with_page.json new file mode 100644 index 00000000..888a878a --- /dev/null +++ b/test/maroto/processor/provider/document_with_page.json @@ -0,0 +1,48 @@ +{ + "type": "maroto", + "details": { + "chunk_workers": 1, + "config_margin_bottom": 20.0025, + "config_margin_left": 10, + "config_margin_right": 10, + "config_margin_top": 10, + "config_max_grid_sum": 12, + "config_provider_type": "gofpdf", + "generation_mode": "sequential", + "maroto_dimension_height": 297, + "maroto_dimension_width": 210, + "prop_font_color": "RGB(0, 0, 0)", + "prop_font_family": "arial", + "prop_font_size": 10 + }, + "nodes": [ + { + "type": "page", + "nodes": [ + { + "value": 10, + "type": "row", + "nodes": [ + { + "value": 0, + "type": "col", + "details": { + "is_max": true + } + } + ] + }, + { + "value": 256.9975, + "type": "row", + "nodes": [ + { + "value": 12, + "type": "col" + } + ] + } + ] + } + ] +} \ No newline at end of file From 4ed6f23b2d9bb277c2208ef173d94eb292b16df7 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sat, 16 Nov 2024 17:44:44 -0300 Subject: [PATCH 074/116] feat: implement document generation --- .../mappers/documentmapper/document.go | 141 +++++++++++++++--- pkg/processor/processorprovider/Maroto.go | 90 +++++++++-- .../processorprovider/builder_maroto.go | 126 ++++++++++------ pkg/processor/processorprovider/provider.go | 7 +- 4 files changed, 282 insertions(+), 82 deletions(-) diff --git a/pkg/processor/mappers/documentmapper/document.go b/pkg/processor/mappers/documentmapper/document.go index 0157ecb8..73b4830d 100644 --- a/pkg/processor/mappers/documentmapper/document.go +++ b/pkg/processor/mappers/documentmapper/document.go @@ -5,9 +5,9 @@ import ( "fmt" "strings" - "github.com/johnfercher/maroto/v2/pkg/core" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/buildermapper" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Document struct { @@ -15,13 +15,16 @@ type Document struct { Builder buildermapper.Builder Header []mappers.Componentmapper Footer []mappers.Componentmapper - pages []mappers.Componentmapper + Pages []mappers.Componentmapper } // NewPdf is responsible for creating the pdf template // parse the model and create the pdf object func NewPdf(template map[string]any, factory mappers.AbstractFactoryMaps) (*Document, error) { - newPdf := Document{factory: factory} + newPdf := Document{ + factory: factory, Builder: buildermapper.Builder{}, Pages: make([]mappers.Componentmapper, 0), + Header: make([]mappers.Componentmapper, 0), Footer: make([]mappers.Componentmapper, 0), + } err := newPdf.addComponentsToPdf(template) if err != nil { @@ -33,8 +36,8 @@ func NewPdf(template map[string]any, factory mappers.AbstractFactoryMaps) (*Docu // addComponentsToPdf is responsible for adding all the components that are part of the template to the PDF. // This is the method where the components that are part of the PDF are created. -func (p *Document) addComponentsToPdf(templates map[string]interface{}) error { - fieldMappers := p.getFieldMappers() +func (d *Document) addComponentsToPdf(templates map[string]interface{}) error { + fieldMappers := d.getFieldMappers() for field, template := range templates { mapper, ok := fieldMappers[field] @@ -51,57 +54,57 @@ func (p *Document) addComponentsToPdf(templates map[string]interface{}) error { // getFieldMappers is responsible for defining which methods are responsible for assembling which components. // To do this, the component name is linked to a function in a Map. -func (p *Document) getFieldMappers() map[string]func(interface{}) error { +func (d *Document) getFieldMappers() map[string]func(interface{}) error { return map[string]func(interface{}) error{ - "builder": p.setBuilder, - "header": p.setHeader, - "footer": p.setFooter, - "pages": p.setPages, + "builder": d.setBuilder, + "header": d.setHeader, + "footer": d.setFooter, + "pages": d.setPages, } } // setBuilder is responsible for factories builder information -func (p *Document) setBuilder(builderDoc interface{}) error { +func (d *Document) setBuilder(builderDoc interface{}) error { builder, err := buildermapper.NewBuilder(builderDoc) if err != nil { return err } - p.Builder = *builder + d.Builder = *builder return nil } // setHeader is responsible for factory the header -func (p *Document) setHeader(rowsDoc interface{}) error { +func (d *Document) setHeader(rowsDoc interface{}) error { rowsTemplate, ok := rowsDoc.(map[string]interface{}) if !ok { return fmt.Errorf("header cannot be deserialized, ensure header has an array of rows") } for templateKey, rowTemplate := range rowsTemplate { - row, err := p.factory.NewRow(rowTemplate, templateKey) + row, err := d.factory.NewRow(rowTemplate, templateKey) if err != nil { return err } - p.Header = append(p.Header, row) + d.Header = append(d.Header, row) } return nil } // setFooter is responsible for factory the footer -func (p *Document) setFooter(rowsDoc interface{}) error { +func (d *Document) setFooter(rowsDoc interface{}) error { rowsTemplate, ok := rowsDoc.(map[string]interface{}) if !ok { return fmt.Errorf("footer cannot be deserialized, ensure footer has an array of rows") } for templateKey, rowTemplate := range rowsTemplate { - row, err := p.factory.NewRow(rowTemplate, templateKey) + row, err := d.factory.NewRow(rowTemplate, templateKey) if err != nil { return err } - p.Footer = append(p.Footer, row) + d.Footer = append(d.Footer, row) } return nil @@ -109,7 +112,7 @@ func (p *Document) setFooter(rowsDoc interface{}) error { // setPages is responsible for factory the pages. // pages can be a list of pages or just one page -func (p *Document) setPages(pagesDoc interface{}) error { +func (d *Document) setPages(pagesDoc interface{}) error { templatePage, ok := pagesDoc.(map[string]interface{}) if !ok { return fmt.Errorf("ensure pages can be converted to map[string] interface{}") @@ -120,21 +123,111 @@ func (p *Document) setPages(pagesDoc interface{}) error { var err error if strings.HasPrefix(templateName, "list") { - page, err = p.factory.NewList(template, templateName, p.factory.NewPage) + page, err = d.factory.NewList(template, templateName, d.factory.NewPage) } else { - page, err = p.factory.NewPage(template, templateName) + page, err = d.factory.NewPage(template, templateName) } if err != nil { return err } - p.pages = append(p.pages, page) + d.Pages = append(d.Pages, page) } return nil } +func (d *Document) GetBuilderCfg() *buildermapper.Builder { + return &d.Builder +} + +// getContent is responsible for obtaining a content with a matching key, when the content is not found, +// an empty array is returned +func (d *Document) getContent(content map[string]interface{}, key string) (map[string]interface{}, error) { + doc, ok := content[key] + if ok { + docArr, ok := doc.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("ensure that the contents of the %s can be converted to map[string]interface{}", key) + } + return docArr, nil + } + return make(map[string]interface{}, 0), nil +} + +// generatePages is responsible for creating and adding pages, if the content does not have a page field +// an empty array is sent to the page +func (d *Document) generatePages(content map[string]interface{}, provider processorprovider.ProcessorProvider) error { + pageContent, err := d.getContent(content, "pages") + if err != nil { + return err + } + + pagesComponents := make([]processorprovider.ProviderComponent, 0, len(d.Pages)) + for _, pageTemplate := range d.Pages { + page, err := pageTemplate.Generate(pageContent, provider) + if err != nil { + return err + } + pagesComponents = append(pagesComponents, page...) + } + + _, err = provider.AddPages(pagesComponents...) + return err +} + +// generateRows is responsible for creating row components, it will extract the content (if it exists) +// and send this content to rows +func (d *Document) generateRows(content map[string]interface{}, provider processorprovider.ProcessorProvider, + sourceKey string, templateRows ...mappers.Componentmapper, +) ([]processorprovider.ProviderComponent, error) { + headerContent, err := d.getContent(content, sourceKey) + if err != nil { + return nil, err + } + + rows := make([]processorprovider.ProviderComponent, 0, len(templateRows)) + for _, row := range templateRows { + componentRow, err := row.Generate(headerContent, provider) + if err != nil { + return nil, err + } + rows = append(rows, componentRow...) + } + return rows, nil +} + // generate is responsible for the builder pdf according to the submitted content -func (p *Document) Generate(content map[string]interface{}) (*core.Component, error) { - return nil, nil +func (d *Document) Generate(content map[string]interface{}, + provider processorprovider.ProcessorProvider) (*processorprovider.ProcessorProvider, error, +) { + if len(d.Pages) > 0 { + if err := d.generatePages(content, provider); err != nil { + return nil, err + } + } + + if len(d.Header) > 0 { + header, err := d.generateRows(content, provider, "header", d.Header...) + if err != nil { + return nil, err + } + _, err = provider.AddHeader(header...) + if err != nil { + return nil, err + } + } + + if len(d.Footer) > 0 { + footer, err := d.generateRows(content, provider, "footer", d.Footer...) + if err != nil { + return nil, err + } + _, err = provider.AddFooter(footer...) + if err != nil { + return nil, err + } + } + + return &provider, nil } diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index f32169fe..392431ea 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -3,6 +3,8 @@ package processorprovider import ( "fmt" + "github.com/johnfercher/go-tree/node" + "github.com/johnfercher/maroto/v2" "github.com/johnfercher/maroto/v2/pkg/components/code" "github.com/johnfercher/maroto/v2/pkg/components/col" "github.com/johnfercher/maroto/v2/pkg/components/image" @@ -11,6 +13,7 @@ import ( "github.com/johnfercher/maroto/v2/pkg/components/row" "github.com/johnfercher/maroto/v2/pkg/components/signature" "github.com/johnfercher/maroto/v2/pkg/components/text" + "github.com/johnfercher/maroto/v2/pkg/config" "github.com/johnfercher/maroto/v2/pkg/consts/align" "github.com/johnfercher/maroto/v2/pkg/consts/barcode" "github.com/johnfercher/maroto/v2/pkg/consts/breakline" @@ -19,29 +22,78 @@ import ( "github.com/johnfercher/maroto/v2/pkg/consts/linestyle" "github.com/johnfercher/maroto/v2/pkg/consts/orientation" "github.com/johnfercher/maroto/v2/pkg/core" + processorcore "github.com/johnfercher/maroto/v2/pkg/processor/core" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/buildermapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/props" ) type Maroto struct { - maroto *core.Maroto + maroto core.Maroto + repository processorcore.ProcessorRepository } -func NewMaroto() *Maroto { - // m := maroto.New() - return nil -} +func NewMaroto(repository processorcore.ProcessorRepository, builder ...buildermapper.Builder) (ProcessorProvider, error) { + cfg := config.NewBuilder() -func convertComponentType[T any](components ...ProviderComponent) ([]T, error) { - newComponents := make([]T, len(components)) - for i, component := range components { - validComponent, ok := component.(T) - if !ok { - return nil, fmt.Errorf("could not convert pdf components to a valid type") + if len(builder) > 0 { + var err error + cfg, err = NewMarotoBuilder(repository, config.NewBuilder()).CreateMarotoBuilder(&builder[0]) + if err != nil { + return nil, err } - newComponents[i] = validComponent } - return newComponents, nil + m := maroto.New(cfg.Build()) + return &Maroto{maroto: m, repository: repository}, nil +} + +func (m *Maroto) GetStructure() *node.Node[core.Structure] { + return m.maroto.GetStructure() +} + +func (m *Maroto) AddPages(pages ...ProviderComponent) (ProcessorProvider, error) { + if len(pages) == 0 { + return m, nil + } + newPages, err := convertComponentType[core.Page](pages...) + if err != nil { + return nil, err + } + + m.maroto.AddPages(newPages...) + return m, nil +} + +func (m *Maroto) AddFooter(footer ...ProviderComponent) (ProcessorProvider, error) { + if len(footer) == 0 { + return m, nil + } + newFooter, err := convertComponentType[core.Row](footer...) + if err != nil { + return nil, err + } + + err = m.maroto.RegisterFooter(newFooter...) + if err != nil { + return nil, err + } + return m, nil +} + +func (m *Maroto) AddHeader(header ...ProviderComponent) (ProcessorProvider, error) { + if len(header) == 0 { + return m, nil + } + newHeader, err := convertComponentType[core.Row](header...) + if err != nil { + return nil, err + } + + err = m.maroto.RegisterHeader(newHeader...) + if err != nil { + return nil, err + } + return m, nil } func (m *Maroto) CreatePage(components ...ProviderComponent) (ProviderComponent, error) { @@ -156,3 +208,15 @@ func (m *Maroto) CreateBarCode(codeValue string, codeProps ...*propsmapper.Barco Proportion: props.Proportion(cProps.Proportion), Center: cProps.Center, Type: barcode.Type(cProps.Type), }) } + +func convertComponentType[T any](components ...ProviderComponent) ([]T, error) { + newComponents := make([]T, len(components)) + for i, component := range components { + validComponent, ok := component.(T) + if !ok { + return nil, fmt.Errorf("could not convert pdf components to a valid type") + } + newComponents[i] = validComponent + } + return newComponents, nil +} diff --git a/pkg/processor/processorprovider/builder_maroto.go b/pkg/processor/processorprovider/builder_maroto.go index 30e1ee94..ac22752d 100644 --- a/pkg/processor/processorprovider/builder_maroto.go +++ b/pkg/processor/processorprovider/builder_maroto.go @@ -9,16 +9,20 @@ import ( "github.com/johnfercher/maroto/v2/pkg/consts/protection" "github.com/johnfercher/maroto/v2/pkg/core/entity" "github.com/johnfercher/maroto/v2/pkg/processor/core" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/buildermapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/props" "github.com/johnfercher/maroto/v2/pkg/repository" ) +// MarotoBuilder is responsible for creating Maroto builder props from buildermapper type MarotoBuilder struct { cfg config.Builder repository core.ProcessorRepository } +// NewMarotoBuilder is responsible for creating an object MarotoBuilder +// - It will use repository for search files like image and font func NewMarotoBuilder(repository core.ProcessorRepository, cfg config.Builder) *MarotoBuilder { return &MarotoBuilder{ repository: repository, @@ -26,71 +30,100 @@ func NewMarotoBuilder(repository core.ProcessorRepository, cfg config.Builder) * } } -func (m *MarotoBuilder) WithPageSize(size string) config.Builder { +// CreateMarotoBuilder is responsible for facilitating the creation of the builder +func (m *MarotoBuilder) CreateMarotoBuilder(builder *buildermapper.Builder) (config.Builder, error) { + m = m.WithPageSize(builder.PageSize).WithDimensions(builder.Dimensions).WithMargin(builder.Margins). + WithConcurrentMode(builder.ConcurrentMode).WithSequentialMode(builder.SequentialMode). + WithSequentialLowMemoryMode(builder.SequentialLowMemoryMode).WithDebug(builder.Debug).WithMaxGridSize(builder.MaxGridSize). + WithDefaultFont(builder.DefaultFont).WithPageNumber(builder.PageNumber).WithProtection(builder.Protection). + WithCompression(builder.Compression).WithOrientation(builder.Orientation).WithMetadata(builder.Metadata). + WithDisableAutoPageBreak(builder.DisableAutoPageBreak) + + if _, err := m.WithBackgroundImage(builder.BackgroundImage); err != nil { + return nil, err + } + if _, err := m.WithCustomFonts(builder.CustomFonts); err != nil { + return nil, err + } + + return m.cfg, nil +} + +// WithPageSize will add page size properties +// - if size is null, size will not be added +func (m *MarotoBuilder) WithPageSize(size string) *MarotoBuilder { validAndRun(func() { m.cfg.WithPageSize(pagesize.Type(size)) }, size != "") - return m.cfg + return m } // WithDimensions defines custom page dimensions, this overrides page size. -func (m *MarotoBuilder) WithDimensions(dimensions *propsmapper.Dimensions) config.Builder { +// - if dimensions is null, dimensions will not be added +func (m *MarotoBuilder) WithDimensions(dimensions *propsmapper.Dimensions) *MarotoBuilder { validAndRun(func() { m.cfg.WithDimensions(dimensions.Width, dimensions.Height) }, dimensions != nil) - return m.cfg + return m } -// WithLeftMargin customize margin. -func (m *MarotoBuilder) WithMargin(margin *propsmapper.Margins) config.Builder { - validAndRun(func() { m.cfg.WithBottomMargin(margin.Bottom) }, margin.Bottom >= 0) - validAndRun(func() { m.cfg.WithTopMargin(margin.Top) }, margin.Top >= 0) - validAndRun(func() { m.cfg.WithLeftMargin(margin.Left) }, margin.Left >= 0) - validAndRun(func() { m.cfg.WithRightMargin(margin.Right) }, margin.Right >= 0) - return m.cfg +// WithMargin customizes each margin individually - Left, Right, top and booton +// - if margin is null or individual margin is less than 0, margin will not be added +func (m *MarotoBuilder) WithMargin(margin *propsmapper.Margins) *MarotoBuilder { + if margin != nil { + validAndRun(func() { m.cfg.WithBottomMargin(margin.Bottom) }, margin.Bottom >= 0) + validAndRun(func() { m.cfg.WithTopMargin(margin.Top) }, margin.Top >= 0) + validAndRun(func() { m.cfg.WithLeftMargin(margin.Left) }, margin.Left >= 0) + validAndRun(func() { m.cfg.WithRightMargin(margin.Right) }, margin.Right >= 0) + } + return m } -// WithConcurrentMode defines concurrent generation, chunk workers define how mano chuncks -// will be executed concurrently. -func (m *MarotoBuilder) WithConcurrentMode(chunkWorkers int) config.Builder { +// WithConcurrentMode defines concurrent generation, chunk workers define how mano chuncks will be executed concurrently. +// - if chunkWorkers is less than 0, will not be added +func (m *MarotoBuilder) WithConcurrentMode(chunkWorkers int) *MarotoBuilder { validAndRun(func() { m.cfg.WithConcurrentMode(chunkWorkers) }, chunkWorkers > 0) - return m.cfg + return m } // WithSequentialMode defines that maroto will run in default mode. -func (m *MarotoBuilder) WithSequentialMode(on bool) config.Builder { +func (m *MarotoBuilder) WithSequentialMode(on bool) *MarotoBuilder { m.cfg.WithSequentialMode() - return m.cfg + return m } // WithSequentialLowMemoryMode defines that maroto will run focusing in reduce memory consumption, // chunk workers define how many divisions the work will have. -func (m *MarotoBuilder) WithSequentialLowMemoryMode(chunkWorkers int) config.Builder { +// - if chunkWorkers is less than 0, will not be added +func (m *MarotoBuilder) WithSequentialLowMemoryMode(chunkWorkers int) *MarotoBuilder { validAndRun(func() { m.cfg.WithSequentialLowMemoryMode(chunkWorkers) }, chunkWorkers > 0) - return m.cfg + return m } // WithDebug defines a debug behaviour where maroto will draw borders in everything. -func (m *MarotoBuilder) WithDebug(on bool) config.Builder { +func (m *MarotoBuilder) WithDebug(on bool) *MarotoBuilder { m.cfg.WithDebug(on) - return m.cfg + return m } // WithMaxGridSize defines a custom max grid sum which it will change the sum of column sizes. -func (m *MarotoBuilder) WithMaxGridSize(maxGridSize int) config.Builder { +// - if maxGridSize is less than 0, will not be added +func (m *MarotoBuilder) WithMaxGridSize(maxGridSize int) *MarotoBuilder { validAndRun(func() { m.cfg.WithMaxGridSize(maxGridSize) }, maxGridSize > 0) - return m.cfg + return m } // WithDefaultFont defines a custom font, other than arial. This can be used to define a custom font as default. -func (m *MarotoBuilder) WithDefaultFont(font *propsmapper.Font) config.Builder { +// - if font is nill, will not be added +func (m *MarotoBuilder) WithDefaultFont(font *propsmapper.Font) *MarotoBuilder { validAndRun(func() { m.cfg.WithDefaultFont(&props.Font{ Family: font.Family, Style: fontstyle.Type(font.Style), Size: font.Size, Color: (*props.Color)(font.Color), }) }, font != nil) - return m.cfg + return m } // WithPageNumber defines a string pattern to write the current page and total. -func (m *MarotoBuilder) WithPageNumber(pageNumber *propsmapper.PageNumber) config.Builder { +// - if pageNumber is nill, will not be added +func (m *MarotoBuilder) WithPageNumber(pageNumber *propsmapper.PageNumber) *MarotoBuilder { validAndRun(func() { m.cfg.WithPageNumber(props.PageNumber{ Pattern: pageNumber.Pattern, Place: props.Place(pageNumber.Place), Family: pageNumber.Family, @@ -98,32 +131,35 @@ func (m *MarotoBuilder) WithPageNumber(pageNumber *propsmapper.PageNumber) confi Color: &props.Color{Red: pageNumber.Color.Red, Green: pageNumber.Color.Green, Blue: pageNumber.Color.Blue}, }) }, pageNumber != nil) - return m.cfg + return m } // WithProtection defines protection types to the PDF document. -func (m *MarotoBuilder) WithProtection(protectionmapper *propsmapper.Protection) config.Builder { +// - if protectionmapper is nill, will not be added +func (m *MarotoBuilder) WithProtection(protectionmapper *propsmapper.Protection) *MarotoBuilder { validAndRun(func() { m.cfg.WithProtection(protection.Type(protectionmapper.Type), protectionmapper.UserPassword, protectionmapper.OwnerPassword) }, protectionmapper != nil) - return m.cfg + return m } // WithCompression defines compression. -func (m *MarotoBuilder) WithCompression(compression bool) config.Builder { +func (m *MarotoBuilder) WithCompression(compression bool) *MarotoBuilder { m.cfg.WithCompression(compression) - return m.cfg + return m } // WithOrientation defines the page orientation. The default orientation is vertical, // if horizontal is defined width and height will be flipped. -func (m *MarotoBuilder) WithOrientation(orientationMapper string) config.Builder { +// - if orientationMapper is nill, will not be added +func (m *MarotoBuilder) WithOrientation(orientationMapper string) *MarotoBuilder { validAndRun(func() { m.cfg.WithOrientation(orientation.Type(orientationMapper)) }, orientationMapper != "") - return m.cfg + return m } -// WithAuthor defines the author name metadata. -func (m *MarotoBuilder) WithMetadata(metadata *propsmapper.Metadata) config.Builder { +// WithMetadata customizes each metadata individually - Author, CreationDate, Creator, Keywords, subject and title +// - if metadata is null or individual metadata is less than 0, metadata will not be added +func (m *MarotoBuilder) WithMetadata(metadata *propsmapper.Metadata) *MarotoBuilder { if metadata != nil { validAndRun(func() { m.cfg.WithAuthor(metadata.Author.Text, metadata.Author.UTF8) }, metadata.Author != nil) validAndRun(func() { m.cfg.WithCreationDate(*metadata.CreationDate) }, metadata.CreationDate != nil) @@ -132,26 +168,28 @@ func (m *MarotoBuilder) WithMetadata(metadata *propsmapper.Metadata) config.Buil validAndRun(func() { m.cfg.WithSubject(metadata.Subject.Text, metadata.Subject.UTF8) }, metadata.Subject != nil) validAndRun(func() { m.cfg.WithTitle(metadata.Title.Text, metadata.Title.UTF8) }, metadata.Title != nil) } - return m.cfg + return m } // WithCustomFonts add custom fonts. -func (m *MarotoBuilder) WithCustomFonts(customFonts []*propsmapper.CustomFont) (config.Builder, error) { +// - if the font file cannot be loaded, an error will be returned +func (m *MarotoBuilder) WithCustomFonts(customFonts []*propsmapper.CustomFont) (*MarotoBuilder, error) { if len(customFonts) == 0 { - return m.cfg, nil + return m, nil } newFonts, err := m.loadFonts(customFonts) if err != nil { return nil, err } m.cfg.WithCustomFonts(newFonts) - return m.cfg, nil + return m, nil } // WithBackgroundImage defines the background image that will be applied in every page. -func (m *MarotoBuilder) WithBackgroundImage(backgroundImage string) (config.Builder, error) { +// - if the image file cannot be loaded, an error will be returned +func (m *MarotoBuilder) WithBackgroundImage(backgroundImage string) (*MarotoBuilder, error) { if backgroundImage == "" { - return m.cfg, nil + return m, nil } ext, imageBytes, err := m.repository.GetDocument(backgroundImage) @@ -159,13 +197,13 @@ func (m *MarotoBuilder) WithBackgroundImage(backgroundImage string) (config.Buil return nil, err } m.cfg.WithBackgroundImage(imageBytes, extension.Type(ext)) - return m.cfg, nil + return m, nil } // WithDisableAutoPageBreak defines the option to disable automatic page breaks. -func (m *MarotoBuilder) WithDisableAutoPageBreak(disabled bool) config.Builder { +func (m *MarotoBuilder) WithDisableAutoPageBreak(disabled bool) *MarotoBuilder { m.cfg.WithDisableAutoPageBreak(disabled) - return m.cfg + return m } func validAndRun(setParam func(), parameter bool) { diff --git a/pkg/processor/processorprovider/provider.go b/pkg/processor/processorprovider/provider.go index fb168e55..57887df2 100644 --- a/pkg/processor/processorprovider/provider.go +++ b/pkg/processor/processorprovider/provider.go @@ -1,6 +1,7 @@ package processorprovider import ( + "github.com/johnfercher/go-tree/node" "github.com/johnfercher/maroto/v2/pkg/core" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" ) @@ -12,6 +13,10 @@ type ProviderComponent interface { // ProcessorProvider provides an interface with all the methods that // Maroto provides for pdf builder type ProcessorProvider interface { + GetStructure() *node.Node[core.Structure] + AddPages(pages ...ProviderComponent) (ProcessorProvider, error) + AddFooter(footer ...ProviderComponent) (ProcessorProvider, error) + AddHeader(header ...ProviderComponent) (ProcessorProvider, error) CreatePage(components ...ProviderComponent) (ProviderComponent, error) CreateRow(height float64, components ...ProviderComponent) (ProviderComponent, error) CreateCol(size int, components ...ProviderComponent) (ProviderComponent, error) @@ -21,5 +26,5 @@ type ProcessorProvider interface { CreateMatrixCode(value string, props ...*propsmapper.Rect) ProviderComponent CreateQrCode(value string, props ...*propsmapper.Rect) ProviderComponent CreateImage(value []byte, extension string, props ...*propsmapper.Rect) ProviderComponent - CreateLine(props *propsmapper.Line) ProviderComponent + CreateLine(props ...*propsmapper.Line) ProviderComponent } From 65e8eefbdf122bffcdfdf04084ec49d57f913454 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 17 Nov 2024 14:29:44 -0300 Subject: [PATCH 075/116] feat: load documents via repository the repository must either get the document into memory or load the document with the loader interface --- mocks/Loader.go | 46 +++++++++++++++++++ pkg/processor/core/core.go | 1 + .../deserializer/json_deserializer.go | 9 +--- pkg/processor/loader/loader.go | 4 +- pkg/processor/processor.go | 4 +- .../processorprovider/Maroto_test.go | 39 ++++++++++------ .../processorprovider/builder_maroto_test.go | 8 ++-- pkg/processor/repository/memory_storage.go | 24 ++++++++-- 8 files changed, 103 insertions(+), 32 deletions(-) diff --git a/mocks/Loader.go b/mocks/Loader.go index 044dc497..ffe16105 100644 --- a/mocks/Loader.go +++ b/mocks/Loader.go @@ -17,6 +17,52 @@ func (_m *Loader) EXPECT() *Loader_Expecter { return &Loader_Expecter{mock: &_m.Mock} } +// GetExt provides a mock function with given fields: path +func (_m *Loader) GetExt(path string) string { + ret := _m.Called(path) + + if len(ret) == 0 { + panic("no return value specified for GetExt") + } + + var r0 string + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// Loader_GetExt_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetExt' +type Loader_GetExt_Call struct { + *mock.Call +} + +// GetExt is a helper method to define mock.On call +// - path string +func (_e *Loader_Expecter) GetExt(path interface{}) *Loader_GetExt_Call { + return &Loader_GetExt_Call{Call: _e.mock.On("GetExt", path)} +} + +func (_c *Loader_GetExt_Call) Run(run func(path string)) *Loader_GetExt_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *Loader_GetExt_Call) Return(_a0 string) *Loader_GetExt_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Loader_GetExt_Call) RunAndReturn(run func(string) string) *Loader_GetExt_Call { + _c.Call.Return(run) + return _c +} + // Load provides a mock function with given fields: path func (_m *Loader) Load(path string) ([]byte, error) { ret := _m.Called(path) diff --git a/pkg/processor/core/core.go b/pkg/processor/core/core.go index 106cd76f..82024ad8 100644 --- a/pkg/processor/core/core.go +++ b/pkg/processor/core/core.go @@ -19,4 +19,5 @@ type Deserializer interface { // path may be file path or url type Loader interface { Load(path string) ([]byte, error) + GetExt(path string) string } diff --git a/pkg/processor/deserializer/json_deserializer.go b/pkg/processor/deserializer/json_deserializer.go index a673d299..aee74588 100644 --- a/pkg/processor/deserializer/json_deserializer.go +++ b/pkg/processor/deserializer/json_deserializer.go @@ -3,18 +3,13 @@ package deserializer import ( "encoding/json" - - "github.com/johnfercher/maroto/v2/pkg/processor/core" - "github.com/johnfercher/maroto/v2/pkg/processor/loader" ) -type jsonDeserializer struct { - loader core.Loader -} +type jsonDeserializer struct{} // The new JSONserializer is responsible for creating a json deserializer func NewJSONDeserializer() *jsonDeserializer { - return &jsonDeserializer{loader: loader.NewLoader()} + return &jsonDeserializer{} } // Deserialize is responsible for parsing a json document and creating an interface map diff --git a/pkg/processor/loader/loader.go b/pkg/processor/loader/loader.go index 0ac806d0..026ff84f 100644 --- a/pkg/processor/loader/loader.go +++ b/pkg/processor/loader/loader.go @@ -20,7 +20,7 @@ func NewLoader() *loader { // Load takes the path/url/uri of an asset (image, font) // and returns its contents. func (l *loader) Load(path string) ([]byte, error) { - ext := getExt(path) + ext := l.GetExt(path) if _, ok := validExts[ext]; !ok { return nil, errors.Wrap(ErrUnsupportedExtension, ext) } @@ -49,7 +49,7 @@ func (l *loader) Load(path string) ([]byte, error) { return data, nil } -func getExt(path string) string { +func (l *loader) GetExt(path string) string { toks := strings.Split(path, ".") if len(toks) < 2 { return "" diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index 50ebf5f4..2b6c92fd 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -5,6 +5,7 @@ import ( "github.com/johnfercher/maroto/v2/pkg/processor/core" "github.com/johnfercher/maroto/v2/pkg/processor/deserializer" + "github.com/johnfercher/maroto/v2/pkg/processor/loader" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/abstractfactory" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/documentmapper" "github.com/johnfercher/maroto/v2/pkg/processor/repository" @@ -13,14 +14,13 @@ import ( type processor struct { repository core.ProcessorRepository deserializer core.Deserializer - loader core.Loader } // NewProcessor is responsible for creating a processor object // The processor object should be used to create PDF from a serialized document func NewProcessor() *processor { return &processor{ - repository: repository.NewMemoryStorage(), + repository: repository.NewMemoryStorage(loader.NewLoader()), deserializer: deserializer.NewJSONDeserializer(), } } diff --git a/pkg/processor/processorprovider/Maroto_test.go b/pkg/processor/processorprovider/Maroto_test.go index 1fe81946..49efb398 100644 --- a/pkg/processor/processorprovider/Maroto_test.go +++ b/pkg/processor/processorprovider/Maroto_test.go @@ -152,7 +152,8 @@ func TestNewMaroto(t *testing.T) { func TestCreateBarCode(t *testing.T) { t.Run("when CreateBarCode is called, should generate a barcode", func(t *testing.T) { - m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) + loader := mocks.NewLoader(t) + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) barcode := m.CreateBarCode("code", &propsmapper.Barcode{ Left: 10.0, Top: 10.0, Percent: 100.0, @@ -168,7 +169,8 @@ func TestCreateBarCode(t *testing.T) { func TestCreateMatrixCode(t *testing.T) { t.Run("when CreateMatrixCode is called, should generate a matrixcode", func(t *testing.T) { - m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) + loader := mocks.NewLoader(t) + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) barcode := m.CreateMatrixCode("code", &propsmapper.Rect{Left: 10.0, Top: 10.0, Percent: 100.0, JustReferenceWidth: false, Center: false}, ) @@ -179,7 +181,8 @@ func TestCreateMatrixCode(t *testing.T) { func TestCreateQRCode(t *testing.T) { t.Run("when CreateQrCode is called, should generate a qrcode", func(t *testing.T) { - m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) + loader := mocks.NewLoader(t) + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) barcode := m.CreateQrCode("code", &propsmapper.Rect{Left: 10.0, Top: 10.0, Percent: 100.0, JustReferenceWidth: false, Center: false}, ) @@ -190,7 +193,8 @@ func TestCreateQRCode(t *testing.T) { func TestCreateImage(t *testing.T) { t.Run("when CreateImage is called, should generate a image", func(t *testing.T) { - m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) + loader := mocks.NewLoader(t) + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) image := m.CreateImage(make([]byte, 0), "png", &propsmapper.Rect{Left: 10.0, Top: 10.0, Percent: 100.0, JustReferenceWidth: false, Center: false}, ) @@ -201,7 +205,8 @@ func TestCreateImage(t *testing.T) { func TestCreateLine(t *testing.T) { t.Run("when CreateLine is called, should generate a line", func(t *testing.T) { - m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) + loader := mocks.NewLoader(t) + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) barcode := m.CreateLine( &propsmapper.Line{ Color: &propsmapper.Color{Red: 10, Green: 10, Blue: 10}, Style: "solid", Thickness: 10.0, @@ -215,7 +220,8 @@ func TestCreateLine(t *testing.T) { func TestCreateSignature(t *testing.T) { t.Run("when CreateSignature is called, should generate a signature", func(t *testing.T) { - m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) + loader := mocks.NewLoader(t) + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) barcode := m.CreateSignature("signature", &propsmapper.Signature{ FontFamily: "Arial", FontStyle: "bold", FontSize: 10.0, FontColor: &propsmapper.Color{Red: 10, Green: 10, Blue: 10}, @@ -229,7 +235,8 @@ func TestCreateSignature(t *testing.T) { func TestCreateText(t *testing.T) { t.Run("when CreateText is called, should generate a text", func(t *testing.T) { - m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) + loader := mocks.NewLoader(t) + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) barcode := m.CreateText("text", &propsmapper.Text{ Top: 10.0, Left: 10.0, Right: 10.0, Family: "Arial", Style: "bold", Size: 10.0, Align: "center", BreakLineStrategy: "dash_strategy", @@ -243,7 +250,8 @@ func TestCreateText(t *testing.T) { func TestCreateCol(t *testing.T) { t.Run("when CreateCol is called, should generate a col", func(t *testing.T) { - m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) + loader := mocks.NewLoader(t) + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) text := text.New("test") col, err := m.CreateCol(10, text) @@ -253,7 +261,8 @@ func TestCreateCol(t *testing.T) { }) t.Run("when invalid components are sent, should return an error", func(t *testing.T) { - m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) + loader := mocks.NewLoader(t) + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) page, err := m.CreatePage(text.NewCol(10, "10")) assert.Nil(t, page) @@ -263,7 +272,8 @@ func TestCreateCol(t *testing.T) { func TestCreateRow(t *testing.T) { t.Run("when CreateRow is called, should generate a row", func(t *testing.T) { - m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) + loader := mocks.NewLoader(t) + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) text := text.NewCol(12, "test") col, err := m.CreateRow(10, text) @@ -273,7 +283,8 @@ func TestCreateRow(t *testing.T) { }) t.Run("when invalid components are sent, should return an error", func(t *testing.T) { - m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) + loader := mocks.NewLoader(t) + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) page, err := m.CreatePage(text.New("10")) assert.Nil(t, page) @@ -283,14 +294,16 @@ func TestCreateRow(t *testing.T) { func TestCreatePage(t *testing.T) { t.Run("when CreatePage is called, should generate a page", func(t *testing.T) { - m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) + loader := mocks.NewLoader(t) + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) page, err := m.CreatePage(row.New(10)) assert.Nil(t, err) assert.NotNil(t, page) }) t.Run("when invalid components are sent, should return an error", func(t *testing.T) { - m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage()) + loader := mocks.NewLoader(t) + m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) page, err := m.CreatePage(text.New("10")) assert.Nil(t, page) diff --git a/pkg/processor/processorprovider/builder_maroto_test.go b/pkg/processor/processorprovider/builder_maroto_test.go index cba8a072..b43359ab 100644 --- a/pkg/processor/processorprovider/builder_maroto_test.go +++ b/pkg/processor/processorprovider/builder_maroto_test.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/mock" ) -func createBuilderMocks(t *testing.T) *mocks.Builder { +func NewBuilderMocks(t *testing.T) *mocks.Builder { build := mocks.NewBuilder(t) build.EXPECT().WithPageSize(mock.Anything).Return(config.NewBuilder()) build.EXPECT().WithDimensions(mock.Anything, mock.Anything).Return(config.NewBuilder()) @@ -45,7 +45,7 @@ func createBuilderMocks(t *testing.T) *mocks.Builder { return build } -func validateCallOfAllMethods(t *testing.T, builder *mocks.Builder) { +func NewvalidateCallOfAllMethods(t *testing.T, builder *mocks.Builder) { builder.AssertNumberOfCalls(t, "WithPageSize", 1) builder.AssertNumberOfCalls(t, "WithDimensions", 1) builder.AssertNumberOfCalls(t, "WithTopMargin", 1) @@ -75,7 +75,7 @@ func TestCreateMarotoBuilder(t *testing.T) { t.Run("when all props are sent, should add all props", func(t *testing.T) { repository := mocks.NewProcessorRepository(t) repository.EXPECT().GetDocument(mock.Anything).Return(string(extension.Png), []byte{123}, nil) - build := createBuilderMocks(t) + build := NewBuilderMocks(t) fixProps := fixture.BuilderProps() builder := processorprovider.NewMarotoBuilder(repository, build) @@ -83,7 +83,7 @@ func TestCreateMarotoBuilder(t *testing.T) { assert.Nil(t, err) assert.NotNil(t, cfg) - validateCallOfAllMethods(t, build) + NewvalidateCallOfAllMethods(t, build) }) } diff --git a/pkg/processor/repository/memory_storage.go b/pkg/processor/repository/memory_storage.go index c3211618..b205a10a 100644 --- a/pkg/processor/repository/memory_storage.go +++ b/pkg/processor/repository/memory_storage.go @@ -1,22 +1,38 @@ // repository package is responsible for managing access to templates package repository +import ( + "github.com/johnfercher/maroto/v2/pkg/processor/core" +) + type memoryStorage struct { - template map[string]map[string]any + template map[string]map[string]any + documents map[string][]byte + loader core.Loader } // NewMemoryStorage is responsible for creating a repository // implementation that stores data in memory -func NewMemoryStorage() *memoryStorage { +func NewMemoryStorage(loader core.Loader) *memoryStorage { return &memoryStorage{ template: make(map[string]map[string]any), + loader: loader, } } // GetDocument is responsible search and return the document according to the name sent // - documentName is the name that the document references -func (m *memoryStorage) GetDocument(documentName string) (string, []byte, error) { - return "", nil, nil +func (m *memoryStorage) GetDocument(documentPath string) (string, []byte, error) { + if doc, ok := m.documents[documentPath]; ok { + return m.loader.GetExt(documentPath), doc, nil + } + + bytes, err := m.loader.Load(documentPath) + if err != nil { + return "", nil, err + } + m.documents[documentPath] = bytes + return m.loader.GetExt(documentPath), bytes, nil } // RegisterTemplate is responsible for register a template in memory From 03a874d71603705d96a90c37166868bfb1d5bae9 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sat, 30 Nov 2024 17:59:43 -0300 Subject: [PATCH 076/116] fix: fix errors in adding pages turn hyperlink into a pointer use default value in text when value is set --- mocks/ProcessorProvider.go | 57 +++++++++++++++++++ .../mappers/components/listmapper/list.go | 25 ++++++-- .../mappers/components/pagemapper/page.go | 6 +- .../mappers/components/rowmapper/row.go | 12 ++-- .../mappers/components/textmapper/text.go | 2 +- .../mappers/documentmapper/document.go | 11 ++-- pkg/processor/mappers/propsmapper/text.go | 4 +- 7 files changed, 95 insertions(+), 22 deletions(-) diff --git a/mocks/ProcessorProvider.go b/mocks/ProcessorProvider.go index e2095962..75d5af72 100644 --- a/mocks/ProcessorProvider.go +++ b/mocks/ProcessorProvider.go @@ -896,6 +896,63 @@ func (_c *ProcessorProvider_CreateText_Call) RunAndReturn(run func(string, ...*p return _c } +// Generate provides a mock function with given fields: +func (_m *ProcessorProvider) Generate() (core.Document, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Generate") + } + + var r0 core.Document + var r1 error + if rf, ok := ret.Get(0).(func() (core.Document, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() core.Document); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(core.Document) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProcessorProvider_Generate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Generate' +type ProcessorProvider_Generate_Call struct { + *mock.Call +} + +// Generate is a helper method to define mock.On call +func (_e *ProcessorProvider_Expecter) Generate() *ProcessorProvider_Generate_Call { + return &ProcessorProvider_Generate_Call{Call: _e.mock.On("Generate")} +} + +func (_c *ProcessorProvider_Generate_Call) Run(run func()) *ProcessorProvider_Generate_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ProcessorProvider_Generate_Call) Return(_a0 core.Document, _a1 error) *ProcessorProvider_Generate_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ProcessorProvider_Generate_Call) RunAndReturn(run func() (core.Document, error)) *ProcessorProvider_Generate_Call { + _c.Call.Return(run) + return _c +} + // GetStructure provides a mock function with given fields: func (_m *ProcessorProvider) GetStructure() *node.Node[core.Structure] { ret := _m.Called() diff --git a/pkg/processor/mappers/components/listmapper/list.go b/pkg/processor/mappers/components/listmapper/list.go index 30a39af7..a91e04ec 100644 --- a/pkg/processor/mappers/components/listmapper/list.go +++ b/pkg/processor/mappers/components/listmapper/list.go @@ -31,6 +31,7 @@ func NewList(list interface{}, sourceKey string, generate mappers.GenerateCompon }, nil } +// createComponents is responsible for generating the list component. Components will be generated through the generate method func createComponents(listMapper map[string]interface{}, generate mappers.GenerateComponent) ([]mappers.Componentmapper, error) { components := make([]mappers.Componentmapper, len(listMapper)) cont := 0 @@ -45,15 +46,31 @@ func createComponents(listMapper map[string]interface{}, generate mappers.Genera return components, nil } +// formatListContent is responsible for converting content into []map[string]interface{} +func (l *List) formatListContent(content interface{}) ([]map[string]interface{}, error) { + listContent, ok := content.([]interface{}) + if !ok { + return nil, fmt.Errorf("ensure that the contents of the list \"%s\" can be converted to []map[string]interface{}", l.SourceKey) + } + + contentMaps := make([]map[string]interface{}, 0, len(listContent)) + for _, content := range listContent { + contentMap, ok := content.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("ensure that the contents of the list \"%s\" can be converted to []map[string]interface{}", l.SourceKey) + } + contentMaps = append(contentMaps, contentMap) + } + return contentMaps, nil +} + func (l *List) getListContent(content map[string]interface{}) ([]map[string]interface{}, error) { listContent, ok := content[l.SourceKey] if !ok { return nil, fmt.Errorf("the list needs the source key \"%s\", but it was not found", l.SourceKey) } - if contents, ok := listContent.([]map[string]interface{}); ok { - return contents, nil - } - return nil, fmt.Errorf("ensure that the contents of the list \"%s\" can be converted to []map[string]interface{}", l.SourceKey) + + return l.formatListContent(listContent) } func (l *List) generateTemplates(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( diff --git a/pkg/processor/mappers/components/pagemapper/page.go b/pkg/processor/mappers/components/pagemapper/page.go index 6b704724..142161f2 100644 --- a/pkg/processor/mappers/components/pagemapper/page.go +++ b/pkg/processor/mappers/components/pagemapper/page.go @@ -32,7 +32,7 @@ func NewPage(rows interface{}, sourceKey string, factory mappers.AbstractFactory func (p *Page) setRows(rowsDoc interface{}) error { templateRows, ok := rowsDoc.(map[string]interface{}) if !ok { - return fmt.Errorf("ensure rows can be converted to map[string] interface{}") + return fmt.Errorf("could not parse template, ensure rows can be converted to map[string] interface{}") } for templateName, template := range templateRows { @@ -57,12 +57,12 @@ func (p *Page) setRows(rowsDoc interface{}) error { func (p *Page) getPageContent(content map[string]interface{}) (map[string]interface{}, error) { pageContent, ok := content[p.SourceKey] if !ok { - return nil, fmt.Errorf("the page needs the source key \"%s\", but it was not found", p.SourceKey) + return nil, fmt.Errorf("could not parse template,the page needs the source key \"%s\", but it was not found", p.SourceKey) } if mapPage, ok := pageContent.(map[string]interface{}); ok { return mapPage, nil } - return nil, fmt.Errorf("ensure that the contents of the page \"%s\" can be converted to map[string]interface{}", p.SourceKey) + return nil, fmt.Errorf("could not parse template, ensure that the contents of the page \"%s\" can be converted to map[string]interface{}", p.SourceKey) } func (p *Page) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( diff --git a/pkg/processor/mappers/components/rowmapper/row.go b/pkg/processor/mappers/components/rowmapper/row.go index 6a793602..a8ccbbb9 100644 --- a/pkg/processor/mappers/components/rowmapper/row.go +++ b/pkg/processor/mappers/components/rowmapper/row.go @@ -18,7 +18,7 @@ type Row struct { func NewRow(templateRows interface{}, sourceKey string, factory mappers.AbstractFactoryMaps) (*Row, error) { mapRows, ok := templateRows.(map[string]interface{}) if !ok { - return nil, fmt.Errorf("ensure that rows can be converted to map[string] interface{}") + return nil, fmt.Errorf("could not parse template, ensure that rows can be converted to map[string] interface{}") } row := &Row{ Height: 0, @@ -42,7 +42,7 @@ func (r *Row) addComponents(mapRows map[string]interface{}) error { for templateName, template := range mapRows { mapper, ok := fieldMappers[templateName] if !ok { - return fmt.Errorf("the field %s present in the row cannot be mapped to any valid component", templateName) + return fmt.Errorf("could not parse template, the field %s present in the row cannot be mapped to any valid component", templateName) } err := mapper(template) if err != nil { @@ -55,7 +55,7 @@ func (r *Row) addComponents(mapRows map[string]interface{}) error { func (r *Row) setHeight(template interface{}) error { height, ok := template.(float64) if !ok { - return fmt.Errorf("ensure that height can be converted to float64") + return fmt.Errorf("could not parse template, ensure that height can be converted to float64") } r.Height = height return nil @@ -64,7 +64,7 @@ func (r *Row) setHeight(template interface{}) error { func (r *Row) setCols(template interface{}) error { cols, ok := template.([]interface{}) if !ok { - return fmt.Errorf("ensure that cols can be converted to []interface{}") + return fmt.Errorf("could not parse template, ensure that cols can be converted to []interface{}") } r.Cols = make([]mappers.Componentmapper, len(cols)) @@ -91,12 +91,12 @@ func (r *Row) getFieldMappers() map[string]func(interface{}) error { func (r *Row) getRowContent(content map[string]interface{}) (map[string]interface{}, error) { rowContent, ok := content[r.SourceKey] if !ok { - return nil, fmt.Errorf("the row needs the source key \"%s\", but it was not found", r.SourceKey) + return nil, fmt.Errorf("could not parse template, the row needs the source key \"%s\", but it was not found", r.SourceKey) } if mapRow, ok := rowContent.(map[string]interface{}); ok { return mapRow, nil } - return nil, fmt.Errorf("ensure that the contents of the row \"%s\" can be converted to map[string]interface{}", r.SourceKey) + return nil, fmt.Errorf("could not parse template, ensure that the contents of the row \"%s\" can be converted to map[string]interface{}", r.SourceKey) } func (r *Row) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( diff --git a/pkg/processor/mappers/components/textmapper/text.go b/pkg/processor/mappers/components/textmapper/text.go index 9ac232ee..91f21442 100644 --- a/pkg/processor/mappers/components/textmapper/text.go +++ b/pkg/processor/mappers/components/textmapper/text.go @@ -93,7 +93,7 @@ func (t *Text) validateFields() error { } func (t *Text) getValue(content map[string]interface{}) (string, error) { - if t.Value != "" { + if t.SourceKey == "" { return t.Value, nil } textFound, ok := content[t.SourceKey] diff --git a/pkg/processor/mappers/documentmapper/document.go b/pkg/processor/mappers/documentmapper/document.go index 73b4830d..eb61213b 100644 --- a/pkg/processor/mappers/documentmapper/document.go +++ b/pkg/processor/mappers/documentmapper/document.go @@ -201,12 +201,6 @@ func (d *Document) generateRows(content map[string]interface{}, provider process func (d *Document) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) (*processorprovider.ProcessorProvider, error, ) { - if len(d.Pages) > 0 { - if err := d.generatePages(content, provider); err != nil { - return nil, err - } - } - if len(d.Header) > 0 { header, err := d.generateRows(content, provider, "header", d.Header...) if err != nil { @@ -229,5 +223,10 @@ func (d *Document) Generate(content map[string]interface{}, } } + if len(d.Pages) > 0 { + if err := d.generatePages(content, provider); err != nil { + return nil, err + } + } return &provider, nil } diff --git a/pkg/processor/mappers/propsmapper/text.go b/pkg/processor/mappers/propsmapper/text.go index e8a3f31b..464a823b 100644 --- a/pkg/processor/mappers/propsmapper/text.go +++ b/pkg/processor/mappers/propsmapper/text.go @@ -25,7 +25,7 @@ type Text struct { // Color define the font style color. Color *Color // Hyperlink define a link to be opened when the text is clicked. - Hyperlink string + Hyperlink *string } // NewText is responsible for creating the Text, if the font fields cannot be @@ -47,6 +47,6 @@ func NewText(signature interface{}) (*Text, error) { BreakLineStrategy: NewBreakLineStrategy(*convertFields(signatureMap["break_line_strategy"], "")), VerticalPadding: *convertFields(signatureMap["vertical_padding"], -1.0), Color: NewColor(signatureMap["color"]), - Hyperlink: *convertFields(signatureMap["hyperlink"], ""), + Hyperlink: *convertFields[*string](signatureMap["hyperlink"], nil), }, nil } From f7eff52d6a6d3db3995a6051631e5665193439e4 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sat, 30 Nov 2024 18:08:01 -0300 Subject: [PATCH 077/116] test: validate simple pdf addition --- pkg/processor/processor_test.go | 68 ++++++++ test/maroto/processor/simple_pdf.json | 213 ++++++++++++++++++++++++++ 2 files changed, 281 insertions(+) create mode 100644 pkg/processor/processor_test.go create mode 100644 test/maroto/processor/simple_pdf.json diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go new file mode 100644 index 00000000..7028eb5a --- /dev/null +++ b/pkg/processor/processor_test.go @@ -0,0 +1,68 @@ +package processor_test + +import ( + "encoding/json" + "testing" + + "github.com/johnfercher/maroto/v2/mocks" + "github.com/johnfercher/maroto/v2/pkg/processor" + "github.com/johnfercher/maroto/v2/pkg/processor/deserializer" + processortest "github.com/johnfercher/maroto/v2/pkg/processor/test" + "github.com/johnfercher/maroto/v2/pkg/test" + "github.com/stretchr/testify/assert" +) + +func TestRegisterTemplate(t *testing.T) { + t.Run("when template is recorded, should no return error", func(t *testing.T) { + }) + t.Run("when is not possible deserialize template, should return an error", func(t *testing.T) { + }) + t.Run("when is not possible register template, should return an error", func(t *testing.T) { + }) +} + +func loadTemplate(templatePath string) map[string]interface{} { + var template map[string]interface{} + file, _ := processortest.NewFileReader().LoadFile(templatePath) + if err := json.Unmarshal(file, &template); err != nil { + return nil + } + return template +} + +func TestGenerateTemplate(t *testing.T) { + t.Run("when valid template is found, should return valid pdf", func(t *testing.T) { + fixtemplate := loadTemplate("processor/json/simple_pdf_templates.json") + fixContent, _ := processortest.NewFileReader().LoadFile("processor/json/simple_pdf_content.json") + + repository := mocks.NewProcessorRepository(t) + repository.EXPECT().ReadTemplate("simple_pdf").Return(fixtemplate, nil) + + provider, err := processor.NewProcessor(repository, deserializer.NewJSONDeserializer()).GenerateDocument("simple_pdf", string(fixContent)) + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("processor/simple_pdf.json") + }) + + t.Run("when template with Addpage is found, should set template", func(t *testing.T) { + fixtemplate := loadTemplate("processor/json/add_page_template.json") + fixContent, _ := processortest.NewFileReader().LoadFile("processor/json/add_page_content.json") + + repository := mocks.NewProcessorRepository(t) + repository.EXPECT().ReadTemplate("add_page").Return(fixtemplate, nil) + + provider, err := processor.NewProcessor(repository, deserializer.NewJSONDeserializer()).GenerateDocument("add_page", string(fixContent)) + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/addpage.json") + + doc, _ := (*provider).Generate() + err = doc.Save("test.pdf") + assert.Nil(t, err) + }) + + t.Run("when sent template is not found, should reuturn an error", func(t *testing.T) { + }) + t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { + }) + t.Run("when invalid content is sent, should return an error", func(t *testing.T) { + }) +} diff --git a/test/maroto/processor/simple_pdf.json b/test/maroto/processor/simple_pdf.json new file mode 100644 index 00000000..74da69af --- /dev/null +++ b/test/maroto/processor/simple_pdf.json @@ -0,0 +1,213 @@ +{ + "type": "maroto", + "details": { + "chunk_workers": 1, + "config_margin_bottom": 20.0025, + "config_margin_left": 10, + "config_margin_right": 10, + "config_margin_top": 10, + "config_max_grid_sum": 12, + "config_provider_type": "gofpdf", + "generation_mode": "sequential", + "maroto_dimension_height": 297, + "maroto_dimension_width": 210, + "prop_font_color": "RGB(0, 0, 0)", + "prop_font_family": "arial", + "prop_font_size": 10 + }, + "nodes": [ + { + "type": "page", + "nodes": [ + { + "value": 3.527777777777778, + "type": "row", + "nodes": [ + { + "value": 12, + "type": "col", + "nodes": [ + { + "value": "header text", + "type": "text", + "details": { + "prop_align": "L", + "prop_breakline_strategy": "empty_space_strategy", + "prop_color": "RGB(0, 0, 0)", + "prop_font_family": "arial", + "prop_font_size": 10 + } + } + ] + } + ] + }, + { + "value": 3.527777777777778, + "type": "row", + "nodes": [ + { + "value": 6, + "type": "col", + "nodes": [ + { + "value": "row 1", + "type": "text", + "details": { + "prop_align": "L", + "prop_breakline_strategy": "empty_space_strategy", + "prop_color": "RGB(0, 0, 0)", + "prop_font_family": "arial", + "prop_font_size": 10 + } + } + ] + }, + { + "value": 6, + "type": "col", + "nodes": [ + { + "value": "row 1", + "type": "text", + "details": { + "prop_align": "L", + "prop_breakline_strategy": "empty_space_strategy", + "prop_color": "RGB(0, 0, 0)", + "prop_font_family": "arial", + "prop_font_size": 10 + } + } + ] + } + ] + }, + { + "value": 3.527777777777778, + "type": "row", + "nodes": [ + { + "value": 10, + "type": "col", + "nodes": [ + { + "value": "row 2", + "type": "text", + "details": { + "prop_align": "L", + "prop_breakline_strategy": "empty_space_strategy", + "prop_color": "RGB(0, 0, 0)", + "prop_font_family": "arial", + "prop_font_size": 10 + } + } + ] + } + ] + }, + { + "value": 3.527777777777778, + "type": "row", + "nodes": [ + { + "value": 10, + "type": "col", + "nodes": [ + { + "value": "row 3", + "type": "text", + "details": { + "prop_align": "L", + "prop_breakline_strategy": "empty_space_strategy", + "prop_color": "RGB(0, 0, 0)", + "prop_font_family": "arial", + "prop_font_size": 10 + } + } + ] + } + ] + }, + { + "value": 3.527777777777778, + "type": "row", + "nodes": [ + { + "value": 10, + "type": "col", + "nodes": [ + { + "value": "row 4", + "type": "text", + "details": { + "prop_align": "L", + "prop_breakline_strategy": "empty_space_strategy", + "prop_color": "RGB(0, 0, 0)", + "prop_font_family": "arial", + "prop_font_size": 10 + } + } + ] + } + ] + }, + { + "value": 3.527777777777778, + "type": "row", + "nodes": [ + { + "value": 10, + "type": "col", + "nodes": [ + { + "value": "row 5", + "type": "text", + "details": { + "prop_align": "L", + "prop_breakline_strategy": "empty_space_strategy", + "prop_color": "RGB(0, 0, 0)", + "prop_font_family": "arial", + "prop_font_size": 10 + } + } + ] + } + ] + }, + { + "value": 242.30305555555557, + "type": "row", + "nodes": [ + { + "value": 12, + "type": "col" + } + ] + }, + { + "value": 3.527777777777778, + "type": "row", + "nodes": [ + { + "value": 12, + "type": "col", + "nodes": [ + { + "value": "footer text", + "type": "text", + "details": { + "prop_align": "L", + "prop_breakline_strategy": "empty_space_strategy", + "prop_color": "RGB(0, 0, 0)", + "prop_font_family": "arial", + "prop_font_size": 10 + } + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file From 3a5185c7af4662714b1e7a7aa9f9f6f83e0cc3ba Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sat, 30 Nov 2024 18:57:43 -0300 Subject: [PATCH 078/116] feat: implement pdf genearition --- .../components/listmapper/list_test.go | 4 +- .../mappers/components/pagemapper/page.go | 5 +- .../mappers/components/rowmapper/row.go | 5 +- pkg/processor/processor.go | 31 ++++++--- pkg/processor/processorprovider/Maroto.go | 13 +++- .../processorprovider/Maroto_test.go | 3 +- .../processorprovider/builder_maroto.go | 2 +- pkg/processor/processorprovider/provider.go | 1 + .../processor/json/simple_pdf_content.json | 38 +++++++++++ .../processor/json/simple_pdf_templates.json | 68 +++++++++++++++++++ 10 files changed, 150 insertions(+), 20 deletions(-) create mode 100644 test/maroto/processor/json/simple_pdf_content.json create mode 100644 test/maroto/processor/json/simple_pdf_templates.json diff --git a/pkg/processor/mappers/components/listmapper/list_test.go b/pkg/processor/mappers/components/listmapper/list_test.go index b4bf50a5..1a5fd3f5 100644 --- a/pkg/processor/mappers/components/listmapper/list_test.go +++ b/pkg/processor/mappers/components/listmapper/list_test.go @@ -80,7 +80,7 @@ func TestGenerate(t *testing.T) { t.Run("when components is not generate, should return an error", func(t *testing.T) { contentRow1 := map[string]interface{}{"row_1": nil} - listContent := map[string]interface{}{"list": []map[string]interface{}{contentRow1}} + listContent := map[string]interface{}{"list": []interface{}{contentRow1}} provider := mocks.NewProcessorProvider(t) component := mocks.NewComponentmapper(t) component.EXPECT().Generate(mock.Anything, provider).Return(nil, fmt.Errorf("any")) @@ -95,7 +95,7 @@ func TestGenerate(t *testing.T) { t.Run("when 2 templates are added, it should generate 4 components", func(t *testing.T) { content1 := map[string]interface{}{"row_1": nil, "row_2": nil} content2 := map[string]interface{}{"row_1": nil, "row_2": nil} - listContent := map[string]interface{}{"list": []map[string]interface{}{content1, content2}} + listContent := map[string]interface{}{"list": []interface{}{content1, content2}} provider := mocks.NewProcessorProvider(t) providerComponent := mocks.NewProviderComponent(t) component := mocks.NewComponentmapper(t) diff --git a/pkg/processor/mappers/components/pagemapper/page.go b/pkg/processor/mappers/components/pagemapper/page.go index 142161f2..2c710116 100644 --- a/pkg/processor/mappers/components/pagemapper/page.go +++ b/pkg/processor/mappers/components/pagemapper/page.go @@ -62,7 +62,10 @@ func (p *Page) getPageContent(content map[string]interface{}) (map[string]interf if mapPage, ok := pageContent.(map[string]interface{}); ok { return mapPage, nil } - return nil, fmt.Errorf("could not parse template, ensure that the contents of the page \"%s\" can be converted to map[string]interface{}", p.SourceKey) + return nil, fmt.Errorf( + "could not parse template, ensure that the contents of the page \"%s\" can be converted to map[string]interface{}", + p.SourceKey, + ) } func (p *Page) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( diff --git a/pkg/processor/mappers/components/rowmapper/row.go b/pkg/processor/mappers/components/rowmapper/row.go index a8ccbbb9..6c371996 100644 --- a/pkg/processor/mappers/components/rowmapper/row.go +++ b/pkg/processor/mappers/components/rowmapper/row.go @@ -96,7 +96,10 @@ func (r *Row) getRowContent(content map[string]interface{}) (map[string]interfac if mapRow, ok := rowContent.(map[string]interface{}); ok { return mapRow, nil } - return nil, fmt.Errorf("could not parse template, ensure that the contents of the row \"%s\" can be converted to map[string]interface{}", r.SourceKey) + return nil, fmt.Errorf( + "could not parse template, ensure that the contents of the row \"%s\" can be converted to map[string]interface{}", + r.SourceKey, + ) } func (r *Row) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index 2b6c92fd..1d5d9466 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -1,14 +1,10 @@ package processor import ( - "fmt" - "github.com/johnfercher/maroto/v2/pkg/processor/core" - "github.com/johnfercher/maroto/v2/pkg/processor/deserializer" - "github.com/johnfercher/maroto/v2/pkg/processor/loader" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/abstractfactory" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/documentmapper" - "github.com/johnfercher/maroto/v2/pkg/processor/repository" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type processor struct { @@ -18,10 +14,10 @@ type processor struct { // NewProcessor is responsible for creating a processor object // The processor object should be used to create PDF from a serialized document -func NewProcessor() *processor { +func NewProcessor(repository core.ProcessorRepository, deserializer core.Deserializer) *processor { return &processor{ - repository: repository.NewMemoryStorage(loader.NewLoader()), - deserializer: deserializer.NewJSONDeserializer(), + repository: repository, + deserializer: deserializer, } } @@ -38,7 +34,7 @@ func (p *processor) RegisterTemplate(templateName string, template string) error // GenerateDocument is responsible for generating the pdf // templateName must reference a previously saved template, // this template will be computed with the data sent in content -func (p *processor) GenerateDocument(templateName string, content string) ([]byte, error) { +func (p *processor) GenerateDocument(templateName string, content string) (*processorprovider.ProcessorProvider, error) { template, err := p.repository.ReadTemplate(templateName) if err != nil { return nil, err @@ -48,7 +44,20 @@ func (p *processor) GenerateDocument(templateName string, content string) ([]byt if err != nil { return nil, err } - fmt.Print(document) - return nil, nil + marotoProvider, err := processorprovider.NewMaroto(p.repository, *document.GetBuilderCfg()) + if err != nil { + return nil, err + } + + contentMap, err := p.deserializer.Deserialize(content) + if err != nil { + return nil, err + } + + provider, err := (*document).Generate(contentMap, marotoProvider) + if err != nil { + return nil, err + } + return provider, nil } diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index 392431ea..65fe6a05 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -47,6 +47,10 @@ func NewMaroto(repository processorcore.ProcessorRepository, builder ...builderm return &Maroto{maroto: m, repository: repository}, nil } +func (m *Maroto) Generate() (core.Document, error) { + return m.maroto.Generate() +} + func (m *Maroto) GetStructure() *node.Node[core.Structure] { return m.maroto.GetStructure() } @@ -119,8 +123,11 @@ func (m *Maroto) CreateCol(size int, components ...ProviderComponent) (ProviderC if err != nil { return nil, err } - - return col.New(size).Add(newComponents...), nil + if size > 0 { + return col.New(size).Add(newComponents...), nil + } else { + return col.New().Add(newComponents...), nil + } } func (m *Maroto) CreateText(value string, textsProps ...*propsmapper.Text) ProviderComponent { @@ -132,7 +139,7 @@ func (m *Maroto) CreateText(value string, textsProps ...*propsmapper.Text) Provi return text.New(value, props.Text{ Top: tProps.Top, Left: tProps.Left, Right: tProps.Right, Family: tProps.Family, Style: fontstyle.Type(tProps.Style), Size: tProps.Size, Align: align.Type(tProps.Align), BreakLineStrategy: breakline.Strategy(tProps.BreakLineStrategy), - VerticalPadding: tProps.VerticalPadding, Color: (*props.Color)(tProps.Color), Hyperlink: &tProps.Hyperlink, + VerticalPadding: tProps.VerticalPadding, Color: (*props.Color)(tProps.Color), Hyperlink: tProps.Hyperlink, }) } diff --git a/pkg/processor/processorprovider/Maroto_test.go b/pkg/processor/processorprovider/Maroto_test.go index 49efb398..b07d3e44 100644 --- a/pkg/processor/processorprovider/Maroto_test.go +++ b/pkg/processor/processorprovider/Maroto_test.go @@ -235,12 +235,13 @@ func TestCreateSignature(t *testing.T) { func TestCreateText(t *testing.T) { t.Run("when CreateText is called, should generate a text", func(t *testing.T) { + hyperlink := "test" loader := mocks.NewLoader(t) m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) barcode := m.CreateText("text", &propsmapper.Text{ Top: 10.0, Left: 10.0, Right: 10.0, Family: "Arial", Style: "bold", Size: 10.0, Align: "center", BreakLineStrategy: "dash_strategy", - VerticalPadding: 10.0, Color: &propsmapper.Color{Red: 10, Green: 10, Blue: 10}, Hyperlink: "test", + VerticalPadding: 10.0, Color: &propsmapper.Color{Red: 10, Green: 10, Blue: 10}, Hyperlink: &hyperlink, }, ) diff --git a/pkg/processor/processorprovider/builder_maroto.go b/pkg/processor/processorprovider/builder_maroto.go index ac22752d..fcaac2bf 100644 --- a/pkg/processor/processorprovider/builder_maroto.go +++ b/pkg/processor/processorprovider/builder_maroto.go @@ -128,7 +128,7 @@ func (m *MarotoBuilder) WithPageNumber(pageNumber *propsmapper.PageNumber) *Maro m.cfg.WithPageNumber(props.PageNumber{ Pattern: pageNumber.Pattern, Place: props.Place(pageNumber.Place), Family: pageNumber.Family, Style: fontstyle.Type(pageNumber.Style), Size: pageNumber.Size, - Color: &props.Color{Red: pageNumber.Color.Red, Green: pageNumber.Color.Green, Blue: pageNumber.Color.Blue}, + Color: (*props.Color)(pageNumber.Color), }) }, pageNumber != nil) return m diff --git a/pkg/processor/processorprovider/provider.go b/pkg/processor/processorprovider/provider.go index 57887df2..e8aa6595 100644 --- a/pkg/processor/processorprovider/provider.go +++ b/pkg/processor/processorprovider/provider.go @@ -13,6 +13,7 @@ type ProviderComponent interface { // ProcessorProvider provides an interface with all the methods that // Maroto provides for pdf builder type ProcessorProvider interface { + Generate() (core.Document, error) GetStructure() *node.Node[core.Structure] AddPages(pages ...ProviderComponent) (ProcessorProvider, error) AddFooter(footer ...ProviderComponent) (ProcessorProvider, error) diff --git a/test/maroto/processor/json/simple_pdf_content.json b/test/maroto/processor/json/simple_pdf_content.json new file mode 100644 index 00000000..6e6aa28a --- /dev/null +++ b/test/maroto/processor/json/simple_pdf_content.json @@ -0,0 +1,38 @@ +{ + "header": { + "row_header": { + "header_value": "header text" + } + }, + "footer": { + "row_footer": { + "footer_value": "footer text" + } + }, + "pages": { + "page_template_1": { + "row_1": { + "value_1": "row 1", + "value_2": "row 1" + }, + "list_row_1": [ + { + "row": { + "value_2": "row 2" + }, + "row_1": { + "value_2": "row 3" + } + }, + { + "row": { + "value_2": "row 4" + }, + "row_1": { + "value_2": "row 5" + } + } + ] + } + } +} \ No newline at end of file diff --git a/test/maroto/processor/json/simple_pdf_templates.json b/test/maroto/processor/json/simple_pdf_templates.json new file mode 100644 index 00000000..8933ea70 --- /dev/null +++ b/test/maroto/processor/json/simple_pdf_templates.json @@ -0,0 +1,68 @@ +{ + "header": { + "row_header": { + "cols": [ + { + "text": { + "source_key": "header_value" + }, + "size": 12 + } + ] + } + }, + "footer": { + "row_footer": { + "cols": [ + { + "text": { + "source_key": "footer_value" + }, + "size": 12 + } + ] + } + }, + "pages": { + "page_template_1": { + "row_1": { + "cols": [ + { + "text": { + "source_key": "value_1" + }, + "size": 6.0 + }, + { + "text": { + "source_key": "value_2" + }, + "size": 6.0 + } + ] + }, + "list_row_1": { + "row": { + "cols": [ + { + "text": { + "source_key": "value_2" + }, + "size": 10.0 + } + ] + }, + "row_1": { + "cols": [ + { + "text": { + "source_key": "value_2" + }, + "size": 10.0 + } + ] + } + } + } + } +} \ No newline at end of file From d63e32e9131897d964b3f227741e238b71b24b07 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sat, 30 Nov 2024 19:00:43 -0300 Subject: [PATCH 079/116] test: validate page addition example --- pkg/processor/processor_test.go | 4 -- .../processor/json/add_page_content.json | 69 +++++++++++++++++++ .../processor/json/add_page_template.json | 36 ++++++++++ 3 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 test/maroto/processor/json/add_page_content.json create mode 100644 test/maroto/processor/json/add_page_template.json diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index 7028eb5a..773c4ae6 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -53,10 +53,6 @@ func TestGenerateTemplate(t *testing.T) { provider, err := processor.NewProcessor(repository, deserializer.NewJSONDeserializer()).GenerateDocument("add_page", string(fixContent)) assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/addpage.json") - - doc, _ := (*provider).Generate() - err = doc.Save("test.pdf") - assert.Nil(t, err) }) t.Run("when sent template is not found, should reuturn an error", func(t *testing.T) { diff --git a/test/maroto/processor/json/add_page_content.json b/test/maroto/processor/json/add_page_content.json new file mode 100644 index 00000000..6fa0d5d8 --- /dev/null +++ b/test/maroto/processor/json/add_page_content.json @@ -0,0 +1,69 @@ +{ + "pages": { + "template_page_1": { + "list_rows": [ + { + "row_1": { + "page_1_row": "page1 row1" + } + }, + { + "row_1": { + "page_1_row": "page1 row2" + } + }, + { + "row_1": { + "page_1_row": "page1 row3" + } + }, + { + "row_1": { + "page_1_row": "page1 row4" + } + }, + { + "row_1": { + "page_1_row": "page1 row5" + } + }, + { + "row_1": { + "page_1_row": "page1 row6" + } + }, + { + "row_1": { + "page_1_row": "page1 row7" + } + }, + { + "row_1": { + "page_1_row": "page1 row8" + } + }, + { + "row_1": { + "page_1_row": "page1 row9" + } + } + ] + }, + "list_pages": [ + { + "template_page_2": { + "row_1": { + "page_2_row": "page2 row1" + } + } + }, + { + "template_page_2": { + "row_1": { + "page_2_row": "page3 row1" + } + } + } + ] + } +} \ No newline at end of file diff --git a/test/maroto/processor/json/add_page_template.json b/test/maroto/processor/json/add_page_template.json new file mode 100644 index 00000000..4e3926d9 --- /dev/null +++ b/test/maroto/processor/json/add_page_template.json @@ -0,0 +1,36 @@ +{ + "builder": { + "page_number": {}, + "debug": true + }, + "pages": { + "template_page_1": { + "list_rows": { + "row_1": { + "height": 30, + "cols": [ + { + "text": { + "source_key": "page_1_row" + } + } + ] + } + } + }, + "list_pages": { + "template_page_2": { + "row_1": { + "height": 10, + "cols": [ + { + "text": { + "source_key": "page_2_row" + } + } + ] + } + } + } + } +} \ No newline at end of file From 628edbe4af1b03a44660bab0db6273d261f0acc2 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Sun, 8 Dec 2024 11:32:47 -0300 Subject: [PATCH 080/116] feat: provide a method to check the source of the resource --- pkg/processor/loader/loader.go | 18 ++++++++++++++++-- pkg/processor/loader/loader_test.go | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pkg/processor/loader/loader.go b/pkg/processor/loader/loader.go index 026ff84f..ecb03a8b 100644 --- a/pkg/processor/loader/loader.go +++ b/pkg/processor/loader/loader.go @@ -17,6 +17,20 @@ func NewLoader() *loader { return &loader{} } +// GetResourceSource is responsible for identifying where the source resource will be loaded from. +// ex: http, https, file... +func GetResourceSource(path string) (*url.URL, error) { + uri, err := url.Parse(path) + if err != nil { + return nil, errors.Wrap(ErrInvalidPath, path) + } + if uri.Scheme == "" { + uri.Scheme = "file" + } + + return uri, nil +} + // Load takes the path/url/uri of an asset (image, font) // and returns its contents. func (l *loader) Load(path string) ([]byte, error) { @@ -25,9 +39,9 @@ func (l *loader) Load(path string) ([]byte, error) { return nil, errors.Wrap(ErrUnsupportedExtension, ext) } - uri, err := url.Parse(path) + uri, err := GetResourceSource(path) if err != nil { - return nil, errors.Wrap(ErrInvalidPath, path) + return nil, err } loadFn, ok := loadFuncs[uri.Scheme] diff --git a/pkg/processor/loader/loader_test.go b/pkg/processor/loader/loader_test.go index 55a0e946..be7e2fc5 100644 --- a/pkg/processor/loader/loader_test.go +++ b/pkg/processor/loader/loader_test.go @@ -41,3 +41,18 @@ func TestLoad(t *testing.T) { assert.NotNil(t, p) }) } + +func TestGetResourceSource(t *testing.T) { + t.Run("when a local path is sent, should return a uri with shema file", func(t *testing.T) { + uri, err := loader.GetResourceSource("file://docs/assets/images/logo.png") + + assert.Nil(t, err) + assert.Equal(t, uri.Scheme, "file") + }) + t.Run("when a path without shema is sent, should return a uri with shema file", func(t *testing.T) { + uri, err := loader.GetResourceSource("docs/assets/images/logo.png") + + assert.Nil(t, err) + assert.Equal(t, uri.Scheme, "file") + }) +} From a717a3133a4b4ace46764122164f723dacb25358 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 17 Dec 2024 21:19:54 -0300 Subject: [PATCH 081/116] fix: use fileimage to generate local images --- mocks/AbstractFactoryMaps.go | 3 +- mocks/Cache.go | 3 +- mocks/CellWriter.go | 3 +- mocks/Code.go | 3 +- mocks/Col.go | 3 +- mocks/Component.go | 3 +- mocks/Componentmapper.go | 3 +- mocks/Deserializer.go | 3 +- mocks/Document.go | 3 +- mocks/Font.go | 3 +- mocks/Fpdf.go | 3 +- mocks/GenerateComponent.go | 3 +- mocks/Image.go | 3 +- mocks/Line.go | 3 +- mocks/Listable.go | 3 +- mocks/Loader.go | 3 +- mocks/Maroto.go | 3 +- mocks/Math.go | 3 +- mocks/Node.go | 3 +- mocks/Page.go | 3 +- mocks/Processor.go | 3 +- mocks/ProcessorProvider.go | 46 +++++++------ mocks/ProcessorRepository.go | 3 +- mocks/Provider.go | 3 +- mocks/ProviderComponent.go | 3 +- mocks/Repository.go | 3 +- mocks/Row.go | 3 +- mocks/Text.go | 3 +- .../abstractfactory/abstractfactory.go | 2 +- .../mappers/components/imagemapper/image.go | 28 ++++---- .../components/imagemapper/image_test.go | 66 ++++-------------- pkg/processor/processorprovider/Maroto.go | 68 ++++++++++++------- .../processorprovider/Maroto_test.go | 3 +- pkg/processor/processorprovider/provider.go | 2 +- pkg/processor/repository/memory_storage.go | 5 +- test/maroto/processor/provider/image.json | 6 +- 36 files changed, 130 insertions(+), 177 deletions(-) diff --git a/mocks/AbstractFactoryMaps.go b/mocks/AbstractFactoryMaps.go index 97faa243..add10d97 100644 --- a/mocks/AbstractFactoryMaps.go +++ b/mocks/AbstractFactoryMaps.go @@ -667,8 +667,7 @@ func (_c *AbstractFactoryMaps_NewText_Call) RunAndReturn(run func(interface{}) ( func NewAbstractFactoryMaps(t interface { mock.TestingT Cleanup(func()) -}, -) *AbstractFactoryMaps { +}) *AbstractFactoryMaps { mock := &AbstractFactoryMaps{} mock.Mock.Test(t) diff --git a/mocks/Cache.go b/mocks/Cache.go index 25ebce39..19569343 100644 --- a/mocks/Cache.go +++ b/mocks/Cache.go @@ -167,8 +167,7 @@ func (_c *Cache_LoadImage_Call) RunAndReturn(run func(string, extension.Type) er func NewCache(t interface { mock.TestingT Cleanup(func()) -}, -) *Cache { +}) *Cache { mock := &Cache{} mock.Mock.Test(t) diff --git a/mocks/CellWriter.go b/mocks/CellWriter.go index 7d47e029..1c037a18 100644 --- a/mocks/CellWriter.go +++ b/mocks/CellWriter.go @@ -190,8 +190,7 @@ func (_c *CellWriter_SetNext_Call) RunAndReturn(run func(cellwriter.CellWriter)) func NewCellWriter(t interface { mock.TestingT Cleanup(func()) -}, -) *CellWriter { +}) *CellWriter { mock := &CellWriter{} mock.Mock.Test(t) diff --git a/mocks/Code.go b/mocks/Code.go index 747d5bc4..4afdf77c 100644 --- a/mocks/Code.go +++ b/mocks/Code.go @@ -203,8 +203,7 @@ func (_c *Code_GenQr_Call) RunAndReturn(run func(string) (*entity.Image, error)) func NewCode(t interface { mock.TestingT Cleanup(func()) -}, -) *Code { +}) *Code { mock := &Code{} mock.Mock.Test(t) diff --git a/mocks/Col.go b/mocks/Col.go index dc4a7276..186dfd06 100644 --- a/mocks/Col.go +++ b/mocks/Col.go @@ -347,8 +347,7 @@ func (_c *Col_WithStyle_Call) RunAndReturn(run func(*props.Cell) core.Col) *Col_ func NewCol(t interface { mock.TestingT Cleanup(func()) -}, -) *Col { +}) *Col { mock := &Col{} mock.Mock.Test(t) diff --git a/mocks/Component.go b/mocks/Component.go index 5b096b9a..64078a01 100644 --- a/mocks/Component.go +++ b/mocks/Component.go @@ -190,8 +190,7 @@ func (_c *Component_SetConfig_Call) RunAndReturn(run func(*entity.Config)) *Comp func NewComponent(t interface { mock.TestingT Cleanup(func()) -}, -) *Component { +}) *Component { mock := &Component{} mock.Mock.Test(t) diff --git a/mocks/Componentmapper.go b/mocks/Componentmapper.go index b6f4c978..098df852 100644 --- a/mocks/Componentmapper.go +++ b/mocks/Componentmapper.go @@ -84,8 +84,7 @@ func (_c *Componentmapper_Generate_Call) RunAndReturn(run func(map[string]interf func NewComponentmapper(t interface { mock.TestingT Cleanup(func()) -}, -) *Componentmapper { +}) *Componentmapper { mock := &Componentmapper{} mock.Mock.Test(t) diff --git a/mocks/Deserializer.go b/mocks/Deserializer.go index b5dcd4c4..db175be7 100644 --- a/mocks/Deserializer.go +++ b/mocks/Deserializer.go @@ -80,8 +80,7 @@ func (_c *Deserializer_Deserialize_Call) RunAndReturn(run func(string) (map[stri func NewDeserializer(t interface { mock.TestingT Cleanup(func()) -}, -) *Deserializer { +}) *Deserializer { mock := &Deserializer{} mock.Mock.Test(t) diff --git a/mocks/Document.go b/mocks/Document.go index c1a675cc..6a55effe 100644 --- a/mocks/Document.go +++ b/mocks/Document.go @@ -256,8 +256,7 @@ func (_c *Document_Save_Call) RunAndReturn(run func(string) error) *Document_Sav func NewDocument(t interface { mock.TestingT Cleanup(func()) -}, -) *Document { +}) *Document { mock := &Document{} mock.Mock.Test(t) diff --git a/mocks/Font.go b/mocks/Font.go index 3c394374..a41d41dd 100644 --- a/mocks/Font.go +++ b/mocks/Font.go @@ -486,8 +486,7 @@ func (_c *Font_SetStyle_Call) RunAndReturn(run func(fontstyle.Type)) *Font_SetSt func NewFont(t interface { mock.TestingT Cleanup(func()) -}, -) *Font { +}) *Font { mock := &Font{} mock.Mock.Test(t) diff --git a/mocks/Fpdf.go b/mocks/Fpdf.go index 2b89935f..b7c28677 100644 --- a/mocks/Fpdf.go +++ b/mocks/Fpdf.go @@ -6934,8 +6934,7 @@ func (_c *Fpdf_Writef_Call) RunAndReturn(run func(float64, string, ...interface{ func NewFpdf(t interface { mock.TestingT Cleanup(func()) -}, -) *Fpdf { +}) *Fpdf { mock := &Fpdf{} mock.Mock.Test(t) diff --git a/mocks/GenerateComponent.go b/mocks/GenerateComponent.go index 932c0278..c1bc629f 100644 --- a/mocks/GenerateComponent.go +++ b/mocks/GenerateComponent.go @@ -84,8 +84,7 @@ func (_c *GenerateComponent_Execute_Call) RunAndReturn(run func(interface{}, str func NewGenerateComponent(t interface { mock.TestingT Cleanup(func()) -}, -) *GenerateComponent { +}) *GenerateComponent { mock := &GenerateComponent{} mock.Mock.Test(t) diff --git a/mocks/Image.go b/mocks/Image.go index fa0bebda..60b52c28 100644 --- a/mocks/Image.go +++ b/mocks/Image.go @@ -145,8 +145,7 @@ func (_c *Image_GetImageInfo_Call) RunAndReturn(run func(*entity.Image, extensio func NewImage(t interface { mock.TestingT Cleanup(func()) -}, -) *Image { +}) *Image { mock := &Image{} mock.Mock.Test(t) diff --git a/mocks/Line.go b/mocks/Line.go index 080731fc..217ef896 100644 --- a/mocks/Line.go +++ b/mocks/Line.go @@ -61,8 +61,7 @@ func (_c *Line_Add_Call) RunAndReturn(run func(*entity.Cell, *props.Line)) *Line func NewLine(t interface { mock.TestingT Cleanup(func()) -}, -) *Line { +}) *Line { mock := &Line{} mock.Mock.Test(t) diff --git a/mocks/Listable.go b/mocks/Listable.go index d9d28d9f..20cda4b9 100644 --- a/mocks/Listable.go +++ b/mocks/Listable.go @@ -121,8 +121,7 @@ func (_c *Listable_GetHeader_Call) RunAndReturn(run func() core.Row) *Listable_G func NewListable(t interface { mock.TestingT Cleanup(func()) -}, -) *Listable { +}) *Listable { mock := &Listable{} mock.Mock.Test(t) diff --git a/mocks/Loader.go b/mocks/Loader.go index ffe16105..cbbdf89c 100644 --- a/mocks/Loader.go +++ b/mocks/Loader.go @@ -126,8 +126,7 @@ func (_c *Loader_Load_Call) RunAndReturn(run func(string) ([]byte, error)) *Load func NewLoader(t interface { mock.TestingT Cleanup(func()) -}, -) *Loader { +}) *Loader { mock := &Loader{} mock.Mock.Test(t) diff --git a/mocks/Maroto.go b/mocks/Maroto.go index 90fb026b..4f66b03e 100644 --- a/mocks/Maroto.go +++ b/mocks/Maroto.go @@ -560,8 +560,7 @@ func (_c *Maroto_RegisterHeader_Call) RunAndReturn(run func(...core.Row) error) func NewMaroto(t interface { mock.TestingT Cleanup(func()) -}, -) *Maroto { +}) *Maroto { mock := &Maroto{} mock.Mock.Test(t) diff --git a/mocks/Math.go b/mocks/Math.go index fad2cbf5..a3759fbb 100644 --- a/mocks/Math.go +++ b/mocks/Math.go @@ -125,8 +125,7 @@ func (_c *Math_Resize_Call) RunAndReturn(run func(*entity.Dimensions, *entity.Di func NewMath(t interface { mock.TestingT Cleanup(func()) -}, -) *Math { +}) *Math { mock := &Math{} mock.Mock.Test(t) diff --git a/mocks/Node.go b/mocks/Node.go index 29bf2a8d..075eb94b 100644 --- a/mocks/Node.go +++ b/mocks/Node.go @@ -109,8 +109,7 @@ func (_c *Node_SetConfig_Call) RunAndReturn(run func(*entity.Config)) *Node_SetC func NewNode(t interface { mock.TestingT Cleanup(func()) -}, -) *Node { +}) *Node { mock := &Node{} mock.Mock.Test(t) diff --git a/mocks/Page.go b/mocks/Page.go index da968dc0..9f2d7062 100644 --- a/mocks/Page.go +++ b/mocks/Page.go @@ -330,8 +330,7 @@ func (_c *Page_SetNumber_Call) RunAndReturn(run func(int, int)) *Page_SetNumber_ func NewPage(t interface { mock.TestingT Cleanup(func()) -}, -) *Page { +}) *Page { mock := &Page{} mock.Mock.Test(t) diff --git a/mocks/Processor.go b/mocks/Processor.go index c8d28d27..2ccfb8b0 100644 --- a/mocks/Processor.go +++ b/mocks/Processor.go @@ -118,8 +118,7 @@ func (_c *Processor_RegisterTemplate_Call) RunAndReturn(run func(string, string) func NewProcessor(t interface { mock.TestingT Cleanup(func()) -}, -) *Processor { +}) *Processor { mock := &Processor{} mock.Mock.Test(t) diff --git a/mocks/ProcessorProvider.go b/mocks/ProcessorProvider.go index 75d5af72..1a8efcd7 100644 --- a/mocks/ProcessorProvider.go +++ b/mocks/ProcessorProvider.go @@ -375,14 +375,14 @@ func (_c *ProcessorProvider_CreateCol_Call) RunAndReturn(run func(int, ...proces return _c } -// CreateImage provides a mock function with given fields: value, extension, props -func (_m *ProcessorProvider) CreateImage(value []byte, extension string, props ...*propsmapper.Rect) processorprovider.ProviderComponent { +// CreateImage provides a mock function with given fields: path, props +func (_m *ProcessorProvider) CreateImage(path string, props ...*propsmapper.Rect) (processorprovider.ProviderComponent, error) { _va := make([]interface{}, len(props)) for _i := range props { _va[_i] = props[_i] } var _ca []interface{} - _ca = append(_ca, value, extension) + _ca = append(_ca, path) _ca = append(_ca, _va...) ret := _m.Called(_ca...) @@ -391,15 +391,25 @@ func (_m *ProcessorProvider) CreateImage(value []byte, extension string, props . } var r0 processorprovider.ProviderComponent - if rf, ok := ret.Get(0).(func([]byte, string, ...*propsmapper.Rect) processorprovider.ProviderComponent); ok { - r0 = rf(value, extension, props...) + var r1 error + if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Rect) (processorprovider.ProviderComponent, error)); ok { + return rf(path, props...) + } + if rf, ok := ret.Get(0).(func(string, ...*propsmapper.Rect) processorprovider.ProviderComponent); ok { + r0 = rf(path, props...) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(processorprovider.ProviderComponent) } } - return r0 + if rf, ok := ret.Get(1).(func(string, ...*propsmapper.Rect) error); ok { + r1 = rf(path, props...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 } // ProcessorProvider_CreateImage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateImage' @@ -408,33 +418,32 @@ type ProcessorProvider_CreateImage_Call struct { } // CreateImage is a helper method to define mock.On call -// - value []byte -// - extension string +// - path string // - props ...*propsmapper.Rect -func (_e *ProcessorProvider_Expecter) CreateImage(value interface{}, extension interface{}, props ...interface{}) *ProcessorProvider_CreateImage_Call { +func (_e *ProcessorProvider_Expecter) CreateImage(path interface{}, props ...interface{}) *ProcessorProvider_CreateImage_Call { return &ProcessorProvider_CreateImage_Call{Call: _e.mock.On("CreateImage", - append([]interface{}{value, extension}, props...)...)} + append([]interface{}{path}, props...)...)} } -func (_c *ProcessorProvider_CreateImage_Call) Run(run func(value []byte, extension string, props ...*propsmapper.Rect)) *ProcessorProvider_CreateImage_Call { +func (_c *ProcessorProvider_CreateImage_Call) Run(run func(path string, props ...*propsmapper.Rect)) *ProcessorProvider_CreateImage_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]*propsmapper.Rect, len(args)-2) - for i, a := range args[2:] { + variadicArgs := make([]*propsmapper.Rect, len(args)-1) + for i, a := range args[1:] { if a != nil { variadicArgs[i] = a.(*propsmapper.Rect) } } - run(args[0].([]byte), args[1].(string), variadicArgs...) + run(args[0].(string), variadicArgs...) }) return _c } -func (_c *ProcessorProvider_CreateImage_Call) Return(_a0 processorprovider.ProviderComponent) *ProcessorProvider_CreateImage_Call { - _c.Call.Return(_a0) +func (_c *ProcessorProvider_CreateImage_Call) Return(_a0 processorprovider.ProviderComponent, _a1 error) *ProcessorProvider_CreateImage_Call { + _c.Call.Return(_a0, _a1) return _c } -func (_c *ProcessorProvider_CreateImage_Call) RunAndReturn(run func([]byte, string, ...*propsmapper.Rect) processorprovider.ProviderComponent) *ProcessorProvider_CreateImage_Call { +func (_c *ProcessorProvider_CreateImage_Call) RunAndReturn(run func(string, ...*propsmapper.Rect) (processorprovider.ProviderComponent, error)) *ProcessorProvider_CreateImage_Call { _c.Call.Return(run) return _c } @@ -1005,8 +1014,7 @@ func (_c *ProcessorProvider_GetStructure_Call) RunAndReturn(run func() *node.Nod func NewProcessorProvider(t interface { mock.TestingT Cleanup(func()) -}, -) *ProcessorProvider { +}) *ProcessorProvider { mock := &ProcessorProvider{} mock.Mock.Test(t) diff --git a/mocks/ProcessorRepository.go b/mocks/ProcessorRepository.go index e1fe28c2..6e1d6a05 100644 --- a/mocks/ProcessorRepository.go +++ b/mocks/ProcessorRepository.go @@ -192,8 +192,7 @@ func (_c *ProcessorRepository_RegisterTemplate_Call) RunAndReturn(run func(strin func NewProcessorRepository(t interface { mock.TestingT Cleanup(func()) -}, -) *ProcessorRepository { +}) *ProcessorRepository { mock := &ProcessorRepository{} mock.Mock.Test(t) diff --git a/mocks/Provider.go b/mocks/Provider.go index dd7b2bf4..f36ae49d 100644 --- a/mocks/Provider.go +++ b/mocks/Provider.go @@ -862,8 +862,7 @@ func (_c *Provider_SetProtection_Call) RunAndReturn(run func(*entity.Protection) func NewProvider(t interface { mock.TestingT Cleanup(func()) -}, -) *Provider { +}) *Provider { mock := &Provider{} mock.Mock.Test(t) diff --git a/mocks/ProviderComponent.go b/mocks/ProviderComponent.go index 6dd0acc9..ddb519a9 100644 --- a/mocks/ProviderComponent.go +++ b/mocks/ProviderComponent.go @@ -109,8 +109,7 @@ func (_c *ProviderComponent_SetConfig_Call) RunAndReturn(run func(*entity.Config func NewProviderComponent(t interface { mock.TestingT Cleanup(func()) -}, -) *ProviderComponent { +}) *ProviderComponent { mock := &ProviderComponent{} mock.Mock.Test(t) diff --git a/mocks/Repository.go b/mocks/Repository.go index 3977c94e..8e5b38f7 100644 --- a/mocks/Repository.go +++ b/mocks/Repository.go @@ -186,8 +186,7 @@ func (_c *Repository_Load_Call) RunAndReturn(run func() ([]*entity.CustomFont, e func NewRepository(t interface { mock.TestingT Cleanup(func()) -}, -) *Repository { +}) *Repository { mock := &Repository{} mock.Mock.Test(t) diff --git a/mocks/Row.go b/mocks/Row.go index f8e8a69c..8917128a 100644 --- a/mocks/Row.go +++ b/mocks/Row.go @@ -348,8 +348,7 @@ func (_c *Row_WithStyle_Call) RunAndReturn(run func(*props.Cell) core.Row) *Row_ func NewRow(t interface { mock.TestingT Cleanup(func()) -}, -) *Row { +}) *Row { mock := &Row{} mock.Mock.Test(t) diff --git a/mocks/Text.go b/mocks/Text.go index 781e9117..4d4681d1 100644 --- a/mocks/Text.go +++ b/mocks/Text.go @@ -110,8 +110,7 @@ func (_c *Text_GetLinesQuantity_Call) RunAndReturn(run func(string, *props.Text, func NewText(t interface { mock.TestingT Cleanup(func()) -}, -) *Text { +}) *Text { mock := &Text{} mock.Mock.Test(t) diff --git a/pkg/processor/mappers/abstractfactory/abstractfactory.go b/pkg/processor/mappers/abstractfactory/abstractfactory.go index 60dbfc23..9a88339f 100644 --- a/pkg/processor/mappers/abstractfactory/abstractfactory.go +++ b/pkg/processor/mappers/abstractfactory/abstractfactory.go @@ -62,7 +62,7 @@ func (f *abstractFactoryMaps) NewQrcode(document interface{}) (mappers.Component // NewImage is responsible for wrapper the creation of a image func (f *abstractFactoryMaps) NewImage(document interface{}) (mappers.Componentmapper, error) { - return imagemapper.NewImage(document, f.repository) + return imagemapper.NewImage(document) } // NewLine is responsible for wrapper the creation of a libe diff --git a/pkg/processor/mappers/components/imagemapper/image.go b/pkg/processor/mappers/components/imagemapper/image.go index 497d7411..c22a34b5 100644 --- a/pkg/processor/mappers/components/imagemapper/image.go +++ b/pkg/processor/mappers/components/imagemapper/image.go @@ -4,25 +4,23 @@ package imagemapper import ( "fmt" - processorcore "github.com/johnfercher/maroto/v2/pkg/processor/core" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Image struct { - Path string - SourceKey string - Props *propsmapper.Rect - Repository processorcore.ProcessorRepository + Path string + SourceKey string + Props *propsmapper.Rect } -func NewImage(templateImage interface{}, repository processorcore.ProcessorRepository) (*Image, error) { +func NewImage(templateImage interface{}) (*Image, error) { imageMap, ok := templateImage.(map[string]interface{}) if !ok { return nil, fmt.Errorf("ensure image can be converted to map[string] interface{}") } - image := &Image{Repository: repository} + image := &Image{} if err := image.addFields(imageMap); err != nil { return nil, err } @@ -106,18 +104,18 @@ func (i *Image) getImagePath(content map[string]interface{}) (string, error) { func (i *Image) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( []processorprovider.ProviderComponent, error, ) { - path, err := i.getImagePath(content) - if err != nil { - return nil, err - } - i.Path = path - extension, img, err := i.Repository.GetDocument(i.Path) + var err error + i.Path, err = i.getImagePath(content) if err != nil { return nil, err } + var img processorprovider.ProviderComponent if i.Props != nil { - return []processorprovider.ProviderComponent{provider.CreateImage(img, extension, i.Props)}, nil + img, err = provider.CreateImage(i.Path, i.Props) + } else { + img, err = provider.CreateImage(i.Path) } - return []processorprovider.ProviderComponent{provider.CreateImage(img, extension)}, nil + + return []processorprovider.ProviderComponent{img}, err } diff --git a/pkg/processor/mappers/components/imagemapper/image_test.go b/pkg/processor/mappers/components/imagemapper/image_test.go index acf7e10c..7c1ca43d 100644 --- a/pkg/processor/mappers/components/imagemapper/image_test.go +++ b/pkg/processor/mappers/components/imagemapper/image_test.go @@ -1,7 +1,6 @@ package imagemapper_test import ( - "fmt" "testing" "github.com/johnfercher/maroto/v2/mocks" @@ -12,9 +11,8 @@ import ( func TestNewImage(t *testing.T) { t.Run("when invalid image is sent, should return an error", func(t *testing.T) { imageTemplate := 1 - repository := mocks.NewProcessorRepository(t) - image, err := imagemapper.NewImage(imageTemplate, repository) + image, err := imagemapper.NewImage(imageTemplate) assert.Nil(t, image) assert.NotNil(t, err) @@ -23,9 +21,8 @@ func TestNewImage(t *testing.T) { imageTemplate := map[string]interface{}{ "source_key": "image", } - repository := mocks.NewProcessorRepository(t) - image, err := imagemapper.NewImage(imageTemplate, repository) + image, err := imagemapper.NewImage(imageTemplate) assert.Nil(t, err) assert.NotNil(t, image) @@ -35,9 +32,8 @@ func TestNewImage(t *testing.T) { "props": 1, "source_key": "name", } - repository := mocks.NewProcessorRepository(t) - image, err := imagemapper.NewImage(imageTemplate, repository) + image, err := imagemapper.NewImage(imageTemplate) assert.Nil(t, image) assert.NotNil(t, err) @@ -47,18 +43,16 @@ func TestNewImage(t *testing.T) { "invalid_field": 1, "source_key": "name", } - repository := mocks.NewProcessorRepository(t) - image, err := imagemapper.NewImage(imageTemplate, repository) + image, err := imagemapper.NewImage(imageTemplate) assert.Nil(t, image) assert.NotNil(t, err) }) t.Run("when source_key is not sent, should return an error", func(t *testing.T) { imageTemplate := map[string]interface{}{} - repository := mocks.NewProcessorRepository(t) - image, err := imagemapper.NewImage(imageTemplate, repository) + image, err := imagemapper.NewImage(imageTemplate) assert.Nil(t, image) assert.NotNil(t, err) @@ -67,18 +61,16 @@ func TestNewImage(t *testing.T) { imageTemplate := map[string]interface{}{ "source_key": 123, } - repository := mocks.NewProcessorRepository(t) - image, err := imagemapper.NewImage(imageTemplate, repository) + image, err := imagemapper.NewImage(imageTemplate) assert.Nil(t, image) assert.NotNil(t, err) }) t.Run("when source_key and path are not sent, should return an error", func(t *testing.T) { imageTemplate := map[string]interface{}{} - repository := mocks.NewProcessorRepository(t) - image, err := imagemapper.NewImage(imageTemplate, repository) + image, err := imagemapper.NewImage(imageTemplate) assert.Nil(t, image) assert.NotNil(t, err) @@ -87,9 +79,8 @@ func TestNewImage(t *testing.T) { imageTemplate := map[string]interface{}{ "source_key": "icon", } - repository := mocks.NewProcessorRepository(t) - image, err := imagemapper.NewImage(imageTemplate, repository) + image, err := imagemapper.NewImage(imageTemplate) assert.Nil(t, err) assert.Equal(t, image.SourceKey, "icon") @@ -101,9 +92,8 @@ func TestNewImage(t *testing.T) { "left": 10.0, }, } - repository := mocks.NewProcessorRepository(t) - image, err := imagemapper.NewImage(imageTemplate, repository) + image, err := imagemapper.NewImage(imageTemplate) assert.Nil(t, err) assert.Equal(t, 10.0, image.Props.Left) @@ -114,9 +104,8 @@ func TestImageGenerate(t *testing.T) { t.Run("if image is not found, should return an error", func(t *testing.T) { content := map[string]interface{}{} provider := mocks.NewProcessorProvider(t) - repository := mocks.NewProcessorRepository(t) - image := imagemapper.Image{SourceKey: "code", Repository: repository} + image := imagemapper.Image{SourceKey: "code"} component, err := image.Generate(content, provider) assert.Nil(t, component) @@ -139,43 +128,12 @@ func TestImageGenerate(t *testing.T) { "Path": "path.png", } provider := mocks.NewProcessorProvider(t) - provider.EXPECT().CreateImage([]byte("image"), "png").Return(nil) - repository := mocks.NewProcessorRepository(t) - repository.EXPECT().GetDocument("path.png").Return("png", []byte("image"), nil) - - image := imagemapper.Image{SourceKey: "Path", Repository: repository} - _, err := image.Generate(content, provider) - - assert.Nil(t, err) - repository.AssertNumberOfCalls(t, "GetDocument", 1) - provider.AssertNumberOfCalls(t, "CreateImage", 1) - }) - t.Run("when it was not possible to load the image, it should return an error", func(t *testing.T) { - content := map[string]interface{}{} - - provider := mocks.NewProcessorProvider(t) - repository := mocks.NewProcessorRepository(t) - repository.EXPECT().GetDocument("path.png").Return("", nil, fmt.Errorf("any")) - - image := imagemapper.Image{Path: "path.png", Repository: repository} - _, err := image.Generate(content, provider) - - assert.NotNil(t, err) - repository.AssertNumberOfCalls(t, "GetDocument", 1) - }) - t.Run("when valid path is sent, should generate image", func(t *testing.T) { - content := map[string]interface{}{} - - provider := mocks.NewProcessorProvider(t) - provider.EXPECT().CreateImage([]byte("image"), "png").Return(nil) - repository := mocks.NewProcessorRepository(t) - repository.EXPECT().GetDocument("path.png").Return("png", []byte("image"), nil) + provider.EXPECT().CreateImage("path.png").Return(nil, nil) - image := imagemapper.Image{Path: "path.png", Repository: repository} + image := imagemapper.Image{SourceKey: "Path"} _, err := image.Generate(content, provider) assert.Nil(t, err) - repository.AssertNumberOfCalls(t, "GetDocument", 1) provider.AssertNumberOfCalls(t, "CreateImage", 1) }) } diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index 65fe6a05..25b38ed8 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -2,6 +2,8 @@ package processorprovider import ( "fmt" + "net/url" + "strings" "github.com/johnfercher/go-tree/node" "github.com/johnfercher/maroto/v2" @@ -23,6 +25,7 @@ import ( "github.com/johnfercher/maroto/v2/pkg/consts/orientation" "github.com/johnfercher/maroto/v2/pkg/core" processorcore "github.com/johnfercher/maroto/v2/pkg/processor/core" + "github.com/johnfercher/maroto/v2/pkg/processor/loader" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/buildermapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/props" @@ -168,40 +171,41 @@ func (m *Maroto) CreateLine(lineProps ...*propsmapper.Line) ProviderComponent { }) } -func (m *Maroto) CreateImage(img []byte, ext string, imgProps ...*propsmapper.Rect) ProviderComponent { - cProps := propsmapper.Rect{} - if len(imgProps) > 0 { - cProps = *imgProps[0] - } +func (m *Maroto) CreateImageWithLocalePath(uri *url.URL, props ...props.Rect) (ProviderComponent, error) { + newPath := strings.TrimPrefix(uri.String(), "file://") + return image.NewFromFile(newPath, props...), nil +} - return image.NewFromBytes(img, extension.Type(ext), props.Rect{ - Left: cProps.Left, Top: cProps.Top, Percent: cProps.Percent, - JustReferenceWidth: cProps.JustReferenceWidth, Center: cProps.Center, - }) +func (m *Maroto) CreateImageWithExternalPath(path *url.URL, props ...props.Rect) (ProviderComponent, error) { + ext, img, err := m.repository.GetDocument(path.String()) + if err != nil { + return nil, err + } + return image.NewFromBytes(img, extension.Type(ext), props...), nil } -func (m *Maroto) CreateMatrixCode(codeValue string, codeProps ...*propsmapper.Rect) ProviderComponent { - cProps := propsmapper.Rect{} - if len(codeProps) > 0 { - cProps = *codeProps[0] +func (m *Maroto) CreateImage(path string, propsMapperArr ...*propsmapper.Rect) (ProviderComponent, error) { + props := createPropsRect(propsMapperArr...) + uri, err := loader.GetResourceSource(path) + if err != nil { + return nil, err } - return code.NewMatrix(codeValue, props.Rect{ - Left: cProps.Left, Top: cProps.Top, Percent: cProps.Percent, - JustReferenceWidth: cProps.JustReferenceWidth, Center: cProps.Center, - }) + if uri.Scheme == "file" { + return m.CreateImageWithLocalePath(uri, props) + } else { + return m.CreateImageWithExternalPath(uri, props) + } } -func (m *Maroto) CreateQrCode(codeValue string, codeProps ...*propsmapper.Rect) ProviderComponent { - cProps := propsmapper.Rect{} - if len(codeProps) > 0 { - cProps = *codeProps[0] - } +func (m *Maroto) CreateMatrixCode(codeValue string, codeProps ...*propsmapper.Rect) ProviderComponent { + props := createPropsRect(codeProps...) + return code.NewMatrix(codeValue, props) +} - return code.NewQr(codeValue, props.Rect{ - Left: cProps.Left, Top: cProps.Top, Percent: cProps.Percent, - JustReferenceWidth: cProps.JustReferenceWidth, Center: cProps.Center, - }) +func (m *Maroto) CreateQrCode(codeValue string, codeProps ...*propsmapper.Rect) ProviderComponent { + props := createPropsRect(codeProps...) + return code.NewQr(codeValue, props) } func (m *Maroto) CreateBarCode(codeValue string, codeProps ...*propsmapper.Barcode) ProviderComponent { @@ -227,3 +231,15 @@ func convertComponentType[T any](components ...ProviderComponent) ([]T, error) { } return newComponents, nil } + +func createPropsRect(propsMapperArr ...*propsmapper.Rect) props.Rect { + propsRect := props.Rect{} + if len(propsMapperArr) > 0 { + propsMapper := *propsMapperArr[0] + propsRect = props.Rect{ + Left: propsMapper.Left, Top: propsMapper.Top, Percent: propsMapper.Percent, + JustReferenceWidth: propsMapper.JustReferenceWidth, Center: propsMapper.Center, + } + } + return propsRect +} diff --git a/pkg/processor/processorprovider/Maroto_test.go b/pkg/processor/processorprovider/Maroto_test.go index b07d3e44..aea28a0a 100644 --- a/pkg/processor/processorprovider/Maroto_test.go +++ b/pkg/processor/processorprovider/Maroto_test.go @@ -195,10 +195,11 @@ func TestCreateImage(t *testing.T) { t.Run("when CreateImage is called, should generate a image", func(t *testing.T) { loader := mocks.NewLoader(t) m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) - image := m.CreateImage(make([]byte, 0), "png", + image, err := m.CreateImage("img.png", &propsmapper.Rect{Left: 10.0, Top: 10.0, Percent: 100.0, JustReferenceWidth: false, Center: false}, ) + assert.Nil(t, err) test.New(t).Assert(image.GetStructure()).Equals("processor/provider/image.json") }) } diff --git a/pkg/processor/processorprovider/provider.go b/pkg/processor/processorprovider/provider.go index e8aa6595..6e2a4291 100644 --- a/pkg/processor/processorprovider/provider.go +++ b/pkg/processor/processorprovider/provider.go @@ -26,6 +26,6 @@ type ProcessorProvider interface { CreateBarCode(value string, props ...*propsmapper.Barcode) ProviderComponent CreateMatrixCode(value string, props ...*propsmapper.Rect) ProviderComponent CreateQrCode(value string, props ...*propsmapper.Rect) ProviderComponent - CreateImage(value []byte, extension string, props ...*propsmapper.Rect) ProviderComponent + CreateImage(path string, props ...*propsmapper.Rect) (ProviderComponent, error) CreateLine(props ...*propsmapper.Line) ProviderComponent } diff --git a/pkg/processor/repository/memory_storage.go b/pkg/processor/repository/memory_storage.go index b205a10a..a59ee008 100644 --- a/pkg/processor/repository/memory_storage.go +++ b/pkg/processor/repository/memory_storage.go @@ -15,8 +15,9 @@ type memoryStorage struct { // implementation that stores data in memory func NewMemoryStorage(loader core.Loader) *memoryStorage { return &memoryStorage{ - template: make(map[string]map[string]any), - loader: loader, + template: make(map[string]map[string]any), + loader: loader, + documents: make(map[string][]byte), } } diff --git a/test/maroto/processor/provider/image.json b/test/maroto/processor/provider/image.json index d89c4ab0..15d53a0e 100644 --- a/test/maroto/processor/provider/image.json +++ b/test/maroto/processor/provider/image.json @@ -1,9 +1,7 @@ { - "value": "", - "type": "bytesImage", + "value": "img.png", + "type": "fileImage", "details": { - "bytes_size": 0, - "extension": "png", "prop_left": 10, "prop_percent": 100, "prop_top": 10 From 88dd24adf5af69d13df15e37441628e5c1022afc Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 17 Dec 2024 21:20:08 -0300 Subject: [PATCH 082/116] fix: validate execution of autorow example --- .../mappers/propsmapper/pagenumber.go | 2 +- pkg/processor/processor_test.go | 57 ++++++++---- .../processor/json/auto_row_content.json | 26 ++++++ .../processor/json/auto_row_template.json | 92 +++++++++++++++++++ 4 files changed, 157 insertions(+), 20 deletions(-) create mode 100644 test/maroto/processor/json/auto_row_content.json create mode 100644 test/maroto/processor/json/auto_row_template.json diff --git a/pkg/processor/mappers/propsmapper/pagenumber.go b/pkg/processor/mappers/propsmapper/pagenumber.go index 6526e25b..8d3cebf0 100644 --- a/pkg/processor/mappers/propsmapper/pagenumber.go +++ b/pkg/processor/mappers/propsmapper/pagenumber.go @@ -21,7 +21,7 @@ type PageNumber struct { func NewPageNumber(pageNumber interface{}) *PageNumber { pageNumberMap, ok := pageNumber.(map[string]interface{}) if !ok { - return &PageNumber{} + return nil } return &PageNumber{ diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index 773c4ae6..d202d2cd 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -1,17 +1,32 @@ package processor_test import ( - "encoding/json" + "os" "testing" - "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/processor" "github.com/johnfercher/maroto/v2/pkg/processor/deserializer" + "github.com/johnfercher/maroto/v2/pkg/processor/loader" + "github.com/johnfercher/maroto/v2/pkg/processor/repository" processortest "github.com/johnfercher/maroto/v2/pkg/processor/test" "github.com/johnfercher/maroto/v2/pkg/test" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) +func setupTestDir(t *testing.T) { + originalDir, err := os.Getwd() + require.NoError(t, err) + + err = os.Chdir("../../") + require.NoError(t, err) + + t.Cleanup(func() { + err := os.Chdir(originalDir) + require.NoError(t, err) + }) +} + func TestRegisterTemplate(t *testing.T) { t.Run("when template is recorded, should no return error", func(t *testing.T) { }) @@ -21,41 +36,45 @@ func TestRegisterTemplate(t *testing.T) { }) } -func loadTemplate(templatePath string) map[string]interface{} { - var template map[string]interface{} - file, _ := processortest.NewFileReader().LoadFile(templatePath) - if err := json.Unmarshal(file, &template); err != nil { - return nil - } - return template -} - func TestGenerateTemplate(t *testing.T) { t.Run("when valid template is found, should return valid pdf", func(t *testing.T) { - fixtemplate := loadTemplate("processor/json/simple_pdf_templates.json") + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/simple_pdf_templates.json") fixContent, _ := processortest.NewFileReader().LoadFile("processor/json/simple_pdf_content.json") - repository := mocks.NewProcessorRepository(t) - repository.EXPECT().ReadTemplate("simple_pdf").Return(fixtemplate, nil) + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + processor.RegisterTemplate("simple_pdf", string(fixtemplate)) + provider, err := processor.GenerateDocument("simple_pdf", string(fixContent)) - provider, err := processor.NewProcessor(repository, deserializer.NewJSONDeserializer()).GenerateDocument("simple_pdf", string(fixContent)) assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("processor/simple_pdf.json") }) t.Run("when template with Addpage is found, should set template", func(t *testing.T) { - fixtemplate := loadTemplate("processor/json/add_page_template.json") + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/add_page_template.json") fixContent, _ := processortest.NewFileReader().LoadFile("processor/json/add_page_content.json") - repository := mocks.NewProcessorRepository(t) - repository.EXPECT().ReadTemplate("add_page").Return(fixtemplate, nil) + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + processor.RegisterTemplate("add_page", string(fixtemplate)) + provider, err := processor.GenerateDocument("add_page", string(fixContent)) - provider, err := processor.NewProcessor(repository, deserializer.NewJSONDeserializer()).GenerateDocument("add_page", string(fixContent)) assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/addpage.json") }) + t.Run("when template with AutoRow is found, should set template", func(t *testing.T) { + setupTestDir(t) + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/auto_row_template.json") + fixContent, _ := processortest.NewFileReader().LoadFile("processor/json/auto_row_content.json") + + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + processor.RegisterTemplate("auto_row", string(fixtemplate)) + provider, err := processor.GenerateDocument("auto_row", string(fixContent)) + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/autorow.json") + }) t.Run("when sent template is not found, should reuturn an error", func(t *testing.T) { + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) diff --git a/test/maroto/processor/json/auto_row_content.json b/test/maroto/processor/json/auto_row_content.json new file mode 100644 index 00000000..f21566de --- /dev/null +++ b/test/maroto/processor/json/auto_row_content.json @@ -0,0 +1,26 @@ +{ + "pages": { + "page_template": { + "row_with_larger_image": { + "biplane": "docs/assets/images/biplane.jpg", + "intro": "Numa toca no chão vivia um hobbit. Não uma toca nojenta, suja, úmida, \ncheia de pontas de minhocas e um cheiro de limo, nem tam pouco uma toca seca, vazia, arenosa, \nsem nenhum lugar onde se sentar ou onde comer: era uma toca de hobbit, e isso significa conforto.\nEla tinha uma porta perfeitamente redonda feito uma escotilha, pintada de verde, com uma maçaneta\namarela e brilhante de latão exatamente no meio. A porta se abria para um corredor em forma de tubo,\nfeito um túnel: um túnel muito confortável, sem fumaça, de paredes com painéis e assoalhos\nazulejados e acarpetados, com cadeiras enceradas e montes e montes de cabieiros para chapéus e\ncasacos - o hobbit apreciava visitas." + }, + "row_with_image_and_text_same": { + "biplane": "docs/assets/images/biplane.jpg", + "intro": "Numa toca no chão vivia um hobbit. Não uma toca nojenta, suja, úmida, \ncheia de pontas de minhocas e um cheiro de limo, nem tam pouco uma toca seca, vazia, arenosa, \nsem nenhum lugar onde se sentar ou onde comer: era uma toca de hobbit, e isso significa conforto.\nEla tinha uma porta perfeitamente redonda feito uma escotilha, pintada de verde, com uma maçaneta\namarela e brilhante de latão exatamente no meio. A porta se abria para um corredor em forma de tubo,\nfeito um túnel: um túnel muito confortável, sem fumaça, de paredes com painéis e assoalhos\nazulejados e acarpetados, com cadeiras enceradas e montes e montes de cabieiros para chapéus e\ncasacos - o hobbit apreciava visitas." + }, + "row_barcode": { + "bar_col": "code", + "intro": "Numa toca no chão vivia um hobbit. Não uma toca nojenta, suja, úmida, \ncheia de pontas de minhocas e um cheiro de limo, nem tam pouco uma toca seca, vazia, arenosa, \nsem nenhum lugar onde se sentar ou onde comer: era uma toca de hobbit, e isso significa conforto.\nEla tinha uma porta perfeitamente redonda feito uma escotilha, pintada de verde, com uma maçaneta\namarela e brilhante de latão exatamente no meio. A porta se abria para um corredor em forma de tubo,\nfeito um túnel: um túnel muito confortável, sem fumaça, de paredes com painéis e assoalhos\nazulejados e acarpetados, com cadeiras enceradas e montes e montes de cabieiros para chapéus e\ncasacos - o hobbit apreciava visitas." + }, + "row_matrixcode": { + "matrix_code": "code", + "intro": "Numa toca no chão vivia um hobbit. Não uma toca nojenta, suja, úmida, \ncheia de pontas de minhocas e um cheiro de limo, nem tam pouco uma toca seca, vazia, arenosa, \nsem nenhum lugar onde se sentar ou onde comer: era uma toca de hobbit, e isso significa conforto.\nEla tinha uma porta perfeitamente redonda feito uma escotilha, pintada de verde, com uma maçaneta\namarela e brilhante de latão exatamente no meio. A porta se abria para um corredor em forma de tubo,\nfeito um túnel: um túnel muito confortável, sem fumaça, de paredes com painéis e assoalhos\nazulejados e acarpetados, com cadeiras enceradas e montes e montes de cabieiros para chapéus e\ncasacos - o hobbit apreciava visitas." + }, + "row_qrcode": { + "qr_code": "code", + "intro": "Numa toca no chão vivia um hobbit. Não uma toca nojenta, suja, úmida, \ncheia de pontas de minhocas e um cheiro de limo, nem tam pouco uma toca seca, vazia, arenosa, \nsem nenhum lugar onde se sentar ou onde comer: era uma toca de hobbit, e isso significa conforto.\nEla tinha uma porta perfeitamente redonda feito uma escotilha, pintada de verde, com uma maçaneta\namarela e brilhante de latão exatamente no meio. A porta se abria para um corredor em forma de tubo,\nfeito um túnel: um túnel muito confortável, sem fumaça, de paredes com painéis e assoalhos\nazulejados e acarpetados, com cadeiras enceradas e montes e montes de cabieiros para chapéus e\ncasacos - o hobbit apreciava visitas." + } + } + } +} \ No newline at end of file diff --git a/test/maroto/processor/json/auto_row_template.json b/test/maroto/processor/json/auto_row_template.json new file mode 100644 index 00000000..9e22b717 --- /dev/null +++ b/test/maroto/processor/json/auto_row_template.json @@ -0,0 +1,92 @@ +{ + "builder":{ + "debug": true + }, + "pages": { + "page_template": { + "row_with_larger_image": { + "cols": [ + { + "image": { + "source_key": "biplane" + }, + "size": 5 + }, + { + "text": { + "source_key": "intro" + }, + "size": 7 + } + ] + }, + "row_with_image_and_text_same": { + "cols": [ + { + "image": { + "source_key": "biplane" + }, + "size": 5 + }, + { + "text": { + "source_key": "intro", + "props": { + "size": 13 + } + }, + "size": 7 + } + ] + }, + "row_barcode": { + "cols": [ + { + "bar_code": { + "source_key": "bar_col" + }, + "size": 4 + }, + { + "text": { + "source_key": "intro" + }, + "size": 8 + } + ] + }, + "row_matrixcode": { + "cols": [ + { + "matrix_code": { + "source_key": "matrix_code" + }, + "size": 3 + }, + { + "text": { + "source_key": "intro" + }, + "size": 9 + } + ] + }, + "row_qrcode": { + "cols": [ + { + "qr_code": { + "source_key": "qr_code" + }, + "size": 2 + }, + { + "text": { + "source_key": "intro" + }, + "size": 10 + } + ] + } + } + } +} \ No newline at end of file From e172d85ad3b9254a7f325319a00c08c672733779 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 24 Dec 2024 17:35:59 -0300 Subject: [PATCH 083/116] fix: Keep the order of components added to the pdf Order components according to the order property that is sent in the template --- internal/fixture/processorfixture.go | 4 +- mocks/AbstractFactoryMaps.go | 45 +++--- mocks/Cache.go | 3 +- mocks/CellWriter.go | 3 +- mocks/Code.go | 3 +- mocks/Col.go | 3 +- mocks/Component.go | 3 +- mocks/Componentmapper.go | 3 +- mocks/Deserializer.go | 3 +- mocks/Document.go | 3 +- mocks/Font.go | 3 +- mocks/Fpdf.go | 3 +- mocks/GenerateComponent.go | 17 ++- mocks/Image.go | 3 +- mocks/Line.go | 3 +- mocks/Listable.go | 3 +- mocks/Loader.go | 3 +- mocks/Maroto.go | 3 +- mocks/Math.go | 3 +- mocks/Node.go | 3 +- mocks/OrderedComponents.go | 140 ++++++++++++++++++ mocks/Page.go | 3 +- mocks/Processor.go | 3 +- mocks/ProcessorProvider.go | 3 +- mocks/ProcessorRepository.go | 3 +- mocks/Provider.go | 3 +- mocks/ProviderComponent.go | 3 +- mocks/Repository.go | 3 +- mocks/Row.go | 3 +- mocks/Text.go | 3 +- .../abstractfactory/abstractfactory.go | 6 +- pkg/processor/mappers/component_mapper.go | 14 +- .../mappers/components/listmapper/list.go | 67 +++++++-- .../components/listmapper/list_test.go | 117 +++++++++++++-- .../mappers/components/pagemapper/page.go | 60 +++++++- .../components/pagemapper/page_test.go | 125 ++++++++++++++-- .../mappers/components/rowmapper/row.go | 28 ++++ .../mappers/components/rowmapper/row_test.go | 40 ++++- .../mappers/documentmapper/document.go | 46 ++++-- .../mappers/documentmapper/document_test.go | 79 ++++++++-- .../processor/json/add_page_template.json | 6 + .../processor/json/simple_pdf_templates.json | 7 + 42 files changed, 746 insertions(+), 133 deletions(-) create mode 100644 mocks/OrderedComponents.go diff --git a/internal/fixture/processorfixture.go b/internal/fixture/processorfixture.go index 6e9d3199..fefbec7c 100644 --- a/internal/fixture/processorfixture.go +++ b/internal/fixture/processorfixture.go @@ -27,7 +27,7 @@ func MapperRow() *rowmapper.Row { func MapperPage() *pagemapper.Page { return &pagemapper.Page{ SourceKey: "template_page_1", - Rows: make([]mappers.Componentmapper, 0), + Rows: make([]mappers.OrderedComponents, 0), } } @@ -158,7 +158,7 @@ func Page(sourceKeyPage, sourceKeyRow, sourceKeyText string) *pagemapper.Page { return &pagemapper.Page{ SourceKey: sourceKeyPage, - Rows: []mappers.Componentmapper{ + Rows: []mappers.OrderedComponents{ &rowmapper.Row{ Height: 10, SourceKey: sourceKeyRow, diff --git a/mocks/AbstractFactoryMaps.go b/mocks/AbstractFactoryMaps.go index add10d97..342c3860 100644 --- a/mocks/AbstractFactoryMaps.go +++ b/mocks/AbstractFactoryMaps.go @@ -253,23 +253,23 @@ func (_c *AbstractFactoryMaps_NewLine_Call) RunAndReturn(run func(interface{}) ( } // NewList provides a mock function with given fields: document, sourceKey, generate -func (_m *AbstractFactoryMaps) NewList(document interface{}, sourceKey string, generate mappers.GenerateComponent) (mappers.Componentmapper, error) { +func (_m *AbstractFactoryMaps) NewList(document interface{}, sourceKey string, generate mappers.GenerateComponent) (mappers.OrderedComponents, error) { ret := _m.Called(document, sourceKey, generate) if len(ret) == 0 { panic("no return value specified for NewList") } - var r0 mappers.Componentmapper + var r0 mappers.OrderedComponents var r1 error - if rf, ok := ret.Get(0).(func(interface{}, string, mappers.GenerateComponent) (mappers.Componentmapper, error)); ok { + if rf, ok := ret.Get(0).(func(interface{}, string, mappers.GenerateComponent) (mappers.OrderedComponents, error)); ok { return rf(document, sourceKey, generate) } - if rf, ok := ret.Get(0).(func(interface{}, string, mappers.GenerateComponent) mappers.Componentmapper); ok { + if rf, ok := ret.Get(0).(func(interface{}, string, mappers.GenerateComponent) mappers.OrderedComponents); ok { r0 = rf(document, sourceKey, generate) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(mappers.Componentmapper) + r0 = ret.Get(0).(mappers.OrderedComponents) } } @@ -302,12 +302,12 @@ func (_c *AbstractFactoryMaps_NewList_Call) Run(run func(document interface{}, s return _c } -func (_c *AbstractFactoryMaps_NewList_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewList_Call { +func (_c *AbstractFactoryMaps_NewList_Call) Return(_a0 mappers.OrderedComponents, _a1 error) *AbstractFactoryMaps_NewList_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *AbstractFactoryMaps_NewList_Call) RunAndReturn(run func(interface{}, string, mappers.GenerateComponent) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewList_Call { +func (_c *AbstractFactoryMaps_NewList_Call) RunAndReturn(run func(interface{}, string, mappers.GenerateComponent) (mappers.OrderedComponents, error)) *AbstractFactoryMaps_NewList_Call { _c.Call.Return(run) return _c } @@ -371,23 +371,23 @@ func (_c *AbstractFactoryMaps_NewMatrixcode_Call) RunAndReturn(run func(interfac } // NewPage provides a mock function with given fields: document, sourceKey -func (_m *AbstractFactoryMaps) NewPage(document interface{}, sourceKey string) (mappers.Componentmapper, error) { +func (_m *AbstractFactoryMaps) NewPage(document interface{}, sourceKey string) (mappers.OrderedComponents, error) { ret := _m.Called(document, sourceKey) if len(ret) == 0 { panic("no return value specified for NewPage") } - var r0 mappers.Componentmapper + var r0 mappers.OrderedComponents var r1 error - if rf, ok := ret.Get(0).(func(interface{}, string) (mappers.Componentmapper, error)); ok { + if rf, ok := ret.Get(0).(func(interface{}, string) (mappers.OrderedComponents, error)); ok { return rf(document, sourceKey) } - if rf, ok := ret.Get(0).(func(interface{}, string) mappers.Componentmapper); ok { + if rf, ok := ret.Get(0).(func(interface{}, string) mappers.OrderedComponents); ok { r0 = rf(document, sourceKey) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(mappers.Componentmapper) + r0 = ret.Get(0).(mappers.OrderedComponents) } } @@ -419,12 +419,12 @@ func (_c *AbstractFactoryMaps_NewPage_Call) Run(run func(document interface{}, s return _c } -func (_c *AbstractFactoryMaps_NewPage_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewPage_Call { +func (_c *AbstractFactoryMaps_NewPage_Call) Return(_a0 mappers.OrderedComponents, _a1 error) *AbstractFactoryMaps_NewPage_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *AbstractFactoryMaps_NewPage_Call) RunAndReturn(run func(interface{}, string) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewPage_Call { +func (_c *AbstractFactoryMaps_NewPage_Call) RunAndReturn(run func(interface{}, string) (mappers.OrderedComponents, error)) *AbstractFactoryMaps_NewPage_Call { _c.Call.Return(run) return _c } @@ -488,23 +488,23 @@ func (_c *AbstractFactoryMaps_NewQrcode_Call) RunAndReturn(run func(interface{}) } // NewRow provides a mock function with given fields: document, sourceKey -func (_m *AbstractFactoryMaps) NewRow(document interface{}, sourceKey string) (mappers.Componentmapper, error) { +func (_m *AbstractFactoryMaps) NewRow(document interface{}, sourceKey string) (mappers.OrderedComponents, error) { ret := _m.Called(document, sourceKey) if len(ret) == 0 { panic("no return value specified for NewRow") } - var r0 mappers.Componentmapper + var r0 mappers.OrderedComponents var r1 error - if rf, ok := ret.Get(0).(func(interface{}, string) (mappers.Componentmapper, error)); ok { + if rf, ok := ret.Get(0).(func(interface{}, string) (mappers.OrderedComponents, error)); ok { return rf(document, sourceKey) } - if rf, ok := ret.Get(0).(func(interface{}, string) mappers.Componentmapper); ok { + if rf, ok := ret.Get(0).(func(interface{}, string) mappers.OrderedComponents); ok { r0 = rf(document, sourceKey) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(mappers.Componentmapper) + r0 = ret.Get(0).(mappers.OrderedComponents) } } @@ -536,12 +536,12 @@ func (_c *AbstractFactoryMaps_NewRow_Call) Run(run func(document interface{}, so return _c } -func (_c *AbstractFactoryMaps_NewRow_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewRow_Call { +func (_c *AbstractFactoryMaps_NewRow_Call) Return(_a0 mappers.OrderedComponents, _a1 error) *AbstractFactoryMaps_NewRow_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *AbstractFactoryMaps_NewRow_Call) RunAndReturn(run func(interface{}, string) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewRow_Call { +func (_c *AbstractFactoryMaps_NewRow_Call) RunAndReturn(run func(interface{}, string) (mappers.OrderedComponents, error)) *AbstractFactoryMaps_NewRow_Call { _c.Call.Return(run) return _c } @@ -667,7 +667,8 @@ func (_c *AbstractFactoryMaps_NewText_Call) RunAndReturn(run func(interface{}) ( func NewAbstractFactoryMaps(t interface { mock.TestingT Cleanup(func()) -}) *AbstractFactoryMaps { +}, +) *AbstractFactoryMaps { mock := &AbstractFactoryMaps{} mock.Mock.Test(t) diff --git a/mocks/Cache.go b/mocks/Cache.go index 19569343..25ebce39 100644 --- a/mocks/Cache.go +++ b/mocks/Cache.go @@ -167,7 +167,8 @@ func (_c *Cache_LoadImage_Call) RunAndReturn(run func(string, extension.Type) er func NewCache(t interface { mock.TestingT Cleanup(func()) -}) *Cache { +}, +) *Cache { mock := &Cache{} mock.Mock.Test(t) diff --git a/mocks/CellWriter.go b/mocks/CellWriter.go index 1c037a18..7d47e029 100644 --- a/mocks/CellWriter.go +++ b/mocks/CellWriter.go @@ -190,7 +190,8 @@ func (_c *CellWriter_SetNext_Call) RunAndReturn(run func(cellwriter.CellWriter)) func NewCellWriter(t interface { mock.TestingT Cleanup(func()) -}) *CellWriter { +}, +) *CellWriter { mock := &CellWriter{} mock.Mock.Test(t) diff --git a/mocks/Code.go b/mocks/Code.go index 4afdf77c..747d5bc4 100644 --- a/mocks/Code.go +++ b/mocks/Code.go @@ -203,7 +203,8 @@ func (_c *Code_GenQr_Call) RunAndReturn(run func(string) (*entity.Image, error)) func NewCode(t interface { mock.TestingT Cleanup(func()) -}) *Code { +}, +) *Code { mock := &Code{} mock.Mock.Test(t) diff --git a/mocks/Col.go b/mocks/Col.go index 186dfd06..dc4a7276 100644 --- a/mocks/Col.go +++ b/mocks/Col.go @@ -347,7 +347,8 @@ func (_c *Col_WithStyle_Call) RunAndReturn(run func(*props.Cell) core.Col) *Col_ func NewCol(t interface { mock.TestingT Cleanup(func()) -}) *Col { +}, +) *Col { mock := &Col{} mock.Mock.Test(t) diff --git a/mocks/Component.go b/mocks/Component.go index 64078a01..5b096b9a 100644 --- a/mocks/Component.go +++ b/mocks/Component.go @@ -190,7 +190,8 @@ func (_c *Component_SetConfig_Call) RunAndReturn(run func(*entity.Config)) *Comp func NewComponent(t interface { mock.TestingT Cleanup(func()) -}) *Component { +}, +) *Component { mock := &Component{} mock.Mock.Test(t) diff --git a/mocks/Componentmapper.go b/mocks/Componentmapper.go index 098df852..b6f4c978 100644 --- a/mocks/Componentmapper.go +++ b/mocks/Componentmapper.go @@ -84,7 +84,8 @@ func (_c *Componentmapper_Generate_Call) RunAndReturn(run func(map[string]interf func NewComponentmapper(t interface { mock.TestingT Cleanup(func()) -}) *Componentmapper { +}, +) *Componentmapper { mock := &Componentmapper{} mock.Mock.Test(t) diff --git a/mocks/Deserializer.go b/mocks/Deserializer.go index db175be7..b5dcd4c4 100644 --- a/mocks/Deserializer.go +++ b/mocks/Deserializer.go @@ -80,7 +80,8 @@ func (_c *Deserializer_Deserialize_Call) RunAndReturn(run func(string) (map[stri func NewDeserializer(t interface { mock.TestingT Cleanup(func()) -}) *Deserializer { +}, +) *Deserializer { mock := &Deserializer{} mock.Mock.Test(t) diff --git a/mocks/Document.go b/mocks/Document.go index 6a55effe..c1a675cc 100644 --- a/mocks/Document.go +++ b/mocks/Document.go @@ -256,7 +256,8 @@ func (_c *Document_Save_Call) RunAndReturn(run func(string) error) *Document_Sav func NewDocument(t interface { mock.TestingT Cleanup(func()) -}) *Document { +}, +) *Document { mock := &Document{} mock.Mock.Test(t) diff --git a/mocks/Font.go b/mocks/Font.go index a41d41dd..3c394374 100644 --- a/mocks/Font.go +++ b/mocks/Font.go @@ -486,7 +486,8 @@ func (_c *Font_SetStyle_Call) RunAndReturn(run func(fontstyle.Type)) *Font_SetSt func NewFont(t interface { mock.TestingT Cleanup(func()) -}) *Font { +}, +) *Font { mock := &Font{} mock.Mock.Test(t) diff --git a/mocks/Fpdf.go b/mocks/Fpdf.go index b7c28677..2b89935f 100644 --- a/mocks/Fpdf.go +++ b/mocks/Fpdf.go @@ -6934,7 +6934,8 @@ func (_c *Fpdf_Writef_Call) RunAndReturn(run func(float64, string, ...interface{ func NewFpdf(t interface { mock.TestingT Cleanup(func()) -}) *Fpdf { +}, +) *Fpdf { mock := &Fpdf{} mock.Mock.Test(t) diff --git a/mocks/GenerateComponent.go b/mocks/GenerateComponent.go index c1bc629f..12e1334d 100644 --- a/mocks/GenerateComponent.go +++ b/mocks/GenerateComponent.go @@ -21,23 +21,23 @@ func (_m *GenerateComponent) EXPECT() *GenerateComponent_Expecter { } // Execute provides a mock function with given fields: document, sourceKey -func (_m *GenerateComponent) Execute(document interface{}, sourceKey string) (mappers.Componentmapper, error) { +func (_m *GenerateComponent) Execute(document interface{}, sourceKey string) (mappers.OrderedComponents, error) { ret := _m.Called(document, sourceKey) if len(ret) == 0 { panic("no return value specified for Execute") } - var r0 mappers.Componentmapper + var r0 mappers.OrderedComponents var r1 error - if rf, ok := ret.Get(0).(func(interface{}, string) (mappers.Componentmapper, error)); ok { + if rf, ok := ret.Get(0).(func(interface{}, string) (mappers.OrderedComponents, error)); ok { return rf(document, sourceKey) } - if rf, ok := ret.Get(0).(func(interface{}, string) mappers.Componentmapper); ok { + if rf, ok := ret.Get(0).(func(interface{}, string) mappers.OrderedComponents); ok { r0 = rf(document, sourceKey) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(mappers.Componentmapper) + r0 = ret.Get(0).(mappers.OrderedComponents) } } @@ -69,12 +69,12 @@ func (_c *GenerateComponent_Execute_Call) Run(run func(document interface{}, sou return _c } -func (_c *GenerateComponent_Execute_Call) Return(_a0 mappers.Componentmapper, _a1 error) *GenerateComponent_Execute_Call { +func (_c *GenerateComponent_Execute_Call) Return(_a0 mappers.OrderedComponents, _a1 error) *GenerateComponent_Execute_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *GenerateComponent_Execute_Call) RunAndReturn(run func(interface{}, string) (mappers.Componentmapper, error)) *GenerateComponent_Execute_Call { +func (_c *GenerateComponent_Execute_Call) RunAndReturn(run func(interface{}, string) (mappers.OrderedComponents, error)) *GenerateComponent_Execute_Call { _c.Call.Return(run) return _c } @@ -84,7 +84,8 @@ func (_c *GenerateComponent_Execute_Call) RunAndReturn(run func(interface{}, str func NewGenerateComponent(t interface { mock.TestingT Cleanup(func()) -}) *GenerateComponent { +}, +) *GenerateComponent { mock := &GenerateComponent{} mock.Mock.Test(t) diff --git a/mocks/Image.go b/mocks/Image.go index 60b52c28..fa0bebda 100644 --- a/mocks/Image.go +++ b/mocks/Image.go @@ -145,7 +145,8 @@ func (_c *Image_GetImageInfo_Call) RunAndReturn(run func(*entity.Image, extensio func NewImage(t interface { mock.TestingT Cleanup(func()) -}) *Image { +}, +) *Image { mock := &Image{} mock.Mock.Test(t) diff --git a/mocks/Line.go b/mocks/Line.go index 217ef896..080731fc 100644 --- a/mocks/Line.go +++ b/mocks/Line.go @@ -61,7 +61,8 @@ func (_c *Line_Add_Call) RunAndReturn(run func(*entity.Cell, *props.Line)) *Line func NewLine(t interface { mock.TestingT Cleanup(func()) -}) *Line { +}, +) *Line { mock := &Line{} mock.Mock.Test(t) diff --git a/mocks/Listable.go b/mocks/Listable.go index 20cda4b9..d9d28d9f 100644 --- a/mocks/Listable.go +++ b/mocks/Listable.go @@ -121,7 +121,8 @@ func (_c *Listable_GetHeader_Call) RunAndReturn(run func() core.Row) *Listable_G func NewListable(t interface { mock.TestingT Cleanup(func()) -}) *Listable { +}, +) *Listable { mock := &Listable{} mock.Mock.Test(t) diff --git a/mocks/Loader.go b/mocks/Loader.go index cbbdf89c..ffe16105 100644 --- a/mocks/Loader.go +++ b/mocks/Loader.go @@ -126,7 +126,8 @@ func (_c *Loader_Load_Call) RunAndReturn(run func(string) ([]byte, error)) *Load func NewLoader(t interface { mock.TestingT Cleanup(func()) -}) *Loader { +}, +) *Loader { mock := &Loader{} mock.Mock.Test(t) diff --git a/mocks/Maroto.go b/mocks/Maroto.go index 4f66b03e..90fb026b 100644 --- a/mocks/Maroto.go +++ b/mocks/Maroto.go @@ -560,7 +560,8 @@ func (_c *Maroto_RegisterHeader_Call) RunAndReturn(run func(...core.Row) error) func NewMaroto(t interface { mock.TestingT Cleanup(func()) -}) *Maroto { +}, +) *Maroto { mock := &Maroto{} mock.Mock.Test(t) diff --git a/mocks/Math.go b/mocks/Math.go index a3759fbb..fad2cbf5 100644 --- a/mocks/Math.go +++ b/mocks/Math.go @@ -125,7 +125,8 @@ func (_c *Math_Resize_Call) RunAndReturn(run func(*entity.Dimensions, *entity.Di func NewMath(t interface { mock.TestingT Cleanup(func()) -}) *Math { +}, +) *Math { mock := &Math{} mock.Mock.Test(t) diff --git a/mocks/Node.go b/mocks/Node.go index 075eb94b..29bf2a8d 100644 --- a/mocks/Node.go +++ b/mocks/Node.go @@ -109,7 +109,8 @@ func (_c *Node_SetConfig_Call) RunAndReturn(run func(*entity.Config)) *Node_SetC func NewNode(t interface { mock.TestingT Cleanup(func()) -}) *Node { +}, +) *Node { mock := &Node{} mock.Mock.Test(t) diff --git a/mocks/OrderedComponents.go b/mocks/OrderedComponents.go new file mode 100644 index 00000000..577c94c2 --- /dev/null +++ b/mocks/OrderedComponents.go @@ -0,0 +1,140 @@ +// Code generated by mockery v2.42.0. DO NOT EDIT. + +package mocks + +import ( + processorprovider "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" + mock "github.com/stretchr/testify/mock" +) + +// OrderedComponents is an autogenerated mock type for the OrderedComponents type +type OrderedComponents struct { + mock.Mock +} + +type OrderedComponents_Expecter struct { + mock *mock.Mock +} + +func (_m *OrderedComponents) EXPECT() *OrderedComponents_Expecter { + return &OrderedComponents_Expecter{mock: &_m.Mock} +} + +// Generate provides a mock function with given fields: content, provider +func (_m *OrderedComponents) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) { + ret := _m.Called(content, provider) + + if len(ret) == 0 { + panic("no return value specified for Generate") + } + + var r0 []processorprovider.ProviderComponent + var r1 error + if rf, ok := ret.Get(0).(func(map[string]interface{}, processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error)); ok { + return rf(content, provider) + } + if rf, ok := ret.Get(0).(func(map[string]interface{}, processorprovider.ProcessorProvider) []processorprovider.ProviderComponent); ok { + r0 = rf(content, provider) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]processorprovider.ProviderComponent) + } + } + + if rf, ok := ret.Get(1).(func(map[string]interface{}, processorprovider.ProcessorProvider) error); ok { + r1 = rf(content, provider) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// OrderedComponents_Generate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Generate' +type OrderedComponents_Generate_Call struct { + *mock.Call +} + +// Generate is a helper method to define mock.On call +// - content map[string]interface{} +// - provider processorprovider.ProcessorProvider +func (_e *OrderedComponents_Expecter) Generate(content interface{}, provider interface{}) *OrderedComponents_Generate_Call { + return &OrderedComponents_Generate_Call{Call: _e.mock.On("Generate", content, provider)} +} + +func (_c *OrderedComponents_Generate_Call) Run(run func(content map[string]interface{}, provider processorprovider.ProcessorProvider)) *OrderedComponents_Generate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(map[string]interface{}), args[1].(processorprovider.ProcessorProvider)) + }) + return _c +} + +func (_c *OrderedComponents_Generate_Call) Return(_a0 []processorprovider.ProviderComponent, _a1 error) *OrderedComponents_Generate_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *OrderedComponents_Generate_Call) RunAndReturn(run func(map[string]interface{}, processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error)) *OrderedComponents_Generate_Call { + _c.Call.Return(run) + return _c +} + +// GetOrder provides a mock function with given fields: +func (_m *OrderedComponents) GetOrder() int { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetOrder") + } + + var r0 int + if rf, ok := ret.Get(0).(func() int); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(int) + } + + return r0 +} + +// OrderedComponents_GetOrder_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetOrder' +type OrderedComponents_GetOrder_Call struct { + *mock.Call +} + +// GetOrder is a helper method to define mock.On call +func (_e *OrderedComponents_Expecter) GetOrder() *OrderedComponents_GetOrder_Call { + return &OrderedComponents_GetOrder_Call{Call: _e.mock.On("GetOrder")} +} + +func (_c *OrderedComponents_GetOrder_Call) Run(run func()) *OrderedComponents_GetOrder_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *OrderedComponents_GetOrder_Call) Return(_a0 int) *OrderedComponents_GetOrder_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *OrderedComponents_GetOrder_Call) RunAndReturn(run func() int) *OrderedComponents_GetOrder_Call { + _c.Call.Return(run) + return _c +} + +// NewOrderedComponents creates a new instance of OrderedComponents. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewOrderedComponents(t interface { + mock.TestingT + Cleanup(func()) +}, +) *OrderedComponents { + mock := &OrderedComponents{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/Page.go b/mocks/Page.go index 9f2d7062..da968dc0 100644 --- a/mocks/Page.go +++ b/mocks/Page.go @@ -330,7 +330,8 @@ func (_c *Page_SetNumber_Call) RunAndReturn(run func(int, int)) *Page_SetNumber_ func NewPage(t interface { mock.TestingT Cleanup(func()) -}) *Page { +}, +) *Page { mock := &Page{} mock.Mock.Test(t) diff --git a/mocks/Processor.go b/mocks/Processor.go index 2ccfb8b0..c8d28d27 100644 --- a/mocks/Processor.go +++ b/mocks/Processor.go @@ -118,7 +118,8 @@ func (_c *Processor_RegisterTemplate_Call) RunAndReturn(run func(string, string) func NewProcessor(t interface { mock.TestingT Cleanup(func()) -}) *Processor { +}, +) *Processor { mock := &Processor{} mock.Mock.Test(t) diff --git a/mocks/ProcessorProvider.go b/mocks/ProcessorProvider.go index 1a8efcd7..55a2ee6a 100644 --- a/mocks/ProcessorProvider.go +++ b/mocks/ProcessorProvider.go @@ -1014,7 +1014,8 @@ func (_c *ProcessorProvider_GetStructure_Call) RunAndReturn(run func() *node.Nod func NewProcessorProvider(t interface { mock.TestingT Cleanup(func()) -}) *ProcessorProvider { +}, +) *ProcessorProvider { mock := &ProcessorProvider{} mock.Mock.Test(t) diff --git a/mocks/ProcessorRepository.go b/mocks/ProcessorRepository.go index 6e1d6a05..e1fe28c2 100644 --- a/mocks/ProcessorRepository.go +++ b/mocks/ProcessorRepository.go @@ -192,7 +192,8 @@ func (_c *ProcessorRepository_RegisterTemplate_Call) RunAndReturn(run func(strin func NewProcessorRepository(t interface { mock.TestingT Cleanup(func()) -}) *ProcessorRepository { +}, +) *ProcessorRepository { mock := &ProcessorRepository{} mock.Mock.Test(t) diff --git a/mocks/Provider.go b/mocks/Provider.go index f36ae49d..dd7b2bf4 100644 --- a/mocks/Provider.go +++ b/mocks/Provider.go @@ -862,7 +862,8 @@ func (_c *Provider_SetProtection_Call) RunAndReturn(run func(*entity.Protection) func NewProvider(t interface { mock.TestingT Cleanup(func()) -}) *Provider { +}, +) *Provider { mock := &Provider{} mock.Mock.Test(t) diff --git a/mocks/ProviderComponent.go b/mocks/ProviderComponent.go index ddb519a9..6dd0acc9 100644 --- a/mocks/ProviderComponent.go +++ b/mocks/ProviderComponent.go @@ -109,7 +109,8 @@ func (_c *ProviderComponent_SetConfig_Call) RunAndReturn(run func(*entity.Config func NewProviderComponent(t interface { mock.TestingT Cleanup(func()) -}) *ProviderComponent { +}, +) *ProviderComponent { mock := &ProviderComponent{} mock.Mock.Test(t) diff --git a/mocks/Repository.go b/mocks/Repository.go index 8e5b38f7..3977c94e 100644 --- a/mocks/Repository.go +++ b/mocks/Repository.go @@ -186,7 +186,8 @@ func (_c *Repository_Load_Call) RunAndReturn(run func() ([]*entity.CustomFont, e func NewRepository(t interface { mock.TestingT Cleanup(func()) -}) *Repository { +}, +) *Repository { mock := &Repository{} mock.Mock.Test(t) diff --git a/mocks/Row.go b/mocks/Row.go index 8917128a..f8e8a69c 100644 --- a/mocks/Row.go +++ b/mocks/Row.go @@ -348,7 +348,8 @@ func (_c *Row_WithStyle_Call) RunAndReturn(run func(*props.Cell) core.Row) *Row_ func NewRow(t interface { mock.TestingT Cleanup(func()) -}) *Row { +}, +) *Row { mock := &Row{} mock.Mock.Test(t) diff --git a/mocks/Text.go b/mocks/Text.go index 4d4681d1..781e9117 100644 --- a/mocks/Text.go +++ b/mocks/Text.go @@ -110,7 +110,8 @@ func (_c *Text_GetLinesQuantity_Call) RunAndReturn(run func(string, *props.Text, func NewText(t interface { mock.TestingT Cleanup(func()) -}) *Text { +}, +) *Text { mock := &Text{} mock.Mock.Test(t) diff --git a/pkg/processor/mappers/abstractfactory/abstractfactory.go b/pkg/processor/mappers/abstractfactory/abstractfactory.go index 9a88339f..5c887f61 100644 --- a/pkg/processor/mappers/abstractfactory/abstractfactory.go +++ b/pkg/processor/mappers/abstractfactory/abstractfactory.go @@ -24,12 +24,12 @@ func NewAbstractFactoryMaps(repository core.ProcessorRepository) *abstractFactor } // NewRow is responsible for wrapper the creation of a row -func (f *abstractFactoryMaps) NewRow(document interface{}, sourceKey string) (mappers.Componentmapper, error) { +func (f *abstractFactoryMaps) NewRow(document interface{}, sourceKey string) (mappers.OrderedComponents, error) { return rowmapper.NewRow(document, sourceKey, f) } // NewPage is responsible for wrapper the creation of a page -func (f *abstractFactoryMaps) NewPage(document interface{}, sourceKey string) (mappers.Componentmapper, error) { +func (f *abstractFactoryMaps) NewPage(document interface{}, sourceKey string) (mappers.OrderedComponents, error) { return pagemapper.NewPage(document, sourceKey, f) } @@ -41,7 +41,7 @@ func (f *abstractFactoryMaps) NewCol(document interface{}) (mappers.Componentmap // NewList is responsible for wrapper the creation of a list func (f *abstractFactoryMaps) NewList(document interface{}, sourceKey string, generate mappers.GenerateComponent, -) (mappers.Componentmapper, error) { +) (mappers.OrderedComponents, error) { return listmapper.NewList(document, sourceKey, generate) } diff --git a/pkg/processor/mappers/component_mapper.go b/pkg/processor/mappers/component_mapper.go index ae8993cc..0f887be3 100644 --- a/pkg/processor/mappers/component_mapper.go +++ b/pkg/processor/mappers/component_mapper.go @@ -6,7 +6,7 @@ import ( // GenerateComponent defines the signature of a factory method, it is used // to make it possible to send a factory method to another object -type GenerateComponent func(document interface{}, sourceKey string) (Componentmapper, error) +type GenerateComponent func(document interface{}, sourceKey string) (OrderedComponents, error) // The Component Mapper Interface defines the mapper component, the mapper component is responsible for // transforming the structured document into the pdf components @@ -14,13 +14,19 @@ type Componentmapper interface { Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ([]processorprovider.ProviderComponent, error) } +// The ordered component interface defines an component that needs to be ordered by parent component +type OrderedComponents interface { + Componentmapper + GetOrder() int +} + // The AbstractFactoryMaps interface defines the object responsible for wrapping the creation of components // it is used to ensure decoupling between components type AbstractFactoryMaps interface { - NewRow(document interface{}, sourceKey string) (Componentmapper, error) - NewPage(document interface{}, sourceKey string) (Componentmapper, error) + NewRow(document interface{}, sourceKey string) (OrderedComponents, error) + NewPage(document interface{}, sourceKey string) (OrderedComponents, error) NewCol(document interface{}) (Componentmapper, error) - NewList(document interface{}, sourceKey string, generate GenerateComponent) (Componentmapper, error) + NewList(document interface{}, sourceKey string, generate GenerateComponent) (OrderedComponents, error) NewBarcode(document interface{}) (Componentmapper, error) NewMatrixcode(document interface{}) (Componentmapper, error) NewQrcode(document interface{}) (Componentmapper, error) diff --git a/pkg/processor/mappers/components/listmapper/list.go b/pkg/processor/mappers/components/listmapper/list.go index a91e04ec..d314954c 100644 --- a/pkg/processor/mappers/components/listmapper/list.go +++ b/pkg/processor/mappers/components/listmapper/list.go @@ -12,7 +12,8 @@ import ( // It will repeat a component for each content sent in the generate method type List struct { SourceKey string - Templates []mappers.Componentmapper + Templates []mappers.OrderedComponents + order int } func NewList(list interface{}, sourceKey string, generate mappers.GenerateComponent) (*List, error) { @@ -21,29 +22,49 @@ func NewList(list interface{}, sourceKey string, generate mappers.GenerateCompon return nil, fmt.Errorf("ensure list can be converted to map[string] interface{}") } - components, err := createComponents(listMapper, generate) - if err != nil { + newList := List{SourceKey: sourceKey} + if err := newList.setListOrder(&listMapper, sourceKey); err != nil { + return nil, err + } + + if err := newList.setComponents(listMapper, generate); err != nil { return nil, err } - return &List{ - Templates: components, - SourceKey: sourceKey, - }, nil + return &newList, nil } -// createComponents is responsible for generating the list component. Components will be generated through the generate method -func createComponents(listMapper map[string]interface{}, generate mappers.GenerateComponent) ([]mappers.Componentmapper, error) { - components := make([]mappers.Componentmapper, len(listMapper)) - cont := 0 +// setComponents is responsible for generating the list component. Components will be generated through the generate method +func (l *List) setComponents(listMapper map[string]interface{}, generate mappers.GenerateComponent) error { + l.Templates = make([]mappers.OrderedComponents, len(listMapper)) + for templateName, template := range listMapper { component, err := generate(template, templateName) if err != nil { - return nil, err + return err + } + if err := l.addComponent(component); err != nil { + return err } - components[cont] = component - cont++ } - return components, nil + return nil +} + +// addComponent is responsible for validating and adding the component to the template +func (l *List) addComponent(component mappers.OrderedComponents) error { + order := component.GetOrder() + if component.GetOrder() > len(l.Templates) { + return fmt.Errorf("component order cannot be greater than %d, this is the number of components in the template", len(l.Templates)) + } + if l.Templates[order-1] != nil { + return fmt.Errorf("cannot create list template, component order cannot be repeated") + } + + l.Templates[order-1] = component + return nil +} + +func (l *List) GetOrder() int { + return l.order } // formatListContent is responsible for converting content into []map[string]interface{} @@ -106,3 +127,19 @@ func (l *List) Generate(content map[string]interface{}, provider processorprovid return newComponents, nil } + +// setListOrder is responsible for validating the component order and adding the order to the list +func (l *List) setListOrder(template *map[string]interface{}, sourceKey string) error { + order, ok := (*template)["order"] + if !ok { + return fmt.Errorf("could not find field order on list \"%s\"", sourceKey) + } + validOrder, ok := order.(float64) + if !ok || validOrder < 1 { + return fmt.Errorf("the order field passed on list \"%s\" is not valid", sourceKey) + } + + delete(*template, "order") + l.order = int(validOrder) + return nil +} diff --git a/pkg/processor/mappers/components/listmapper/list_test.go b/pkg/processor/mappers/components/listmapper/list_test.go index 1a5fd3f5..43b15b26 100644 --- a/pkg/processor/mappers/components/listmapper/list_test.go +++ b/pkg/processor/mappers/components/listmapper/list_test.go @@ -5,7 +5,6 @@ import ( "fmt" "testing" - "github.com/johnfercher/maroto/v2/internal/fixture" "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/listmapper" @@ -14,6 +13,19 @@ import ( "github.com/stretchr/testify/mock" ) +func TestGetOrder(t *testing.T) { + t.Run("when getOrder is called, should return defined order", func(t *testing.T) { + templateRows := map[string]interface{}{ + "order": 10.0, + } + factory := mocks.NewAbstractFactoryMaps(t) + + doc, _ := listmapper.NewList(templateRows, "test", factory.NewRow) + + assert.Equal(t, 10, doc.GetOrder()) + }) +} + func TestNewList(t *testing.T) { t.Run("when invalid interface is sent, it should return an error", func(t *testing.T) { var invalidInterface interface{} = 1 @@ -25,10 +37,67 @@ func TestNewList(t *testing.T) { assert.NotNil(t, err) }) + t.Run("when the component order is greater than the number of components, an error should be returned", func(t *testing.T) { + templateList := map[string]interface{}{ + "page_template_1": nil, + "order": 1.0, + } + + orderedComponent := mocks.NewOrderedComponents(t) + orderedComponent.EXPECT().GetOrder().Return(2) + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewPage", mock.Anything, "page_template_1").Return(orderedComponent, nil) + + _, err := listmapper.NewList(templateList, "test", factory.NewPage) + + assert.NotNil(t, err) + }) + + t.Run("when the template order is repeated, an error should be returned", func(t *testing.T) { + templateList := map[string]interface{}{ + "page_template_1": nil, + "page_template_2": nil, + "order": 1.0, + } + + orderedComponent := mocks.NewOrderedComponents(t) + orderedComponent.EXPECT().GetOrder().Return(2) + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewPage", mock.Anything, "page_template_1").Return(orderedComponent, nil) + factory.On("NewPage", mock.Anything, "page_template_2").Return(orderedComponent, nil) + + _, err := listmapper.NewList(templateList, "test", factory.NewPage) + + assert.NotNil(t, err) + }) + + t.Run("when 2 pages are submitted, should add the 2 pages in the correct order", func(t *testing.T) { + templatePages := map[string]interface{}{ + "page_template_2": nil, + "page_template_1": nil, + "order": 1.0, + } + orderedComponent1 := mocks.NewOrderedComponents(t) + orderedComponent1.EXPECT().GetOrder().Return(1) + orderedComponent2 := mocks.NewOrderedComponents(t) + orderedComponent2.EXPECT().GetOrder().Return(2) + + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewPage", mock.Anything, "page_template_1").Return(orderedComponent1, nil) + factory.On("NewPage", mock.Anything, "page_template_2").Return(orderedComponent2, nil) + + doc, err := listmapper.NewList(templatePages, "test", factory.NewPage) + + assert.Nil(t, err) + assert.Equal(t, len(doc.Templates), 2) + assert.Equal(t, orderedComponent1, doc.Templates[0]) + }) + t.Run("when component not can generate, it should return an error", func(t *testing.T) { templatePages := map[string]interface{}{ "page_template_1": nil, "page_template_2": nil, + "order": 1.0, } factory := mocks.NewAbstractFactoryMaps(t) @@ -39,15 +108,43 @@ func TestNewList(t *testing.T) { assert.NotNil(t, err) }) + t.Run("when the order field is not sent, should return an error", func(t *testing.T) { + templateRows := map[string]interface{}{ + "row_template_1": nil, + } + factory := mocks.NewAbstractFactoryMaps(t) + + _, err := listmapper.NewList(templateRows, "test", factory.NewRow) + + assert.NotNil(t, err) + }) + + t.Run("when the order field is less than 1, should return an error", func(t *testing.T) { + templateRows := map[string]interface{}{ + "row_template_1": nil, + "order": 0, + } + factory := mocks.NewAbstractFactoryMaps(t) + + _, err := listmapper.NewList(templateRows, "test", factory.NewRow) + + assert.NotNil(t, err) + }) + t.Run("when 2-components are sent, it should add 2 components in list", func(t *testing.T) { - validPage := fixture.MapperPage() templatePages := map[string]interface{}{ "page_template_1": nil, "page_template_2": nil, + "order": 1.0, } + orderedComponent1 := mocks.NewOrderedComponents(t) + orderedComponent1.EXPECT().GetOrder().Return(1) + orderedComponent2 := mocks.NewOrderedComponents(t) + orderedComponent2.EXPECT().GetOrder().Return(2) + factory := mocks.NewAbstractFactoryMaps(t) - factory.On("NewPage", mock.Anything, "page_template_1").Return(validPage, nil) - factory.On("NewPage", mock.Anything, "page_template_2").Return(validPage, nil) + factory.On("NewPage", mock.Anything, "page_template_1").Return(orderedComponent1, nil) + factory.On("NewPage", mock.Anything, "page_template_2").Return(orderedComponent2, nil) doc, err := listmapper.NewList(templatePages, "test", factory.NewPage) @@ -60,7 +157,7 @@ func TestGenerate(t *testing.T) { t.Run("when source_key is not found, should return an error", func(t *testing.T) { provider := mocks.NewProcessorProvider(t) content := map[string]interface{}{} - list := listmapper.List{SourceKey: "list", Templates: make([]mappers.Componentmapper, 0)} + list := listmapper.List{SourceKey: "list", Templates: make([]mappers.OrderedComponents, 0)} components, err := list.Generate(content, provider) @@ -70,7 +167,7 @@ func TestGenerate(t *testing.T) { t.Run("when invalid content is sent, should return an error", func(t *testing.T) { provider := mocks.NewProcessorProvider(t) content := map[string]interface{}{"list": 1} - list := listmapper.List{SourceKey: "list", Templates: make([]mappers.Componentmapper, 0)} + list := listmapper.List{SourceKey: "list", Templates: make([]mappers.OrderedComponents, 0)} components, err := list.Generate(content, provider) @@ -82,10 +179,10 @@ func TestGenerate(t *testing.T) { contentRow1 := map[string]interface{}{"row_1": nil} listContent := map[string]interface{}{"list": []interface{}{contentRow1}} provider := mocks.NewProcessorProvider(t) - component := mocks.NewComponentmapper(t) + component := mocks.NewOrderedComponents(t) component.EXPECT().Generate(mock.Anything, provider).Return(nil, fmt.Errorf("any")) - list := listmapper.List{SourceKey: "list", Templates: []mappers.Componentmapper{component}} + list := listmapper.List{SourceKey: "list", Templates: []mappers.OrderedComponents{component}} components, err := list.Generate(listContent, provider) assert.Nil(t, components) @@ -98,10 +195,10 @@ func TestGenerate(t *testing.T) { listContent := map[string]interface{}{"list": []interface{}{content1, content2}} provider := mocks.NewProcessorProvider(t) providerComponent := mocks.NewProviderComponent(t) - component := mocks.NewComponentmapper(t) + component := mocks.NewOrderedComponents(t) component.EXPECT().Generate(mock.Anything, provider).Return([]processorprovider.ProviderComponent{providerComponent}, nil) - list := listmapper.List{SourceKey: "list", Templates: []mappers.Componentmapper{component, component}} + list := listmapper.List{SourceKey: "list", Templates: []mappers.OrderedComponents{component, component}} components, err := list.Generate(listContent, provider) assert.NotNil(t, components) diff --git a/pkg/processor/mappers/components/pagemapper/page.go b/pkg/processor/mappers/components/pagemapper/page.go index 2c710116..2356f388 100644 --- a/pkg/processor/mappers/components/pagemapper/page.go +++ b/pkg/processor/mappers/components/pagemapper/page.go @@ -11,16 +11,18 @@ import ( type Page struct { SourceKey string - Rows []mappers.Componentmapper + Rows []mappers.OrderedComponents Factory mappers.AbstractFactoryMaps + order int } -func NewPage(rows interface{}, sourceKey string, factory mappers.AbstractFactoryMaps) (*Page, error) { +// NewPage is responsible for create an template page +func NewPage(templatePage interface{}, sourceKey string, factory mappers.AbstractFactoryMaps) (*Page, error) { newPage := &Page{ SourceKey: sourceKey, Factory: factory, } - if err := newPage.setRows(rows); err != nil { + if err := newPage.setRows(templatePage); err != nil { return nil, err } @@ -34,23 +36,64 @@ func (p *Page) setRows(rowsDoc interface{}) error { if !ok { return fmt.Errorf("could not parse template, ensure rows can be converted to map[string] interface{}") } + err := p.setPageOrder(&templateRows) + if err != nil { + return err + } + p.Rows = make([]mappers.OrderedComponents, len(templateRows)) for templateName, template := range templateRows { - var rows mappers.Componentmapper - var err error + var row mappers.OrderedComponents if strings.HasPrefix(templateName, "list") { - rows, err = p.Factory.NewList(template, templateName, p.Factory.NewRow) + row, err = p.Factory.NewList(template, templateName, p.Factory.NewRow) } else { - rows, err = p.Factory.NewRow(template, templateName) + row, err = p.Factory.NewRow(template, templateName) } if err != nil { return err } - p.Rows = append(p.Rows, rows) + + if err := p.addComponent(row); err != nil { + return err + } + } + return nil +} + +// addPage is responsible for validating and adding the page to the template +func (p *Page) addComponent(row mappers.OrderedComponents) error { + order := row.GetOrder() + if order > len(p.Rows) { + return fmt.Errorf("component order cannot be greater than %d, this is the number of components in the template", len(p.Rows)) + } + if p.Rows[order-1] != nil { + return fmt.Errorf("cannot create page template, component order cannot be repeated") + } + + p.Rows[order-1] = row + return nil +} + +// GetOrder is responsible for returning the component's defined order +func (p *Page) GetOrder() int { + return p.order +} + +// setPageOrder is responsible for validating the component order and adding the order to the page +func (p *Page) setPageOrder(template *map[string]interface{}) error { + order, ok := (*template)["order"] + if !ok { + return fmt.Errorf("could not find field order on page \"%s\"", p.SourceKey) + } + validOrder, ok := order.(float64) + if !ok || validOrder < 1 { + return fmt.Errorf("the order field passed on page \"%s\" is not valid", p.SourceKey) } + p.order = int(validOrder) + delete(*template, "order") return nil } @@ -68,6 +111,7 @@ func (p *Page) getPageContent(content map[string]interface{}) (map[string]interf ) } +// Generate is responsible for computing the page component with shipping data func (p *Page) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( []processorprovider.ProviderComponent, error, ) { diff --git a/pkg/processor/mappers/components/pagemapper/page_test.go b/pkg/processor/mappers/components/pagemapper/page_test.go index b71a4722..2ca13141 100644 --- a/pkg/processor/mappers/components/pagemapper/page_test.go +++ b/pkg/processor/mappers/components/pagemapper/page_test.go @@ -4,17 +4,84 @@ import ( "fmt" "testing" - "github.com/johnfercher/maroto/v2/internal/fixture" "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/listmapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/pagemapper" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/rowmapper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) +func TestGetOrder(t *testing.T) { + t.Run("when getOrder is called, should return defined order", func(t *testing.T) { + templateRows := map[string]interface{}{ + "order": 10.0, + } + doc, _ := pagemapper.NewPage(templateRows, "test", mocks.NewAbstractFactoryMaps(t)) + + assert.Equal(t, 10, doc.GetOrder()) + }) +} + func TestNewPage(t *testing.T) { + + t.Run("when the component order is greater than the number of components, an error should be returned", func(t *testing.T) { + templateRows := map[string]interface{}{ + "row_template_1": nil, + "order": 1.0, + } + + orderedComponent := mocks.NewOrderedComponents(t) + orderedComponent.EXPECT().GetOrder().Return(2) + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewRow", mock.Anything, "row_template_1").Return(orderedComponent, nil) + + _, err := pagemapper.NewPage(templateRows, "test", factory) + + assert.NotNil(t, err) + }) + + t.Run("when the template order is repeated, an error should be returned", func(t *testing.T) { + templateRows := map[string]interface{}{ + "row_template_1": nil, + "row_template_2": nil, + "order": 1.0, + } + + orderedComponent := mocks.NewOrderedComponents(t) + orderedComponent.EXPECT().GetOrder().Return(1) + + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewRow", mock.Anything, "row_template_1").Return(orderedComponent, nil) + factory.On("NewRow", mock.Anything, "row_template_2").Return(orderedComponent, nil) + + _, err := pagemapper.NewPage(templateRows, "test", factory) + + assert.NotNil(t, err) + }) + + t.Run("when 2 rows are submitted, should add the 2 rows in the correct order", func(t *testing.T) { + templateRows := map[string]interface{}{ + "row_template_2": nil, + "row_template_1": nil, + "order": 1.0, + } + + orderedComponent1 := mocks.NewOrderedComponents(t) + orderedComponent1.EXPECT().GetOrder().Return(1) + orderedComponent2 := mocks.NewOrderedComponents(t) + orderedComponent2.EXPECT().GetOrder().Return(2) + + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewRow", mock.Anything, "row_template_1").Return(orderedComponent1, nil) + factory.On("NewRow", mock.Anything, "row_template_2").Return(orderedComponent2, nil) + + doc, err := pagemapper.NewPage(templateRows, "test", factory) + + assert.Nil(t, err) + assert.Equal(t, len(doc.Rows), 2) + assert.Equal(t, orderedComponent1, doc.Rows[0]) + }) + t.Run("When an invalid field is submitted, should return an error", func(t *testing.T) { var invalidInterface interface{} = 1 factory := mocks.NewAbstractFactoryMaps(t) @@ -29,34 +96,62 @@ func TestNewPage(t *testing.T) { templateRows := map[string]interface{}{ "row_template_1": nil, "row_template_2": nil, + "order": 1.0, } - validRow := fixture.MapperRow() + orderedComponent1 := mocks.NewOrderedComponents(t) + orderedComponent1.EXPECT().GetOrder().Return(1) + orderedComponent2 := mocks.NewOrderedComponents(t) + orderedComponent2.EXPECT().GetOrder().Return(2) + factory := mocks.NewAbstractFactoryMaps(t) - factory.On("NewRow", mock.Anything, "row_template_1").Return(validRow, nil) - factory.On("NewRow", mock.Anything, "row_template_2").Return(validRow, nil) + factory.On("NewRow", mock.Anything, "row_template_1").Return(orderedComponent1, nil) + factory.On("NewRow", mock.Anything, "row_template_2").Return(orderedComponent2, nil) doc, err := pagemapper.NewPage(templateRows, "test", factory) assert.Nil(t, err) assert.Equal(t, 2, len(doc.Rows)) - assert.IsType(t, &rowmapper.Row{}, doc.Rows[0]) }) t.Run("when 1 list is sent, it should add 1 list to the document", func(t *testing.T) { templateRows := map[string]interface{}{ "list_rows_1": nil, + "order": 1.0, } - validPage := fixture.MapperList() + orderedComponent1 := mocks.NewOrderedComponents(t) + orderedComponent1.EXPECT().GetOrder().Return(1) factory := mocks.NewAbstractFactoryMaps(t) - factory.On("NewList", mock.Anything, "list_rows_1", mock.Anything).Return(validPage, nil) + factory.On("NewList", mock.Anything, "list_rows_1", mock.Anything).Return(orderedComponent1, nil) doc, err := pagemapper.NewPage(templateRows, "test", factory) assert.Nil(t, err) assert.Equal(t, len(doc.Rows), 1) - assert.IsType(t, &listmapper.List{}, doc.Rows[0]) + }) + + t.Run("when the order field is not sent, should return an error", func(t *testing.T) { + templateRows := map[string]interface{}{ + "row_template_1": nil, + } + factory := mocks.NewAbstractFactoryMaps(t) + + _, err := pagemapper.NewPage(templateRows, "test", factory) + + assert.NotNil(t, err) + }) + + t.Run("when the order field is less than 1, should return an error", func(t *testing.T) { + templateRows := map[string]interface{}{ + "row_template_1": nil, + "order": 0, + } + factory := mocks.NewAbstractFactoryMaps(t) + + _, err := pagemapper.NewPage(templateRows, "test", factory) + + assert.NotNil(t, err) }) } @@ -66,7 +161,7 @@ func TestGenerate(t *testing.T) { factory := mocks.NewAbstractFactoryMaps(t) provider := mocks.NewProcessorProvider(t) - page := pagemapper.Page{Rows: make([]mappers.Componentmapper, 0), Factory: factory, SourceKey: "test"} + page := pagemapper.Page{Rows: make([]mappers.OrderedComponents, 0), Factory: factory, SourceKey: "test"} newPage, err := page.Generate(content, provider) assert.NotNil(t, err) @@ -78,7 +173,7 @@ func TestGenerate(t *testing.T) { provider := mocks.NewProcessorProvider(t) provider.EXPECT().CreatePage().Return(nil, nil) - page := pagemapper.Page{Rows: make([]mappers.Componentmapper, 0), Factory: factory, SourceKey: "content"} + page := pagemapper.Page{Rows: make([]mappers.OrderedComponents, 0), Factory: factory, SourceKey: "content"} _, err := page.Generate(content, provider) assert.Nil(t, err) @@ -87,10 +182,10 @@ func TestGenerate(t *testing.T) { content := map[string]interface{}{"content": map[string]interface{}{"text": "value"}} factory := mocks.NewAbstractFactoryMaps(t) provider := mocks.NewProcessorProvider(t) - component := mocks.NewComponentmapper(t) + component := mocks.NewOrderedComponents(t) component.EXPECT().Generate(mock.Anything, provider).Return(nil, fmt.Errorf("any")) - page := pagemapper.Page{Rows: []mappers.Componentmapper{component}, Factory: factory, SourceKey: "content"} + page := pagemapper.Page{Rows: []mappers.OrderedComponents{component}, Factory: factory, SourceKey: "content"} _, err := page.Generate(content, provider) assert.NotNil(t, err) @@ -101,7 +196,7 @@ func TestGenerate(t *testing.T) { provider := mocks.NewProcessorProvider(t) provider.EXPECT().CreatePage().Return(nil, fmt.Errorf("any")) - page := pagemapper.Page{Rows: make([]mappers.Componentmapper, 0), Factory: factory, SourceKey: "content"} + page := pagemapper.Page{Rows: make([]mappers.OrderedComponents, 0), Factory: factory, SourceKey: "content"} _, err := page.Generate(content, provider) assert.NotNil(t, err) diff --git a/pkg/processor/mappers/components/rowmapper/row.go b/pkg/processor/mappers/components/rowmapper/row.go index 6c371996..68999fa6 100644 --- a/pkg/processor/mappers/components/rowmapper/row.go +++ b/pkg/processor/mappers/components/rowmapper/row.go @@ -13,6 +13,7 @@ type Row struct { Cols []mappers.Componentmapper Factory mappers.AbstractFactoryMaps SourceKey string + order int } func NewRow(templateRows interface{}, sourceKey string, factory mappers.AbstractFactoryMaps) (*Row, error) { @@ -27,6 +28,10 @@ func NewRow(templateRows interface{}, sourceKey string, factory mappers.Abstract SourceKey: sourceKey, } + if err := row.setComponentOrder(&mapRows); err != nil { + return nil, err + } + err := row.addComponents(mapRows) if err != nil { return nil, err @@ -34,6 +39,29 @@ func NewRow(templateRows interface{}, sourceKey string, factory mappers.Abstract return row, nil } +func (r *Row) GetOrder() int { + return r.order +} + +// setPageOrder is responsible for validating the component order and adding the order to the page +func (r *Row) setComponentOrder(template *map[string]interface{}) error { + order, ok := (*template)["order"] + if !ok { + return fmt.Errorf("could not find field order on page \"%s\"", r.SourceKey) + } + validOrder, ok := order.(float64) + if !ok { + return fmt.Errorf("the order field passed on row \"%s\" is not valid", r.SourceKey) + } + if validOrder < 1 { + return fmt.Errorf("the order field in \"%s\" must be greater than 0", r.SourceKey) + } + + r.order = int(validOrder) + delete(*template, "order") + return nil +} + // addComponents is responsible for adding the row components according to // the properties informed in the map func (r *Row) addComponents(mapRows map[string]interface{}) error { diff --git a/pkg/processor/mappers/components/rowmapper/row_test.go b/pkg/processor/mappers/components/rowmapper/row_test.go index 9192cfa6..1b7d6509 100644 --- a/pkg/processor/mappers/components/rowmapper/row_test.go +++ b/pkg/processor/mappers/components/rowmapper/row_test.go @@ -6,11 +6,25 @@ import ( "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/listmapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/rowmapper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) +func TestGetOrder(t *testing.T) { + t.Run("when getOrder is called, should return defined order", func(t *testing.T) { + templateRows := map[string]interface{}{ + "order": 10.0, + } + factory := mocks.NewAbstractFactoryMaps(t) + + doc, _ := rowmapper.NewRow(templateRows, "test", factory) + + assert.Equal(t, 10, doc.GetOrder()) + }) +} + func TestNewRow(t *testing.T) { t.Run("when invalid interface is sent, should return an error", func(t *testing.T) { factory := mocks.NewAbstractFactoryMaps(t) @@ -23,7 +37,9 @@ func TestNewRow(t *testing.T) { }) t.Run("when row height is not sent, should set height to 0", func(t *testing.T) { factory := mocks.NewAbstractFactoryMaps(t) - var templateRow map[string]interface{} + templateRow := map[string]interface{}{ + "order": 1.0, + } doc, err := rowmapper.NewRow(templateRow, "", factory) @@ -63,6 +79,28 @@ func TestNewRow(t *testing.T) { assert.Nil(t, doc) assert.NotNil(t, err) }) + + t.Run("when the order field is not sent, should return an error", func(t *testing.T) { + templateRows := map[string]interface{}{ + "row_template_1": nil, + } + factory := mocks.NewAbstractFactoryMaps(t) + + _, err := listmapper.NewList(templateRows, "test", factory.NewRow) + + assert.NotNil(t, err) + }) + t.Run("when the order field is less than 1, should return an error", func(t *testing.T) { + templateRows := map[string]interface{}{ + "row_template_1": nil, + "order": 0.0, + } + factory := mocks.NewAbstractFactoryMaps(t) + + _, err := listmapper.NewList(templateRows, "test", factory.NewRow) + + assert.NotNil(t, err) + }) } func TestGenerate(t *testing.T) { diff --git a/pkg/processor/mappers/documentmapper/document.go b/pkg/processor/mappers/documentmapper/document.go index eb61213b..909a028c 100644 --- a/pkg/processor/mappers/documentmapper/document.go +++ b/pkg/processor/mappers/documentmapper/document.go @@ -118,25 +118,51 @@ func (d *Document) setPages(pagesDoc interface{}) error { return fmt.Errorf("ensure pages can be converted to map[string] interface{}") } + d.Pages = make([]mappers.Componentmapper, len(templatePage)) for templateName, template := range templatePage { - var page mappers.Componentmapper - var err error - - if strings.HasPrefix(templateName, "list") { - page, err = d.factory.NewList(template, templateName, d.factory.NewPage) - } else { - page, err = d.factory.NewPage(template, templateName) - } - + page, err := d.factoryPage(template, templateName) if err != nil { return err } - d.Pages = append(d.Pages, page) + if err := d.addPage(page); err != nil { + return err + } } return nil } +// addPage is responsible for validating and adding the page to the template +func (d *Document) addPage(page mappers.OrderedComponents) error { + order := page.GetOrder() + if page.GetOrder() > len(d.Pages) { + return fmt.Errorf("component order cannot be greater than %d, this is the number of components in the template", len(d.Pages)) + } + if d.Pages[order-1] != nil { + return fmt.Errorf("cannot create document template, component order cannot be repeated") + } + + d.Pages[order-1] = page + return nil +} + +// factoryPage is responsible for making a template of a page or a list of pages +func (d *Document) factoryPage(template interface{}, templateName string) (mappers.OrderedComponents, error) { + var page mappers.OrderedComponents + var err error + + if strings.HasPrefix(templateName, "list") { + page, err = d.factory.NewList(template, templateName, d.factory.NewPage) + } else { + page, err = d.factory.NewPage(template, templateName) + } + + if err != nil { + return nil, err + } + return page, nil +} + func (d *Document) GetBuilderCfg() *buildermapper.Builder { return &d.Builder } diff --git a/pkg/processor/mappers/documentmapper/document_test.go b/pkg/processor/mappers/documentmapper/document_test.go index e86d6006..89511af9 100644 --- a/pkg/processor/mappers/documentmapper/document_test.go +++ b/pkg/processor/mappers/documentmapper/document_test.go @@ -8,8 +8,6 @@ import ( "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/processor/deserializer" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/listmapper" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/pagemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/documentmapper" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" "github.com/stretchr/testify/assert" @@ -109,6 +107,65 @@ func TestNewPdf(t *testing.T) { assert.NotNil(t, err) }) + t.Run("when the template order is greater than the number of pages, an error should be returned", func(t *testing.T) { + builderDocument := `{"pages": {"page_template_1":{}}}` + orderedComponent := mocks.NewOrderedComponents(t) + orderedComponent.EXPECT().GetOrder().Return(2) + + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewPage", mock.Anything, "page_template_1").Return(orderedComponent, nil) + + template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) + assert.Nil(t, err) + + _, err = documentmapper.NewPdf(template, factory) + + assert.NotNil(t, err) + }) + + t.Run("when the template order is repeated, an error should be returned", func(t *testing.T) { + builderDocument := `{"pages": {"page_template_2":{}, "page_template_1":{}}}` + orderedComponent := mocks.NewOrderedComponents(t) + orderedComponent.EXPECT().GetOrder().Return(2) + + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewPage", mock.Anything, "page_template_1").Return(orderedComponent, nil) + factory.On("NewPage", mock.Anything, "page_template_2").Return(orderedComponent, nil) + + template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) + assert.Nil(t, err) + + _, err = documentmapper.NewPdf(template, factory) + + assert.NotNil(t, err) + }) + + t.Run("when 2 pages are submitted, should add the 2 pages in the correct order", func(t *testing.T) { + builderDocument := ` + {"pages": { + "page_template_1":{}, + "page_template_2":{} + }} + ` + orderedComponent1 := mocks.NewOrderedComponents(t) + orderedComponent1.EXPECT().GetOrder().Return(1) + orderedComponent2 := mocks.NewOrderedComponents(t) + orderedComponent2.EXPECT().GetOrder().Return(2) + + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewPage", mock.Anything, "page_template_1").Return(orderedComponent1, nil) + factory.On("NewPage", mock.Anything, "page_template_2").Return(orderedComponent2, nil) + + template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) + assert.Nil(t, err) + + doc, err := documentmapper.NewPdf(template, factory) + + assert.Nil(t, err) + assert.Equal(t, len(doc.Pages), 2) + assert.Equal(t, orderedComponent1, doc.Pages[0]) + }) + t.Run("when 2 pages are sent, it should add 2 pages to the document", func(t *testing.T) { builderDocument := ` {"pages": { @@ -116,10 +173,14 @@ func TestNewPdf(t *testing.T) { "page_template_2":{} }} ` - validPage := fixture.MapperPage() + orderedComponent1 := mocks.NewOrderedComponents(t) + orderedComponent1.EXPECT().GetOrder().Return(1) + orderedComponent2 := mocks.NewOrderedComponents(t) + orderedComponent2.EXPECT().GetOrder().Return(2) + factory := mocks.NewAbstractFactoryMaps(t) - factory.On("NewPage", mock.Anything, "page_template_1").Return(validPage, nil) - factory.On("NewPage", mock.Anything, "page_template_2").Return(validPage, nil) + factory.On("NewPage", mock.Anything, "page_template_1").Return(orderedComponent1, nil) + factory.On("NewPage", mock.Anything, "page_template_2").Return(orderedComponent2, nil) template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) @@ -128,7 +189,6 @@ func TestNewPdf(t *testing.T) { assert.Nil(t, err) assert.Equal(t, len(doc.Pages), 2) - assert.IsType(t, &pagemapper.Page{}, doc.Pages[0]) }) t.Run("when 1 list is sent, it should add 1 list to the document", func(t *testing.T) { @@ -137,9 +197,11 @@ func TestNewPdf(t *testing.T) { "list_template_1":{} }} ` - validPage := fixture.MapperList() + orderedComponent1 := mocks.NewOrderedComponents(t) + orderedComponent1.EXPECT().GetOrder().Return(1) + factory := mocks.NewAbstractFactoryMaps(t) - factory.On("NewList", mock.Anything, "list_template_1", mock.Anything).Return(validPage, nil) + factory.On("NewList", mock.Anything, "list_template_1", mock.Anything).Return(orderedComponent1, nil) template, err := deserializer.NewJSONDeserializer().Deserialize(builderDocument) assert.Nil(t, err) @@ -148,7 +210,6 @@ func TestNewPdf(t *testing.T) { assert.Nil(t, err) assert.Equal(t, len(doc.Pages), 1) - assert.IsType(t, &listmapper.List{}, doc.Pages[0]) }) t.Run("when an invalid page is sent, it should return an error", func(t *testing.T) { diff --git a/test/maroto/processor/json/add_page_template.json b/test/maroto/processor/json/add_page_template.json index 4e3926d9..30c86792 100644 --- a/test/maroto/processor/json/add_page_template.json +++ b/test/maroto/processor/json/add_page_template.json @@ -5,8 +5,11 @@ }, "pages": { "template_page_1": { + "order": 1, "list_rows": { + "order": 1, "row_1": { + "order": 1, "height": 30, "cols": [ { @@ -19,8 +22,11 @@ } }, "list_pages": { + "order":2, "template_page_2": { + "order": 1, "row_1": { + "order": 1, "height": 10, "cols": [ { diff --git a/test/maroto/processor/json/simple_pdf_templates.json b/test/maroto/processor/json/simple_pdf_templates.json index 8933ea70..becc029f 100644 --- a/test/maroto/processor/json/simple_pdf_templates.json +++ b/test/maroto/processor/json/simple_pdf_templates.json @@ -1,6 +1,7 @@ { "header": { "row_header": { + "order": 1, "cols": [ { "text": { @@ -13,6 +14,7 @@ }, "footer": { "row_footer": { + "order": 1, "cols": [ { "text": { @@ -25,7 +27,9 @@ }, "pages": { "page_template_1": { + "order": 1, "row_1": { + "order": 1, "cols": [ { "text": { @@ -42,7 +46,9 @@ ] }, "list_row_1": { + "order": 2, "row": { + "order": 1, "cols": [ { "text": { @@ -53,6 +59,7 @@ ] }, "row_1": { + "order": 2, "cols": [ { "text": { From 80cfbeb1c40ae28a293f413606f5e21018871232 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 25 Dec 2024 12:02:11 -0300 Subject: [PATCH 084/116] fix: load image dimensions in test set working directory in test to ensure images can be loaded --- docs/assets/examples/autorow/v2/main_test.go | 2 ++ pkg/test/test.go | 17 +++++++++++++++++ pkg/test/test_test.go | 10 ++++++++++ test/maroto/examples/autorow.json | 4 ++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/assets/examples/autorow/v2/main_test.go b/docs/assets/examples/autorow/v2/main_test.go index 793c4452..baf88dcd 100644 --- a/docs/assets/examples/autorow/v2/main_test.go +++ b/docs/assets/examples/autorow/v2/main_test.go @@ -7,6 +7,8 @@ import ( ) func TestGetMaroto(t *testing.T) { + test.SetupTestDir(t) + // Act sut := GetMaroto() diff --git a/pkg/test/test.go b/pkg/test/test.go index 7ab68db2..aa1cc590 100644 --- a/pkg/test/test.go +++ b/pkg/test/test.go @@ -10,6 +10,7 @@ import ( "github.com/johnfercher/go-tree/node" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" "github.com/johnfercher/maroto/v2/pkg/core" @@ -34,6 +35,22 @@ type MarotoTest struct { node *node.Node[core.Structure] } +// SetupTestDir sets the directory where the test will be built +// after the test is finished, the original directory will be set +func SetupTestDir(t *testing.T) { + New(t) + originalDir, err := os.Getwd() + require.NoError(t, err) + + err = os.Chdir(configSingleton.AbsolutePath) + require.NoError(t, err) + + defer t.Cleanup(func() { + err := os.Chdir(originalDir) + require.NoError(t, err) + }) +} + // New creates the MarotoTest instance to unit tests. func New(t *testing.T) *MarotoTest { if configSingleton == nil { diff --git a/pkg/test/test_test.go b/pkg/test/test_test.go index c929193a..56e4a6ad 100644 --- a/pkg/test/test_test.go +++ b/pkg/test/test_test.go @@ -14,6 +14,16 @@ const ( file = "maroto_test.json" ) +func TestSetupTestDir(t *testing.T) { + t.Run("when directory is setup correctly, it should load maroto.yml", func(t *testing.T) { + SetupTestDir(t) + + _, err := os.Open(".maroto.yml") + + assert.Nil(t, err) + }) +} + func TestNew(t *testing.T) { t.Run("when called first, should setup singleton and set t", func(t *testing.T) { // Act diff --git a/test/maroto/examples/autorow.json b/test/maroto/examples/autorow.json index ca067061..8d87a4a1 100755 --- a/test/maroto/examples/autorow.json +++ b/test/maroto/examples/autorow.json @@ -21,7 +21,7 @@ "type": "page", "nodes": [ { - "value": 38.80555555555556, + "value": 62.36222222222222, "type": "row", "nodes": [ { @@ -203,7 +203,7 @@ ] }, { - "value": 49.541944444444454, + "value": 25.98527777777778, "type": "row", "nodes": [ { From fd79aaa093cbfa9df3077880a88872b22ff583b2 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 25 Dec 2024 12:05:13 -0300 Subject: [PATCH 085/116] test: validate autorow example build --- pkg/processor/processor_test.go | 33 +++++++------------ pkg/processor/processorprovider/Maroto.go | 7 ++-- .../processor/json/auto_row_template.json | 6 ++++ 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index d202d2cd..d8d4a1d9 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -1,7 +1,6 @@ package processor_test import ( - "os" "testing" "github.com/johnfercher/maroto/v2/pkg/processor" @@ -14,19 +13,6 @@ import ( "github.com/stretchr/testify/require" ) -func setupTestDir(t *testing.T) { - originalDir, err := os.Getwd() - require.NoError(t, err) - - err = os.Chdir("../../") - require.NoError(t, err) - - t.Cleanup(func() { - err := os.Chdir(originalDir) - require.NoError(t, err) - }) -} - func TestRegisterTemplate(t *testing.T) { t.Run("when template is recorded, should no return error", func(t *testing.T) { }) @@ -40,9 +26,10 @@ func TestGenerateTemplate(t *testing.T) { t.Run("when valid template is found, should return valid pdf", func(t *testing.T) { fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/simple_pdf_templates.json") fixContent, _ := processortest.NewFileReader().LoadFile("processor/json/simple_pdf_content.json") - processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) - processor.RegisterTemplate("simple_pdf", string(fixtemplate)) + err := processor.RegisterTemplate("simple_pdf", string(fixtemplate)) + require.NoError(t, err) + provider, err := processor.GenerateDocument("simple_pdf", string(fixContent)) assert.Nil(t, err) @@ -52,9 +39,10 @@ func TestGenerateTemplate(t *testing.T) { t.Run("when template with Addpage is found, should set template", func(t *testing.T) { fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/add_page_template.json") fixContent, _ := processortest.NewFileReader().LoadFile("processor/json/add_page_content.json") - processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) - processor.RegisterTemplate("add_page", string(fixtemplate)) + err := processor.RegisterTemplate("add_page", string(fixtemplate)) + require.NoError(t, err) + provider, err := processor.GenerateDocument("add_page", string(fixContent)) assert.Nil(t, err) @@ -62,19 +50,20 @@ func TestGenerateTemplate(t *testing.T) { }) t.Run("when template with AutoRow is found, should set template", func(t *testing.T) { - setupTestDir(t) + test.SetupTestDir(t) + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/auto_row_template.json") fixContent, _ := processortest.NewFileReader().LoadFile("processor/json/auto_row_content.json") - processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) - processor.RegisterTemplate("auto_row", string(fixtemplate)) + err := processor.RegisterTemplate("auto_row", string(fixtemplate)) + require.NoError(t, err) + provider, err := processor.GenerateDocument("auto_row", string(fixContent)) assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/autorow.json") }) t.Run("when sent template is not found, should reuturn an error", func(t *testing.T) { - }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index 25b38ed8..b0433914 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -117,8 +117,11 @@ func (m *Maroto) CreateRow(height float64, components ...ProviderComponent) (Pro if err != nil { return nil, err } - - return row.New(height).Add(newComponents...), nil + if height > 0 { + return row.New(height).Add(newComponents...), nil + } else { + return row.New().Add(newComponents...), nil + } } func (m *Maroto) CreateCol(size int, components ...ProviderComponent) (ProviderComponent, error) { diff --git a/test/maroto/processor/json/auto_row_template.json b/test/maroto/processor/json/auto_row_template.json index 9e22b717..8539ae29 100644 --- a/test/maroto/processor/json/auto_row_template.json +++ b/test/maroto/processor/json/auto_row_template.json @@ -4,7 +4,9 @@ }, "pages": { "page_template": { + "order": 1, "row_with_larger_image": { + "order": 1, "cols": [ { "image": { @@ -21,6 +23,7 @@ ] }, "row_with_image_and_text_same": { + "order": 2, "cols": [ { "image": { @@ -40,6 +43,7 @@ ] }, "row_barcode": { + "order": 3, "cols": [ { "bar_code": { @@ -56,6 +60,7 @@ ] }, "row_matrixcode": { + "order": 4, "cols": [ { "matrix_code": { @@ -72,6 +77,7 @@ ] }, "row_qrcode": { + "order": 5, "cols": [ { "qr_code": { From 0f309416fad2fefc86a48d2ff59d971092d7effc Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 26 Dec 2024 12:24:14 -0300 Subject: [PATCH 086/116] test: validate background example build --- .../mappers/components/imagemapper/image.go | 18 +++--- .../mappers/components/rowmapper/row.go | 6 +- pkg/processor/processor_test.go | 18 +++++- .../processor/json/background_content.json | 41 ++++++++++++ .../processor/json/background_template.json | 64 +++++++++++++++++++ 5 files changed, 133 insertions(+), 14 deletions(-) create mode 100644 test/maroto/processor/json/background_content.json create mode 100644 test/maroto/processor/json/background_template.json diff --git a/pkg/processor/mappers/components/imagemapper/image.go b/pkg/processor/mappers/components/imagemapper/image.go index c22a34b5..923728f0 100644 --- a/pkg/processor/mappers/components/imagemapper/image.go +++ b/pkg/processor/mappers/components/imagemapper/image.go @@ -9,7 +9,7 @@ import ( ) type Image struct { - Path string + Value string SourceKey string Props *propsmapper.Rect } @@ -24,7 +24,7 @@ func NewImage(templateImage interface{}) (*Image, error) { if err := image.addFields(imageMap); err != nil { return nil, err } - if image.SourceKey == "" { + if image.SourceKey == "" && image.Value == "" { return nil, fmt.Errorf("no value passed for image. Add the 'source_key' or a path") } @@ -55,7 +55,7 @@ func (i *Image) getFieldMappers() map[string]func(interface{}) error { return map[string]func(interface{}) error{ "source_key": i.setSourceKey, "props": i.setProps, - "path": i.setPath, + "value": i.setPath, } } @@ -73,7 +73,7 @@ func (i *Image) setPath(template interface{}) error { if !ok { return fmt.Errorf("path cannot be converted to a string") } - i.Path = path + i.Value = path return nil } @@ -87,8 +87,8 @@ func (i *Image) setProps(template interface{}) error { } func (i *Image) getImagePath(content map[string]interface{}) (string, error) { - if i.Path != "" { - return i.Path, nil + if i.Value != "" { + return i.Value, nil } imageFound, ok := content[i.SourceKey] if !ok { @@ -105,16 +105,16 @@ func (i *Image) Generate(content map[string]interface{}, provider processorprovi []processorprovider.ProviderComponent, error, ) { var err error - i.Path, err = i.getImagePath(content) + i.Value, err = i.getImagePath(content) if err != nil { return nil, err } var img processorprovider.ProviderComponent if i.Props != nil { - img, err = provider.CreateImage(i.Path, i.Props) + img, err = provider.CreateImage(i.Value, i.Props) } else { - img, err = provider.CreateImage(i.Path) + img, err = provider.CreateImage(i.Value) } return []processorprovider.ProviderComponent{img}, err diff --git a/pkg/processor/mappers/components/rowmapper/row.go b/pkg/processor/mappers/components/rowmapper/row.go index 68999fa6..3b437256 100644 --- a/pkg/processor/mappers/components/rowmapper/row.go +++ b/pkg/processor/mappers/components/rowmapper/row.go @@ -83,7 +83,7 @@ func (r *Row) addComponents(mapRows map[string]interface{}) error { func (r *Row) setHeight(template interface{}) error { height, ok := template.(float64) if !ok { - return fmt.Errorf("could not parse template, ensure that height can be converted to float64") + return fmt.Errorf("could not parse \"%s\" template, ensure that height can be converted to float64", r.SourceKey) } r.Height = height return nil @@ -92,7 +92,7 @@ func (r *Row) setHeight(template interface{}) error { func (r *Row) setCols(template interface{}) error { cols, ok := template.([]interface{}) if !ok { - return fmt.Errorf("could not parse template, ensure that cols can be converted to []interface{}") + return fmt.Errorf("could not parse \"%s\" template, ensure that cols can be converted to []interface{}", r.SourceKey) } r.Cols = make([]mappers.Componentmapper, len(cols)) @@ -119,7 +119,7 @@ func (r *Row) getFieldMappers() map[string]func(interface{}) error { func (r *Row) getRowContent(content map[string]interface{}) (map[string]interface{}, error) { rowContent, ok := content[r.SourceKey] if !ok { - return nil, fmt.Errorf("could not parse template, the row needs the source key \"%s\", but it was not found", r.SourceKey) + return map[string]interface{}{}, nil } if mapRow, ok := rowContent.(map[string]interface{}); ok { return mapRow, nil diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index d8d4a1d9..2f8cbc07 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -36,7 +36,7 @@ func TestGenerateTemplate(t *testing.T) { test.New(t).Assert((*provider).GetStructure()).Equals("processor/simple_pdf.json") }) - t.Run("when template with Addpage is found, should set template", func(t *testing.T) { + t.Run("when template with Addpage example is found, should set template", func(t *testing.T) { fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/add_page_template.json") fixContent, _ := processortest.NewFileReader().LoadFile("processor/json/add_page_content.json") processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) @@ -49,7 +49,7 @@ func TestGenerateTemplate(t *testing.T) { test.New(t).Assert((*provider).GetStructure()).Equals("examples/addpage.json") }) - t.Run("when template with AutoRow is found, should set template", func(t *testing.T) { + t.Run("when template with AutoRow example is found, should set template", func(t *testing.T) { test.SetupTestDir(t) fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/auto_row_template.json") @@ -63,6 +63,20 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/autorow.json") }) + t.Run("when template with background example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/background_template.json") + fixContent, _ := processortest.NewFileReader().LoadFile("processor/json/background_content.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("auto_row", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("auto_row", string(fixContent)) + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/background.json") + }) t.Run("when sent template is not found, should reuturn an error", func(t *testing.T) { }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { diff --git a/test/maroto/processor/json/background_content.json b/test/maroto/processor/json/background_content.json new file mode 100644 index 00000000..becfc152 --- /dev/null +++ b/test/maroto/processor/json/background_content.json @@ -0,0 +1,41 @@ +{ + "pages": { + "list_pages": [ + { + "page": { + "row_title": { + "title": "O GDG-Petrópolis certifica que Fulano de Tal 123 participou do Evento Exemplo 123 no dia 2019-03-30." + } + } + }, + { + "page": { + "row_title": { + "title": "O GDG-Petrópolis certifica que Fulano de Tal 123 participou do Evento Exemplo 123 no dia 2019-03-30." + } + } + }, + { + "page": { + "row_title": { + "title": "O GDG-Petrópolis certifica que Fulano de Tal 123 participou do Evento Exemplo 123 no dia 2019-03-30." + } + } + }, + { + "page": { + "row_title": { + "title": "O GDG-Petrópolis certifica que Fulano de Tal 123 participou do Evento Exemplo 123 no dia 2019-03-30." + } + } + }, + { + "page": { + "row_title": { + "title": "O GDG-Petrópolis certifica que Fulano de Tal 123 participou do Evento Exemplo 123 no dia 2019-03-30." + } + } + } + ] + } +} \ No newline at end of file diff --git a/test/maroto/processor/json/background_template.json b/test/maroto/processor/json/background_template.json new file mode 100644 index 00000000..8f21af9c --- /dev/null +++ b/test/maroto/processor/json/background_template.json @@ -0,0 +1,64 @@ +{ + "builder": { + "margins": { + "left": 0, + "top": 0, + "right": 0 + }, + "orientation": "horizontal", + "max_grid_size": 20, + "background_image": "docs/assets/images/certificate.png" + }, + "pages": { + "list_pages": { + "order": 1, + "page": { + "order": 1, + "row_space": { + "order": 1, + "height": 70 + }, + "row_title": { + "height": 20, + "order": 2, + "cols": [ + { + "size": 4 + }, + { + "size": 12, + "text": { + "source_key": "title", + "props": { + "size": 18 + } + } + }, + { + "size": 4 + } + ] + }, + "row_space2": { + "order": 3, + "height": 15 + }, + "row_signature": { + "order": 4, + "height": 30, + "cols": [ + { + "size": 20, + "image": { + "value": "docs/assets/images/signature.png", + "props": { + "center": true + } + } + } + ] + } + } + } + } +} \ No newline at end of file From 189cfba0d3b35d8af70ebfde0cc051b4fbea034b Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 26 Dec 2024 13:55:18 -0300 Subject: [PATCH 087/116] test: validate barcodegrid example build --- pkg/processor/mappers/propsmapper/barcode.go | 2 +- .../mappers/propsmapper/proportion.go | 9 +- pkg/processor/processor_test.go | 14 ++ .../processor/json/barcodegrid_content.json | 24 ++ .../processor/json/barcodegrid_template.json | 219 ++++++++++++++++++ 5 files changed, 261 insertions(+), 7 deletions(-) create mode 100644 test/maroto/processor/json/barcodegrid_content.json create mode 100644 test/maroto/processor/json/barcodegrid_template.json diff --git a/pkg/processor/mappers/propsmapper/barcode.go b/pkg/processor/mappers/propsmapper/barcode.go index 2fefbb39..2e14df58 100644 --- a/pkg/processor/mappers/propsmapper/barcode.go +++ b/pkg/processor/mappers/propsmapper/barcode.go @@ -33,7 +33,7 @@ func NewBarcode(barcode interface{}) (*Barcode, error) { Left: *convertFields(barcodeMap["left"], -1.0), Top: *convertFields(barcodeMap["top"], -1.0), Percent: *convertFields(barcodeMap["percent"], -1.0), - Proportion: *NewProportion(barcodeMap["proportion"]), + Proportion: NewProportion(barcodeMap["proportion"]), Center: *convertFields(barcodeMap["center"], false), Type: NewCodeType(*convertFields(barcodeMap["type"], "")), }, nil diff --git a/pkg/processor/mappers/propsmapper/proportion.go b/pkg/processor/mappers/propsmapper/proportion.go index 5ab8498f..dc2d976e 100644 --- a/pkg/processor/mappers/propsmapper/proportion.go +++ b/pkg/processor/mappers/propsmapper/proportion.go @@ -10,13 +10,10 @@ type Proportion struct { // NewProportion is responsible for creating the proportion, if the font fields cannot be // converted, an invalid value is set. -func NewProportion(barcode interface{}) *Proportion { - barcodeMap, ok := barcode.(map[string]interface{}) - if !ok { - return nil - } +func NewProportion(barcode interface{}) Proportion { + barcodeMap, _ := barcode.(map[string]interface{}) - return &Proportion{ + return Proportion{ Width: *convertFields(barcodeMap["width"], 0.0), Height: *convertFields(barcodeMap["height"], 0.0), } diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index 2f8cbc07..fd6cb4a3 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -77,6 +77,20 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/background.json") }) + t.Run("when template with barcodegrid example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/barcodegrid_template.json") + fixContent, _ := processortest.NewFileReader().LoadFile("processor/json/barcodegrid_content.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("auto_row", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("auto_row", string(fixContent)) + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/barcodegrid.json") + }) t.Run("when sent template is not found, should reuturn an error", func(t *testing.T) { }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { diff --git a/test/maroto/processor/json/barcodegrid_content.json b/test/maroto/processor/json/barcodegrid_content.json new file mode 100644 index 00000000..8999a02b --- /dev/null +++ b/test/maroto/processor/json/barcodegrid_content.json @@ -0,0 +1,24 @@ +{ + "pages": { + "template_page": { + "bar_code_row1": { + "maroto_url": "https://github.com/johnfercher/maroto" + }, + "bar_code_center_row1": { + "maroto_url": "https://github.com/johnfercher/maroto" + }, + "bar_code_row2": { + "maroto_url": "https://github.com/johnfercher/maroto" + }, + "bar_code_center_row2": { + "maroto_url": "https://github.com/johnfercher/maroto" + }, + "bar_code_EAN_row2": { + "code_number": "123456789123" + }, + "bar_code_auto_row": { + "code_number": "123456789123" + } + } + } +} \ No newline at end of file diff --git a/test/maroto/processor/json/barcodegrid_template.json b/test/maroto/processor/json/barcodegrid_template.json new file mode 100644 index 00000000..88a8332d --- /dev/null +++ b/test/maroto/processor/json/barcodegrid_template.json @@ -0,0 +1,219 @@ +{ + "builder": { + "debug": true + }, + "pages": { + "template_page": { + "order": 1, + "bar_code_row1": { + "order": 1, + "height": 40, + "cols": [ + { + "size": 2, + "bar_code": { + "source_key": "maroto_url", + "props": { + "percent": 50 + } + } + }, + { + "size": 4, + "bar_code": { + "source_key": "maroto_url", + "props": { + "percent": 75 + } + } + }, + { + "size": 6, + "bar_code": { + "source_key": "maroto_url", + "props": { + "percent": 100 + } + } + } + ] + }, + "bar_code_center_row1": { + "order": 2, + "height": 40, + "cols": [ + { + "size": 2, + "bar_code": { + "source_key": "maroto_url", + "props": { + "center": true, + "percent": 50 + } + } + }, + { + "size": 4, + "bar_code": { + "source_key": "maroto_url", + "props": { + "center": true, + "percent": 75 + } + } + }, + { + "size": 6, + "bar_code": { + "source_key": "maroto_url", + "props": { + "center": true, + "percent": 100 + } + } + } + ] + }, + "bar_code_row2": { + "order": 3, + "height": 40, + "cols": [ + { + "size": 6, + "bar_code": { + "source_key": "maroto_url", + "props": { + "percent": 50 + } + } + }, + { + "size": 4, + "bar_code": { + "source_key": "maroto_url", + "props": { + "percent": 75 + } + } + }, + { + "size": 2, + "bar_code": { + "source_key": "maroto_url", + "props": { + "percent": 100 + } + } + } + ] + }, + "bar_code_center_row2": { + "order": 4, + "height": 40, + "cols": [ + { + "size": 6, + "bar_code": { + "source_key": "maroto_url", + "props": { + "center": true, + "percent": 50 + } + } + }, + { + "size": 4, + "bar_code": { + "source_key": "maroto_url", + "props": { + "center": true, + "percent": 75 + } + } + }, + { + "size": 2, + "bar_code": { + "source_key": "maroto_url", + "props": { + "center": true, + "percent": 100 + } + } + } + ] + }, + "bar_code_EAN_row2": { + "order": 5, + "height": 40, + "cols": [ + { + "size": 2, + "bar_code": { + "source_key": "code_number", + "props": { + "center": true, + "type": "EAN" + } + } + }, + { + "size": 4, + "bar_code": { + "source_key": "code_number", + "props": { + "center": true, + "type": "EAN" + } + } + }, + { + "size": 6, + "bar_code": { + "source_key": "code_number", + "props": { + "center": true, + "type": "EAN" + } + } + } + ] + }, + "bar_code_auto_row": { + "order": 6, + "cols": [ + { + "size": 2, + "bar_code": { + "source_key": "code_number", + "props": { + "center": true, + "type": "EAN" + } + } + }, + { + "size": 4, + "bar_code": { + "source_key": "code_number", + "props": { + "center": true, + "type": "EAN" + } + } + }, + { + "size": 6, + "bar_code": { + "source_key": "code_number", + "props": { + "center": true, + "type": "EAN" + } + } + } + ] + } + } + } +} \ No newline at end of file From f8d348fe40da060013450faa9bd783e8c10d1e2e Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Fri, 27 Dec 2024 16:07:06 -0300 Subject: [PATCH 088/116] fix: allow adding more than one component in a column allow using different names to represent components add order field in components --- internal/fixture/processorfixture.go | 18 ++-- mocks/AbstractFactoryMaps.go | 98 +++++++++---------- mocks/orderedComponentCreator.go | 94 ++++++++++++++++++ .../abstractfactory/abstractfactory.go | 14 +-- pkg/processor/mappers/component_mapper.go | 14 +-- .../mappers/components/codemapper/barcode.go | 16 ++- .../components/codemapper/barcode_test.go | 31 +++++- .../components/codemapper/matrixcode.go | 14 ++- .../components/codemapper/matrixcode_test.go | 44 +++++++-- .../mappers/components/codemapper/qrcode.go | 15 ++- .../components/codemapper/qrcode_test.go | 30 +++++- .../mappers/components/colmapper/col.go | 48 +++++++-- .../mappers/components/colmapper/col_test.go | 57 ++++++++++- .../mappers/components/imagemapper/image.go | 14 ++- .../components/imagemapper/image_test.go | 19 ++++ .../mappers/components/linemapper/line.go | 12 +++ .../components/linemapper/line_test.go | 18 +++- .../components/order/componentorganizer.go | 23 +++++ .../order/componentorganizer_test.go | 42 ++++++++ .../mappers/components/rowmapper/row.go | 1 + .../mappers/components/rowmapper/row_test.go | 13 ++- .../components/signaturemapper/signature.go | 12 +++ .../signaturemapper/signature_test.go | 20 ++++ .../mappers/components/textmapper/text.go | 12 +++ .../components/textmapper/text_test.go | 24 ++++- .../processor/json/add_page_template.json | 2 + .../processor/json/auto_row_template.json | 10 ++ .../processor/json/background_template.json | 2 + .../processor/json/barcodegrid_template.json | 18 ++++ .../processor/json/simple_pdf_templates.json | 6 ++ 30 files changed, 627 insertions(+), 114 deletions(-) create mode 100644 mocks/orderedComponentCreator.go create mode 100644 pkg/processor/mappers/components/order/componentorganizer.go create mode 100644 pkg/processor/mappers/components/order/componentorganizer_test.go diff --git a/internal/fixture/processorfixture.go b/internal/fixture/processorfixture.go index fefbec7c..19f704e7 100644 --- a/internal/fixture/processorfixture.go +++ b/internal/fixture/processorfixture.go @@ -36,31 +36,31 @@ func MapperList() *listmapper.List { } func Barcode() *codemapper.Barcode { - return &codemapper.Barcode{} + return &codemapper.Barcode{Order: 1} } func Matrixcode() *codemapper.Matrixcode { - return &codemapper.Matrixcode{} + return &codemapper.Matrixcode{Order: 1} } func Qrcode() *codemapper.Qrcode { - return &codemapper.Qrcode{} + return &codemapper.Qrcode{Order: 1} } func Image() *imagemapper.Image { - return &imagemapper.Image{} + return &imagemapper.Image{Order: 1} } func Line() *linemapper.Line { - return &linemapper.Line{} + return &linemapper.Line{Order: 1} } func Signature() *signaturemapper.Signature { - return &signaturemapper.Signature{} + return &signaturemapper.Signature{Order: 1} } func Text() *textmapper.Text { - return &textmapper.Text{} + return &textmapper.Text{Order: 1} } func Metadata() *propsmapper.Metadata { @@ -140,7 +140,7 @@ func BuilderProps() *buildermapper.Builder { func Row(sourceKeyRow, sourceKeyText string) *rowmapper.Row { col := colmapper.Col{ Size: 12, - Components: []mappers.Componentmapper{&textmapper.Text{SourceKey: sourceKeyText}}, + Components: []mappers.OrderedComponents{}, } return &rowmapper.Row{ @@ -153,7 +153,7 @@ func Row(sourceKeyRow, sourceKeyText string) *rowmapper.Row { func Page(sourceKeyPage, sourceKeyRow, sourceKeyText string) *pagemapper.Page { col := colmapper.Col{ Size: 12, - Components: []mappers.Componentmapper{&textmapper.Text{SourceKey: sourceKeyText}}, + Components: []mappers.OrderedComponents{}, } return &pagemapper.Page{ diff --git a/mocks/AbstractFactoryMaps.go b/mocks/AbstractFactoryMaps.go index 342c3860..6ab3df3c 100644 --- a/mocks/AbstractFactoryMaps.go +++ b/mocks/AbstractFactoryMaps.go @@ -21,23 +21,23 @@ func (_m *AbstractFactoryMaps) EXPECT() *AbstractFactoryMaps_Expecter { } // NewBarcode provides a mock function with given fields: document -func (_m *AbstractFactoryMaps) NewBarcode(document interface{}) (mappers.Componentmapper, error) { +func (_m *AbstractFactoryMaps) NewBarcode(document interface{}) (mappers.OrderedComponents, error) { ret := _m.Called(document) if len(ret) == 0 { panic("no return value specified for NewBarcode") } - var r0 mappers.Componentmapper + var r0 mappers.OrderedComponents var r1 error - if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + if rf, ok := ret.Get(0).(func(interface{}) (mappers.OrderedComponents, error)); ok { return rf(document) } - if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + if rf, ok := ret.Get(0).(func(interface{}) mappers.OrderedComponents); ok { r0 = rf(document) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(mappers.Componentmapper) + r0 = ret.Get(0).(mappers.OrderedComponents) } } @@ -68,12 +68,12 @@ func (_c *AbstractFactoryMaps_NewBarcode_Call) Run(run func(document interface{} return _c } -func (_c *AbstractFactoryMaps_NewBarcode_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewBarcode_Call { +func (_c *AbstractFactoryMaps_NewBarcode_Call) Return(_a0 mappers.OrderedComponents, _a1 error) *AbstractFactoryMaps_NewBarcode_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *AbstractFactoryMaps_NewBarcode_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewBarcode_Call { +func (_c *AbstractFactoryMaps_NewBarcode_Call) RunAndReturn(run func(interface{}) (mappers.OrderedComponents, error)) *AbstractFactoryMaps_NewBarcode_Call { _c.Call.Return(run) return _c } @@ -137,23 +137,23 @@ func (_c *AbstractFactoryMaps_NewCol_Call) RunAndReturn(run func(interface{}) (m } // NewImage provides a mock function with given fields: document -func (_m *AbstractFactoryMaps) NewImage(document interface{}) (mappers.Componentmapper, error) { +func (_m *AbstractFactoryMaps) NewImage(document interface{}) (mappers.OrderedComponents, error) { ret := _m.Called(document) if len(ret) == 0 { panic("no return value specified for NewImage") } - var r0 mappers.Componentmapper + var r0 mappers.OrderedComponents var r1 error - if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + if rf, ok := ret.Get(0).(func(interface{}) (mappers.OrderedComponents, error)); ok { return rf(document) } - if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + if rf, ok := ret.Get(0).(func(interface{}) mappers.OrderedComponents); ok { r0 = rf(document) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(mappers.Componentmapper) + r0 = ret.Get(0).(mappers.OrderedComponents) } } @@ -184,34 +184,34 @@ func (_c *AbstractFactoryMaps_NewImage_Call) Run(run func(document interface{})) return _c } -func (_c *AbstractFactoryMaps_NewImage_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewImage_Call { +func (_c *AbstractFactoryMaps_NewImage_Call) Return(_a0 mappers.OrderedComponents, _a1 error) *AbstractFactoryMaps_NewImage_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *AbstractFactoryMaps_NewImage_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewImage_Call { +func (_c *AbstractFactoryMaps_NewImage_Call) RunAndReturn(run func(interface{}) (mappers.OrderedComponents, error)) *AbstractFactoryMaps_NewImage_Call { _c.Call.Return(run) return _c } // NewLine provides a mock function with given fields: document -func (_m *AbstractFactoryMaps) NewLine(document interface{}) (mappers.Componentmapper, error) { +func (_m *AbstractFactoryMaps) NewLine(document interface{}) (mappers.OrderedComponents, error) { ret := _m.Called(document) if len(ret) == 0 { panic("no return value specified for NewLine") } - var r0 mappers.Componentmapper + var r0 mappers.OrderedComponents var r1 error - if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + if rf, ok := ret.Get(0).(func(interface{}) (mappers.OrderedComponents, error)); ok { return rf(document) } - if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + if rf, ok := ret.Get(0).(func(interface{}) mappers.OrderedComponents); ok { r0 = rf(document) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(mappers.Componentmapper) + r0 = ret.Get(0).(mappers.OrderedComponents) } } @@ -242,12 +242,12 @@ func (_c *AbstractFactoryMaps_NewLine_Call) Run(run func(document interface{})) return _c } -func (_c *AbstractFactoryMaps_NewLine_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewLine_Call { +func (_c *AbstractFactoryMaps_NewLine_Call) Return(_a0 mappers.OrderedComponents, _a1 error) *AbstractFactoryMaps_NewLine_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *AbstractFactoryMaps_NewLine_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewLine_Call { +func (_c *AbstractFactoryMaps_NewLine_Call) RunAndReturn(run func(interface{}) (mappers.OrderedComponents, error)) *AbstractFactoryMaps_NewLine_Call { _c.Call.Return(run) return _c } @@ -313,23 +313,23 @@ func (_c *AbstractFactoryMaps_NewList_Call) RunAndReturn(run func(interface{}, s } // NewMatrixcode provides a mock function with given fields: document -func (_m *AbstractFactoryMaps) NewMatrixcode(document interface{}) (mappers.Componentmapper, error) { +func (_m *AbstractFactoryMaps) NewMatrixcode(document interface{}) (mappers.OrderedComponents, error) { ret := _m.Called(document) if len(ret) == 0 { panic("no return value specified for NewMatrixcode") } - var r0 mappers.Componentmapper + var r0 mappers.OrderedComponents var r1 error - if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + if rf, ok := ret.Get(0).(func(interface{}) (mappers.OrderedComponents, error)); ok { return rf(document) } - if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + if rf, ok := ret.Get(0).(func(interface{}) mappers.OrderedComponents); ok { r0 = rf(document) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(mappers.Componentmapper) + r0 = ret.Get(0).(mappers.OrderedComponents) } } @@ -360,12 +360,12 @@ func (_c *AbstractFactoryMaps_NewMatrixcode_Call) Run(run func(document interfac return _c } -func (_c *AbstractFactoryMaps_NewMatrixcode_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewMatrixcode_Call { +func (_c *AbstractFactoryMaps_NewMatrixcode_Call) Return(_a0 mappers.OrderedComponents, _a1 error) *AbstractFactoryMaps_NewMatrixcode_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *AbstractFactoryMaps_NewMatrixcode_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewMatrixcode_Call { +func (_c *AbstractFactoryMaps_NewMatrixcode_Call) RunAndReturn(run func(interface{}) (mappers.OrderedComponents, error)) *AbstractFactoryMaps_NewMatrixcode_Call { _c.Call.Return(run) return _c } @@ -430,23 +430,23 @@ func (_c *AbstractFactoryMaps_NewPage_Call) RunAndReturn(run func(interface{}, s } // NewQrcode provides a mock function with given fields: document -func (_m *AbstractFactoryMaps) NewQrcode(document interface{}) (mappers.Componentmapper, error) { +func (_m *AbstractFactoryMaps) NewQrcode(document interface{}) (mappers.OrderedComponents, error) { ret := _m.Called(document) if len(ret) == 0 { panic("no return value specified for NewQrcode") } - var r0 mappers.Componentmapper + var r0 mappers.OrderedComponents var r1 error - if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + if rf, ok := ret.Get(0).(func(interface{}) (mappers.OrderedComponents, error)); ok { return rf(document) } - if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + if rf, ok := ret.Get(0).(func(interface{}) mappers.OrderedComponents); ok { r0 = rf(document) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(mappers.Componentmapper) + r0 = ret.Get(0).(mappers.OrderedComponents) } } @@ -477,12 +477,12 @@ func (_c *AbstractFactoryMaps_NewQrcode_Call) Run(run func(document interface{}) return _c } -func (_c *AbstractFactoryMaps_NewQrcode_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewQrcode_Call { +func (_c *AbstractFactoryMaps_NewQrcode_Call) Return(_a0 mappers.OrderedComponents, _a1 error) *AbstractFactoryMaps_NewQrcode_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *AbstractFactoryMaps_NewQrcode_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewQrcode_Call { +func (_c *AbstractFactoryMaps_NewQrcode_Call) RunAndReturn(run func(interface{}) (mappers.OrderedComponents, error)) *AbstractFactoryMaps_NewQrcode_Call { _c.Call.Return(run) return _c } @@ -547,23 +547,23 @@ func (_c *AbstractFactoryMaps_NewRow_Call) RunAndReturn(run func(interface{}, st } // NewSignature provides a mock function with given fields: document -func (_m *AbstractFactoryMaps) NewSignature(document interface{}) (mappers.Componentmapper, error) { +func (_m *AbstractFactoryMaps) NewSignature(document interface{}) (mappers.OrderedComponents, error) { ret := _m.Called(document) if len(ret) == 0 { panic("no return value specified for NewSignature") } - var r0 mappers.Componentmapper + var r0 mappers.OrderedComponents var r1 error - if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + if rf, ok := ret.Get(0).(func(interface{}) (mappers.OrderedComponents, error)); ok { return rf(document) } - if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + if rf, ok := ret.Get(0).(func(interface{}) mappers.OrderedComponents); ok { r0 = rf(document) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(mappers.Componentmapper) + r0 = ret.Get(0).(mappers.OrderedComponents) } } @@ -594,34 +594,34 @@ func (_c *AbstractFactoryMaps_NewSignature_Call) Run(run func(document interface return _c } -func (_c *AbstractFactoryMaps_NewSignature_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewSignature_Call { +func (_c *AbstractFactoryMaps_NewSignature_Call) Return(_a0 mappers.OrderedComponents, _a1 error) *AbstractFactoryMaps_NewSignature_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *AbstractFactoryMaps_NewSignature_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewSignature_Call { +func (_c *AbstractFactoryMaps_NewSignature_Call) RunAndReturn(run func(interface{}) (mappers.OrderedComponents, error)) *AbstractFactoryMaps_NewSignature_Call { _c.Call.Return(run) return _c } // NewText provides a mock function with given fields: document -func (_m *AbstractFactoryMaps) NewText(document interface{}) (mappers.Componentmapper, error) { +func (_m *AbstractFactoryMaps) NewText(document interface{}) (mappers.OrderedComponents, error) { ret := _m.Called(document) if len(ret) == 0 { panic("no return value specified for NewText") } - var r0 mappers.Componentmapper + var r0 mappers.OrderedComponents var r1 error - if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + if rf, ok := ret.Get(0).(func(interface{}) (mappers.OrderedComponents, error)); ok { return rf(document) } - if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + if rf, ok := ret.Get(0).(func(interface{}) mappers.OrderedComponents); ok { r0 = rf(document) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(mappers.Componentmapper) + r0 = ret.Get(0).(mappers.OrderedComponents) } } @@ -652,12 +652,12 @@ func (_c *AbstractFactoryMaps_NewText_Call) Run(run func(document interface{})) return _c } -func (_c *AbstractFactoryMaps_NewText_Call) Return(_a0 mappers.Componentmapper, _a1 error) *AbstractFactoryMaps_NewText_Call { +func (_c *AbstractFactoryMaps_NewText_Call) Return(_a0 mappers.OrderedComponents, _a1 error) *AbstractFactoryMaps_NewText_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *AbstractFactoryMaps_NewText_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *AbstractFactoryMaps_NewText_Call { +func (_c *AbstractFactoryMaps_NewText_Call) RunAndReturn(run func(interface{}) (mappers.OrderedComponents, error)) *AbstractFactoryMaps_NewText_Call { _c.Call.Return(run) return _c } diff --git a/mocks/orderedComponentCreator.go b/mocks/orderedComponentCreator.go new file mode 100644 index 00000000..61faee75 --- /dev/null +++ b/mocks/orderedComponentCreator.go @@ -0,0 +1,94 @@ +// Code generated by mockery v2.42.0. DO NOT EDIT. + +package mocks + +import ( + mappers "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + mock "github.com/stretchr/testify/mock" +) + +// orderedComponentCreator is an autogenerated mock type for the orderedComponentCreator type +type orderedComponentCreator struct { + mock.Mock +} + +type orderedComponentCreator_Expecter struct { + mock *mock.Mock +} + +func (_m *orderedComponentCreator) EXPECT() *orderedComponentCreator_Expecter { + return &orderedComponentCreator_Expecter{mock: &_m.Mock} +} + +// Execute provides a mock function with given fields: template +func (_m *orderedComponentCreator) Execute(template interface{}) (mappers.Componentmapper, error) { + ret := _m.Called(template) + + if len(ret) == 0 { + panic("no return value specified for Execute") + } + + var r0 mappers.Componentmapper + var r1 error + if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { + return rf(template) + } + if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { + r0 = rf(template) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(mappers.Componentmapper) + } + } + + if rf, ok := ret.Get(1).(func(interface{}) error); ok { + r1 = rf(template) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// orderedComponentCreator_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' +type orderedComponentCreator_Execute_Call struct { + *mock.Call +} + +// Execute is a helper method to define mock.On call +// - template interface{} +func (_e *orderedComponentCreator_Expecter) Execute(template interface{}) *orderedComponentCreator_Execute_Call { + return &orderedComponentCreator_Execute_Call{Call: _e.mock.On("Execute", template)} +} + +func (_c *orderedComponentCreator_Execute_Call) Run(run func(template interface{})) *orderedComponentCreator_Execute_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{})) + }) + return _c +} + +func (_c *orderedComponentCreator_Execute_Call) Return(_a0 mappers.Componentmapper, _a1 error) *orderedComponentCreator_Execute_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *orderedComponentCreator_Execute_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *orderedComponentCreator_Execute_Call { + _c.Call.Return(run) + return _c +} + +// newOrderedComponentCreator creates a new instance of orderedComponentCreator. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newOrderedComponentCreator(t interface { + mock.TestingT + Cleanup(func()) +}, +) *orderedComponentCreator { + mock := &orderedComponentCreator{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/processor/mappers/abstractfactory/abstractfactory.go b/pkg/processor/mappers/abstractfactory/abstractfactory.go index 5c887f61..6cf51daa 100644 --- a/pkg/processor/mappers/abstractfactory/abstractfactory.go +++ b/pkg/processor/mappers/abstractfactory/abstractfactory.go @@ -46,36 +46,36 @@ func (f *abstractFactoryMaps) NewList(document interface{}, sourceKey string, } // NewBarcode is responsible for wrapper the creation of a barcode -func (f *abstractFactoryMaps) NewBarcode(document interface{}) (mappers.Componentmapper, error) { +func (f *abstractFactoryMaps) NewBarcode(document interface{}) (mappers.OrderedComponents, error) { return codemapper.NewBarcode(document) } // NewMatrixcode is responsible for wrapper the creation of a matrix code -func (f *abstractFactoryMaps) NewMatrixcode(document interface{}) (mappers.Componentmapper, error) { +func (f *abstractFactoryMaps) NewMatrixcode(document interface{}) (mappers.OrderedComponents, error) { return codemapper.NewMatrixcode(document) } // NewQrcode is responsible for wrapper the creation of a qrcode -func (f *abstractFactoryMaps) NewQrcode(document interface{}) (mappers.Componentmapper, error) { +func (f *abstractFactoryMaps) NewQrcode(document interface{}) (mappers.OrderedComponents, error) { return codemapper.NewQrcode(document) } // NewImage is responsible for wrapper the creation of a image -func (f *abstractFactoryMaps) NewImage(document interface{}) (mappers.Componentmapper, error) { +func (f *abstractFactoryMaps) NewImage(document interface{}) (mappers.OrderedComponents, error) { return imagemapper.NewImage(document) } // NewLine is responsible for wrapper the creation of a libe -func (f *abstractFactoryMaps) NewLine(document interface{}) (mappers.Componentmapper, error) { +func (f *abstractFactoryMaps) NewLine(document interface{}) (mappers.OrderedComponents, error) { return linemapper.NewLine(document) } // NewSignature is responsible for wrapper the creation of a signature -func (f *abstractFactoryMaps) NewSignature(document interface{}) (mappers.Componentmapper, error) { +func (f *abstractFactoryMaps) NewSignature(document interface{}) (mappers.OrderedComponents, error) { return signaturemapper.NewSignature(document) } // NewText is responsible for wrapper the creation of a text -func (f *abstractFactoryMaps) NewText(document interface{}) (mappers.Componentmapper, error) { +func (f *abstractFactoryMaps) NewText(document interface{}) (mappers.OrderedComponents, error) { return textmapper.NewText(document) } diff --git a/pkg/processor/mappers/component_mapper.go b/pkg/processor/mappers/component_mapper.go index 0f887be3..f0e39852 100644 --- a/pkg/processor/mappers/component_mapper.go +++ b/pkg/processor/mappers/component_mapper.go @@ -27,11 +27,11 @@ type AbstractFactoryMaps interface { NewPage(document interface{}, sourceKey string) (OrderedComponents, error) NewCol(document interface{}) (Componentmapper, error) NewList(document interface{}, sourceKey string, generate GenerateComponent) (OrderedComponents, error) - NewBarcode(document interface{}) (Componentmapper, error) - NewMatrixcode(document interface{}) (Componentmapper, error) - NewQrcode(document interface{}) (Componentmapper, error) - NewImage(document interface{}) (Componentmapper, error) - NewLine(document interface{}) (Componentmapper, error) - NewSignature(document interface{}) (Componentmapper, error) - NewText(document interface{}) (Componentmapper, error) + NewBarcode(document interface{}) (OrderedComponents, error) + NewMatrixcode(document interface{}) (OrderedComponents, error) + NewQrcode(document interface{}) (OrderedComponents, error) + NewImage(document interface{}) (OrderedComponents, error) + NewLine(document interface{}) (OrderedComponents, error) + NewSignature(document interface{}) (OrderedComponents, error) + NewText(document interface{}) (OrderedComponents, error) } diff --git a/pkg/processor/mappers/components/codemapper/barcode.go b/pkg/processor/mappers/components/codemapper/barcode.go index 59e1ded6..100697e2 100644 --- a/pkg/processor/mappers/components/codemapper/barcode.go +++ b/pkg/processor/mappers/components/codemapper/barcode.go @@ -5,6 +5,7 @@ package codemapper import ( "fmt" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/order" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) @@ -13,6 +14,7 @@ type Barcode struct { SourceKey string Code string Props *propsmapper.Barcode + Order int } func NewBarcode(code interface{}) (*Barcode, error) { @@ -35,6 +37,12 @@ func NewBarcode(code interface{}) (*Barcode, error) { // addFields is responsible for adding the barcode fields according to // the properties informed in the map func (b *Barcode) addFields(codeMap map[string]interface{}) error { + order, err := order.SetPageOrder(&codeMap, "barcode", b.SourceKey) + if err != nil { + return err + } + b.Order = order + fieldMappers := b.getFieldMappers() for templateName, template := range codeMap { @@ -50,12 +58,17 @@ func (b *Barcode) addFields(codeMap map[string]interface{}) error { return nil } +// GetOrder is responsible for returning the component's defined order +func (b *Barcode) GetOrder() int { + return b.Order +} + // getFieldMappers is responsible for defining which methods are responsible for assembling which components. // To do this, the component name is linked to a function in a Map. func (b *Barcode) getFieldMappers() map[string]func(interface{}) error { return map[string]func(interface{}) error{ "source_key": b.setSourceKey, - "code": b.setCode, + "value": b.setCode, "props": b.setProps, } } @@ -109,6 +122,7 @@ func (b *Barcode) getCode(content map[string]interface{}) (string, error) { return codeValid, nil } +// Generate is responsible for computing the page component with shipping data func (b *Barcode) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( []processorprovider.ProviderComponent, error, ) { diff --git a/pkg/processor/mappers/components/codemapper/barcode_test.go b/pkg/processor/mappers/components/codemapper/barcode_test.go index a04ae62a..31620273 100644 --- a/pkg/processor/mappers/components/codemapper/barcode_test.go +++ b/pkg/processor/mappers/components/codemapper/barcode_test.go @@ -9,6 +9,20 @@ import ( "github.com/stretchr/testify/assert" ) +func TestBarcodeGetOrder(t *testing.T) { + t.Run("when getOrder is called, should return defined order", func(t *testing.T) { + templateRows := map[string]interface{}{ + "order": 10.0, + "value": "test", + } + + doc, err := codemapper.NewBarcode(templateRows) + + assert.Nil(t, err) + assert.Equal(t, 10, doc.GetOrder()) + }) +} + func TestNewBarcode(t *testing.T) { t.Run("when invalid barcode is sent, should return an error", func(t *testing.T) { barcodeTemplate := 1 @@ -20,7 +34,8 @@ func TestNewBarcode(t *testing.T) { }) t.Run("when props is not sent, barcode is created", func(t *testing.T) { barcodeTemplate := map[string]interface{}{ - "code": "123456789", + "value": "123456789", + "order": 1.0, } barcode, err := codemapper.NewBarcode(barcodeTemplate) @@ -31,7 +46,8 @@ func TestNewBarcode(t *testing.T) { t.Run("when invalid props is sent, should return an error", func(t *testing.T) { barcodeTemplate := map[string]interface{}{ "props": 1, - "code": "123456789", + "value": "123456789", + "order": 1.0, } barcode, err := codemapper.NewBarcode(barcodeTemplate) @@ -42,7 +58,8 @@ func TestNewBarcode(t *testing.T) { t.Run("when invalid field is sent, should return an error", func(t *testing.T) { barcodeTemplate := map[string]interface{}{ "invalid_field": 1, - "code": "123456789", + "value": "123456789", + "order": 1.0, } barcode, err := codemapper.NewBarcode(barcodeTemplate) @@ -60,7 +77,8 @@ func TestNewBarcode(t *testing.T) { }) t.Run("when invalid code is sent, should return an error", func(t *testing.T) { barcodeTemplate := map[string]interface{}{ - "code": 123, + "value": 123, + "order": 1.0, } barcode, err := codemapper.NewBarcode(barcodeTemplate) @@ -71,6 +89,7 @@ func TestNewBarcode(t *testing.T) { t.Run("when invalid source_key is sent, should return an error", func(t *testing.T) { barcodeTemplate := map[string]interface{}{ "source_key": 123, + "order": 1.0, } barcode, err := codemapper.NewBarcode(barcodeTemplate) @@ -81,6 +100,7 @@ func TestNewBarcode(t *testing.T) { t.Run("when code is not sent, should add source key", func(t *testing.T) { barcodeTemplate := map[string]interface{}{ "source_key": "source", + "order": 1.0, } barcode, err := codemapper.NewBarcode(barcodeTemplate) @@ -91,7 +111,8 @@ func TestNewBarcode(t *testing.T) { t.Run("when source_key is not sent, should add code", func(t *testing.T) { barcodeTemplate := map[string]interface{}{ - "code": "code", + "value": "code", + "order": 1.0, } barcode, err := codemapper.NewBarcode(barcodeTemplate) diff --git a/pkg/processor/mappers/components/codemapper/matrixcode.go b/pkg/processor/mappers/components/codemapper/matrixcode.go index 745357c9..ffbc9cef 100644 --- a/pkg/processor/mappers/components/codemapper/matrixcode.go +++ b/pkg/processor/mappers/components/codemapper/matrixcode.go @@ -5,6 +5,7 @@ package codemapper import ( "fmt" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/order" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) @@ -13,6 +14,7 @@ type Matrixcode struct { SourceKey string Code string Props *propsmapper.Rect + Order int } func NewMatrixcode(code interface{}) (*Matrixcode, error) { @@ -35,6 +37,11 @@ func NewMatrixcode(code interface{}) (*Matrixcode, error) { // addFields is responsible for adding the matrix code fields according to // the properties informed in the map func (m *Matrixcode) addFields(codeMap map[string]interface{}) error { + order, err := order.SetPageOrder(&codeMap, "matrixcode", m.SourceKey) + if err != nil { + return err + } + m.Order = order fieldMappers := m.getFieldMappers() for templateName, template := range codeMap { @@ -50,12 +57,17 @@ func (m *Matrixcode) addFields(codeMap map[string]interface{}) error { return nil } +// GetOrder is responsible for returning the component's defined order +func (m *Matrixcode) GetOrder() int { + return m.Order +} + // getFieldMappers is responsible for defining which methods are responsible for assembling which components. // To do this, the component name is linked to a function in a Map. func (m *Matrixcode) getFieldMappers() map[string]func(interface{}) error { return map[string]func(interface{}) error{ "source_key": m.setSourceKey, - "code": m.setCode, + "value": m.setCode, "props": m.setProps, } } diff --git a/pkg/processor/mappers/components/codemapper/matrixcode_test.go b/pkg/processor/mappers/components/codemapper/matrixcode_test.go index 91a43162..be38ff6f 100644 --- a/pkg/processor/mappers/components/codemapper/matrixcode_test.go +++ b/pkg/processor/mappers/components/codemapper/matrixcode_test.go @@ -9,6 +9,19 @@ import ( "github.com/stretchr/testify/assert" ) +func TestMatrixCodeGetOrder(t *testing.T) { + t.Run("when getOrder is called, should return defined order", func(t *testing.T) { + templateRows := map[string]interface{}{ + "order": 10.0, + "value": "code", + } + + doc, _ := codemapper.NewMatrixcode(templateRows) + + assert.Equal(t, 10, doc.GetOrder()) + }) +} + func TestNewMatrixcode(t *testing.T) { t.Run("when invalid matrixcode is sent, should return an error", func(t *testing.T) { matrixcodeTemplate := 1 @@ -20,7 +33,8 @@ func TestNewMatrixcode(t *testing.T) { }) t.Run("when props is not sent, matrixcode is created", func(t *testing.T) { matrixcodeTemplate := map[string]interface{}{ - "code": "123456789", + "order": 1.0, + "value": "123456789", } matrixcode, err := codemapper.NewMatrixcode(matrixcodeTemplate) @@ -30,6 +44,7 @@ func TestNewMatrixcode(t *testing.T) { }) t.Run("when invalid props is sent, should return an error", func(t *testing.T) { matrixcodeTemplate := map[string]interface{}{ + "order": 1.0, "props": 1, "code": "123456789", } @@ -41,6 +56,7 @@ func TestNewMatrixcode(t *testing.T) { }) t.Run("when invalid field is sent, should return an error", func(t *testing.T) { matrixcodeTemplate := map[string]interface{}{ + "order": 1.0, "invalid_field": 1, "code": "123456789", } @@ -51,7 +67,9 @@ func TestNewMatrixcode(t *testing.T) { assert.NotNil(t, err) }) t.Run("when source_key and code are not sent, should return an error", func(t *testing.T) { - matrixcodeTemplate := map[string]interface{}{} + matrixcodeTemplate := map[string]interface{}{ + "order": 1.0, + } matrixcode, err := codemapper.NewMatrixcode(matrixcodeTemplate) @@ -60,7 +78,8 @@ func TestNewMatrixcode(t *testing.T) { }) t.Run("when invalid code is sent, should return an error", func(t *testing.T) { matrixcodeTemplate := map[string]interface{}{ - "code": 123, + "order": 1.0, + "value": 123, } matrixcode, err := codemapper.NewMatrixcode(matrixcodeTemplate) @@ -70,6 +89,7 @@ func TestNewMatrixcode(t *testing.T) { }) t.Run("when invalid source_key is sent, should return an error", func(t *testing.T) { matrixcodeTemplate := map[string]interface{}{ + "order": 1.0, "source_key": 123, } @@ -80,6 +100,7 @@ func TestNewMatrixcode(t *testing.T) { }) t.Run("when code is not sent, should add source key", func(t *testing.T) { matrixcodeTemplate := map[string]interface{}{ + "order": 1.0, "source_key": "source", } @@ -91,7 +112,8 @@ func TestNewMatrixcode(t *testing.T) { t.Run("when source_key is not sent, should add code", func(t *testing.T) { matrixcodeTemplate := map[string]interface{}{ - "code": "code", + "order": 1.0, + "value": "code", } matrixcode, err := codemapper.NewMatrixcode(matrixcodeTemplate) @@ -103,7 +125,9 @@ func TestNewMatrixcode(t *testing.T) { func TestMatrixcodeGenerate(t *testing.T) { t.Run("if source key is not found, should return an error", func(t *testing.T) { - content := map[string]interface{}{} + content := map[string]interface{}{ + "order": 1.0, + } provider := mocks.NewProcessorProvider(t) matrixcode := codemapper.Matrixcode{SourceKey: "code"} @@ -114,7 +138,8 @@ func TestMatrixcodeGenerate(t *testing.T) { }) t.Run("if source key content is not valid, should return an error", func(t *testing.T) { content := map[string]interface{}{ - "code": 1, + "order": 1.0, + "code": 1, } provider := mocks.NewProcessorProvider(t) @@ -126,7 +151,8 @@ func TestMatrixcodeGenerate(t *testing.T) { }) t.Run("If the matrixcode has no props, the props will not be sent", func(t *testing.T) { content := map[string]interface{}{ - "code": "code", + "order": 1.0, + "code": "code", } provider := mocks.NewProcessorProvider(t) @@ -139,7 +165,9 @@ func TestMatrixcodeGenerate(t *testing.T) { provider.AssertNumberOfCalls(t, "CreateMatrixCode", 1) }) t.Run("when valid code is sent, should generate matrixcode", func(t *testing.T) { - content := map[string]interface{}{} + content := map[string]interface{}{ + "order": 1.0, + } provider := mocks.NewProcessorProvider(t) provider.EXPECT().CreateMatrixCode("code").Return(nil) diff --git a/pkg/processor/mappers/components/codemapper/qrcode.go b/pkg/processor/mappers/components/codemapper/qrcode.go index 21a1f820..e20db41f 100644 --- a/pkg/processor/mappers/components/codemapper/qrcode.go +++ b/pkg/processor/mappers/components/codemapper/qrcode.go @@ -5,6 +5,7 @@ package codemapper import ( "fmt" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/order" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) @@ -13,6 +14,7 @@ type Qrcode struct { SourceKey string Code string Props *propsmapper.Rect + Order int } func NewQrcode(code interface{}) (*Qrcode, error) { @@ -35,6 +37,12 @@ func NewQrcode(code interface{}) (*Qrcode, error) { // addFields is responsible for adding the qrcode fields according to // the properties informed in the map func (q *Qrcode) addFields(codeMap map[string]interface{}) error { + order, err := order.SetPageOrder(&codeMap, "qrcode", q.SourceKey) + if err != nil { + return err + } + q.Order = order + fieldMappers := q.getFieldMappers() for templateName, template := range codeMap { @@ -50,12 +58,17 @@ func (q *Qrcode) addFields(codeMap map[string]interface{}) error { return nil } +// GetOrder is responsible for returning the component's defined order +func (q *Qrcode) GetOrder() int { + return q.Order +} + // getFieldMappers is responsible for defining which methods are responsible for assembling which components. // To do this, the component name is linked to a function in a Map. func (q *Qrcode) getFieldMappers() map[string]func(interface{}) error { return map[string]func(interface{}) error{ "source_key": q.setSourceKey, - "code": q.setCode, + "value": q.setCode, "props": q.setProps, } } diff --git a/pkg/processor/mappers/components/codemapper/qrcode_test.go b/pkg/processor/mappers/components/codemapper/qrcode_test.go index 30df87df..409c5bc6 100644 --- a/pkg/processor/mappers/components/codemapper/qrcode_test.go +++ b/pkg/processor/mappers/components/codemapper/qrcode_test.go @@ -9,6 +9,19 @@ import ( "github.com/stretchr/testify/assert" ) +func TestQrcodeGetOrder(t *testing.T) { + t.Run("when getOrder is called, should return defined order", func(t *testing.T) { + templateRows := map[string]interface{}{ + "order": 10.0, + "value": "code", + } + + doc, _ := codemapper.NewBarcode(templateRows) + + assert.Equal(t, 10, doc.GetOrder()) + }) +} + func TestNewQrCode(t *testing.T) { t.Run("when invalid qrcode is sent, should return an error", func(t *testing.T) { qrcodeTemplate := 1 @@ -20,7 +33,8 @@ func TestNewQrCode(t *testing.T) { }) t.Run("when props is not sent, should create qrcode", func(t *testing.T) { qrcodeTemplate := map[string]interface{}{ - "code": "123456789", + "order": 1.0, + "value": "123456789", } qrcode, err := codemapper.NewQrcode(qrcodeTemplate) @@ -31,7 +45,8 @@ func TestNewQrCode(t *testing.T) { t.Run("when invalid props is sent, should return an error", func(t *testing.T) { qrcodeTemplate := map[string]interface{}{ "props": 1, - "code": "123456789", + "order": 1.0, + "value": "123456789", } qrcode, err := codemapper.NewQrcode(qrcodeTemplate) @@ -42,7 +57,8 @@ func TestNewQrCode(t *testing.T) { t.Run("when invalid field is sent, should return an error", func(t *testing.T) { qrcodeTemplate := map[string]interface{}{ "invalid_field": 1, - "code": "123456789", + "order": 1.0, + "value": "123456789", } qrcode, err := codemapper.NewQrcode(qrcodeTemplate) @@ -60,7 +76,8 @@ func TestNewQrCode(t *testing.T) { }) t.Run("when invalid code is sent, should return an error", func(t *testing.T) { qrcodeTemplate := map[string]interface{}{ - "code": 123, + "order": 1.0, + "value": 123, } qrcode, err := codemapper.NewQrcode(qrcodeTemplate) @@ -71,6 +88,7 @@ func TestNewQrCode(t *testing.T) { t.Run("when invalid source_key is sent, should return an error", func(t *testing.T) { qrcodeTemplate := map[string]interface{}{ "source_key": 123, + "order": 1.0, } qrcode, err := codemapper.NewQrcode(qrcodeTemplate) @@ -81,6 +99,7 @@ func TestNewQrCode(t *testing.T) { t.Run("when code is not sent, should add source key", func(t *testing.T) { qrcodeTemplate := map[string]interface{}{ "source_key": "source", + "order": 1.0, } qrcode, err := codemapper.NewQrcode(qrcodeTemplate) @@ -91,7 +110,8 @@ func TestNewQrCode(t *testing.T) { t.Run("when source_key is not sent, should add code", func(t *testing.T) { qrcodeTemplate := map[string]interface{}{ - "code": "code", + "order": 1.0, + "value": "code", } qrcode, err := codemapper.NewQrcode(qrcodeTemplate) diff --git a/pkg/processor/mappers/components/colmapper/col.go b/pkg/processor/mappers/components/colmapper/col.go index 6f667d1d..ff579894 100644 --- a/pkg/processor/mappers/components/colmapper/col.go +++ b/pkg/processor/mappers/components/colmapper/col.go @@ -2,14 +2,17 @@ package colmapper import ( "fmt" + "strings" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) +type factoryComponent = func(interface{}) (mappers.OrderedComponents, error) + type Col struct { Size int - Components []mappers.Componentmapper + Components []mappers.OrderedComponents factory mappers.AbstractFactoryMaps } @@ -19,7 +22,7 @@ func NewCol(templateCols interface{}, factory mappers.AbstractFactoryMaps) (*Col return nil, fmt.Errorf("ensure that rows can be converted to map[string] interface{}") } - col := &Col{Size: 0, Components: make([]mappers.Componentmapper, 0), factory: factory} + col := &Col{Size: 0, Components: make([]mappers.OrderedComponents, 0), factory: factory} if err := col.setSize(&mapCols); err != nil { return nil, err @@ -34,20 +37,38 @@ func NewCol(templateCols interface{}, factory mappers.AbstractFactoryMaps) (*Col func (c *Col) addComponents(mapComponents map[string]interface{}) error { fieldMappers := c.getFieldMappers() + c.Components = make([]mappers.OrderedComponents, len(mapComponents)) for templateName, template := range mapComponents { - mapper, ok := fieldMappers[templateName] - if !ok { - return fmt.Errorf("the field %s present in the col cannot be mapped to any valid component", templateName) + mapper, err := c.getFieldMapperByTemplateName(templateName, fieldMappers) + if err != nil { + return err } component, err := mapper(template) if err != nil { return err } - c.Components = append(c.Components, component) + + if err := c.addComponent(component); err != nil { + return err + } } return nil } +// addComponent is responsible for validating and adding the component to the template +func (c *Col) addComponent(component mappers.OrderedComponents) error { + order := component.GetOrder() + if order > len(c.Components) { + return fmt.Errorf("component order cannot be greater than %d, this is the number of components in the template", len(c.Components)) + } + if c.Components[order-1] != nil { + return fmt.Errorf("cannot create col template, component order cannot be repeated") + } + + c.Components[order-1] = component + return nil +} + func (c *Col) setSize(template *map[string]interface{}) error { defer delete(*template, "size") templateSize, ok := (*template)["size"] @@ -61,10 +82,21 @@ func (c *Col) setSize(template *map[string]interface{}) error { return nil } +func (c *Col) getFieldMapperByTemplateName(templateName string, mappers map[string]factoryComponent) (factoryComponent, error) { + for mapperName, mapper := range mappers { + if strings.HasPrefix(templateName, mapperName) { + return mapper, nil + } + } + return nil, fmt.Errorf( + "the field \"%s\" present in the col cannot be mapped to any valid component, ensure the field name starts with a valid component", + templateName) +} + // getFieldMappers is responsible for defining which methods are responsible for assembling which components. // To do this, the component name is linked to a function in a Map. -func (c *Col) getFieldMappers() map[string]func(interface{}) (mappers.Componentmapper, error) { - return map[string]func(interface{}) (mappers.Componentmapper, error){ +func (c *Col) getFieldMappers() map[string]factoryComponent { + return map[string]factoryComponent{ "bar_code": c.factory.NewBarcode, "matrix_code": c.factory.NewMatrixcode, "qr_code": c.factory.NewQrcode, diff --git a/pkg/processor/mappers/components/colmapper/col_test.go b/pkg/processor/mappers/components/colmapper/col_test.go index a98d4683..511bf0bc 100644 --- a/pkg/processor/mappers/components/colmapper/col_test.go +++ b/pkg/processor/mappers/components/colmapper/col_test.go @@ -20,9 +20,55 @@ import ( ) func TestNewCol(t *testing.T) { + t.Run("when the template order is greater than the number of components, an error should be returned", func(t *testing.T) { + col := map[string]interface{}{"bar_code": nil} + orderedComponent := mocks.NewOrderedComponents(t) + orderedComponent.EXPECT().GetOrder().Return(2) + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewBarcode", mock.Anything).Return(orderedComponent, nil) + + _, err := colmapper.NewCol(col, factory) + + assert.NotNil(t, err) + }) + + t.Run("when the template order is repeated, an error should be returned", func(t *testing.T) { + col := map[string]interface{}{"bar_code_1": nil, "bar_code_2": nil} + orderedComponent := mocks.NewOrderedComponents(t) + orderedComponent.EXPECT().GetOrder().Return(2) + + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewBarcode", mock.Anything).Return(orderedComponent, nil) + factory.On("NewBarcode", mock.Anything).Return(orderedComponent, nil) + + _, err := colmapper.NewCol(col, factory) + + assert.NotNil(t, err) + }) + + t.Run("when 2 components are submitted, should add the 2 components in the correct order", func(t *testing.T) { + col := map[string]interface{}{"bar_code_1": 1, "bar_code_2": 2} + + orderedComponent1 := mocks.NewOrderedComponents(t) + orderedComponent1.EXPECT().GetOrder().Return(1) + orderedComponent2 := mocks.NewOrderedComponents(t) + orderedComponent2.EXPECT().GetOrder().Return(2) + + factory := mocks.NewAbstractFactoryMaps(t) + factory.On("NewBarcode", 1).Return(orderedComponent1, nil) + factory.On("NewBarcode", 2).Return(orderedComponent2, nil) + + doc, err := colmapper.NewCol(col, factory) + + assert.Nil(t, err) + assert.Equal(t, len(doc.Components), 2) + assert.Equal(t, orderedComponent1, doc.Components[0]) + }) + t.Run("when a barcode is sent, a barcode is created", func(t *testing.T) { col := map[string]interface{}{"bar_code": nil} validBarcode := fixture.Barcode() + factory := mocks.NewAbstractFactoryMaps(t) factory.On("NewBarcode", mock.Anything).Return(validBarcode, nil) @@ -32,6 +78,7 @@ func TestNewCol(t *testing.T) { assert.Len(t, doc.Components, 1) assert.IsType(t, &codemapper.Barcode{}, doc.Components[0]) }) + t.Run("when a matrixcode is sent, a matrixcode is created", func(t *testing.T) { col := map[string]interface{}{"matrix_code": nil} validMatrixcode := fixture.Matrixcode() @@ -173,7 +220,7 @@ func TestNewCol(t *testing.T) { func TestGenerate(t *testing.T) { t.Run("when col has no components, it should not send components", func(t *testing.T) { content := map[string]interface{}{} - col := colmapper.Col{Size: 10, Components: make([]mappers.Componentmapper, 0)} + col := colmapper.Col{Size: 10, Components: make([]mappers.OrderedComponents, 0)} provider := mocks.NewProcessorProvider(t) provider.EXPECT().CreateCol(10).Return(nil, nil) @@ -187,9 +234,9 @@ func TestGenerate(t *testing.T) { provider := mocks.NewProcessorProvider(t) provider.EXPECT().CreateCol(10, text.New("test"), text.New("test")).Return(nil, nil) - component := mocks.NewComponentmapper(t) + component := mocks.NewOrderedComponents(t) component.EXPECT().Generate(content, provider).Return([]processorprovider.ProviderComponent{text.New("test")}, nil) - col := colmapper.Col{Size: 10, Components: []mappers.Componentmapper{component, component}} + col := colmapper.Col{Size: 10, Components: []mappers.OrderedComponents{component, component}} _, err := col.Generate(content, provider) @@ -201,9 +248,9 @@ func TestGenerate(t *testing.T) { content := map[string]interface{}{"text1": "test"} provider := mocks.NewProcessorProvider(t) - component := mocks.NewComponentmapper(t) + component := mocks.NewOrderedComponents(t) component.EXPECT().Generate(content, provider).Return(nil, errors.New("any")) - col := colmapper.Col{Size: 10, Components: []mappers.Componentmapper{component}} + col := colmapper.Col{Size: 10, Components: []mappers.OrderedComponents{component}} _, err := col.Generate(content, provider) diff --git a/pkg/processor/mappers/components/imagemapper/image.go b/pkg/processor/mappers/components/imagemapper/image.go index 923728f0..ee777b9d 100644 --- a/pkg/processor/mappers/components/imagemapper/image.go +++ b/pkg/processor/mappers/components/imagemapper/image.go @@ -4,6 +4,7 @@ package imagemapper import ( "fmt" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/order" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) @@ -12,6 +13,7 @@ type Image struct { Value string SourceKey string Props *propsmapper.Rect + Order int } func NewImage(templateImage interface{}) (*Image, error) { @@ -25,7 +27,7 @@ func NewImage(templateImage interface{}) (*Image, error) { return nil, err } if image.SourceKey == "" && image.Value == "" { - return nil, fmt.Errorf("no value passed for image. Add the 'source_key' or a path") + return nil, fmt.Errorf("no value passed for image. Add the 'source_key' or a value") } return image, nil @@ -34,6 +36,11 @@ func NewImage(templateImage interface{}) (*Image, error) { // addFields is responsible for adding the barcode fields according to // the properties informed in the map func (i *Image) addFields(imageMap map[string]interface{}) error { + order, err := order.SetPageOrder(&imageMap, "image", i.SourceKey) + if err != nil { + return err + } + i.Order = order fieldMappers := i.getFieldMappers() for templateName, template := range imageMap { @@ -49,6 +56,11 @@ func (i *Image) addFields(imageMap map[string]interface{}) error { return nil } +// GetOrder is responsible for returning the component's defined order +func (i *Image) GetOrder() int { + return i.Order +} + // getFieldMappers is responsible for defining which methods are responsible for assembling which components. // To do this, the component name is linked to a function in a Map. func (i *Image) getFieldMappers() map[string]func(interface{}) error { diff --git a/pkg/processor/mappers/components/imagemapper/image_test.go b/pkg/processor/mappers/components/imagemapper/image_test.go index 7c1ca43d..52723655 100644 --- a/pkg/processor/mappers/components/imagemapper/image_test.go +++ b/pkg/processor/mappers/components/imagemapper/image_test.go @@ -8,6 +8,19 @@ import ( "github.com/stretchr/testify/assert" ) +func TestGetOrder(t *testing.T) { + t.Run("when getOrder is called, should return defined order", func(t *testing.T) { + templateRows := map[string]interface{}{ + "order": 10.0, + "value": "img", + } + + doc, _ := imagemapper.NewImage(templateRows) + + assert.Equal(t, 10, doc.GetOrder()) + }) +} + func TestNewImage(t *testing.T) { t.Run("when invalid image is sent, should return an error", func(t *testing.T) { imageTemplate := 1 @@ -20,6 +33,7 @@ func TestNewImage(t *testing.T) { t.Run("when props is not sent, image is created", func(t *testing.T) { imageTemplate := map[string]interface{}{ "source_key": "image", + "order": 1.0, } image, err := imagemapper.NewImage(imageTemplate) @@ -31,6 +45,7 @@ func TestNewImage(t *testing.T) { imageTemplate := map[string]interface{}{ "props": 1, "source_key": "name", + "order": 1.0, } image, err := imagemapper.NewImage(imageTemplate) @@ -42,6 +57,7 @@ func TestNewImage(t *testing.T) { imageTemplate := map[string]interface{}{ "invalid_field": 1, "source_key": "name", + "order": 1.0, } image, err := imagemapper.NewImage(imageTemplate) @@ -60,6 +76,7 @@ func TestNewImage(t *testing.T) { t.Run("when invalid source_key is sent, should return an error", func(t *testing.T) { imageTemplate := map[string]interface{}{ "source_key": 123, + "order": 1.0, } image, err := imagemapper.NewImage(imageTemplate) @@ -78,6 +95,7 @@ func TestNewImage(t *testing.T) { t.Run("when source_key is sent, should add source_key", func(t *testing.T) { imageTemplate := map[string]interface{}{ "source_key": "icon", + "order": 1.0, } image, err := imagemapper.NewImage(imageTemplate) @@ -88,6 +106,7 @@ func TestNewImage(t *testing.T) { t.Run("when props is sent, should add props", func(t *testing.T) { imageTemplate := map[string]interface{}{ "source_key": "name", + "order": 1.0, "props": map[string]interface{}{ "left": 10.0, }, diff --git a/pkg/processor/mappers/components/linemapper/line.go b/pkg/processor/mappers/components/linemapper/line.go index d93bdcd3..65af4a05 100644 --- a/pkg/processor/mappers/components/linemapper/line.go +++ b/pkg/processor/mappers/components/linemapper/line.go @@ -4,12 +4,14 @@ package linemapper import ( "fmt" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/order" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Line struct { Props *propsmapper.Line + Order int } func NewLine(code interface{}) (*Line, error) { @@ -28,6 +30,11 @@ func NewLine(code interface{}) (*Line, error) { // addFields is responsible for adding the barcode fields according to // the properties informed in the map func (l *Line) addFields(lineMapper map[string]interface{}) error { + order, err := order.SetPageOrder(&lineMapper, "line", "") + if err != nil { + return err + } + l.Order = order fieldMappers := l.getFieldMappers() for templateName, template := range lineMapper { @@ -43,6 +50,11 @@ func (l *Line) addFields(lineMapper map[string]interface{}) error { return nil } +// GetOrder is responsible for returning the component's defined order +func (l *Line) GetOrder() int { + return l.Order +} + // getFieldMappers is responsible for defining which methods are responsible for assembling which components. // To do this, the component name is linked to a function in a Map. func (l *Line) getFieldMappers() map[string]func(interface{}) error { diff --git a/pkg/processor/mappers/components/linemapper/line_test.go b/pkg/processor/mappers/components/linemapper/line_test.go index d989e2d9..5ed43f2c 100644 --- a/pkg/processor/mappers/components/linemapper/line_test.go +++ b/pkg/processor/mappers/components/linemapper/line_test.go @@ -8,6 +8,18 @@ import ( "github.com/stretchr/testify/assert" ) +func TestQrcodeGetOrder(t *testing.T) { + t.Run("when getOrder is called, should return defined order", func(t *testing.T) { + templateRows := map[string]interface{}{ + "order": 10.0, + } + + doc, _ := linemapper.NewLine(templateRows) + + assert.Equal(t, 10, doc.GetOrder()) + }) +} + func TestNewLine(t *testing.T) { t.Run("when invalid line is sent, should return an error", func(t *testing.T) { lineTemplate := 1 @@ -18,7 +30,9 @@ func TestNewLine(t *testing.T) { assert.NotNil(t, err) }) t.Run("when props is not sent, line is created", func(t *testing.T) { - lineTemplate := map[string]interface{}{} + lineTemplate := map[string]interface{}{ + "order": 1.0, + } line, err := linemapper.NewLine(lineTemplate) @@ -28,6 +42,7 @@ func TestNewLine(t *testing.T) { t.Run("when invalid props is sent, should return an error", func(t *testing.T) { lineTemplate := map[string]interface{}{ "props": 1, + "order": 1.0, } line, err := linemapper.NewLine(lineTemplate) @@ -39,6 +54,7 @@ func TestNewLine(t *testing.T) { lineTemplate := map[string]interface{}{ "invalid_field": 1, "code": "123456789", + "order": 1.0, } line, err := linemapper.NewLine(lineTemplate) diff --git a/pkg/processor/mappers/components/order/componentorganizer.go b/pkg/processor/mappers/components/order/componentorganizer.go new file mode 100644 index 00000000..3a8a3553 --- /dev/null +++ b/pkg/processor/mappers/components/order/componentorganizer.go @@ -0,0 +1,23 @@ +// ordering package is a group of functions associated with component ordering, +// This package seeks to avoid code duplication between ordered components +package order + +import ( + "fmt" +) + +// SetPageOrder is responsible for validating the component order and adding the order to the page +func SetPageOrder(template *map[string]interface{}, resourceName, sourceKey string) (int, error) { + defer delete(*template, "order") + + order, ok := (*template)["order"] + if !ok { + return 0, fmt.Errorf("could not find field order on %s \"%s\"", resourceName, sourceKey) + } + validOrder, ok := order.(float64) + if !ok || validOrder < 1 { + return 0, fmt.Errorf("the order field passed on %s \"%s\" is not valid", resourceName, sourceKey) + } + + return int(validOrder), nil +} diff --git a/pkg/processor/mappers/components/order/componentorganizer_test.go b/pkg/processor/mappers/components/order/componentorganizer_test.go new file mode 100644 index 00000000..fb132ae9 --- /dev/null +++ b/pkg/processor/mappers/components/order/componentorganizer_test.go @@ -0,0 +1,42 @@ +package order_test + +import ( + "testing" + + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/order" + "github.com/stretchr/testify/assert" +) + +func TestN(t *testing.T) { + t.Run("when the order field is not sent, should return an error", func(t *testing.T) { + template := map[string]interface{}{ + "template_1": nil, + } + + _, err := order.SetPageOrder(&template, "resource_name", "resource_key") + + assert.NotNil(t, err) + }) + t.Run("when the order field is less than 1, should return an error", func(t *testing.T) { + template := map[string]interface{}{ + "row_template_1": nil, + "order": 0.0, + } + + _, err := order.SetPageOrder(&template, "resource_name", "resource_key") + + assert.NotNil(t, err) + }) + t.Run("when the order field found, should remove order field", func(t *testing.T) { + template := map[string]interface{}{ + "row_template_1": nil, + "order": 1.0, + } + + _, err := order.SetPageOrder(&template, "resource_name", "resource_key") + _, ok := template["order"] + + assert.Nil(t, err) + assert.False(t, ok) + }) +} diff --git a/pkg/processor/mappers/components/rowmapper/row.go b/pkg/processor/mappers/components/rowmapper/row.go index 3b437256..beb8589c 100644 --- a/pkg/processor/mappers/components/rowmapper/row.go +++ b/pkg/processor/mappers/components/rowmapper/row.go @@ -39,6 +39,7 @@ func NewRow(templateRows interface{}, sourceKey string, factory mappers.Abstract return row, nil } +// GetOrder is responsible for returning the component's defined order func (r *Row) GetOrder() int { return r.order } diff --git a/pkg/processor/mappers/components/rowmapper/row_test.go b/pkg/processor/mappers/components/rowmapper/row_test.go index 1b7d6509..4fbc77d0 100644 --- a/pkg/processor/mappers/components/rowmapper/row_test.go +++ b/pkg/processor/mappers/components/rowmapper/row_test.go @@ -104,16 +104,19 @@ func TestNewRow(t *testing.T) { } func TestGenerate(t *testing.T) { - t.Run("when content no has source_key, should return an error", func(t *testing.T) { - content := map[string]interface{}{} + t.Run("when content no has source_key, should send an empty list", func(t *testing.T) { + content := map[string]interface{}{"source_key_test": 1} factory := mocks.NewAbstractFactoryMaps(t) provider := mocks.NewProcessorProvider(t) + provider.EXPECT().CreateRow(10.0).Return(nil, nil) + component := mocks.NewComponentmapper(t) + component.EXPECT().Generate(map[string]interface{}{}, provider).Return(nil, nil) - row := rowmapper.Row{Height: 10, Cols: make([]mappers.Componentmapper, 0), Factory: factory, SourceKey: "test"} + row := rowmapper.Row{Height: 10, Cols: []mappers.Componentmapper{component}, Factory: factory, SourceKey: "test"} newRow, err := row.Generate(content, provider) - assert.NotNil(t, err) - assert.Nil(t, newRow) + assert.NotNil(t, newRow) + assert.Nil(t, err) }) t.Run("when row no has row, it should no sent row", func(t *testing.T) { content := map[string]interface{}{"content": map[string]interface{}{"text": "value"}} diff --git a/pkg/processor/mappers/components/signaturemapper/signature.go b/pkg/processor/mappers/components/signaturemapper/signature.go index 25d64dc4..84deec61 100644 --- a/pkg/processor/mappers/components/signaturemapper/signature.go +++ b/pkg/processor/mappers/components/signaturemapper/signature.go @@ -4,6 +4,7 @@ package signaturemapper import ( "fmt" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/order" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) @@ -12,6 +13,7 @@ type Signature struct { SourceKey string Value string Props *propsmapper.Signature + Order int } func NewSignature(code interface{}) (*Signature, error) { @@ -34,6 +36,11 @@ func NewSignature(code interface{}) (*Signature, error) { // addFields is responsible for adding the signature fields according to // the properties informed in the map func (s *Signature) addFields(signatureMap map[string]interface{}) error { + order, err := order.SetPageOrder(&signatureMap, "signature", s.SourceKey) + if err != nil { + return err + } + s.Order = order fieldMappers := s.getFieldMappers() for templateName, template := range signatureMap { @@ -49,6 +56,11 @@ func (s *Signature) addFields(signatureMap map[string]interface{}) error { return nil } +// GetOrder is responsible for returning the component's defined order +func (s *Signature) GetOrder() int { + return s.Order +} + // getFieldMappers is responsible for defining which methods are responsible for assembling which components. // To do this, the component name is linked to a function in a Map. func (s *Signature) getFieldMappers() map[string]func(interface{}) error { diff --git a/pkg/processor/mappers/components/signaturemapper/signature_test.go b/pkg/processor/mappers/components/signaturemapper/signature_test.go index 98ee4708..8ee19871 100644 --- a/pkg/processor/mappers/components/signaturemapper/signature_test.go +++ b/pkg/processor/mappers/components/signaturemapper/signature_test.go @@ -8,6 +8,19 @@ import ( "github.com/stretchr/testify/assert" ) +func TestQrcodeGetOrder(t *testing.T) { + t.Run("when getOrder is called, should return defined order", func(t *testing.T) { + templateRows := map[string]interface{}{ + "order": 10.0, + "value": "test", + } + + doc, _ := signaturemapper.NewSignature(templateRows) + + assert.Equal(t, 10, doc.GetOrder()) + }) +} + func TestNewSignature(t *testing.T) { t.Run("when invalid signature is sent, should return an error", func(t *testing.T) { signatureTemplate := 1 @@ -20,6 +33,7 @@ func TestNewSignature(t *testing.T) { t.Run("when props is not sent, signature is created", func(t *testing.T) { signatureTemplate := map[string]interface{}{ "value": "123456789", + "order": 1.0, } signature, err := signaturemapper.NewSignature(signatureTemplate) @@ -31,6 +45,7 @@ func TestNewSignature(t *testing.T) { signatureTemplate := map[string]interface{}{ "props": 1, "value": "123456789", + "order": 1.0, } signature, err := signaturemapper.NewSignature(signatureTemplate) @@ -41,6 +56,7 @@ func TestNewSignature(t *testing.T) { t.Run("when invalid field is sent, should return an error", func(t *testing.T) { signatureTemplate := map[string]interface{}{ "invalid_field": 1, + "order": 1.0, } signature, err := signaturemapper.NewSignature(signatureTemplate) @@ -59,6 +75,7 @@ func TestNewSignature(t *testing.T) { t.Run("when invalid value is sent, should return an error", func(t *testing.T) { signatureTemplate := map[string]interface{}{ "value": 123, + "order": 1.0, } signature, err := signaturemapper.NewSignature(signatureTemplate) @@ -69,6 +86,7 @@ func TestNewSignature(t *testing.T) { t.Run("when invalid source_key is sent, should return an error", func(t *testing.T) { signatureTemplate := map[string]interface{}{ "source_key": 123, + "order": 1.0, } signature, err := signaturemapper.NewSignature(signatureTemplate) @@ -79,6 +97,7 @@ func TestNewSignature(t *testing.T) { t.Run("when value is not sent, should add source key", func(t *testing.T) { signatureTemplate := map[string]interface{}{ "source_key": "source", + "order": 1.0, } signature, err := signaturemapper.NewSignature(signatureTemplate) @@ -90,6 +109,7 @@ func TestNewSignature(t *testing.T) { t.Run("when source_key is not sent, should add code", func(t *testing.T) { signatureTemplate := map[string]interface{}{ "value": "value", + "order": 1.0, } signature, err := signaturemapper.NewSignature(signatureTemplate) diff --git a/pkg/processor/mappers/components/textmapper/text.go b/pkg/processor/mappers/components/textmapper/text.go index 91f21442..0521786d 100644 --- a/pkg/processor/mappers/components/textmapper/text.go +++ b/pkg/processor/mappers/components/textmapper/text.go @@ -3,6 +3,7 @@ package textmapper import ( "fmt" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/order" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) @@ -11,6 +12,7 @@ type Text struct { SourceKey string Value string Props *propsmapper.Text + Order int } func NewText(templateText interface{}) (*Text, error) { @@ -33,6 +35,11 @@ func NewText(templateText interface{}) (*Text, error) { // addFields is responsible for adding the text fields according to // the properties informed in the map func (t *Text) addFields(valueMap map[string]interface{}) error { + order, err := order.SetPageOrder(&valueMap, "text", t.SourceKey) + if err != nil { + return err + } + t.Order = order fieldMappers := t.getFieldMappers() for templateName, template := range valueMap { @@ -48,6 +55,11 @@ func (t *Text) addFields(valueMap map[string]interface{}) error { return nil } +// GetOrder is responsible for returning the component's defined order +func (t *Text) GetOrder() int { + return t.Order +} + // getFieldMappers is responsible for defining which methods are responsible for assembling which components. // To do this, the component name is linked to a function in a Map. func (t *Text) getFieldMappers() map[string]func(interface{}) error { diff --git a/pkg/processor/mappers/components/textmapper/text_test.go b/pkg/processor/mappers/components/textmapper/text_test.go index a7cfb2cd..e4c0d8a7 100644 --- a/pkg/processor/mappers/components/textmapper/text_test.go +++ b/pkg/processor/mappers/components/textmapper/text_test.go @@ -8,6 +8,19 @@ import ( "github.com/stretchr/testify/assert" ) +func TestQrcodeGetOrder(t *testing.T) { + t.Run("when getOrder is called, should return defined order", func(t *testing.T) { + templateRows := map[string]interface{}{ + "order": 10.0, + "value": "text", + } + + doc, _ := textmapper.NewText(templateRows) + + assert.Equal(t, 10, doc.GetOrder()) + }) +} + func TestNewText(t *testing.T) { t.Run("when invalid text is sent, should return an error", func(t *testing.T) { textTemplate := 1 @@ -20,6 +33,7 @@ func TestNewText(t *testing.T) { t.Run("when props is not sent, text is created", func(t *testing.T) { textTemplate := map[string]interface{}{ "value": "123456789", + "order": 1.0, } text, err := textmapper.NewText(textTemplate) @@ -31,6 +45,7 @@ func TestNewText(t *testing.T) { textTemplate := map[string]interface{}{ "props": 1, "value": "123456789", + "order": 1.0, } text, err := textmapper.NewText(textTemplate) @@ -42,6 +57,7 @@ func TestNewText(t *testing.T) { textTemplate := map[string]interface{}{ "invalid_field": 1, "value": "123456789", + "order": 1.0, } text, err := textmapper.NewText(textTemplate) @@ -50,7 +66,9 @@ func TestNewText(t *testing.T) { assert.NotNil(t, err) }) t.Run("when source_key and value are not sent, should return an error", func(t *testing.T) { - textTemplate := map[string]interface{}{} + textTemplate := map[string]interface{}{ + "order": 1.0, + } text, err := textmapper.NewText(textTemplate) @@ -60,6 +78,7 @@ func TestNewText(t *testing.T) { t.Run("when invalid value is sent, should return an error", func(t *testing.T) { textTemplate := map[string]interface{}{ "value": 123, + "order": 1.0, } text, err := textmapper.NewText(textTemplate) @@ -70,6 +89,7 @@ func TestNewText(t *testing.T) { t.Run("when invalid source_key is sent, should return an error", func(t *testing.T) { textTemplate := map[string]interface{}{ "source_key": 123, + "order": 1.0, } text, err := textmapper.NewText(textTemplate) @@ -80,6 +100,7 @@ func TestNewText(t *testing.T) { t.Run("when value is not sent, should add source key", func(t *testing.T) { textTemplate := map[string]interface{}{ "source_key": "source", + "order": 1.0, } text, err := textmapper.NewText(textTemplate) @@ -91,6 +112,7 @@ func TestNewText(t *testing.T) { t.Run("when source_key is not sent, should add value", func(t *testing.T) { textTemplate := map[string]interface{}{ "value": "value", + "order": 1.0, } text, err := textmapper.NewText(textTemplate) diff --git a/test/maroto/processor/json/add_page_template.json b/test/maroto/processor/json/add_page_template.json index 30c86792..bc28b0d2 100644 --- a/test/maroto/processor/json/add_page_template.json +++ b/test/maroto/processor/json/add_page_template.json @@ -14,6 +14,7 @@ "cols": [ { "text": { + "order": 1, "source_key": "page_1_row" } } @@ -31,6 +32,7 @@ "cols": [ { "text": { + "order": 1, "source_key": "page_2_row" } } diff --git a/test/maroto/processor/json/auto_row_template.json b/test/maroto/processor/json/auto_row_template.json index 8539ae29..62c5bdea 100644 --- a/test/maroto/processor/json/auto_row_template.json +++ b/test/maroto/processor/json/auto_row_template.json @@ -10,12 +10,14 @@ "cols": [ { "image": { + "order": 1, "source_key": "biplane" }, "size": 5 }, { "text": { + "order": 1, "source_key": "intro" }, "size": 7 @@ -27,12 +29,14 @@ "cols": [ { "image": { + "order": 1, "source_key": "biplane" }, "size": 5 }, { "text": { + "order": 1, "source_key": "intro", "props": { "size": 13 @@ -47,12 +51,14 @@ "cols": [ { "bar_code": { + "order": 1, "source_key": "bar_col" }, "size": 4 }, { "text": { + "order": 1, "source_key": "intro" }, "size": 8 @@ -64,12 +70,14 @@ "cols": [ { "matrix_code": { + "order": 1, "source_key": "matrix_code" }, "size": 3 }, { "text": { + "order": 1, "source_key": "intro" }, "size": 9 @@ -81,12 +89,14 @@ "cols": [ { "qr_code": { + "order": 1, "source_key": "qr_code" }, "size": 2 }, { "text": { + "order": 1, "source_key": "intro" }, "size": 10 diff --git a/test/maroto/processor/json/background_template.json b/test/maroto/processor/json/background_template.json index 8f21af9c..35e77026 100644 --- a/test/maroto/processor/json/background_template.json +++ b/test/maroto/processor/json/background_template.json @@ -28,6 +28,7 @@ { "size": 12, "text": { + "order": 1, "source_key": "title", "props": { "size": 18 @@ -50,6 +51,7 @@ { "size": 20, "image": { + "order": 1, "value": "docs/assets/images/signature.png", "props": { "center": true diff --git a/test/maroto/processor/json/barcodegrid_template.json b/test/maroto/processor/json/barcodegrid_template.json index 88a8332d..6916a9d8 100644 --- a/test/maroto/processor/json/barcodegrid_template.json +++ b/test/maroto/processor/json/barcodegrid_template.json @@ -12,6 +12,7 @@ { "size": 2, "bar_code": { + "order": 1, "source_key": "maroto_url", "props": { "percent": 50 @@ -21,6 +22,7 @@ { "size": 4, "bar_code": { + "order": 1, "source_key": "maroto_url", "props": { "percent": 75 @@ -30,6 +32,7 @@ { "size": 6, "bar_code": { + "order": 1, "source_key": "maroto_url", "props": { "percent": 100 @@ -45,6 +48,7 @@ { "size": 2, "bar_code": { + "order": 1, "source_key": "maroto_url", "props": { "center": true, @@ -55,6 +59,7 @@ { "size": 4, "bar_code": { + "order": 1, "source_key": "maroto_url", "props": { "center": true, @@ -65,6 +70,7 @@ { "size": 6, "bar_code": { + "order": 1, "source_key": "maroto_url", "props": { "center": true, @@ -81,6 +87,7 @@ { "size": 6, "bar_code": { + "order": 1, "source_key": "maroto_url", "props": { "percent": 50 @@ -90,6 +97,7 @@ { "size": 4, "bar_code": { + "order": 1, "source_key": "maroto_url", "props": { "percent": 75 @@ -99,6 +107,7 @@ { "size": 2, "bar_code": { + "order": 1, "source_key": "maroto_url", "props": { "percent": 100 @@ -114,6 +123,7 @@ { "size": 6, "bar_code": { + "order": 1, "source_key": "maroto_url", "props": { "center": true, @@ -124,6 +134,7 @@ { "size": 4, "bar_code": { + "order": 1, "source_key": "maroto_url", "props": { "center": true, @@ -134,6 +145,7 @@ { "size": 2, "bar_code": { + "order": 1, "source_key": "maroto_url", "props": { "center": true, @@ -150,6 +162,7 @@ { "size": 2, "bar_code": { + "order": 1, "source_key": "code_number", "props": { "center": true, @@ -160,6 +173,7 @@ { "size": 4, "bar_code": { + "order": 1, "source_key": "code_number", "props": { "center": true, @@ -170,6 +184,7 @@ { "size": 6, "bar_code": { + "order": 1, "source_key": "code_number", "props": { "center": true, @@ -185,6 +200,7 @@ { "size": 2, "bar_code": { + "order": 1, "source_key": "code_number", "props": { "center": true, @@ -195,6 +211,7 @@ { "size": 4, "bar_code": { + "order": 1, "source_key": "code_number", "props": { "center": true, @@ -205,6 +222,7 @@ { "size": 6, "bar_code": { + "order": 1, "source_key": "code_number", "props": { "center": true, diff --git a/test/maroto/processor/json/simple_pdf_templates.json b/test/maroto/processor/json/simple_pdf_templates.json index becc029f..bda2b326 100644 --- a/test/maroto/processor/json/simple_pdf_templates.json +++ b/test/maroto/processor/json/simple_pdf_templates.json @@ -5,6 +5,7 @@ "cols": [ { "text": { + "order": 1, "source_key": "header_value" }, "size": 12 @@ -18,6 +19,7 @@ "cols": [ { "text": { + "order": 1, "source_key": "footer_value" }, "size": 12 @@ -33,12 +35,14 @@ "cols": [ { "text": { + "order": 1, "source_key": "value_1" }, "size": 6.0 }, { "text": { + "order": 1, "source_key": "value_2" }, "size": 6.0 @@ -52,6 +56,7 @@ "cols": [ { "text": { + "order": 1, "source_key": "value_2" }, "size": 10.0 @@ -63,6 +68,7 @@ "cols": [ { "text": { + "order": 1, "source_key": "value_2" }, "size": 10.0 From 2c98929d2cd4986a50d201ea6b07823bce762748 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Mon, 30 Dec 2024 12:17:54 -0300 Subject: [PATCH 089/116] feat: add cell props in row --- mocks/ProcessorProvider.go | 66 ++++++------- mocks/orderedComponentCreator.go | 94 ------------------- .../mappers/components/colmapper/col.go | 24 ++++- .../mappers/components/colmapper/col_test.go | 5 +- .../mappers/components/rowmapper/row.go | 20 +++- .../mappers/components/rowmapper/row_test.go | 47 +++++++--- pkg/processor/mappers/propsmapper/cell.go | 41 ++++++++ .../mappers/propsmapper/cell_test.go | 1 + pkg/processor/mappers/propsmapper/consts.go | 35 ++++--- pkg/processor/processorprovider/Maroto.go | 39 ++++++-- .../processorprovider/Maroto_test.go | 4 +- pkg/processor/processorprovider/provider.go | 4 +- 12 files changed, 216 insertions(+), 164 deletions(-) delete mode 100644 mocks/orderedComponentCreator.go create mode 100644 pkg/processor/mappers/propsmapper/cell.go create mode 100644 pkg/processor/mappers/propsmapper/cell_test.go diff --git a/mocks/ProcessorProvider.go b/mocks/ProcessorProvider.go index 55a2ee6a..5d881003 100644 --- a/mocks/ProcessorProvider.go +++ b/mocks/ProcessorProvider.go @@ -302,14 +302,14 @@ func (_c *ProcessorProvider_CreateBarCode_Call) RunAndReturn(run func(string, .. return _c } -// CreateCol provides a mock function with given fields: size, components -func (_m *ProcessorProvider) CreateCol(size int, components ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error) { +// CreateCol provides a mock function with given fields: size, props, components +func (_m *ProcessorProvider) CreateCol(size int, props *propsmapper.Cell, components ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error) { _va := make([]interface{}, len(components)) for _i := range components { _va[_i] = components[_i] } var _ca []interface{} - _ca = append(_ca, size) + _ca = append(_ca, size, props) _ca = append(_ca, _va...) ret := _m.Called(_ca...) @@ -319,19 +319,19 @@ func (_m *ProcessorProvider) CreateCol(size int, components ...processorprovider var r0 processorprovider.ProviderComponent var r1 error - if rf, ok := ret.Get(0).(func(int, ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error)); ok { - return rf(size, components...) + if rf, ok := ret.Get(0).(func(int, *propsmapper.Cell, ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error)); ok { + return rf(size, props, components...) } - if rf, ok := ret.Get(0).(func(int, ...processorprovider.ProviderComponent) processorprovider.ProviderComponent); ok { - r0 = rf(size, components...) + if rf, ok := ret.Get(0).(func(int, *propsmapper.Cell, ...processorprovider.ProviderComponent) processorprovider.ProviderComponent); ok { + r0 = rf(size, props, components...) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(processorprovider.ProviderComponent) } } - if rf, ok := ret.Get(1).(func(int, ...processorprovider.ProviderComponent) error); ok { - r1 = rf(size, components...) + if rf, ok := ret.Get(1).(func(int, *propsmapper.Cell, ...processorprovider.ProviderComponent) error); ok { + r1 = rf(size, props, components...) } else { r1 = ret.Error(1) } @@ -346,21 +346,22 @@ type ProcessorProvider_CreateCol_Call struct { // CreateCol is a helper method to define mock.On call // - size int +// - props *propsmapper.Cell // - components ...processorprovider.ProviderComponent -func (_e *ProcessorProvider_Expecter) CreateCol(size interface{}, components ...interface{}) *ProcessorProvider_CreateCol_Call { +func (_e *ProcessorProvider_Expecter) CreateCol(size interface{}, props interface{}, components ...interface{}) *ProcessorProvider_CreateCol_Call { return &ProcessorProvider_CreateCol_Call{Call: _e.mock.On("CreateCol", - append([]interface{}{size}, components...)...)} + append([]interface{}{size, props}, components...)...)} } -func (_c *ProcessorProvider_CreateCol_Call) Run(run func(size int, components ...processorprovider.ProviderComponent)) *ProcessorProvider_CreateCol_Call { +func (_c *ProcessorProvider_CreateCol_Call) Run(run func(size int, props *propsmapper.Cell, components ...processorprovider.ProviderComponent)) *ProcessorProvider_CreateCol_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]processorprovider.ProviderComponent, len(args)-1) - for i, a := range args[1:] { + variadicArgs := make([]processorprovider.ProviderComponent, len(args)-2) + for i, a := range args[2:] { if a != nil { variadicArgs[i] = a.(processorprovider.ProviderComponent) } } - run(args[0].(int), variadicArgs...) + run(args[0].(int), args[1].(*propsmapper.Cell), variadicArgs...) }) return _c } @@ -370,7 +371,7 @@ func (_c *ProcessorProvider_CreateCol_Call) Return(_a0 processorprovider.Provide return _c } -func (_c *ProcessorProvider_CreateCol_Call) RunAndReturn(run func(int, ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error)) *ProcessorProvider_CreateCol_Call { +func (_c *ProcessorProvider_CreateCol_Call) RunAndReturn(run func(int, *propsmapper.Cell, ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error)) *ProcessorProvider_CreateCol_Call { _c.Call.Return(run) return _c } @@ -706,14 +707,14 @@ func (_c *ProcessorProvider_CreateQrCode_Call) RunAndReturn(run func(string, ... return _c } -// CreateRow provides a mock function with given fields: height, components -func (_m *ProcessorProvider) CreateRow(height float64, components ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error) { +// CreateRow provides a mock function with given fields: height, props, components +func (_m *ProcessorProvider) CreateRow(height float64, props *propsmapper.Cell, components ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error) { _va := make([]interface{}, len(components)) for _i := range components { _va[_i] = components[_i] } var _ca []interface{} - _ca = append(_ca, height) + _ca = append(_ca, height, props) _ca = append(_ca, _va...) ret := _m.Called(_ca...) @@ -723,19 +724,19 @@ func (_m *ProcessorProvider) CreateRow(height float64, components ...processorpr var r0 processorprovider.ProviderComponent var r1 error - if rf, ok := ret.Get(0).(func(float64, ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error)); ok { - return rf(height, components...) + if rf, ok := ret.Get(0).(func(float64, *propsmapper.Cell, ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error)); ok { + return rf(height, props, components...) } - if rf, ok := ret.Get(0).(func(float64, ...processorprovider.ProviderComponent) processorprovider.ProviderComponent); ok { - r0 = rf(height, components...) + if rf, ok := ret.Get(0).(func(float64, *propsmapper.Cell, ...processorprovider.ProviderComponent) processorprovider.ProviderComponent); ok { + r0 = rf(height, props, components...) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(processorprovider.ProviderComponent) } } - if rf, ok := ret.Get(1).(func(float64, ...processorprovider.ProviderComponent) error); ok { - r1 = rf(height, components...) + if rf, ok := ret.Get(1).(func(float64, *propsmapper.Cell, ...processorprovider.ProviderComponent) error); ok { + r1 = rf(height, props, components...) } else { r1 = ret.Error(1) } @@ -750,21 +751,22 @@ type ProcessorProvider_CreateRow_Call struct { // CreateRow is a helper method to define mock.On call // - height float64 +// - props *propsmapper.Cell // - components ...processorprovider.ProviderComponent -func (_e *ProcessorProvider_Expecter) CreateRow(height interface{}, components ...interface{}) *ProcessorProvider_CreateRow_Call { +func (_e *ProcessorProvider_Expecter) CreateRow(height interface{}, props interface{}, components ...interface{}) *ProcessorProvider_CreateRow_Call { return &ProcessorProvider_CreateRow_Call{Call: _e.mock.On("CreateRow", - append([]interface{}{height}, components...)...)} + append([]interface{}{height, props}, components...)...)} } -func (_c *ProcessorProvider_CreateRow_Call) Run(run func(height float64, components ...processorprovider.ProviderComponent)) *ProcessorProvider_CreateRow_Call { +func (_c *ProcessorProvider_CreateRow_Call) Run(run func(height float64, props *propsmapper.Cell, components ...processorprovider.ProviderComponent)) *ProcessorProvider_CreateRow_Call { _c.Call.Run(func(args mock.Arguments) { - variadicArgs := make([]processorprovider.ProviderComponent, len(args)-1) - for i, a := range args[1:] { + variadicArgs := make([]processorprovider.ProviderComponent, len(args)-2) + for i, a := range args[2:] { if a != nil { variadicArgs[i] = a.(processorprovider.ProviderComponent) } } - run(args[0].(float64), variadicArgs...) + run(args[0].(float64), args[1].(*propsmapper.Cell), variadicArgs...) }) return _c } @@ -774,7 +776,7 @@ func (_c *ProcessorProvider_CreateRow_Call) Return(_a0 processorprovider.Provide return _c } -func (_c *ProcessorProvider_CreateRow_Call) RunAndReturn(run func(float64, ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error)) *ProcessorProvider_CreateRow_Call { +func (_c *ProcessorProvider_CreateRow_Call) RunAndReturn(run func(float64, *propsmapper.Cell, ...processorprovider.ProviderComponent) (processorprovider.ProviderComponent, error)) *ProcessorProvider_CreateRow_Call { _c.Call.Return(run) return _c } diff --git a/mocks/orderedComponentCreator.go b/mocks/orderedComponentCreator.go deleted file mode 100644 index 61faee75..00000000 --- a/mocks/orderedComponentCreator.go +++ /dev/null @@ -1,94 +0,0 @@ -// Code generated by mockery v2.42.0. DO NOT EDIT. - -package mocks - -import ( - mappers "github.com/johnfercher/maroto/v2/pkg/processor/mappers" - mock "github.com/stretchr/testify/mock" -) - -// orderedComponentCreator is an autogenerated mock type for the orderedComponentCreator type -type orderedComponentCreator struct { - mock.Mock -} - -type orderedComponentCreator_Expecter struct { - mock *mock.Mock -} - -func (_m *orderedComponentCreator) EXPECT() *orderedComponentCreator_Expecter { - return &orderedComponentCreator_Expecter{mock: &_m.Mock} -} - -// Execute provides a mock function with given fields: template -func (_m *orderedComponentCreator) Execute(template interface{}) (mappers.Componentmapper, error) { - ret := _m.Called(template) - - if len(ret) == 0 { - panic("no return value specified for Execute") - } - - var r0 mappers.Componentmapper - var r1 error - if rf, ok := ret.Get(0).(func(interface{}) (mappers.Componentmapper, error)); ok { - return rf(template) - } - if rf, ok := ret.Get(0).(func(interface{}) mappers.Componentmapper); ok { - r0 = rf(template) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(mappers.Componentmapper) - } - } - - if rf, ok := ret.Get(1).(func(interface{}) error); ok { - r1 = rf(template) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// orderedComponentCreator_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' -type orderedComponentCreator_Execute_Call struct { - *mock.Call -} - -// Execute is a helper method to define mock.On call -// - template interface{} -func (_e *orderedComponentCreator_Expecter) Execute(template interface{}) *orderedComponentCreator_Execute_Call { - return &orderedComponentCreator_Execute_Call{Call: _e.mock.On("Execute", template)} -} - -func (_c *orderedComponentCreator_Execute_Call) Run(run func(template interface{})) *orderedComponentCreator_Execute_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(interface{})) - }) - return _c -} - -func (_c *orderedComponentCreator_Execute_Call) Return(_a0 mappers.Componentmapper, _a1 error) *orderedComponentCreator_Execute_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *orderedComponentCreator_Execute_Call) RunAndReturn(run func(interface{}) (mappers.Componentmapper, error)) *orderedComponentCreator_Execute_Call { - _c.Call.Return(run) - return _c -} - -// newOrderedComponentCreator creates a new instance of orderedComponentCreator. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func newOrderedComponentCreator(t interface { - mock.TestingT - Cleanup(func()) -}, -) *orderedComponentCreator { - mock := &orderedComponentCreator{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/pkg/processor/mappers/components/colmapper/col.go b/pkg/processor/mappers/components/colmapper/col.go index ff579894..9531cac7 100644 --- a/pkg/processor/mappers/components/colmapper/col.go +++ b/pkg/processor/mappers/components/colmapper/col.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) @@ -14,6 +15,7 @@ type Col struct { Size int Components []mappers.OrderedComponents factory mappers.AbstractFactoryMaps + props *propsmapper.Cell } func NewCol(templateCols interface{}, factory mappers.AbstractFactoryMaps) (*Col, error) { @@ -24,6 +26,10 @@ func NewCol(templateCols interface{}, factory mappers.AbstractFactoryMaps) (*Col col := &Col{Size: 0, Components: make([]mappers.OrderedComponents, 0), factory: factory} + if err := col.setProps(&mapCols); err != nil { + return nil, err + } + if err := col.setSize(&mapCols); err != nil { return nil, err } @@ -82,6 +88,22 @@ func (c *Col) setSize(template *map[string]interface{}) error { return nil } +// setProps is responsible for creating template col props +func (c *Col) setProps(template *map[string]interface{}) error { + props, ok := (*template)["props"] + if !ok { + return nil + } + defer delete(*template, "props") + + propsRow, err := propsmapper.NewCell(props) + if err != nil { + return err + } + c.props = propsRow + return nil +} + func (c *Col) getFieldMapperByTemplateName(templateName string, mappers map[string]factoryComponent) (factoryComponent, error) { for mapperName, mapper := range mappers { if strings.HasPrefix(templateName, mapperName) { @@ -121,7 +143,7 @@ func (c *Col) Generate(content map[string]interface{}, provider processorprovide components = append(components, newComponent...) } - col, err := provider.CreateCol(c.Size, components...) + col, err := provider.CreateCol(c.Size, c.props, components...) if err != nil { return nil, err } diff --git a/pkg/processor/mappers/components/colmapper/col_test.go b/pkg/processor/mappers/components/colmapper/col_test.go index 511bf0bc..56e6c02f 100644 --- a/pkg/processor/mappers/components/colmapper/col_test.go +++ b/pkg/processor/mappers/components/colmapper/col_test.go @@ -14,6 +14,7 @@ import ( "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/linemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/signaturemapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/textmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -222,7 +223,7 @@ func TestGenerate(t *testing.T) { content := map[string]interface{}{} col := colmapper.Col{Size: 10, Components: make([]mappers.OrderedComponents, 0)} provider := mocks.NewProcessorProvider(t) - provider.EXPECT().CreateCol(10).Return(nil, nil) + provider.EXPECT().CreateCol(10, (*propsmapper.Cell)(nil)).Return(nil, nil) _, err := col.Generate(content, provider) @@ -232,7 +233,7 @@ func TestGenerate(t *testing.T) { t.Run("when col has two components, it should add two components", func(t *testing.T) { content := map[string]interface{}{"text1": "test", "text2": "test"} provider := mocks.NewProcessorProvider(t) - provider.EXPECT().CreateCol(10, text.New("test"), text.New("test")).Return(nil, nil) + provider.EXPECT().CreateCol(10, (*propsmapper.Cell)(nil), text.New("test"), text.New("test")).Return(nil, nil) component := mocks.NewOrderedComponents(t) component.EXPECT().Generate(content, provider).Return([]processorprovider.ProviderComponent{text.New("test")}, nil) diff --git a/pkg/processor/mappers/components/rowmapper/row.go b/pkg/processor/mappers/components/rowmapper/row.go index beb8589c..41c9000a 100644 --- a/pkg/processor/mappers/components/rowmapper/row.go +++ b/pkg/processor/mappers/components/rowmapper/row.go @@ -5,17 +5,20 @@ import ( "fmt" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" ) type Row struct { Height float64 + Props *propsmapper.Cell Cols []mappers.Componentmapper Factory mappers.AbstractFactoryMaps SourceKey string order int } +// NewRow is responsible for creating a row template func NewRow(templateRows interface{}, sourceKey string, factory mappers.AbstractFactoryMaps) (*Row, error) { mapRows, ok := templateRows.(map[string]interface{}) if !ok { @@ -81,6 +84,7 @@ func (r *Row) addComponents(mapRows map[string]interface{}) error { return nil } +// setHeight is responsible for creating template row height func (r *Row) setHeight(template interface{}) error { height, ok := template.(float64) if !ok { @@ -90,6 +94,7 @@ func (r *Row) setHeight(template interface{}) error { return nil } +// setCols is responsible for creating template row cols func (r *Row) setCols(template interface{}) error { cols, ok := template.([]interface{}) if !ok { @@ -108,15 +113,27 @@ func (r *Row) setCols(template interface{}) error { return nil } +// setProps is responsible for creating template row props +func (r *Row) setProps(template interface{}) error { + propsRow, err := propsmapper.NewCell(template) + if err != nil { + return err + } + r.Props = propsRow + return nil +} + // getFieldMappers is responsible for defining which methods are responsible for assembling which components. // To do this, the component name is linked to a function in a Map. func (r *Row) getFieldMappers() map[string]func(interface{}) error { return map[string]func(interface{}) error{ "height": r.setHeight, "cols": r.setCols, + "props": r.setProps, } } +// getRowContent is responsible for getting content data according to sourceKey func (r *Row) getRowContent(content map[string]interface{}) (map[string]interface{}, error) { rowContent, ok := content[r.SourceKey] if !ok { @@ -131,6 +148,7 @@ func (r *Row) getRowContent(content map[string]interface{}) (map[string]interfac ) } +// Generate is responsible for computer template and generate line component func (r *Row) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( []processorprovider.ProviderComponent, error, ) { @@ -148,7 +166,7 @@ func (r *Row) Generate(content map[string]interface{}, provider processorprovide cols = append(cols, newCol...) } - row, err := provider.CreateRow(r.Height, cols...) + row, err := provider.CreateRow(r.Height, r.Props, cols...) if err != nil { return nil, err } diff --git a/pkg/processor/mappers/components/rowmapper/row_test.go b/pkg/processor/mappers/components/rowmapper/row_test.go index 4fbc77d0..02c728c3 100644 --- a/pkg/processor/mappers/components/rowmapper/row_test.go +++ b/pkg/processor/mappers/components/rowmapper/row_test.go @@ -6,8 +6,8 @@ import ( "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" - "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/listmapper" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/rowmapper" + "github.com/johnfercher/maroto/v2/pkg/processor/mappers/propsmapper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -79,28 +79,51 @@ func TestNewRow(t *testing.T) { assert.Nil(t, doc) assert.NotNil(t, err) }) - t.Run("when the order field is not sent, should return an error", func(t *testing.T) { - templateRows := map[string]interface{}{ - "row_template_1": nil, - } + templateRows := map[string]interface{}{} factory := mocks.NewAbstractFactoryMaps(t) - _, err := listmapper.NewList(templateRows, "test", factory.NewRow) + _, err := rowmapper.NewRow(templateRows, "test", factory) assert.NotNil(t, err) }) t.Run("when the order field is less than 1, should return an error", func(t *testing.T) { templateRows := map[string]interface{}{ - "row_template_1": nil, - "order": 0.0, + "order": 0.0, + } + factory := mocks.NewAbstractFactoryMaps(t) + + _, err := rowmapper.NewRow(templateRows, "test", factory) + + assert.NotNil(t, err) + }) + t.Run("when invalid props is sent, should return an erros", func(t *testing.T) { + templateRow := map[string]interface{}{ + "height": 10.0, + "props": 1, + "order": 1.0, } factory := mocks.NewAbstractFactoryMaps(t) - _, err := listmapper.NewList(templateRows, "test", factory.NewRow) + _, err := rowmapper.NewRow(templateRow, "test", factory) assert.NotNil(t, err) }) + t.Run("when valid props is sent, should create row", func(t *testing.T) { + templateRow := map[string]interface{}{ + "height": 10.0, + "props": map[string]interface{}{ + "line_style": "solid", + "border_type": "top", + }, + "order": 1.0, + } + factory := mocks.NewAbstractFactoryMaps(t) + + _, err := rowmapper.NewRow(templateRow, "test_row", factory) + + assert.Nil(t, err) + }) } func TestGenerate(t *testing.T) { @@ -108,7 +131,7 @@ func TestGenerate(t *testing.T) { content := map[string]interface{}{"source_key_test": 1} factory := mocks.NewAbstractFactoryMaps(t) provider := mocks.NewProcessorProvider(t) - provider.EXPECT().CreateRow(10.0).Return(nil, nil) + provider.EXPECT().CreateRow(10.0, (*propsmapper.Cell)(nil)).Return(nil, nil) component := mocks.NewComponentmapper(t) component.EXPECT().Generate(map[string]interface{}{}, provider).Return(nil, nil) @@ -122,7 +145,7 @@ func TestGenerate(t *testing.T) { content := map[string]interface{}{"content": map[string]interface{}{"text": "value"}} factory := mocks.NewAbstractFactoryMaps(t) provider := mocks.NewProcessorProvider(t) - provider.EXPECT().CreateRow(10.0).Return(nil, nil) + provider.EXPECT().CreateRow(10.0, (*propsmapper.Cell)(nil)).Return(nil, nil) row := rowmapper.Row{Height: 10.0, Cols: make([]mappers.Componentmapper, 0), Factory: factory, SourceKey: "content"} _, err := row.Generate(content, provider) @@ -145,7 +168,7 @@ func TestGenerate(t *testing.T) { content := map[string]interface{}{"content": map[string]interface{}{"text": "value"}} factory := mocks.NewAbstractFactoryMaps(t) provider := mocks.NewProcessorProvider(t) - provider.EXPECT().CreateRow(10.0).Return(nil, fmt.Errorf("any")) + provider.EXPECT().CreateRow(10.0, (*propsmapper.Cell)(nil)).Return(nil, fmt.Errorf("any")) row := rowmapper.Row{Height: 10.0, Cols: make([]mappers.Componentmapper, 0), Factory: factory, SourceKey: "content"} _, err := row.Generate(content, provider) diff --git a/pkg/processor/mappers/propsmapper/cell.go b/pkg/processor/mappers/propsmapper/cell.go new file mode 100644 index 00000000..2cab6b2e --- /dev/null +++ b/pkg/processor/mappers/propsmapper/cell.go @@ -0,0 +1,41 @@ +package propsmapper + +import ( + "fmt" +) + +// Cell is the representation of a cell in the grid system. +// This can be applied to Col or Row +type Cell struct { + // BackgroundColor defines which color will be applied to a cell. + // Default: nil + BackgroundColor *Color + // BorderColor defines which color will be applied to a border cell + // Default: nil + BorderColor *Color + // BorderType defines which kind of border will be applied to a cell. + // Default: border.None + BorderType string + // BorderThickness defines the border thickness applied to a cell. + // Default: 0.2 + BorderThickness float64 + // LineStyle defines which line style will be applied to a cell. + // Default: Solid + LineStyle string +} + +// NewCell is responsible for creating the cell +func NewCell(cell interface{}) (*Cell, error) { + cellMap, ok := cell.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("ensure cell props can be converted to map[string] interface{}") + } + + return &Cell{ + BackgroundColor: NewColor(cellMap["background_color"]), + BorderColor: NewColor(cellMap["border_color"]), + BorderType: NewBorder(*convertFields(cellMap["border_type"], "")), + BorderThickness: *convertFields(cellMap["border_thickness"], -1.0), + LineStyle: NewLineStyle(*convertFields(cellMap["line_style"], "")), + }, nil +} diff --git a/pkg/processor/mappers/propsmapper/cell_test.go b/pkg/processor/mappers/propsmapper/cell_test.go new file mode 100644 index 00000000..9426b76e --- /dev/null +++ b/pkg/processor/mappers/propsmapper/cell_test.go @@ -0,0 +1 @@ +package propsmapper_test diff --git a/pkg/processor/mappers/propsmapper/consts.go b/pkg/processor/mappers/propsmapper/consts.go index 133ec450..0f99a1ca 100644 --- a/pkg/processor/mappers/propsmapper/consts.go +++ b/pkg/processor/mappers/propsmapper/consts.go @@ -2,7 +2,7 @@ package propsmapper func NewAlign(align string) string { mapAligns := map[string]string{ - "Left": "L", "Right": "R", "Center": "C", "Top": "T", "Bottom": "B", "Middle": "M", "Justify": "J", + "left": "L", "right": "R", "center": "C", "top": "T", "bottom": "B", "middle": "M", "justify": "J", } align, ok := mapAligns[align] if !ok { @@ -11,12 +11,23 @@ func NewAlign(align string) string { return align } +func NewBorder(border string) string { + mapBorder := map[string]string{ + "full": "1", "top": "T", "bottom": "B", "left": "L", "right": "R", + } + border, ok := mapBorder[border] + if !ok { + return "" + } + return border +} + func NewBreakLineStrategy(strategy string) string { switch strategy { - case "EmptySpaceStrategy": - return "empty_space_strategy" - case "DashStrategy": - return "dash_strategy" + case "empty_space_strategy": + return strategy + case "dash_strategy": + return strategy } return "" } @@ -47,13 +58,13 @@ func NewOrientation(orientation string) string { func NewTypeProtection(typeProtection string) byte { switch typeProtection { - case "Print": + case "print": return 4 - case "Modify": + case "modify": return 8 - case "Copy": + case "copy": return 16 - case "AnnotForms": + case "annot_forms": return 32 } @@ -62,11 +73,11 @@ func NewTypeProtection(typeProtection string) byte { func NewFontStyle(fontType string) string { switch fontType { - case "Bold": + case "bold": return "B" - case "Italic": + case "italic": return "I" - case "BoldItalic": + case "bold_italic": return "BI" } diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index b0433914..a4776278 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -18,6 +18,7 @@ import ( "github.com/johnfercher/maroto/v2/pkg/config" "github.com/johnfercher/maroto/v2/pkg/consts/align" "github.com/johnfercher/maroto/v2/pkg/consts/barcode" + "github.com/johnfercher/maroto/v2/pkg/consts/border" "github.com/johnfercher/maroto/v2/pkg/consts/breakline" "github.com/johnfercher/maroto/v2/pkg/consts/extension" "github.com/johnfercher/maroto/v2/pkg/consts/fontstyle" @@ -112,27 +113,43 @@ func (m *Maroto) CreatePage(components ...ProviderComponent) (ProviderComponent, return page.New().Add(newComponents...), nil } -func (m *Maroto) CreateRow(height float64, components ...ProviderComponent) (ProviderComponent, error) { +func (m *Maroto) CreateRow(height float64, props *propsmapper.Cell, components ...ProviderComponent) (ProviderComponent, error) { newComponents, err := convertComponentType[core.Col](components...) if err != nil { return nil, err } + + var createdRow core.Row if height > 0 { - return row.New(height).Add(newComponents...), nil + createdRow = row.New(height).Add(newComponents...) + } else { + createdRow = row.New().Add(newComponents...) + } + + if props != nil { + return createdRow.WithStyle(createPropsCell(*props)), nil } else { - return row.New().Add(newComponents...), nil + return createdRow, nil } } -func (m *Maroto) CreateCol(size int, components ...ProviderComponent) (ProviderComponent, error) { +func (m *Maroto) CreateCol(size int, props *propsmapper.Cell, components ...ProviderComponent) (ProviderComponent, error) { newComponents, err := convertComponentType[core.Component](components...) if err != nil { return nil, err } + + var createdCol core.Col if size > 0 { - return col.New(size).Add(newComponents...), nil + createdCol = col.New(size).Add(newComponents...) } else { - return col.New().Add(newComponents...), nil + createdCol = col.New().Add(newComponents...) + } + + if props != nil { + return createdCol.WithStyle(createPropsCell(*props)), nil + } else { + return createdCol, nil } } @@ -246,3 +263,13 @@ func createPropsRect(propsMapperArr ...*propsmapper.Rect) props.Rect { } return propsRect } + +func createPropsCell(propsCell propsmapper.Cell) *props.Cell { + return &props.Cell{ + BackgroundColor: (*props.Color)(propsCell.BackgroundColor), + BorderColor: (*props.Color)(propsCell.BorderColor), + BorderType: border.Type(propsCell.BorderType), + BorderThickness: propsCell.BorderThickness, + LineStyle: linestyle.Type(propsCell.LineStyle), + } +} diff --git a/pkg/processor/processorprovider/Maroto_test.go b/pkg/processor/processorprovider/Maroto_test.go index aea28a0a..1ebf8546 100644 --- a/pkg/processor/processorprovider/Maroto_test.go +++ b/pkg/processor/processorprovider/Maroto_test.go @@ -256,7 +256,7 @@ func TestCreateCol(t *testing.T) { m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) text := text.New("test") - col, err := m.CreateCol(10, text) + col, err := m.CreateCol(10, (*propsmapper.Cell)(nil), text) assert.Nil(t, err) assert.NotNil(t, col) @@ -278,7 +278,7 @@ func TestCreateRow(t *testing.T) { m, _ := processorprovider.NewMaroto(repository.NewMemoryStorage(loader)) text := text.NewCol(12, "test") - col, err := m.CreateRow(10, text) + col, err := m.CreateRow(10, (*propsmapper.Cell)(nil), text) assert.Nil(t, err) assert.NotNil(t, col) diff --git a/pkg/processor/processorprovider/provider.go b/pkg/processor/processorprovider/provider.go index 6e2a4291..359aa02d 100644 --- a/pkg/processor/processorprovider/provider.go +++ b/pkg/processor/processorprovider/provider.go @@ -19,8 +19,8 @@ type ProcessorProvider interface { AddFooter(footer ...ProviderComponent) (ProcessorProvider, error) AddHeader(header ...ProviderComponent) (ProcessorProvider, error) CreatePage(components ...ProviderComponent) (ProviderComponent, error) - CreateRow(height float64, components ...ProviderComponent) (ProviderComponent, error) - CreateCol(size int, components ...ProviderComponent) (ProviderComponent, error) + CreateRow(height float64, props *propsmapper.Cell, components ...ProviderComponent) (ProviderComponent, error) + CreateCol(size int, props *propsmapper.Cell, components ...ProviderComponent) (ProviderComponent, error) CreateText(value string, props ...*propsmapper.Text) ProviderComponent CreateSignature(value string, props ...*propsmapper.Signature) ProviderComponent CreateBarCode(value string, props ...*propsmapper.Barcode) ProviderComponent From b3de0a8f6a795d3459257ad7f15c1192954265c8 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Mon, 30 Dec 2024 16:24:52 -0300 Subject: [PATCH 090/116] test: validate billing example build --- .../mappers/components/listmapper/list.go | 6 +- .../components/listmapper/list_test.go | 15 - pkg/processor/mappers/propsmapper/cell.go | 2 +- pkg/processor/processor_test.go | 22 +- test/maroto/processor/all_builder_pros.json | 2 +- .../processor/json/billing_content.json | 194 +++++++++ .../processor/json/billing_template.json | 380 ++++++++++++++++++ 7 files changed, 596 insertions(+), 25 deletions(-) create mode 100644 test/maroto/processor/json/billing_content.json create mode 100644 test/maroto/processor/json/billing_template.json diff --git a/pkg/processor/mappers/components/listmapper/list.go b/pkg/processor/mappers/components/listmapper/list.go index d314954c..b67d6e26 100644 --- a/pkg/processor/mappers/components/listmapper/list.go +++ b/pkg/processor/mappers/components/listmapper/list.go @@ -99,11 +99,9 @@ func (l *List) generateTemplates(content map[string]interface{}, provider proces ) { components := make([]processorprovider.ProviderComponent, 0, len(l.Templates)) for _, template := range l.Templates { - component, err := template.Generate(content, provider) - if err != nil { - return nil, err + if component, err := template.Generate(content, provider); err == nil { + components = append(components, component...) } - components = append(components, component...) } return components, nil } diff --git a/pkg/processor/mappers/components/listmapper/list_test.go b/pkg/processor/mappers/components/listmapper/list_test.go index 43b15b26..1c764bb3 100644 --- a/pkg/processor/mappers/components/listmapper/list_test.go +++ b/pkg/processor/mappers/components/listmapper/list_test.go @@ -2,7 +2,6 @@ package listmapper_test import ( "errors" - "fmt" "testing" "github.com/johnfercher/maroto/v2/mocks" @@ -175,20 +174,6 @@ func TestGenerate(t *testing.T) { assert.NotNil(t, err) }) - t.Run("when components is not generate, should return an error", func(t *testing.T) { - contentRow1 := map[string]interface{}{"row_1": nil} - listContent := map[string]interface{}{"list": []interface{}{contentRow1}} - provider := mocks.NewProcessorProvider(t) - component := mocks.NewOrderedComponents(t) - component.EXPECT().Generate(mock.Anything, provider).Return(nil, fmt.Errorf("any")) - - list := listmapper.List{SourceKey: "list", Templates: []mappers.OrderedComponents{component}} - components, err := list.Generate(listContent, provider) - - assert.Nil(t, components) - assert.NotNil(t, err) - }) - t.Run("when 2 templates are added, it should generate 4 components", func(t *testing.T) { content1 := map[string]interface{}{"row_1": nil, "row_2": nil} content2 := map[string]interface{}{"row_1": nil, "row_2": nil} diff --git a/pkg/processor/mappers/propsmapper/cell.go b/pkg/processor/mappers/propsmapper/cell.go index 2cab6b2e..a27a1bb9 100644 --- a/pkg/processor/mappers/propsmapper/cell.go +++ b/pkg/processor/mappers/propsmapper/cell.go @@ -35,7 +35,7 @@ func NewCell(cell interface{}) (*Cell, error) { BackgroundColor: NewColor(cellMap["background_color"]), BorderColor: NewColor(cellMap["border_color"]), BorderType: NewBorder(*convertFields(cellMap["border_type"], "")), - BorderThickness: *convertFields(cellMap["border_thickness"], -1.0), + BorderThickness: *convertFields(cellMap["border_thickness"], 0.0), LineStyle: NewLineStyle(*convertFields(cellMap["line_style"], "")), }, nil } diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index fd6cb4a3..f0a85021 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -69,10 +69,10 @@ func TestGenerateTemplate(t *testing.T) { fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/background_template.json") fixContent, _ := processortest.NewFileReader().LoadFile("processor/json/background_content.json") processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) - err := processor.RegisterTemplate("auto_row", string(fixtemplate)) + err := processor.RegisterTemplate("background", string(fixtemplate)) require.NoError(t, err) - provider, err := processor.GenerateDocument("auto_row", string(fixContent)) + provider, err := processor.GenerateDocument("background", string(fixContent)) assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/background.json") @@ -83,14 +83,28 @@ func TestGenerateTemplate(t *testing.T) { fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/barcodegrid_template.json") fixContent, _ := processortest.NewFileReader().LoadFile("processor/json/barcodegrid_content.json") processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) - err := processor.RegisterTemplate("auto_row", string(fixtemplate)) + err := processor.RegisterTemplate("barcodegrid", string(fixtemplate)) require.NoError(t, err) - provider, err := processor.GenerateDocument("auto_row", string(fixContent)) + provider, err := processor.GenerateDocument("barcodegrid", string(fixContent)) assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/barcodegrid.json") }) + t.Run("when template with billing example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/billing_template.json") + fixContent, _ := processortest.NewFileReader().LoadFile("processor/json/billing_content.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("billing", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("billing", string(fixContent)) + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/billing.json") + }) t.Run("when sent template is not found, should reuturn an error", func(t *testing.T) { }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { diff --git a/test/maroto/processor/all_builder_pros.json b/test/maroto/processor/all_builder_pros.json index 1dad8398..6650ea3e 100644 --- a/test/maroto/processor/all_builder_pros.json +++ b/test/maroto/processor/all_builder_pros.json @@ -40,7 +40,7 @@ {"family": "family_test2", "style": "style_test2", "file_path": "file_test2"} ], "protection": { - "type": "Print", + "type": "print", "user_password": "senha123", "owner_password": "senha123" }, diff --git a/test/maroto/processor/json/billing_content.json b/test/maroto/processor/json/billing_content.json new file mode 100644 index 00000000..12b3597c --- /dev/null +++ b/test/maroto/processor/json/billing_content.json @@ -0,0 +1,194 @@ +{ + "header": { + "template_row": { + "biplane": "docs/assets/images/biplane.jpg", + "company_address": "AnyCompany Name Inc. 851 Any Street Name, Suite 120, Any City, CA 45123.", + "company_phone": "Tel: 55 024 12345-1234", + "company_site": "www.mycompany.com" + } + }, + "footer": { + "row_footer": { + "company_phone": "Tel: 55 024 12345-1234", + "company_site": "www.mycompany.com" + } + }, + "pages": { + "template_page": { + "invoice_row": { + "invoice": "Invoice ABC123456789" + }, + "list_transactions_row": [ + { + "transaction_gray": { + "product": "Swamp", + "quantity": "12", + "price": "R$ 4,00" + }, + "transaction_white": { + "product": "Sorin, A Planeswalker", + "quantity": "4", + "price": "R$ 90,00" + } + }, + { + "transaction_gray": { + "product": "Tassa", + "quantity": "4", + "price": "R$ 30,00" + }, + "transaction_white": { + "product": "Skinrender", + "quantity": "4", + "price": "R$ 9,00" + } + }, + { + "transaction_gray": { + "product": "Island", + "quantity": "12", + "price": "R$ 4,00" + }, + "transaction_white": { + "product": "Mountain", + "quantity": "12", + "price": "R$ 4,00" + } + }, + { + "transaction_gray": { + "product": "Plain", + "quantity": "12", + "price": "R$ 4,00" + }, + "transaction_white": { + "product": "Black Lotus", + "quantity": "1", + "price": "R$ 1.000,00" + } + }, + { + "transaction_gray": { + "product": "Time Walk", + "quantity": "1", + "price": "R$ 1.000,00" + }, + "transaction_white": { + "product": "Emberclave", + "quantity": "4", + "price": "R$ 44,00" + } + }, + { + "transaction_gray": { + "product": "Anax", + "quantity": "4", + "price": "R$ 32,00" + }, + "transaction_white": { + "product": "Murderous Rider", + "quantity": "4", + "price": "R$ 22,00" + } + }, + { + "transaction_gray": { + "product": "Gray Merchant of Asphodel", + "quantity": "4", + "price": "R$ 2,00" + }, + "transaction_white": { + "product": "Ajani's Pridemate", + "quantity": "4", + "price": "R$ 2,00" + } + }, + { + "transaction_gray": { + "product": "Renan, Chatuba", + "quantity": "4", + "price": "R$ 19,00" + }, + "transaction_white": { + "product": "Tymarett", + "quantity": "4", + "price": "R$ 13,00" + } + }, + { + "transaction_gray": { + "product": "Doom Blade", + "quantity": "4", + "price": "R$ 5,00" + }, + "transaction_white": { + "product": "Dark Lord", + "quantity": "3", + "price": "R$ 7,00" + } + }, + { + "transaction_gray": { + "product": "Memory of Thanatos", + "quantity": "3", + "price": "R$ 32,00" + }, + "transaction_white": { + "product": "Poring", + "quantity": "4", + "price": "R$ 1,00" + } + }, + { + "transaction_gray": { + "product": "Deviling", + "quantity": "4", + "price": "R$ 99,00" + }, + "transaction_white": { + "product": "Seiya", + "quantity": "4", + "price": "R$ 45,00" + } + }, + { + "transaction_gray": { + "product": "Harry Potter", + "quantity": "4", + "price": "R$ 62,00" + }, + "transaction_white": { + "product": "Goku", + "quantity": "4", + "price": "R$ 77,00" + } + }, + { + "transaction_gray": { + "product": "Phreoni", + "quantity": "4", + "price": "R$ 22,00" + }, + "transaction_white": { + "product": "Katheryn High Wizard", + "quantity": "4", + "price": "R$ 25,00" + } + }, + { + "transaction_gray": { + "product": "Lord Seyren", + "quantity": "4", + "price": "R$ 55,00" + } + } + ], + "total_row": { + "total": "R$ 2.567,00" + }, + "code_bar_row": { + "code": "5123.151231.512314.1251251.123215" + } + } + } +} \ No newline at end of file diff --git a/test/maroto/processor/json/billing_template.json b/test/maroto/processor/json/billing_template.json new file mode 100644 index 00000000..7016fe1e --- /dev/null +++ b/test/maroto/processor/json/billing_template.json @@ -0,0 +1,380 @@ +{ + "builder": { + "margins": { + "left": 10, + "top": 15, + "right": 10 + }, + "page_number": {} + }, + "header": { + "template_row": { + "order": 1, + "height": 20, + "cols": [ + { + "size": 3, + "image": { + "order": 1, + "source_key": "biplane", + "props": { + "center": true, + "percent": 80 + } + } + }, + { + "size": 6 + }, + { + "size": 3, + "text_address": { + "order": 1, + "source_key": "company_address", + "props": { + "size": 8, + "align": "right", + "color": { + "red": 150, + "green": 10, + "blue": 10 + } + } + }, + "text_phone": { + "order": 2, + "source_key": "company_phone", + "props": { + "top": 12, + "style": "bold_italic", + "size": 8, + "align": "right", + "color": { + "red": 10, + "green": 10, + "blue": 150 + } + } + }, + "text_site": { + "order": 3, + "source_key": "company_site", + "props": { + "top": 15, + "style": "bold_italic", + "size": 8, + "align": "right", + "color": { + "red": 10, + "green": 10, + "blue": 150 + } + } + } + } + ] + } + }, + "footer": { + "row_footer": { + "order": 1, + "height": 20, + "cols": [ + { + "size": 12, + "text_phone": { + "order": 1, + "source_key": "company_phone", + "props": { + "top": 13, + "style": "bold_italic", + "size": 8, + "align": "left", + "color": { + "red": 10, + "green": 10, + "blue": 150 + } + } + }, + "text_site": { + "order": 2, + "source_key": "company_site", + "props": { + "top": 16, + "style": "bold_italic", + "size": 8, + "align": "left", + "color": { + "red": 10, + "green": 10, + "blue": 150 + } + } + } + } + ] + } + }, + "pages": { + "template_page": { + "order": 1, + "invoice_row": { + "order": 1, + "height": 10, + "cols": [ + { + "text": { + "order": 1, + "source_key": "invoice", + "props": { + "top": 3, + "style": "bold", + "align": "center" + } + } + } + ] + }, + "transactions_row": { + "order": 2, + "height": 7, + "props": { + "background_color": { + "red": 55, + "blue": 55, + "green": 55 + } + }, + "cols": [ + { + "size": 3, + "text": { + "order": 1, + "value": "Transactions", + "props": { + "top": 1.5, + "size": 9, + "style": "bold", + "align": "center", + "color": { + "red": 255, + "green": 255, + "blue": 255 + } + } + } + } + ] + }, + "transactions_header_row": { + "order": 3, + "height": 5, + "cols": [ + { + "size": 3 + }, + { + "size": 4, + "text": { + "order": 1, + "value": "Product", + "props": { + "size": 9, + "style": "bold", + "align": "center" + } + } + }, + { + "size": 2, + "text": { + "order": 1, + "value": "Quantity", + "props": { + "size": 9, + "style": "bold", + "align": "center" + } + } + }, + { + "size": 3, + "text": { + "order": 1, + "value": "Price", + "props": { + "size": 9, + "style": "bold", + "align": "center" + } + } + } + ] + }, + "list_transactions_row": { + "order": 4, + "transaction_gray": { + "order": 1, + "height": 4, + "props": { + "background_color": { + "red": 200, + "green": 200, + "blue": 200 + } + }, + "cols": [ + { + "size": 3 + }, + { + "size": 4, + "text": { + "order": 1, + "source_key": "product", + "props": { + "size": 8, + "align": "center" + } + } + }, + { + "size": 2, + "text": { + "order": 1, + "source_key": "quantity", + "props": { + "size": 8, + "align": "center" + } + } + }, + { + "size": 3, + "text": { + "order": 1, + "source_key": "price", + "props": { + "size": 8, + "align": "center" + } + } + } + ] + }, + "transaction_white": { + "order": 2, + "height": 4, + "cols": [ + { + "size": 3 + }, + { + "size": 4, + "text": { + "order": 1, + "source_key": "product", + "props": { + "size": 8, + "align": "center" + } + } + }, + { + "size": 2, + "text": { + "order": 1, + "source_key": "quantity", + "props": { + "size": 8, + "align": "center" + } + } + }, + { + "size": 3, + "text": { + "order": 1, + "source_key": "price", + "props": { + "size": 8, + "align": "center" + } + } + } + ] + } + }, + "total_row": { + "order": 5, + "height": 20, + "cols": [ + { + "size": 7 + }, + { + "size": 2, + "text": { + "order": 1, + "value": "Total:", + "props": { + "top": 5, + "style": "bold", + "size": 8, + "align": "right" + } + } + }, + { + "size": 3, + "text": { + "order": 1, + "source_key": "total", + "props": { + "top": 5, + "style": "bold", + "size": 8, + "align": "center" + } + } + } + ] + }, + "code_bar_row": { + "order": 6, + "height": 15, + "cols": [ + { + "size": 6, + "bar_code":{ + "order": 1, + "source_key": "code", + "props": { + "proportion": { + "width": 20, + "height": 2 + }, + "percent": 100 + } + }, + "text": { + "order": 2, + "source_key": "code", + "props": { + "top": 12, + "family": "", + "style": "bold", + "size": 9, + "align": "center" + } + } + }, + { + "size": 6 + } + ] + } + } + } +} \ No newline at end of file From 3e0d2a2542eb76ea4887231559e736ecc7a9c052 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 31 Dec 2024 11:37:29 -0300 Subject: [PATCH 091/116] test: validate cellstyle example build --- .../mappers/components/pagemapper/page.go | 2 +- pkg/processor/processor_test.go | 11 + test/maroto/processor/json/cell_template.json | 2578 +++++++++++++++++ 3 files changed, 2590 insertions(+), 1 deletion(-) create mode 100644 test/maroto/processor/json/cell_template.json diff --git a/pkg/processor/mappers/components/pagemapper/page.go b/pkg/processor/mappers/components/pagemapper/page.go index 2356f388..8338184f 100644 --- a/pkg/processor/mappers/components/pagemapper/page.go +++ b/pkg/processor/mappers/components/pagemapper/page.go @@ -100,7 +100,7 @@ func (p *Page) setPageOrder(template *map[string]interface{}) error { func (p *Page) getPageContent(content map[string]interface{}) (map[string]interface{}, error) { pageContent, ok := content[p.SourceKey] if !ok { - return nil, fmt.Errorf("could not parse template,the page needs the source key \"%s\", but it was not found", p.SourceKey) + return map[string]interface{}{}, nil } if mapPage, ok := pageContent.(map[string]interface{}); ok { return mapPage, nil diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index f0a85021..a20e63a0 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -106,6 +106,17 @@ func TestGenerateTemplate(t *testing.T) { test.New(t).Assert((*provider).GetStructure()).Equals("examples/billing.json") }) t.Run("when sent template is not found, should reuturn an error", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/cell_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("billing", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("billing", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/cellstyle.json") }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) diff --git a/test/maroto/processor/json/cell_template.json b/test/maroto/processor/json/cell_template.json new file mode 100644 index 00000000..10e54bb6 --- /dev/null +++ b/test/maroto/processor/json/cell_template.json @@ -0,0 +1,2578 @@ +{ + "builder": { + "debug": false + }, + "pages": { + "template_page": { + "order": 1, + "default_style_row_1": { + "order": 1, + "height": 10, + "cols": [ + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_1": { + "order": 2, + "height": 10 + }, + "template_row_1": { + "props": { + "background_color": { + "red": 220, + "green": 220, + "blue": 220 + }, + "border_color": { + "red": 0, + "green": 0, + "blue": 200 + }, + "border_type": "none" + + }, + "order": 3, + "height": 10, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_2": { + "order": 4, + "height": 10 + }, + "default_style_row_2": { + "order": 5, + "height": 10, + "cols": [ + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_3": { + "order": 6, + "height": 10 + }, + "template_row_2": { + "props": { + "background_color": { + "red": 220, + "green": 220, + "blue": 220 + }, + "border_color": { + "red": 0, + "green": 0, + "blue": 200 + }, + "border_type": "full" + }, + "order": 7, + "height": 10, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_4": { + "order": 8, + "height": 10 + }, + "default_style_row_3": { + "order": 9, + "height": 10, + "cols": [ + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_5": { + "order": 10, + "height": 10 + }, + "template_row_3": { + "props": { + "background_color": { + "red": 220, + "green": 220, + "blue": 220 + }, + "border_color": { + "red": 0, + "green": 0, + "blue": 200 + }, + "border_type": "left" + }, + "order": 11, + "height": 10, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_6": { + "order": 12, + "height": 10 + }, + "default_style_row_4": { + "order": 13, + "height": 10, + "cols": [ + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_7": { + "order": 14, + "height": 10 + }, + "template_row_4": { + "props": { + "background_color": { + "red": 220, + "green": 220, + "blue": 220 + }, + "border_color": { + "red": 0, + "green": 0, + "blue": 200 + }, + "border_type": "right" + }, + "order": 15, + "height": 10, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_8": { + "order": 16, + "height": 10 + }, + "default_style_row_5": { + "order": 17, + "height": 10, + "cols": [ + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_9": { + "order": 18, + "height": 10 + }, + "template_row_5": { + "props": { + "background_color": { + "red": 220, + "green": 220, + "blue": 220 + }, + "border_color": { + "red": 0, + "green": 0, + "blue": 200 + }, + "border_type": "top" + }, + "order": 19, + "height": 10, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_10": { + "order": 20, + "height": 10 + }, + "default_style_row_6": { + "order": 21, + "height": 10, + "cols": [ + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_11": { + "order": 22, + "height": 10 + }, + "template_row_6": { + "props": { + "background_color": { + "red": 220, + "green": 220, + "blue": 220 + }, + "border_color": { + "red": 0, + "green": 0, + "blue": 200 + }, + "border_type": "bottom" + }, + "order": 23, + "height": 10, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_12": { + "order": 24, + "height": 10 + }, + "default_style_row_7": { + "order": 25, + "height": 10, + "cols": [ + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_13": { + "order": 26, + "height": 10 + }, + "template_row_7": { + "props": { + "background_color": { + "red": 220, + "green": 220, + "blue": 220 + }, + "border_color": { + "red": 0, + "green": 0, + "blue": 200 + }, + "border_type": "none" + + }, + "order": 27, + "height": 10, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_14": { + "order": 28, + "height": 10 + }, + "default_style_row_8": { + "order": 29, + "height": 10, + "cols": [ + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_15": { + "order": 30, + "height": 10 + }, + "template_row_8": { + "props": { + "background_color": { + "red": 220, + "green": 220, + "blue": 220 + }, + "border_color": { + "red": 0, + "green": 0, + "blue": 200 + }, + "border_type": "full" + }, + "order": 31, + "height": 10, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_16": { + "order": 32, + "height": 10 + }, + "default_style_row_9": { + "order": 33, + "height": 10, + "cols": [ + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_17": { + "order": 34, + "height": 10 + }, + "template_row_9": { + "props": { + "background_color": { + "red": 220, + "green": 220, + "blue": 220 + }, + "border_color": { + "red": 0, + "green": 0, + "blue": 200 + }, + "border_type": "left" + }, + "order": 35, + "height": 10, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_18": { + "order": 36, + "height": 10 + }, + "default_style_row_10": { + "order": 37, + "height": 10, + "cols": [ + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_19": { + "order": 38, + "height": 10 + }, + "template_row_10": { + "props": { + "background_color": { + "red": 220, + "green": 220, + "blue": 220 + }, + "border_color": { + "red": 0, + "green": 0, + "blue": 200 + }, + "border_type": "right" + }, + "order": 39, + "height": 10, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_20": { + "order": 40, + "height": 10 + }, + "default_style_row_11": { + "order": 41, + "height": 10, + "cols": [ + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_21": { + "order": 42, + "height": 10 + }, + "template_row_11": { + "props": { + "background_color": { + "red": 220, + "green": 220, + "blue": 220 + }, + "border_color": { + "red": 0, + "green": 0, + "blue": 200 + }, + "border_type": "top" + }, + "order": 43, + "height": 10, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_22": { + "order": 44, + "height": 10 + }, + "default_style_row_12": { + "order": 45, + "height": 10, + "cols": [ + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_23": { + "order": 46, + "height": 10 + }, + "template_row_12": { + "props": { + "background_color": { + "red": 220, + "green": 220, + "blue": 220 + }, + "border_color": { + "red": 0, + "green": 0, + "blue": 200 + }, + "border_type": "bottom" + }, + "order": 47, + "height": 10, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_24": { + "order": 48, + "height": 10 + }, + "default_style_row_13": { + "order": 49, + "height": 10, + "cols": [ + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_25": { + "order": 50, + "height": 10 + }, + "template_row_13": { + "props": { + "background_color": { + "red": 220, + "green": 220, + "blue": 220 + }, + "border_color": { + "red": 0, + "green": 0, + "blue": 200 + }, + "border_type": "none" + + }, + "order": 51, + "height": 10, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_26": { + "order": 52, + "height": 10 + }, + "default_style_row_14": { + "order": 53, + "height": 10, + "cols": [ + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_27": { + "order": 54, + "height": 10 + }, + "template_row_14": { + "props": { + "background_color": { + "red": 220, + "green": 220, + "blue": 220 + }, + "border_color": { + "red": 0, + "green": 0, + "blue": 200 + }, + "border_type": "full" + }, + "order": 55, + "height": 10, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_28": { + "order": 56, + "height": 10 + }, + "default_style_row_15": { + "order": 57, + "height": 10, + "cols": [ + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "props": { + "background_color": { + "red": 80, + "green": 80, + "blue": 80 + }, + "border_type": "full", + "border_color": { + "red": 200, + "green": 0, + "blue": 0 + }, + "line_style": "dashed", + "border_thickness": 0.5 + }, + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "color": { + "red": 255, + "green": 255, + "blue": 255 + }, + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_29": { + "order": 58, + "height": 10 + }, + "template_row_15": { + "props": { + "background_color": { + "red": 220, + "green": 220, + "blue": 220 + }, + "border_color": { + "red": 0, + "green": 0, + "blue": 200 + }, + "border_type": "left" + }, + "order": 59, + "height": 10, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "string", + "props": { + "style": "bold", + "size": 12, + "align": "center", + "top": 2 + } + } + } + ] + }, + "space_row_30": { + "order": 60, + "height": 10 + } + } + } +} \ No newline at end of file From ad514b95156fbe40edf58dd222c1c4d166416ded Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 31 Dec 2024 13:00:12 -0300 Subject: [PATCH 092/116] test: validate compression example build refactor load external images --- pkg/processor/loader/loader.go | 5 +- pkg/processor/loader/loader_test.go | 2 +- pkg/processor/processor_test.go | 19 +- .../json/compressionv2_template.json | 229 ++++++++++++++++++ 4 files changed, 248 insertions(+), 7 deletions(-) create mode 100644 test/maroto/processor/json/compressionv2_template.json diff --git a/pkg/processor/loader/loader.go b/pkg/processor/loader/loader.go index ecb03a8b..8c9682c7 100644 --- a/pkg/processor/loader/loader.go +++ b/pkg/processor/loader/loader.go @@ -64,7 +64,8 @@ func (l *loader) Load(path string) ([]byte, error) { } func (l *loader) GetExt(path string) string { - toks := strings.Split(path, ".") + toks := strings.Split(path, "?") + toks = strings.Split(toks[0], ".") if len(toks) < 2 { return "" } @@ -74,9 +75,7 @@ func (l *loader) GetExt(path string) string { var validExts = map[string]struct{}{ "png": {}, "jpg": {}, - "svg": {}, "jpeg": {}, - "ttf": {}, } var loadFuncs = map[string]func(string) (io.ReadCloser, error){ diff --git a/pkg/processor/loader/loader_test.go b/pkg/processor/loader/loader_test.go index be7e2fc5..219e4b52 100644 --- a/pkg/processor/loader/loader_test.go +++ b/pkg/processor/loader/loader_test.go @@ -36,7 +36,7 @@ func TestLoad(t *testing.T) { }) t.Run("when valid network path sent, should return bytes of asset", func(t *testing.T) { - p, err := loader.NewLoader().Load("https://www.iana.org/_img/2013.1/rir-map.svg") + p, err := loader.NewLoader().Load("https://github.com/johnfercher/maroto/blob/master/docs/assets/images/biplane.jpg?raw=true") assert.NoError(t, err) assert.NotNil(t, p) }) diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index a20e63a0..b5df9f1a 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -105,19 +105,32 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/billing.json") }) - t.Run("when sent template is not found, should reuturn an error", func(t *testing.T) { + t.Run("when template with cellstyle example is found, should set template", func(t *testing.T) { test.SetupTestDir(t) fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/cell_template.json") processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) - err := processor.RegisterTemplate("billing", string(fixtemplate)) + err := processor.RegisterTemplate("cellstyle", string(fixtemplate)) require.NoError(t, err) - provider, err := processor.GenerateDocument("billing", "{}") + provider, err := processor.GenerateDocument("cellstyle", "{}") assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/cellstyle.json") }) + t.Run("when template with compression example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/compressionv2_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("compression", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("compression", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/compression.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) t.Run("when invalid content is sent, should return an error", func(t *testing.T) { diff --git a/test/maroto/processor/json/compressionv2_template.json b/test/maroto/processor/json/compressionv2_template.json new file mode 100644 index 00000000..8f34c85a --- /dev/null +++ b/test/maroto/processor/json/compressionv2_template.json @@ -0,0 +1,229 @@ +{ + "builder": { + "compression": true + }, + "pages": { + "template_page": { + "order": 1, + "title_row": { + "order": 1, + "height": 20, + "cols": [ + { + "text": { + "order": 1, + "value": "Main features", + "props": { + "size": 15, + "top": 6.5 + } + } + } + ] + }, + "barcode_row": { + "order": 2, + "height": 20, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "Barcode:", + "props": { + "size": 15, + "top": 6, + "align": "center" + } + } + }, + { + "size": 8, + "bar_code": { + "order": 1, + "value": "barcode", + "props": { + "center": true, + "percent": 70 + } + } + } + ] + }, + "qrcode_row": { + "order": 3, + "height": 20, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "QrCode:", + "props": { + "size": 15, + "top": 6, + "align": "center" + } + } + }, + { + "size": 8, + "qr_code": { + "order": 1, + "value": "qrcode", + "props": { + "center": true, + "percent": 70 + } + } + } + ] + }, + "matrixcode_row": { + "order": 4, + "height": 20, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "MatrixCode:", + "props": { + "size": 15, + "top": 6, + "align": "center" + } + } + }, + { + "size": 8, + "matrix_code": { + "order": 1, + "value": "matrixcode", + "props": { + "center": true, + "percent": 70 + } + } + } + ] + }, + "image_file_row": { + "order": 5, + "height": 20, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "Image From File:", + "props": { + "size": 15, + "top": 6, + "align": "center" + } + } + }, + { + "size": 8, + "image": { + "order": 1, + "value": "docs/assets/images/biplane.jpg", + "props": { + "center": true, + "percent": 90 + } + } + } + ] + }, + "image_base64_row": { + "order": 6, + "height": 20, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "Image From Base64::", + "props": { + "size": 15, + "top": 6, + "align": "center" + } + } + }, + { + "size": 8, + "image": { + "order": 1, + "value": "https://github.com/johnfercher/maroto/blob/master/docs/assets/images/frontpage.png?raw=true", + "props": { + "center": true, + "percent": 90 + } + } + } + ] + }, + "text_row": { + "order": 7, + "height": 20, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "Text:", + "props": { + "size": 15, + "top": 6, + "align": "center" + } + } + }, + { + "size": 8, + "text": { + "order": 1, + "value": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac condimentum sem.", + "props": { + "size": 12, + "top": 5, + "align": "center" + } + } + } + ] + }, + "signature_row": { + "order": 8, + "height": 40, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "value": "Signature:", + "props": { + "size": 15, + "top": 17, + "align": "center" + } + } + }, + { + "size": 8, + "signature": { + "order": 1, + "value": "Name", + "props": { + "font_size": 10 + } + } + } + ] + } + } + } +} \ No newline at end of file From 1979fd1538e876a37ad1b63a7e62f279eeb8db43 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Tue, 31 Dec 2024 20:56:05 -0300 Subject: [PATCH 093/116] test: validate customdimensions example build --- pkg/processor/processor_test.go | 16 +++++++ .../json/customdimensions_template.json | 45 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 test/maroto/processor/json/customdimensions_template.json diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index b5df9f1a..82c4fc77 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -131,7 +131,23 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/compression.json") }) + t.Run("when template with customdimensions example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/customdimensions_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("dimensions", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("dimensions", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/customdimensions.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { + // doc, _ := (*provider).Generate() + // err = doc.Save("test.pdf") + // assert.Nil(t, err) }) t.Run("when invalid content is sent, should return an error", func(t *testing.T) { }) diff --git a/test/maroto/processor/json/customdimensions_template.json b/test/maroto/processor/json/customdimensions_template.json new file mode 100644 index 00000000..e6f5885b --- /dev/null +++ b/test/maroto/processor/json/customdimensions_template.json @@ -0,0 +1,45 @@ +{ + "builder": { + "debug": true, + "dimensions": { + "width": 200, + "height": 200 + } + }, + "pages": { + "template_page": { + "order": 1, + "template_row": { + "height": 40, + "order": 1, + "cols": [ + { + "size": 4, + "image": { + "order": 1, + "value": "docs/assets/images/biplane.jpg", + "props": { + "center": true, + "percent": 50 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "Gopher International Shipping, Inc.", + "props": { + "top": 12, + "size": 12 + } + } + }, + { + "size": 4 + } + ] + } + } + } +} \ No newline at end of file From 62cdf26d2359a0eddbafce0513a681734c593868 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 1 Jan 2025 18:10:46 -0300 Subject: [PATCH 094/116] test: validate customfont example build --- pkg/processor/loader/loader.go | 1 + .../mappers/buildermapper/builder.go | 2 +- .../mappers/propsmapper/customfont.go | 2 +- pkg/processor/mappers/propsmapper/font.go | 2 +- .../processor/json/customfont_content.json | 561 ++++++++++++++++++ .../processor/json/customfont_template.json | 183 ++++++ 6 files changed, 748 insertions(+), 3 deletions(-) create mode 100644 test/maroto/processor/json/customfont_content.json create mode 100644 test/maroto/processor/json/customfont_template.json diff --git a/pkg/processor/loader/loader.go b/pkg/processor/loader/loader.go index 8c9682c7..154d82d7 100644 --- a/pkg/processor/loader/loader.go +++ b/pkg/processor/loader/loader.go @@ -76,6 +76,7 @@ var validExts = map[string]struct{}{ "png": {}, "jpg": {}, "jpeg": {}, + "ttf": {}, } var loadFuncs = map[string]func(string) (io.ReadCloser, error){ diff --git a/pkg/processor/mappers/buildermapper/builder.go b/pkg/processor/mappers/buildermapper/builder.go index 44003d57..9febb6de 100644 --- a/pkg/processor/mappers/buildermapper/builder.go +++ b/pkg/processor/mappers/buildermapper/builder.go @@ -44,7 +44,7 @@ func NewBuilder(builder interface{}) (*Builder, error) { Debug: factoryField(builderMap["debug"], false), MaxGridSize: int(factoryField(builderMap["max_grid_size"], -1.0)), DefaultFont: propsmapper.NewFont(builderMap["default_font"]), - CustomFonts: propsmapper.NewCustomFonts(builderMap["custom_font"]), + CustomFonts: propsmapper.NewCustomFonts(builderMap["custom_fonts"]), PageNumber: propsmapper.NewPageNumber(builderMap["page_number"]), Protection: propsmapper.NewProtection(builderMap["protection"]), Compression: factoryField(builderMap["compression"], false), diff --git a/pkg/processor/mappers/propsmapper/customfont.go b/pkg/processor/mappers/propsmapper/customfont.go index 250475f4..c36f5ae6 100644 --- a/pkg/processor/mappers/propsmapper/customfont.go +++ b/pkg/processor/mappers/propsmapper/customfont.go @@ -16,7 +16,7 @@ func newCustomFont(font interface{}) *CustomFont { return &CustomFont{ Family: *convertFields(fontMap["family"], ""), - Style: *convertFields(fontMap["style"], ""), + Style: NewFontStyle(*convertFields(fontMap["style"], "")), File: *convertFields(fontMap["file_path"], ""), } } diff --git a/pkg/processor/mappers/propsmapper/font.go b/pkg/processor/mappers/propsmapper/font.go index 4fe0dceb..8d34d043 100644 --- a/pkg/processor/mappers/propsmapper/font.go +++ b/pkg/processor/mappers/propsmapper/font.go @@ -22,7 +22,7 @@ func NewFont(font interface{}) *Font { return &Font{ Family: *convertFields(fontMap["family"], ""), - Style: *convertFields(fontMap["style"], ""), + Style: NewFontStyle(*convertFields(fontMap["style"], "")), Size: *convertFields(fontMap["size"], 0.0), Color: NewColor(fontMap["color"]), } diff --git a/test/maroto/processor/json/customfont_content.json b/test/maroto/processor/json/customfont_content.json new file mode 100644 index 00000000..cb74775d --- /dev/null +++ b/test/maroto/processor/json/customfont_content.json @@ -0,0 +1,561 @@ +{ + "pages": { + "template_page": { + "template_header_row": { + "column_1": "Language", + "column_2": "Phrase: Talk is cheap. Show me the code." + }, + "list_languages": [ + { + "template_white_row": { + "content_column_1": "Albanês", + "content_column_2": "Biseda është e lirë. Më trego kodin." + }, + "template_white_gray": { + "content_column_1": "Africâner", + "content_column_2": "Praat is goedkoop. Wys my die kode." + } + }, + { + "template_white_row": { + "content_column_1": "Amárico", + "content_column_2": "ወሬ ርካሽ ነው ፡፡ ኮዱን አሳዩኝ ፡፡" + }, + "template_white_gray": { + "content_column_1": "Alemão", + "content_column_2": "Reden ist billig. Zeig mir den Code." + } + }, + { + "template_white_row": { + "content_column_1": "Armênio", + "content_column_2": "Խոսակցությունն էժան է: Showույց տվեք ինձ ծածկագիրը:" + }, + "template_white_gray": { + "content_column_1": "Árabe", + "content_column_2": "كلام رخيص. أرني الكود." + } + }, + { + "template_white_row": { + "content_column_1": "Basco", + "content_column_2": "Eztabaida merkea da. Erakutsi kodea." + }, + "template_white_gray": { + "content_column_1": "Azerbaijano", + "content_column_2": "Danışıq ucuzdur. Kodu göstərin." + } + }, + { + "template_white_row": { + "content_column_1": "Bielorusso", + "content_column_2": "Размовы танныя. Пакажыце мне код." + }, + "template_white_gray": { + "content_column_1": "Bengali", + "content_column_2": "টক সস্তা। আমাকে কোডটি দেখান" + } + }, + { + "template_white_row": { + "content_column_1": "Bósnio", + "content_column_2": "Govor je jeftin. Pokaži mi šifru." + }, + "template_white_gray": { + "content_column_1": "Birmanês", + "content_column_2": "ဟောပြောချက်ကစျေးပေါတယ် ကုဒ်ကိုပြပါ။" + } + }, + { + "template_white_row": { + "content_column_1": "Canarim", + "content_column_2": "ಮಾತುಕತೆ ಅಗ್ಗವಾಗಿದೆ. ನನಗೆ ಕೋಡ್ ತೋರಿಸಿ." + }, + "template_white_gray": { + "content_column_1": "Búlgaro", + "content_column_2": "Разговорите са евтини. Покажи ми кода." + } + }, + { + "template_white_row": { + "content_column_1": "Cazeque", + "content_column_2": "Сөйлесу арзан. Маған кодты көрсетіңіз." + }, + "template_white_gray": { + "content_column_1": "Catalão", + "content_column_2": "Parlar és barat. Mostra’m el codi." + } + }, + { + "template_white_row": { + "content_column_1": "Chinês Simplificado", + "content_column_2": "谈话很便宜。给我看代码。" + }, + "template_white_gray": { + "content_column_1": "Cebuano", + "content_column_2": "Barato ra ang sulti. Ipakita kanako ang code." + } + }, + { + "template_white_row": { + "content_column_1": "Cingalês", + "content_column_2": "කතාව ලාභයි. කේතය මට පෙන්වන්න." + }, + "template_white_gray": { + "content_column_1": "Chinês Tradicional", + "content_column_2": "談話很便宜。給我看代碼。" + } + }, + { + "template_white_row": { + "content_column_1": "Corso", + "content_column_2": "Parlà hè bonu. Mostrami u codice." + }, + "template_white_gray": { + "content_column_1": "Coreano", + "content_column_2": "토크는 싸다. 코드를 보여주세요." + } + }, + { + "template_white_row": { + "content_column_1": "Curdo", + "content_column_2": "Axaftin erzan e. Kodê nîşanî min bidin." + }, + "template_white_gray": { + "content_column_1": "Croata", + "content_column_2": "Razgovor je jeftin. Pokaži mi šifru." + } + }, + { + "template_white_row": { + "content_column_1": "Eslovaco", + "content_column_2": "Hovor je lacný. Ukáž mi kód." + }, + "template_white_gray": { + "content_column_1": "Dinamarquês", + "content_column_2": "Tal er billig. Vis mig koden." + } + }, + { + "template_white_gray": { + "content_column_1": "Esloveno", + "content_column_2": "Pogovor je poceni. Pokaži mi kodo." + }, + "template_white_row": { + "content_column_1": "Espanhol", + "content_column_2": "Hablar es barato. Enséñame el código." + } + }, + { + "template_white_gray": { + "content_column_1": "Esperanto", + "content_column_2": "Babilado estas malmultekosta. Montru al mi la kodon." + }, + "template_white_row": { + "content_column_1": "Estoniano", + "content_column_2": "Rääkimine on odav. Näita mulle koodi." + } + }, + { + "template_white_gray": { + "content_column_1": "Filipino", + "content_column_2": "Mura ang usapan. Ipakita sa akin ang code." + }, + "template_white_row": { + "content_column_1": "Finlandês", + "content_column_2": "Puhe on halpaa. Näytä koodi." + } + }, + { + "template_white_gray": { + "content_column_1": "Francês", + "content_column_2": "Parler n'est pas cher. Montre-moi le code." + }, + "template_white_row": { + "content_column_1": "Frísio Ocidental", + "content_column_2": "Prate is goedkeap. Lit my de koade sjen." + } + }, + { + "template_white_gray": { + "content_column_1": "Gaélico Escocês", + "content_column_2": "Tha còmhradh saor. Seall dhomh an còd." + }, + "template_white_row": { + "content_column_1": "Galego", + "content_column_2": "Falar é barato. Móstrame o código." + } + }, + { + "template_white_gray": { + "content_column_1": "Galês", + "content_column_2": "Mae siarad yn rhad. Dangoswch y cod i mi." + }, + "template_white_row": { + "content_column_1": "Georgiano", + "content_column_2": "აუბარი იაფია. მაჩვენე კოდი." + } + }, + { + "template_white_gray": { + "content_column_1": "Grego", + "content_column_2": "Η συζήτηση είναι φθηνή. Δείξε μου τον κωδικό." + }, + "template_white_row": { + "content_column_1": "Guzerate", + "content_column_2": "વાતો કરવી સસ્તી છે. મને કોડ બતાવો." + } + }, + { + "template_white_gray": { + "content_column_1": "Haitiano", + "content_column_2": "Pale bon mache. Montre m kòd la." + }, + "template_white_row": { + "content_column_1": "Hauçá", + "content_column_2": "Magana tana da arha. Nuna min lambar." + } + }, + { + "template_white_gray": { + "content_column_1": "Havaiano", + "content_column_2": "Kūʻai ke kamaʻilio. E hōʻike mai iaʻu i ke pāʻālua." + }, + "template_white_row": { + "content_column_1": "Hebraico", + "content_column_2": "הדיבורים זולים. הראה לי את הקוד." + } + }, + { + "template_white_gray": { + "content_column_1": "Híndi", + "content_column_2": "बोलना आसान है। मुझे कोड दिखाओ।" + }, + "template_white_row": { + "content_column_1": "Hmong", + "content_column_2": "Kev hais lus yog pheej yig. Qhia kuv cov code." + } + }, + { + "template_white_gray": { + "content_column_1": "Holandês", + "content_column_2": "Praten is goedkoop. Laat me de code zien." + }, + "template_white_row": { + "content_column_1": "Húngaro", + "content_column_2": "Beszélni olcsó. Mutasd meg a kódot." + } + }, + { + "template_white_gray": { + "content_column_1": "Igbo", + "content_column_2": "Okwu dị ọnụ ala. Gosi m koodu." + }, + "template_white_row": { + "content_column_1": "Lídiche", + "content_column_2": "רעדן איז ביליק. ווייַזן מיר דעם קאָד." + } + }, + { + "template_white_gray": { + "content_column_1": "Indonésio", + "content_column_2": "Berbicara itu murah. Tunjukkan kodenya." + }, + "template_white_row": { + "content_column_1": "Inglês", + "content_column_2": "Talk is cheap. Show me the code." + } + }, + { + "template_white_gray": { + "content_column_1": "Iorubá", + "content_column_2": "Ọrọ jẹ olowo poku. Fi koodu naa han mi." + }, + "template_white_row": { + "content_column_1": "Irlandês", + "content_column_2": "Tá caint saor. Taispeáin dom an cód." + } + }, + { + "template_white_gray": { + "content_column_1": "Islandês", + "content_column_2": "Tal er ódýrt. Sýndu mér kóðann." + }, + "template_white_row": { + "content_column_1": "Italiano", + "content_column_2": "Parlare è economico. Mostrami il codice." + } + }, + { + "template_white_gray": { + "content_column_1": "Japonês", + "content_column_2": "口で言うだけなら簡単です。コードを見せてください。" + }, + "template_white_row": { + "content_column_1": "Javanês", + "content_column_2": "Omongan iku murah. Tampilake kode kasebut." + } + }, + { + "template_white_gray": { + "content_column_1": "Khmer", + "content_column_2": "ការនិយាយគឺថោក។ បង្ហាញលេខកូដមកខ្ញុំ" + }, + "template_white_row": { + "content_column_1": "Laosiano", + "content_column_2": "ການສົນທະນາແມ່ນລາຄາຖືກ. ສະແດງລະຫັດໃຫ້ຂ້ອຍ." + } + }, + { + "template_white_gray": { + "content_column_1": "Latim", + "content_column_2": "Disputatio vilis est. Ostende mihi codice." + }, + "template_white_row": { + "content_column_1": "Letão", + "content_column_2": "Saruna ir lēta. Parādiet man kodu." + } + }, + { + "template_white_gray": { + "content_column_1": "Lituano", + "content_column_2": "Kalbėti pigu. Parodyk man kodą." + }, + "template_white_row": { + "content_column_1": "Luxemburguês", + "content_column_2": "Schwätzen ass bëlleg. Weist mir de Code." + } + }, + { + "template_white_gray": { + "content_column_1": "Macedônio", + "content_column_2": "Зборувањето е ефтино. Покажи ми го кодот." + }, + "template_white_row": { + "content_column_1": "Malaiala", + "content_column_2": "സംസാരം വിലകുറഞ്ഞതാണ്. എനിക്ക് കോഡ് കാണിക്കുക." + } + }, + { + "template_white_gray": { + "content_column_1": "Malaio", + "content_column_2": "Perbincangan murah. Tunjukkan kod saya." + }, + "template_white_row": { + "content_column_1": "Malgaxe", + "content_column_2": "Mora ny resaka. Asehoy ahy ny kaody." + } + }, + { + "template_white_gray": { + "content_column_1": "Maltês", + "content_column_2": "It-taħdita hija rħisa. Urini l-kodiċi." + }, + "template_white_row": { + "content_column_1": "Maori", + "content_column_2": "He iti te korero. Whakaatuhia mai te tohu." + } + }, + { + "template_white_gray": { + "content_column_1": "Marati", + "content_column_2": "चर्चा स्वस्त आहे. मला कोड दाखवा." + }, + "template_white_row": { + "content_column_1": "Mongol", + "content_column_2": "Яриа хямд. Надад кодоо харуул." + } + }, + { + "template_white_gray": { + "content_column_1": "Nepalês", + "content_column_2": "कुरा सस्तो छ। मलाई कोड देखाउनुहोस्।" + }, + "template_white_row": { + "content_column_1": "Nianja", + "content_column_2": "Kulankhula ndikotsika mtengo. Ndiwonetseni nambala" + } + }, + { + "template_white_gray": { + "content_column_1": "Norueguês", + "content_column_2": "Snakk er billig. Vis meg koden." + }, + "template_white_row": { + "content_column_1": "Oriá", + "content_column_2": "କଥାବାର୍ତ୍ତା ଶସ୍ତା ଅଟେ | ମୋତେ କୋଡ୍ ଦେଖାନ୍ତୁ |" + } + }, + { + "template_white_gray": { + "content_column_1": "Panjabi", + "content_column_2": "ਗੱਲ ਸਸਤਾ ਹੈ. ਮੈਨੂੰ ਕੋਡ ਦਿਖਾਓ." + }, + "template_white_row": { + "content_column_1": "Pashto", + "content_column_2": "خبرې ارزانه دي. ما ته کوډ وښایاست" + } + }, + { + "template_white_gray": { + "content_column_1": "Persa", + "content_column_2": "بحث ارزان است. کد را به من نشان دهید" + }, + "template_white_row": { + "content_column_1": "Polonês", + "content_column_2": "Rozmowa jest tania. Pokaż mi kod." + } + }, + { + "template_white_gray": { + "content_column_1": "Português", + "content_column_2": "Falar é fácil. Mostre-me o código." + }, + "template_white_row": { + "content_column_1": "Quiniaruanda", + "content_column_2": "Ibiganiro birahendutse. Nyereka kode." + } + }, + { + "template_white_gray": { + "content_column_1": "Quirguiz", + "content_column_2": "Сүйлөшүү арзан. Мага кодду көрсөтүңүз." + }, + "template_white_row": { + "content_column_1": "Romeno", + "content_column_2": "Vorbirea este ieftină. Arată-mi codul." + } + }, + { + "template_white_gray": { + "content_column_1": "Russo", + "content_column_2": "Обсуждение дешево. Покажи мне код." + }, + "template_white_row": { + "content_column_1": "Samoano", + "content_column_2": "E taugofie talanoaga. Faʻaali mai le code." + } + }, + { + "template_white_gray": { + "content_column_1": "Sérvio", + "content_column_2": "Причање је јефтино. Покажи ми шифру." + }, + "template_white_row": { + "content_column_1": "Sindi", + "content_column_2": "ڳالهه سستا آهي. مونکي ڪوڊ ڏيکاريو." + } + }, + { + "template_white_gray": { + "content_column_1": "Somali", + "content_column_2": "Hadalku waa jaban yahay. I tus lambarka." + }, + "template_white_row": { + "content_column_1": "Soto do Sul", + "content_column_2": "Puo e theko e tlase. Mpontshe khoutu." + } + }, + { + "template_white_gray": { + "content_column_1": "Suaíli", + "content_column_2": "Mazungumzo ni ya bei rahisi. Nionyeshe nambari." + }, + "template_white_row": { + "content_column_1": "Sueco", + "content_column_2": "Prat är billigt. Visa mig koden." + } + }, + { + "template_white_gray": { + "content_column_1": "Sundanês", + "content_column_2": "Omongan mirah. Tunjukkeun kode na." + }, + "template_white_row": { + "content_column_1": "Tadjique", + "content_column_2": "Сӯҳбат арзон аст. Рамзро ба ман нишон диҳед." + } + }, + { + "template_white_gray": { + "content_column_1": "Tailandês", + "content_column_2": "พูดคุยราคาถูก แสดงรหัส" + }, + "template_white_row": { + "content_column_1": "Tâmil", + "content_column_2": "பேச்சு மலிவானது. குறியீட்டை எனக்குக் காட்டு." + } + }, + { + "template_white_gray": { + "content_column_1": "Tártaro", + "content_column_2": "Сөйләшү арзан. Миңа код күрсәтегез." + }, + "template_white_row": { + "content_column_1": "Tcheco", + "content_column_2": "Mluvení je levné. Ukaž mi kód." + } + }, + { + "template_white_gray": { + "content_column_1": "Télugo", + "content_column_2": "చర్చ చౌకగా ఉంటుంది. నాకు కోడ్ చూపించు." + }, + "template_white_row": { + "content_column_1": "Turco", + "content_column_2": "Konuşma ucuz. Bana kodu göster." + } + }, + { + "template_white_gray": { + "content_column_1": "Turcomeno", + "content_column_2": "Gepleşik arzan. Kody görkez" + }, + "template_white_row": { + "content_column_1": "Ucraniano", + "content_column_2": "Розмова дешева. Покажи мені код." + } + }, + { + "template_white_gray": { + "content_column_1": "Uigur", + "content_column_2": "پاراڭ ئەرزان. ماڭا كودنى كۆرسەت." + }, + "template_white_row": { + "content_column_1": "Urdu", + "content_column_2": "بات گھٹیا ہے. مجھے کوڈ دکھائیں۔" + } + }, + { + "template_white_gray": { + "content_column_1": "Uzbeque", + "content_column_2": "Gapirish arzon. Menga kodni ko'rsating." + }, + "template_white_row": { + "content_column_1": "Vietnamita", + "content_column_2": "Nói chuyện là rẻ. Cho tôi xem mã." + } + }, + { + "template_white_gray": { + "content_column_1": "Xhosa", + "content_column_2": "Ukuthetha akubizi. Ndibonise ikhowudi." + }, + "template_white_row": { + "content_column_1": "Xona", + "content_column_2": "Kutaura kwakachipa. Ndiratidze kodhi." + } + }, + { + "template_white_gray": { + "content_column_1": "Zulu", + "content_column_2": "Ukukhuluma kushibhile. Ngikhombise ikhodi." + } + } + ], + "template_long_text_row": { + "long_text": "聲音之道㣲矣天地有自然之聲人聲有自然之節古之聖人得其節之自然者而為之依永和聲至於八音諧而神人和胥是道也文字之作無不講求音韻顧南北異其風土古今殊其轉變喉舌唇齒清濁輕重之分辨在毫釐動多訛舛樊然淆混不可究極自西域梵僧定字母為三十六分五音以總天下之聲而翻切之學興儒者若司馬光鄭樵皆宗之其法有音和類隔互用借聲類例不一後人苦其委曲繁重難以驟曉往往以類隔互用之切改從音和而終莫能得其原也我聖祖仁皇帝" + } + } + } +} \ No newline at end of file diff --git a/test/maroto/processor/json/customfont_template.json b/test/maroto/processor/json/customfont_template.json new file mode 100644 index 00000000..80bca525 --- /dev/null +++ b/test/maroto/processor/json/customfont_template.json @@ -0,0 +1,183 @@ +{ + "builder": { + "custom_fonts": [ + { + "family": "arial-unicode-ms", + "style": "", + "file_path": "docs/assets/fonts/arial-unicode-ms.ttf" + }, + { + "family": "arial-unicode-ms", + "style": "italic", + "file_path": "docs/assets/fonts/arial-unicode-ms.ttf" + }, + { + "family": "arial-unicode-ms", + "style": "bold", + "file_path": "docs/assets/fonts/arial-unicode-ms.ttf" + }, + { + "family": "arial-unicode-ms", + "style": "bold_italic", + "file_path": "docs/assets/fonts/arial-unicode-ms.ttf" + } + ], + "default_font": { + "family": "arial-unicode-ms" + } + }, + "pages": { + "template_page": { + "order": 1, + "template_header_row": { + "order": 1, + "height": 8, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "props": { + "style": "bold", + "family": "arial", + "align": "center" + }, + "source_key": "column_1" + } + }, + { + "size": 8, + "text": { + "order": 1, + "props": { + "style": "bold", + "family": "arial", + "align": "center" + }, + "source_key": "column_2" + } + } + ] + }, + "list_languages": { + "order": 2, + "template_white_gray": { + "height": 5, + "order": 1, + "props": { + "background_color": { + "red": 200, + "green": 200, + "blue": 200 + } + }, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "source_key": "content_column_1", + "props": { + "align": "center" + } + } + }, + { + "size": 8, + "text": { + "order": 1, + "source_key": "content_column_2", + "props": { + "align": "center" + } + } + } + ] + }, + "template_white_row": { + "height": 5, + "order": 2, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "source_key": "content_column_1", + "props": { + "align": "center" + } + } + }, + { + "size": 8, + "text": { + "order": 1, + "source_key": "content_column_2", + "props": { + "align": "center" + } + } + } + ] + } + }, + "template_long_text_title_row": { + "order": 3, + "height": 10, + "cols": [ + { + "text": { + "order": 1, + "value": "long text without spaces", + "props": { + "top": 5, + "style": "bold", + "family": "arial" + } + } + } + ] + }, + "template_long_text_row": { + "order": 4, + "height": 80, + "cols": [ + { + "size": 4, + "text": { + "order": 1, + "source_key": "long_text", + "props": { + "align": "center", + "break_line_strategy": "dash_strategy" + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "source_key": "long_text", + "props": { + "align": "left", + "break_line_strategy": "dash_strategy" + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "source_key": "long_text", + "props": { + "align": "right", + "break_line_strategy": "dash_strategy" + } + } + } + ] + } + + } + } +} \ No newline at end of file From c4da9ddf9ca04053b0d00d1bd0319b747c6499c8 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 1 Jan 2025 18:22:17 -0300 Subject: [PATCH 095/116] test: validate custompage example build --- pkg/processor/processor_test.go | 31 ++++++++++++-- .../processor/json/custompage_template.json | 42 +++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 test/maroto/processor/json/custompage_template.json diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index 82c4fc77..4eadb592 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -144,10 +144,35 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/customdimensions.json") }) + t.Run("when template with customfont example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/customfont_template.json") + fixcontent, _ := processortest.NewFileReader().LoadFile("processor/json/customfont_content.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("font", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("font", string(fixcontent)) + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/customfont.json") + }) + t.Run("when template with custompage example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/custompage_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("page", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("page", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/custompage.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { - // doc, _ := (*provider).Generate() - // err = doc.Save("test.pdf") - // assert.Nil(t, err) + }) t.Run("when invalid content is sent, should return an error", func(t *testing.T) { }) diff --git a/test/maroto/processor/json/custompage_template.json b/test/maroto/processor/json/custompage_template.json new file mode 100644 index 00000000..bd614826 --- /dev/null +++ b/test/maroto/processor/json/custompage_template.json @@ -0,0 +1,42 @@ +{ + "builder": { + "debug": true, + "page_size": "a2" + }, + "pages": { + "template_page": { + "order": 1, + "template_row": { + "order": 1, + "height": 40, + "cols": [ + { + "size": 4, + "image": { + "order": 1, + "value": "docs/assets/images/biplane.jpg", + "props": { + "center": true, + "percent": 50 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "Gopher International Shipping, Inc.", + "props": { + "top": 12, + "size": 12 + } + } + }, + { + "size": 4 + } + ] + } + } + } +} \ No newline at end of file From 2d6c8ad2a838ce4728936fa07fa6b99aa3a2aa1c Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 1 Jan 2025 18:38:03 -0300 Subject: [PATCH 096/116] test: validate datamatrixgrid example build --- pkg/processor/processor_test.go | 13 ++ .../json/datamatrixgrid_template.json | 201 ++++++++++++++++++ 2 files changed, 214 insertions(+) create mode 100644 test/maroto/processor/json/datamatrixgrid_template.json diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index 4eadb592..bb0fb865 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -171,6 +171,19 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/custompage.json") }) + t.Run("when template with datamatrixgrid example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/datamatrixgrid_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("datamatrixgrid", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("datamatrixgrid", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/datamatrixgrid.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) diff --git a/test/maroto/processor/json/datamatrixgrid_template.json b/test/maroto/processor/json/datamatrixgrid_template.json new file mode 100644 index 00000000..eaafcc90 --- /dev/null +++ b/test/maroto/processor/json/datamatrixgrid_template.json @@ -0,0 +1,201 @@ +{ + "builder": { + "debug": true + }, + "pages": { + "template_page": { + "order": 1, + "matrixcode_row": { + "order": 1, + "height": 40, + "cols": [ + { + "size": 2, + "matrix_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 50 + } + } + }, + { + "size": 4, + "matrix_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 75 + } + } + }, + { + "size": 6, + "matrix_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 100 + } + } + } + ] + }, + "matrixcode_center_row": { + "order": 2, + "height": 40, + "cols": [ + { + "size": 2, + "matrix_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 50, + "center": true + } + } + }, + { + "size": 4, + "matrix_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 75, + "center": true + } + } + }, + { + "size": 6, + "matrix_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 100, + "center": true + } + } + } + ] + }, + "inverse_matrixcode_row": { + "order": 3, + "height": 40, + "cols": [ + { + "size": 6, + "matrix_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 50 + } + } + }, + { + "size": 4, + "matrix_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 75 + } + } + }, + { + "size": 2, + "matrix_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 100 + } + } + } + ] + }, + "inverse_matrixcode_center_row": { + "order": 4, + "height": 40, + "cols": [ + { + "size": 6, + "matrix_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 50, + "center": true + } + } + }, + { + "size": 4, + "matrix_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 75, + "center": true + } + } + }, + { + "size": 2, + "matrix_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 100, + "center": true + } + } + } + ] + }, + "matrixcode_autorow": { + "order": 5, + "cols": [ + { + "size": 6, + "matrix_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 20, + "center": true, + "just_reference_width": true + } + } + }, + { + "size": 4, + "matrix_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 75, + "center": true, + "just_reference_width": true + } + } + }, + { + "size": 2, + "matrix_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 100, + "center": true, + "just_reference_width": true + } + } + } + ] + } + } + } +} \ No newline at end of file From fc6cd298b5214933e3fa3075deb016687f23d611 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 1 Jan 2025 18:54:22 -0300 Subject: [PATCH 097/116] test: validate disableautopagebreak example build --- pkg/processor/processor_test.go | 13 +++++++++++ .../json/disablepagebreak_template.json | 23 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 test/maroto/processor/json/disablepagebreak_template.json diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index bb0fb865..d7f24801 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -184,6 +184,19 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/datamatrixgrid.json") }) + t.Run("when template with autopagebreak example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/disablepagebreak_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("disablepagebreak", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("disablepagebreak", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/disablepagebreak.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) diff --git a/test/maroto/processor/json/disablepagebreak_template.json b/test/maroto/processor/json/disablepagebreak_template.json new file mode 100644 index 00000000..1d646851 --- /dev/null +++ b/test/maroto/processor/json/disablepagebreak_template.json @@ -0,0 +1,23 @@ +{ + "builder": { + "margins": { + "top": 0, + "right": 0, + "left": 0, + "bottom": 0 + }, + "dimensions": { + "width": 361.8, + "height": 203.2 + }, + "disable_auto_page_break": true, + "orientation": "horizontal", + "max_grid_size": 20, + "background_image": "docs/assets/images/certificate.png" + }, + "pages": { + "template_page": { + "order": 1 + } + } +} \ No newline at end of file From 61639de3802e30faee8f5656d4cfcf45fa5c0e9a Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Wed, 1 Jan 2025 19:15:41 -0300 Subject: [PATCH 098/116] test: validate build of footer and header example --- pkg/processor/processor_test.go | 28 ++ .../maroto/processor/json/footer_content.json | 258 ++++++++++++++++++ .../processor/json/footer_template.json | 47 ++++ .../maroto/processor/json/header_content.json | 258 ++++++++++++++++++ .../processor/json/header_template.json | 47 ++++ 5 files changed, 638 insertions(+) create mode 100644 test/maroto/processor/json/footer_content.json create mode 100644 test/maroto/processor/json/footer_template.json create mode 100644 test/maroto/processor/json/header_content.json create mode 100644 test/maroto/processor/json/header_template.json diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index d7f24801..23dd89a3 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -197,6 +197,34 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/disablepagebreak.json") }) + t.Run("when template with footer example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/footer_template.json") + fixcontent, _ := processortest.NewFileReader().LoadFile("processor/json/footer_content.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("footer", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("footer", string(fixcontent)) + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/footer.json") + }) + t.Run("when template with header example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/header_template.json") + fixcontent, _ := processortest.NewFileReader().LoadFile("processor/json/header_content.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("header", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("header", string(fixcontent)) + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/header.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) diff --git a/test/maroto/processor/json/footer_content.json b/test/maroto/processor/json/footer_content.json new file mode 100644 index 00000000..a25ab2b3 --- /dev/null +++ b/test/maroto/processor/json/footer_content.json @@ -0,0 +1,258 @@ +{ + "pages": { + "template_page": { + "list_rows": [ + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + } + ] + } + } +} \ No newline at end of file diff --git a/test/maroto/processor/json/footer_template.json b/test/maroto/processor/json/footer_template.json new file mode 100644 index 00000000..6554d7ef --- /dev/null +++ b/test/maroto/processor/json/footer_template.json @@ -0,0 +1,47 @@ +{ + "builder": { + "debug": true + }, + "footer": { + "template_row": { + "order": 1, + "height": 20, + "cols": [ + { + "text": { + "order": 1, + "value": "Footer", + "props": { + "size": 10, + "style": "bold", + "align": "center" + } + } + } + ] + } + }, + "pages": { + "template_page": { + "order": 1, + "list_rows": { + "order": 1, + "template_row": { + "order": 1, + "height": 10, + "cols": [ + { + "text": { + "order": 1, + "source_key": "text_value", + "props": { + "size": 8 + } + } + } + ] + } + } + } + } +} \ No newline at end of file diff --git a/test/maroto/processor/json/header_content.json b/test/maroto/processor/json/header_content.json new file mode 100644 index 00000000..a25ab2b3 --- /dev/null +++ b/test/maroto/processor/json/header_content.json @@ -0,0 +1,258 @@ +{ + "pages": { + "template_page": { + "list_rows": [ + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + } + ] + } + } +} \ No newline at end of file diff --git a/test/maroto/processor/json/header_template.json b/test/maroto/processor/json/header_template.json new file mode 100644 index 00000000..66033c06 --- /dev/null +++ b/test/maroto/processor/json/header_template.json @@ -0,0 +1,47 @@ +{ + "builder": { + "debug": true + }, + "header": { + "template_row": { + "order": 1, + "height": 20, + "cols": [ + { + "text": { + "order": 1, + "value": "Header", + "props": { + "size": 10, + "style": "bold", + "align": "center" + } + } + } + ] + } + }, + "pages": { + "template_page": { + "order": 1, + "list_rows": { + "order": 1, + "template_row": { + "order": 1, + "height": 10, + "cols": [ + { + "text": { + "order": 1, + "source_key": "text_value", + "props": { + "size": 8 + } + } + } + ] + } + } + } + } +} \ No newline at end of file From 6f343dd8b5fb35736520b1c8a6432f05db34be36 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 08:57:06 -0300 Subject: [PATCH 099/116] test: set the test build directory to allow pulling the image --- .../assets/examples/imagegrid/v2/main_test.go | 1 + test/maroto/examples/imagegrid.json | 21 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/assets/examples/imagegrid/v2/main_test.go b/docs/assets/examples/imagegrid/v2/main_test.go index 43c4802e..80db12fe 100644 --- a/docs/assets/examples/imagegrid/v2/main_test.go +++ b/docs/assets/examples/imagegrid/v2/main_test.go @@ -7,6 +7,7 @@ import ( ) func TestGetMaroto(t *testing.T) { + test.SetupTestDir(t) // Act sut := GetMaroto() diff --git a/test/maroto/examples/imagegrid.json b/test/maroto/examples/imagegrid.json index 807d6eaf..d628188f 100755 --- a/test/maroto/examples/imagegrid.json +++ b/test/maroto/examples/imagegrid.json @@ -283,7 +283,22 @@ ] }, { - "value": 0, + "value": 26.997500000000002, + "type": "row", + "nodes": [ + { + "value": 12, + "type": "col" + } + ] + } + ] + }, + { + "type": "page", + "nodes": [ + { + "value": 51.67999999999999, "type": "row", "nodes": [ { @@ -319,7 +334,7 @@ ] }, { - "value": 0, + "value": 52.41733333333333, "type": "row", "nodes": [ { @@ -371,7 +386,7 @@ ] }, { - "value": 26.997500000000002, + "value": 162.90016666666668, "type": "row", "nodes": [ { From 4eb910b0bdf5edd6a3a9c20da6a7613ee9f520b3 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 08:57:39 -0300 Subject: [PATCH 100/116] test: validate imagegrid example build --- pkg/processor/processor_test.go | 13 + .../processor/json/imagegrid_template.json | 304 ++++++++++++++++++ 2 files changed, 317 insertions(+) create mode 100644 test/maroto/processor/json/imagegrid_template.json diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index 23dd89a3..07d7a1ae 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -225,6 +225,19 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/header.json") }) + t.Run("when template with imagegrid example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/imagegrid_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("imagegrid", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("imagegrid", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/imagegrid.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) diff --git a/test/maroto/processor/json/imagegrid_template.json b/test/maroto/processor/json/imagegrid_template.json new file mode 100644 index 00000000..05d2e347 --- /dev/null +++ b/test/maroto/processor/json/imagegrid_template.json @@ -0,0 +1,304 @@ +{ + "builder": { + "debug": true + }, + "pages": { + "template_page": { + "order": 1, + "template_row1": { + "order": 1, + "height": 40, + "cols": [ + { + "size": 2, + "image": { + "order": 1, + "value": "docs/assets/images/biplane.jpg", + "props": { + "center": true, + "percent": 80 + } + } + }, + { + "size": 4, + "image": { + "order": 1, + "value": "docs/assets/images/biplane.jpg", + "props": { + "center": true, + "percent": 80 + } + } + }, + { + "size": 6, + "image": { + "order": 1, + "value": "docs/assets/images/biplane.jpg", + "props": { + "center": true, + "percent": 80 + } + } + } + ] + }, + "template_row2": { + "order": 2, + "height": 40, + "cols": [ + { + "size": 2, + "image": { + "order": 1, + "value": "docs/assets/images/biplane.jpg", + "props": { + "center": false, + "percent": 50, + "left": 10 + } + } + }, + { + "size": 4, + "image": { + "order": 1, + "value": "docs/assets/images/biplane.jpg", + "props": { + "center": false, + "percent": 50, + "top": 10 + } + } + }, + { + "size": 6, + "image": { + "order": 1, + "value": "docs/assets/images/biplane.jpg", + "props": { + "center": false, + "percent": 50, + "left": 15, + "top": 15 + } + } + } + ] + }, + "template_row3": { + "order": 3, + "height": 40, + "cols": [ + { + "size": 8, + "image": { + "order": 1, + "value": "docs/assets/images/biplane.jpg", + "props": { + "center": true, + "percent": 80 + } + } + }, + { + "size": 4, + "image": { + "order": 1, + "value": "docs/assets/images/biplane.jpg", + "props": { + "center": true, + "percent": 80 + } + } + } + ] + }, + "template_row4": { + "order": 4, + "height": 40, + "cols": [ + { + "size": 6, + "image": { + "order": 1, + "value": "docs/assets/images/frontpage.png", + "props": { + "center": false, + "percent": 80, + "top": 5, + "left": 10 + } + } + }, + { + "size": 4, + "image": { + "order": 1, + "value": "docs/assets/images/frontpage.png", + "props": { + "center": false, + "percent": 80, + "top": 5 + } + } + }, + { + "size": 2, + "image": { + "order": 1, + "value": "docs/assets/images/frontpage.png", + "props": { + "center": false, + "percent": 80, + "left": 5 + } + } + } + ] + }, + "template_row5": { + "order": 5, + "height": 40, + "cols": [ + { + "size": 6, + "image": { + "order": 1, + "value": "docs/assets/images/frontpage.png", + "props": { + "center": true, + "percent": 50 + } + } + }, + { + "size": 4, + "image": { + "order": 1, + "value": "docs/assets/images/frontpage.png", + "props": { + "center": true, + "percent": 50 + } + } + }, + { + "size": 2, + "image": { + "order": 1, + "value": "docs/assets/images/frontpage.png", + "props": { + "center": true, + "percent": 50 + } + } + } + ] + }, + "template_row6": { + "order": 6, + "height": 40, + "cols": [ + { + "size": 4, + "image": { + "order": 1, + "value": "docs/assets/images/frontpage.png", + "props": { + "center": true, + "percent": 80 + } + } + }, + { + "size": 8, + "image": { + "order": 1, + "value": "docs/assets/images/frontpage.png", + "props": { + "center": true, + "percent": 80 + } + } + } + ] + }, + "template_autorow1": { + "order": 7, + "cols": [ + { + "size": 4, + "image": { + "order": 1, + "value": "docs/assets/images/frontpage.png", + "props": { + "center": true, + "just_reference_width": true, + "percent": 20 + } + } + }, + { + "size": 8, + "image": { + "order": 1, + "value": "docs/assets/images/frontpage.png", + "props": { + "center": true, + "just_reference_width": true, + "percent": 30 + } + } + } + ] + }, + "template_autorow2": { + "order": 8, + "cols": [ + { + "size": 2, + "image": { + "order": 1, + "value": "docs/assets/images/biplane.jpg", + "props": { + "center": false, + "just_reference_width": true, + "percent": 50, + "left": 10 + } + } + }, + { + "size": 4, + "image": { + "order": 1, + "value": "docs/assets/images/biplane.jpg", + "props": { + "center": false, + "just_reference_width": true, + "percent": 50, + "top": 10 + } + } + }, + { + "size": 6, + "image": { + "order": 1, + "value": "docs/assets/images/biplane.jpg", + "props": { + "center": false, + "just_reference_width": true, + "percent": 50, + "left": 15, + "top": 15 + } + } + } + ] + } + } + } +} \ No newline at end of file From 0887a38359e89d6a036044423309376881148ce5 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 09:18:11 -0300 Subject: [PATCH 101/116] test: validate linegrid example build --- .../mappers/components/linemapper/line.go | 5 +- pkg/processor/processor_test.go | 13 + .../processor/json/linegrid_template.json | 230 ++++++++++++++++++ 3 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 test/maroto/processor/json/linegrid_template.json diff --git a/pkg/processor/mappers/components/linemapper/line.go b/pkg/processor/mappers/components/linemapper/line.go index 65af4a05..3cbb213a 100644 --- a/pkg/processor/mappers/components/linemapper/line.go +++ b/pkg/processor/mappers/components/linemapper/line.go @@ -75,5 +75,8 @@ func (l *Line) setProps(templateProps interface{}) error { func (l *Line) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( []processorprovider.ProviderComponent, error, ) { - return []processorprovider.ProviderComponent{provider.CreateLine(l.Props)}, nil + if l.Props != nil { + return []processorprovider.ProviderComponent{provider.CreateLine(l.Props)}, nil + } + return []processorprovider.ProviderComponent{provider.CreateLine()}, nil } diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index 07d7a1ae..6394f5c2 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -238,6 +238,19 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/imagegrid.json") }) + t.Run("when template with linegrid example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/linegrid_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("line", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("line", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/line.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) diff --git a/test/maroto/processor/json/linegrid_template.json b/test/maroto/processor/json/linegrid_template.json new file mode 100644 index 00000000..97848335 --- /dev/null +++ b/test/maroto/processor/json/linegrid_template.json @@ -0,0 +1,230 @@ +{ + "builder": { + "debug": true + }, + "pages": { + "template_page": { + "order": 1, + "template_row1": { + "order": 1, + "height": 40, + "cols": [ + { + "size": 2, + "line": { + "order": 1 + } + }, + { + "size": 4, + "line": { + "order": 1 + } + }, + { + "size": 6, + "line": { + "order": 1 + } + } + ] + }, + "template_row2": { + "order": 2, + "height": 40, + "cols": [ + { + "size": 6, + "line": { + "order": 1 + } + }, + { + "size": 4, + "line": { + "order": 1 + } + }, + { + "size": 2, + "line": { + "order": 1 + } + } + ] + }, + "template_row3": { + "order": 3, + "height": 40, + "cols": [ + { + "size": 2, + "line": { + "order": 1, + "props": { + "thickness": 0.5 + } + } + }, + { + "size": 4, + "line": { + "order": 1, + "props": { + "color": { + "red": 255, + "green": 0, + "blue": 0 + } + } + } + }, + { + "size": 6, + "line": { + "order": 1, + "props": { + "orientation": "vertical" + } + } + } + ] + }, + "template_row4": { + "order": 4, + "height": 40, + "cols": [ + { + "size": 6, + "line": { + "order": 1, + "props": { + "offset_percent": 50 + } + } + }, + { + "size": 4, + "line": { + "order": 1, + "props": { + "offset_percent": 50, + "orientation": "vertical" + } + } + }, + { + "size": 2, + "line": { + "order": 1, + "props": { + "size_percent": 50 + } + } + } + ] + }, + "template_row5": { + "order": 5, + "height": 40, + "cols": [ + { + "size": 2, + "line": { + "order": 1, + "props": { + "style": "dashed" + } + } + }, + { + "size": 4, + "line": { + "order": 1, + "props": { + "color": { + "red": 255, + "green": 0, + "blue": 0 + }, + "style": "dashed", + "thickness": 0.8, + "orientation": "vertical", + "offset_percent": 70, + "size_percent": 70 + } + } + }, + { + "size": 6, + "line": { + "order": 1, + "props": { + "color": { + "red": 255, + "green": 0, + "blue": 0 + }, + "style": "dashed", + "thickness": 0.8, + "orientation": "horizontal", + "offset_percent": 40, + "size_percent": 40 + } + } + } + ] + }, + "template_autorow": { + "order": 6, + "cols": [ + { + "size": 2, + "line": { + "order": 1, + "props": { + "style": "dashed" + } + } + }, + { + "size": 4, + "line": { + "order": 1, + "props": { + "color": { + "red": 255, + "green": 0, + "blue": 0 + }, + "style": "dashed", + "thickness": 0.8, + "orientation": "vertical", + "offset_percent": 70, + "size_percent": 70 + } + } + }, + { + "size": 6, + "line": { + "order": 1, + "props": { + "color": { + "red": 255, + "green": 0, + "blue": 0 + }, + "style": "dashed", + "thickness": 0.8, + "orientation": "horizontal", + "offset_percent": 40, + "size_percent": 40 + } + } + } + ] + } + } + } +} \ No newline at end of file From 65cae529189c93ce6b6d47d5636ddf0da6f4c2eb Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 09:28:56 -0300 Subject: [PATCH 102/116] test: validate lowmemory example build --- pkg/processor/processor_test.go | 14 + .../processor/json/lowmemory_content.json | 258 ++++++++++++++++++ .../processor/json/lowmemory_template.json | 30 ++ 3 files changed, 302 insertions(+) create mode 100644 test/maroto/processor/json/lowmemory_content.json create mode 100644 test/maroto/processor/json/lowmemory_template.json diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index 6394f5c2..ff8802ca 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -251,6 +251,20 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/line.json") }) + t.Run("when template with lowmemory example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/lowmemory_template.json") + fixcontent, _ := processortest.NewFileReader().LoadFile("processor/json/lowmemory_content.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("lowmemory", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("lowmemory", string(fixcontent)) + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/lowmemory.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) diff --git a/test/maroto/processor/json/lowmemory_content.json b/test/maroto/processor/json/lowmemory_content.json new file mode 100644 index 00000000..a25ab2b3 --- /dev/null +++ b/test/maroto/processor/json/lowmemory_content.json @@ -0,0 +1,258 @@ +{ + "pages": { + "template_page": { + "list_rows": [ + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + } + ] + } + } +} \ No newline at end of file diff --git a/test/maroto/processor/json/lowmemory_template.json b/test/maroto/processor/json/lowmemory_template.json new file mode 100644 index 00000000..2faf7833 --- /dev/null +++ b/test/maroto/processor/json/lowmemory_template.json @@ -0,0 +1,30 @@ +{ + "builder": { + "debug": true, + "sequential_low_memory_mode": 7, + "page_number": {} + }, + "pages": { + "template_page": { + "order": 1, + "list_rows": { + "order": 1, + "template_row": { + "order": 1, + "height": 10, + "cols": [ + { + "text": { + "order": 1, + "source_key": "text_value", + "props": { + "size": 8 + } + } + } + ] + } + } + } + } +} \ No newline at end of file From 3b87045aa102616cef2f0475a1eb7da1a98f1270 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 09:38:38 -0300 Subject: [PATCH 103/116] test: validate margins example build --- pkg/processor/processor_test.go | 14 +++++ .../processor/json/margins_content.json | 58 +++++++++++++++++ .../processor/json/margins_template.json | 63 +++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 test/maroto/processor/json/margins_content.json create mode 100644 test/maroto/processor/json/margins_template.json diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index ff8802ca..e1e85279 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -265,6 +265,20 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/lowmemory.json") }) + t.Run("when template with margins example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/margins_template.json") + fixcontent, _ := processortest.NewFileReader().LoadFile("processor/json/margins_content.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("margins", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("margins", string(fixcontent)) + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/margins.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) diff --git a/test/maroto/processor/json/margins_content.json b/test/maroto/processor/json/margins_content.json new file mode 100644 index 00000000..9f25fdd9 --- /dev/null +++ b/test/maroto/processor/json/margins_content.json @@ -0,0 +1,58 @@ +{ + "pages": { + "template_page": { + "list_rows": [ + { + "template_row": { + "text_value": "any text" + } + }, + { + "template_row": { + "text_value": "any text" + } + }, + { + "template_row": { + "text_value": "any text" + } + }, + { + "template_row": { + "text_value": "any text" + } + }, + { + "template_row": { + "text_value": "any text" + } + }, + { + "template_row": { + "text_value": "any text" + } + }, + { + "template_row": { + "text_value": "any text" + } + }, + { + "template_row": { + "text_value": "any text" + } + }, + { + "template_row": { + "text_value": "any text" + } + }, + { + "template_row": { + "text_value": "any text" + } + } + ] + } + } +} \ No newline at end of file diff --git a/test/maroto/processor/json/margins_template.json b/test/maroto/processor/json/margins_template.json new file mode 100644 index 00000000..2366c2dd --- /dev/null +++ b/test/maroto/processor/json/margins_template.json @@ -0,0 +1,63 @@ +{ + "builder": { + "debug": true, + "margins": { + "top": 20, + "left": 20, + "right": 20 + } + }, + "header": { + "template_row": { + "order": 1, + "height": 40, + "cols": [ + { + "size": 4, + "image": { + "order": 1, + "value": "docs/assets/images/gopherbw.png", + "props": { + "center": true, + "percent": 50 + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "Margins Test", + "props": { + "size": 12, + "top": 12 + } + } + }, + { + "size": 4 + } + ] + } + }, + "pages": { + "template_page": { + "order": 1, + "list_rows": { + "order": 1, + "template_row": { + "order": 1, + "height": 30, + "cols": [ + { + "text": { + "order": 1, + "source_key": "text_value" + } + } + ] + } + } + } + } +} \ No newline at end of file From 029f0b2b73ef2e83c62f58551237cd6ddd56a7d1 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 10:00:56 -0300 Subject: [PATCH 104/116] test: validate maxgridsum example build --- pkg/processor/processor_test.go | 13 + .../processor/json/maxgridsum_template.json | 374 ++++++++++++++++++ 2 files changed, 387 insertions(+) create mode 100644 test/maroto/processor/json/maxgridsum_template.json diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index e1e85279..6be2428e 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -279,6 +279,19 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/margins.json") }) + t.Run("when template with maxgridsum example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/maxgridsum_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("margins", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("margins", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/maxgridsum.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) diff --git a/test/maroto/processor/json/maxgridsum_template.json b/test/maroto/processor/json/maxgridsum_template.json new file mode 100644 index 00000000..1aa3d60b --- /dev/null +++ b/test/maroto/processor/json/maxgridsum_template.json @@ -0,0 +1,374 @@ +{ + "builder": { + "debug": true, + "max_grid_size": 14 + }, + "pages": { + "template_page": { + "order": 1, + "template_title_row": { + "height": 10, + "order": 1, + "cols": [ + { + "text": { + "order": 1, + "value":"Table with 14 Columns", + "props": { + "style": "bold" + } + } + } + ] + }, + "template_header_row": { + "order": 2, + "height": 8, + "cols": [ + { + "size": 1, + "text": { + "order": 1, + "value": "H 0", + "props": { + "style": "bold", + "top": 1.5, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "H 1", + "props": { + "style": "bold", + "top": 1.5, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "H 2", + "props": { + "style": "bold", + "top": 1.5, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "H 3", + "props": { + "style": "bold", + "top": 1.5, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "H 4", + "props": { + "style": "bold", + "top": 1.5, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "H 5", + "props": { + "style": "bold", + "top": 1.5, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "H 6", + "props": { + "style": "bold", + "top": 1.5, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "H 7", + "props": { + "style": "bold", + "top": 1.5, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "H 8", + "props": { + "style": "bold", + "top": 1.5, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "H 9", + "props": { + "style": "bold", + "top": 1.5, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "H 10", + "props": { + "style": "bold", + "top": 1.5, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "H 11", + "props": { + "style": "bold", + "top": 1.5, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "H 12", + "props": { + "style": "bold", + "top": 1.5, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "H 13", + "props": { + "style": "bold", + "top": 1.5, + "left": 1.5 + } + } + } + ] + }, + "template_content_row": { + "order": 3, + "height": 8, + "cols": [ + { + "size": 1, + "text": { + "order": 1, + "value": "C 0", + "props": { + "top": 1, + "size": 9, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "C 1", + "props": { + "top": 1, + "size": 9, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "C 2", + "props": { + "top": 1, + "size": 9, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "C 3", + "props": { + "top": 1, + "size": 9, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "C 4", + "props": { + "top": 1, + "size": 9, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "C 5", + "props": { + "top": 1, + "size": 9, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "C 6", + "props": { + "top": 1, + "size": 9, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "C 7", + "props": { + "top": 1, + "size": 9, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "C 8", + "props": { + "top": 1, + "size": 9, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "C 9", + "props": { + "top": 1, + "size": 9, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "C 10", + "props": { + "top": 1, + "size": 9, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "C 11", + "props": { + "top": 1, + "size": 9, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "C 12", + "props": { + "top": 1, + "size": 9, + "left": 1.5 + } + } + }, + { + "size": 1, + "text": { + "order": 1, + "value": "C 13", + "props": { + "top": 1, + "size": 9, + "left": 1.5 + } + } + } + ] + } + } + } +} \ No newline at end of file From 0f18b296104736e66c252391d212ced8b33a6a93 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 11:09:01 -0300 Subject: [PATCH 105/116] test: validate metadata example build --- .../mappers/buildermapper/bulder_test.go | 8 ++-- .../mappers/components/listmapper/list.go | 13 +++--- .../components/pagemapper/page_test.go | 12 +++-- pkg/processor/mappers/propsmapper/metadata.go | 2 +- pkg/processor/processor_test.go | 14 +++++- test/maroto/processor/all_builder_pros.json | 10 ++--- .../processor/json/metadata_template.json | 45 +++++++++++++++++++ 7 files changed, 81 insertions(+), 23 deletions(-) create mode 100644 test/maroto/processor/json/metadata_template.json diff --git a/pkg/processor/mappers/buildermapper/bulder_test.go b/pkg/processor/mappers/buildermapper/bulder_test.go index 6269befd..5dc665f6 100644 --- a/pkg/processor/mappers/buildermapper/bulder_test.go +++ b/pkg/processor/mappers/buildermapper/bulder_test.go @@ -30,7 +30,7 @@ func DefaultBuilderMap() *Builder { MaxGridSize: 10, DefaultFont: &propsmapper.Font{ Family: "Arial", - Style: "bold", + Style: "B", Size: 10, Color: &propsmapper.Color{ Red: 10, @@ -42,7 +42,7 @@ func DefaultBuilderMap() *Builder { Pattern: "pattern_test", Place: "place_test", Family: "family_test", - Style: "style_test", + Style: "italic", Size: 10.0, Color: &propsmapper.Color{ Red: 10, @@ -51,8 +51,8 @@ func DefaultBuilderMap() *Builder { }, }, CustomFonts: []*propsmapper.CustomFont{ - {Family: "family_test", Style: "style_test", File: "file_test"}, - {Family: "family_test2", Style: "style_test2", File: "file_test2"}, + {Family: "family_test", Style: "B", File: "file_test"}, + {Family: "family_test2", Style: "B", File: "file_test2"}, }, Protection: &propsmapper.Protection{ Type: 4, diff --git a/pkg/processor/mappers/components/listmapper/list.go b/pkg/processor/mappers/components/listmapper/list.go index b67d6e26..e3e211ca 100644 --- a/pkg/processor/mappers/components/listmapper/list.go +++ b/pkg/processor/mappers/components/listmapper/list.go @@ -94,16 +94,16 @@ func (l *List) getListContent(content map[string]interface{}) ([]map[string]inte return l.formatListContent(listContent) } -func (l *List) generateTemplates(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( - []processorprovider.ProviderComponent, error, -) { +func (l *List) generateTemplates(content map[string]interface{}, + provider processorprovider.ProcessorProvider, +) []processorprovider.ProviderComponent { components := make([]processorprovider.ProviderComponent, 0, len(l.Templates)) for _, template := range l.Templates { if component, err := template.Generate(content, provider); err == nil { components = append(components, component...) } } - return components, nil + return components } func (l *List) Generate(content map[string]interface{}, provider processorprovider.ProcessorProvider) ( @@ -116,10 +116,7 @@ func (l *List) Generate(content map[string]interface{}, provider processorprovid newComponents := make([]processorprovider.ProviderComponent, 0, len(l.Templates)*len(listContent)) for _, content := range listContent { - components, err := l.generateTemplates(content, provider) - if err != nil { - return nil, err - } + components := l.generateTemplates(content, provider) newComponents = append(newComponents, components...) } diff --git a/pkg/processor/mappers/components/pagemapper/page_test.go b/pkg/processor/mappers/components/pagemapper/page_test.go index 2ca13141..6bbb7f78 100644 --- a/pkg/processor/mappers/components/pagemapper/page_test.go +++ b/pkg/processor/mappers/components/pagemapper/page_test.go @@ -7,6 +7,7 @@ import ( "github.com/johnfercher/maroto/v2/mocks" "github.com/johnfercher/maroto/v2/pkg/processor/mappers" "github.com/johnfercher/maroto/v2/pkg/processor/mappers/components/pagemapper" + "github.com/johnfercher/maroto/v2/pkg/processor/processorprovider" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -23,7 +24,6 @@ func TestGetOrder(t *testing.T) { } func TestNewPage(t *testing.T) { - t.Run("when the component order is greater than the number of components, an error should be returned", func(t *testing.T) { templateRows := map[string]interface{}{ "row_template_1": nil, @@ -159,13 +159,17 @@ func TestGenerate(t *testing.T) { t.Run("when content no has source_key, should return an error", func(t *testing.T) { content := map[string]interface{}{} factory := mocks.NewAbstractFactoryMaps(t) + providercomponent := []processorprovider.ProviderComponent{mocks.NewProviderComponent(t)} provider := mocks.NewProcessorProvider(t) + component := mocks.NewOrderedComponents(t) + component.EXPECT().Generate(content, provider).Return(providercomponent, nil) + provider.EXPECT().CreatePage(providercomponent[0]).Return(nil, nil) - page := pagemapper.Page{Rows: make([]mappers.OrderedComponents, 0), Factory: factory, SourceKey: "test"} + page := pagemapper.Page{Rows: []mappers.OrderedComponents{component}, Factory: factory, SourceKey: "test"} newPage, err := page.Generate(content, provider) - assert.NotNil(t, err) - assert.Nil(t, newPage) + assert.Nil(t, err) + assert.NotNil(t, newPage) }) t.Run("when page no has rows, it should no sent rows", func(t *testing.T) { content := map[string]interface{}{"content": map[string]interface{}{"row_1": "any"}} diff --git a/pkg/processor/mappers/propsmapper/metadata.go b/pkg/processor/mappers/propsmapper/metadata.go index 941cfa1c..dc5a21b8 100644 --- a/pkg/processor/mappers/propsmapper/metadata.go +++ b/pkg/processor/mappers/propsmapper/metadata.go @@ -48,6 +48,6 @@ func NewMetadata(metadata interface{}) *Metadata { Subject: NewUtf8Text(metadataMap["subject"]), Title: NewUtf8Text(metadataMap["title"]), CreationDate: factoryTime(*convertFields(metadataMap["creation_date"], ""), "2006-01-02 15:04:05", time.Now()), - KeywordsStr: NewUtf8Text(metadataMap["keywords_str"]), + KeywordsStr: NewUtf8Text(metadataMap["keywords"]), } } diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index 6be2428e..c08885bc 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -292,8 +292,20 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/maxgridsum.json") }) - t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { + t.Run("when template with metadata example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/metadata_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("metadata", string(fixtemplate)) + require.NoError(t, err) + provider, err := processor.GenerateDocument("metadata", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/metadatas.json") + }) + t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) t.Run("when invalid content is sent, should return an error", func(t *testing.T) { }) diff --git a/test/maroto/processor/all_builder_pros.json b/test/maroto/processor/all_builder_pros.json index 6650ea3e..19d338ca 100644 --- a/test/maroto/processor/all_builder_pros.json +++ b/test/maroto/processor/all_builder_pros.json @@ -27,7 +27,7 @@ "pattern": "pattern_test", "place": "place_test", "family": "family_test", - "style": "style_test", + "style": "italic", "size": 10, "color": { "red": 10, @@ -35,9 +35,9 @@ "blue": 150 } }, - "custom_font": [ - {"family": "family_test", "style": "style_test", "file_path": "file_test"}, - {"family": "family_test2", "style": "style_test2", "file_path": "file_test2"} + "custom_fonts": [ + {"family": "family_test", "style": "bold", "file_path": "file_test"}, + {"family": "family_test2", "style": "bold", "file_path": "file_test2"} ], "protection": { "type": "print", @@ -53,7 +53,7 @@ "subject": {"text": "test", "utf8": true}, "title": {"text": "report", "utf8": true}, "creation_date": "2024-10-09 14:30:00", - "keywords_str": {"text": "test", "utf8": true} + "keywords": {"text": "test", "utf8": true} }, "disable_auto_page_break": true, "generation_mode": "concurrent" diff --git a/test/maroto/processor/json/metadata_template.json b/test/maroto/processor/json/metadata_template.json new file mode 100644 index 00000000..65864f94 --- /dev/null +++ b/test/maroto/processor/json/metadata_template.json @@ -0,0 +1,45 @@ +{ + "builder": { + "metadata": { + "author": { + "text": "author", + "utf8": false + }, + "creator": { + "text": "creator", + "utf8": false + }, + "subject": { + "text": "subject", + "utf8": false + }, + "title": { + "text": "title", + "utf8": false + }, + "keywords": { + "text": "keyword", + "utf8": false + }, + "creationDate": "2025-02-01 10:50:05" + } + }, + "pages": { + "template_page": { + "order": 1, + "template_row": { + "height": 30, + "order": 1, + "cols": [ + { + "text": { + "order": 1, + "value": "metadatas" + } + } + ] + + } + } + } +} \ No newline at end of file From 74c50dac0953458ccb994dd179018a37babdeae6 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 11:17:43 -0300 Subject: [PATCH 106/116] test: validate orientation example build --- pkg/processor/processor_test.go | 13 +++++++++++ .../processor/json/orientation_template.json | 23 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 test/maroto/processor/json/orientation_template.json diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index c08885bc..00ff5038 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -305,6 +305,19 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/metadatas.json") }) + t.Run("when template with orientation example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/orientation_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("orientation", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("orientation", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/orientation.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) t.Run("when invalid content is sent, should return an error", func(t *testing.T) { diff --git a/test/maroto/processor/json/orientation_template.json b/test/maroto/processor/json/orientation_template.json new file mode 100644 index 00000000..e4b1ce6f --- /dev/null +++ b/test/maroto/processor/json/orientation_template.json @@ -0,0 +1,23 @@ +{ + "builder": { + "orientation": "horizontal", + "debug": true + }, + "pages": { + "template_page": { + "order": 1, + "template_row": { + "order": 1, + "height": 30, + "cols": [ + { + "text": { + "order": 1, + "value": "content" + } + } + ] + } + } + } +} \ No newline at end of file From 8a19f9b9013ee58a4c609394e242ba729b873ce0 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 11:31:02 -0300 Subject: [PATCH 107/116] test: validate pagenumber example build --- .../mappers/propsmapper/pagenumber.go | 2 +- pkg/processor/processor_test.go | 14 ++++ .../processor/json/pagenumber_content.json | 83 +++++++++++++++++++ .../processor/json/pagenumber_template.json | 35 ++++++++ 4 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 test/maroto/processor/json/pagenumber_content.json create mode 100644 test/maroto/processor/json/pagenumber_template.json diff --git a/pkg/processor/mappers/propsmapper/pagenumber.go b/pkg/processor/mappers/propsmapper/pagenumber.go index 8d3cebf0..86721ef4 100644 --- a/pkg/processor/mappers/propsmapper/pagenumber.go +++ b/pkg/processor/mappers/propsmapper/pagenumber.go @@ -28,7 +28,7 @@ func NewPageNumber(pageNumber interface{}) *PageNumber { Pattern: *convertFields(pageNumberMap["pattern"], ""), Place: *convertFields(pageNumberMap["place"], ""), Family: *convertFields(pageNumberMap["family"], ""), - Style: *convertFields(pageNumberMap["style"], ""), + Style: NewFontStyle(*convertFields(pageNumberMap["style"], "")), Size: *convertFields(pageNumberMap["size"], 0.0), Color: NewColor(pageNumberMap["color"]), } diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index 00ff5038..b5e99b1e 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -318,6 +318,20 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/orientation.json") }) + t.Run("when template with pagenumber example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/pagenumber_template.json") + fixcontent, _ := processortest.NewFileReader().LoadFile("processor/json/pagenumber_content.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("orientation", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("orientation", string(fixcontent)) + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/pagenumber.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) t.Run("when invalid content is sent, should return an error", func(t *testing.T) { diff --git a/test/maroto/processor/json/pagenumber_content.json b/test/maroto/processor/json/pagenumber_content.json new file mode 100644 index 00000000..1fb5ab0e --- /dev/null +++ b/test/maroto/processor/json/pagenumber_content.json @@ -0,0 +1,83 @@ +{ + "pages": { + "template_page": { + "list_rows": [ + { + "template_row": { + "text_value": "dummy text" + } + }, + { + "template_row": { + "text_value": "dummy text" + } + }, + { + "template_row": { + "text_value": "dummy text" + } + }, + { + "template_row": { + "text_value": "dummy text" + } + }, + { + "template_row": { + "text_value": "dummy text" + } + }, + { + "template_row": { + "text_value": "dummy text" + } + }, + { + "template_row": { + "text_value": "dummy text" + } + }, + { + "template_row": { + "text_value": "dummy text" + } + }, + { + "template_row": { + "text_value": "dummy text" + } + }, + { + "template_row": { + "text_value": "dummy text" + } + }, + { + "template_row": { + "text_value": "dummy text" + } + }, + { + "template_row": { + "text_value": "dummy text" + } + }, + { + "template_row": { + "text_value": "dummy text" + } + }, + { + "template_row": { + "text_value": "dummy text" + } + }, + { + "template_row": { + "text_value": "dummy text" + } + } + ] + } + } +} \ No newline at end of file diff --git a/test/maroto/processor/json/pagenumber_template.json b/test/maroto/processor/json/pagenumber_template.json new file mode 100644 index 00000000..81145719 --- /dev/null +++ b/test/maroto/processor/json/pagenumber_template.json @@ -0,0 +1,35 @@ +{ + "builder": { + "debug": true, + "page_number": { + "pattern": "Page {current} of {total}", + "place": "bottom", + "family": "courier", + "style": "bold", + "size": 9, + "color": { + "red": 255 + } + } + }, + "pages": { + "template_page": { + "order": 1, + "list_rows": { + "order": 1, + "template_row": { + "order": 1, + "height": 20, + "cols": [ + { + "text": { + "order": 1, + "source_key": "text_value" + } + } + ] + } + } + } + } +} \ No newline at end of file From 951b884b5358fa4a18925fe392875b2b9a8285f3 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 11:51:21 -0300 Subject: [PATCH 108/116] test: validate parallelism example build --- pkg/processor/processor_test.go | 14 + .../processorprovider/builder_maroto.go | 2 +- .../processor/json/parallelism_content.json | 258 ++++++++++++++++++ .../processor/json/parallelism_template.json | 31 +++ 4 files changed, 304 insertions(+), 1 deletion(-) create mode 100644 test/maroto/processor/json/parallelism_content.json create mode 100644 test/maroto/processor/json/parallelism_template.json diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index b5e99b1e..c933fe7a 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -332,6 +332,20 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/pagenumber.json") }) + t.Run("when template with parallelism example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/parallelism_template.json") + fixcontent, _ := processortest.NewFileReader().LoadFile("processor/json/parallelism_content.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("parallelism", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("parallelism", string(fixcontent)) + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/parallelism.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) t.Run("when invalid content is sent, should return an error", func(t *testing.T) { diff --git a/pkg/processor/processorprovider/builder_maroto.go b/pkg/processor/processorprovider/builder_maroto.go index fcaac2bf..3c15fe04 100644 --- a/pkg/processor/processorprovider/builder_maroto.go +++ b/pkg/processor/processorprovider/builder_maroto.go @@ -84,7 +84,7 @@ func (m *MarotoBuilder) WithConcurrentMode(chunkWorkers int) *MarotoBuilder { // WithSequentialMode defines that maroto will run in default mode. func (m *MarotoBuilder) WithSequentialMode(on bool) *MarotoBuilder { - m.cfg.WithSequentialMode() + validAndRun(func() { m.cfg.WithSequentialMode() }, on) return m } diff --git a/test/maroto/processor/json/parallelism_content.json b/test/maroto/processor/json/parallelism_content.json new file mode 100644 index 00000000..a25ab2b3 --- /dev/null +++ b/test/maroto/processor/json/parallelism_content.json @@ -0,0 +1,258 @@ +{ + "pages": { + "template_page": { + "list_rows": [ + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + }, + { + "template_row": { + "text_value": "Dummy text" + } + } + ] + } + } +} \ No newline at end of file diff --git a/test/maroto/processor/json/parallelism_template.json b/test/maroto/processor/json/parallelism_template.json new file mode 100644 index 00000000..643c1dae --- /dev/null +++ b/test/maroto/processor/json/parallelism_template.json @@ -0,0 +1,31 @@ +{ + "builder": { + "debug": true, + "concurrent_mode": 7, + "page_number": {} + }, + + "pages": { + "template_page": { + "order": 1, + "list_rows": { + "order": 1, + "template_row": { + "order": 1, + "height": 10, + "cols": [ + { + "text": { + "order": 1, + "source_key": "text_value", + "props": { + "size": 8 + } + } + } + ] + } + } + } + } +} \ No newline at end of file From 407e07ef740bf507c3b366e4e86dfff58dae7e1e Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 13:42:25 -0300 Subject: [PATCH 109/116] test: validate protection example build --- .../mappers/buildermapper/bulder_test.go | 2 +- pkg/processor/processor_test.go | 13 ++++++++++ .../processorprovider/builder_maroto_test.go | 5 +--- .../processor/json/protection_template.json | 26 +++++++++++++++++++ 4 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 test/maroto/processor/json/protection_template.json diff --git a/pkg/processor/mappers/buildermapper/bulder_test.go b/pkg/processor/mappers/buildermapper/bulder_test.go index 5dc665f6..26b58b9d 100644 --- a/pkg/processor/mappers/buildermapper/bulder_test.go +++ b/pkg/processor/mappers/buildermapper/bulder_test.go @@ -42,7 +42,7 @@ func DefaultBuilderMap() *Builder { Pattern: "pattern_test", Place: "place_test", Family: "family_test", - Style: "italic", + Style: "I", Size: 10.0, Color: &propsmapper.Color{ Red: 10, diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index c933fe7a..106b785b 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -346,6 +346,19 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/parallelism.json") }) + t.Run("when template with protection example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/protection_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("parallelism", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("parallelism", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/protection.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) t.Run("when invalid content is sent, should return an error", func(t *testing.T) { diff --git a/pkg/processor/processorprovider/builder_maroto_test.go b/pkg/processor/processorprovider/builder_maroto_test.go index b43359ab..44fc3c1d 100644 --- a/pkg/processor/processorprovider/builder_maroto_test.go +++ b/pkg/processor/processorprovider/builder_maroto_test.go @@ -26,7 +26,6 @@ func NewBuilderMocks(t *testing.T) *mocks.Builder { build.EXPECT().WithLeftMargin(mock.Anything).Return(config.NewBuilder()) build.EXPECT().WithRightMargin(mock.Anything).Return(config.NewBuilder()) build.EXPECT().WithConcurrentMode(mock.Anything).Return(config.NewBuilder()) - build.EXPECT().WithSequentialMode().Return(config.NewBuilder()) build.EXPECT().WithDebug(mock.Anything).Return(config.NewBuilder()) build.EXPECT().WithMaxGridSize(mock.Anything).Return(config.NewBuilder()) build.EXPECT().WithDefaultFont(mock.Anything).Return(config.NewBuilder()) @@ -53,7 +52,7 @@ func NewvalidateCallOfAllMethods(t *testing.T, builder *mocks.Builder) { builder.AssertNumberOfCalls(t, "WithLeftMargin", 1) builder.AssertNumberOfCalls(t, "WithRightMargin", 1) builder.AssertNumberOfCalls(t, "WithConcurrentMode", 1) - builder.AssertNumberOfCalls(t, "WithSequentialMode", 1) + builder.AssertNumberOfCalls(t, "WithSequentialMode", 0) builder.AssertNumberOfCalls(t, "WithDebug", 1) builder.AssertNumberOfCalls(t, "WithMaxGridSize", 1) builder.AssertNumberOfCalls(t, "WithDefaultFont", 1) @@ -241,13 +240,11 @@ func TestWithSequentialMode(t *testing.T) { t.Run("when sequential mode is false, should not set sequential mode", func(t *testing.T) { repository := mocks.NewProcessorRepository(t) build := mocks.NewBuilder(t) - build.EXPECT().WithSequentialMode().Return(config.NewBuilder()) builder := processorprovider.NewMarotoBuilder(repository, build) cfg := builder.WithSequentialMode(false) assert.NotNil(t, cfg) - build.AssertNumberOfCalls(t, "WithSequentialMode", 1) }) } diff --git a/test/maroto/processor/json/protection_template.json b/test/maroto/processor/json/protection_template.json new file mode 100644 index 00000000..97894cf3 --- /dev/null +++ b/test/maroto/processor/json/protection_template.json @@ -0,0 +1,26 @@ +{ + "builder": { + "protection": { + "type": "none", + "user_password": "user", + "owner_password": "owner" + } + }, + "pages": { + "template_page": { + "order": 1, + "template_row": { + "order": 1, + "height": 30, + "cols": [ + { + "text": { + "order": 1, + "value": "supersecret content" + } + } + ] + } + } + } +} \ No newline at end of file From 90873ac599f9764d8084469ef37c4ab6e29af1e5 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 13:56:09 -0300 Subject: [PATCH 110/116] test: validate qrcodegrid example build --- pkg/processor/processor_test.go | 17 +- .../processor/json/qrcodegrid_template.json | 201 ++++++++++++++++++ 2 files changed, 216 insertions(+), 2 deletions(-) create mode 100644 test/maroto/processor/json/qrcodegrid_template.json diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index 106b785b..015d7ef5 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -351,14 +351,27 @@ func TestGenerateTemplate(t *testing.T) { fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/protection_template.json") processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) - err := processor.RegisterTemplate("parallelism", string(fixtemplate)) + err := processor.RegisterTemplate("protection", string(fixtemplate)) require.NoError(t, err) - provider, err := processor.GenerateDocument("parallelism", "{}") + provider, err := processor.GenerateDocument("protection", "{}") assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/protection.json") }) + t.Run("when template with qrcodegrid example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/qrcodegrid_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("qrcodegrid", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("qrcodegrid", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/qrcodegrid.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) t.Run("when invalid content is sent, should return an error", func(t *testing.T) { diff --git a/test/maroto/processor/json/qrcodegrid_template.json b/test/maroto/processor/json/qrcodegrid_template.json new file mode 100644 index 00000000..dd7e117f --- /dev/null +++ b/test/maroto/processor/json/qrcodegrid_template.json @@ -0,0 +1,201 @@ +{ + "builder": { + "debug": true + }, + "pages": { + "template_page": { + "order": 1, + "qr_code_row1": { + "order": 1, + "height": 40, + "cols": [ + { + "size": 2, + "qr_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 50 + } + } + }, + { + "size": 4, + "qr_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 75 + } + } + }, + { + "size": 6, + "qr_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 100 + } + } + } + ] + }, + "qr_code_center_row1": { + "order": 2, + "height": 40, + "cols": [ + { + "size": 2, + "qr_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "center": true, + "percent": 50 + } + } + }, + { + "size": 4, + "qr_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "center": true, + "percent": 75 + } + } + }, + { + "size": 6, + "qr_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "center": true, + "percent": 100 + } + } + } + ] + }, + "qr_code_row2": { + "order": 3, + "height": 40, + "cols": [ + { + "size": 6, + "qr_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 50 + } + } + }, + { + "size": 4, + "qr_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 75 + } + } + }, + { + "size": 2, + "qr_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "percent": 100 + } + } + } + ] + }, + "qr_code_center_row2": { + "order": 4, + "height": 40, + "cols": [ + { + "size": 6, + "qr_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "center": true, + "percent": 50 + } + } + }, + { + "size": 4, + "qr_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "center": true, + "percent": 75 + } + } + }, + { + "size": 2, + "qr_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "center": true, + "percent": 100 + } + } + } + ] + }, + "qr_code_auto_row": { + "order": 5, + "cols": [ + { + "size": 6, + "qr_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "center": true, + "percent": 30, + "just_reference_width": true + } + } + }, + { + "size": 4, + "qr_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "center": true, + "percent": 75, + "just_reference_width": true + } + } + }, + { + "size": 2, + "qr_code": { + "order": 1, + "value": "https://github.com/johnfercher/maroto", + "props": { + "center": true, + "percent": 100, + "just_reference_width": true + } + } + } + ] + } + } + } +} \ No newline at end of file From 69f162aa9e974ed6fd3b3824b43b157cf98a50ea Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 14:13:51 -0300 Subject: [PATCH 111/116] test: validate signature example build --- .../mappers/propsmapper/signature.go | 2 +- pkg/processor/processor_test.go | 13 ++ .../processor/json/signature_template.json | 162 ++++++++++++++++++ 3 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 test/maroto/processor/json/signature_template.json diff --git a/pkg/processor/mappers/propsmapper/signature.go b/pkg/processor/mappers/propsmapper/signature.go index fc1cbaeb..e087dbe3 100644 --- a/pkg/processor/mappers/propsmapper/signature.go +++ b/pkg/processor/mappers/propsmapper/signature.go @@ -38,7 +38,7 @@ func NewSignature(signature interface{}) (*Signature, error) { FontFamily: *convertFields(signatureMap["font_family"], ""), FontStyle: NewFontStyle(*convertFields(signatureMap["font_style"], "")), FontSize: *convertFields(signatureMap["font_size"], 0.0), - FontColor: NewColor(signatureMap["font_Color"]), + FontColor: NewColor(signatureMap["font_color"]), LineColor: NewColor(signatureMap["line_color"]), LineStyle: linestyle.Type(NewLineStyle(*convertFields(signatureMap["line_style"], ""))), LineThickness: *convertFields(signatureMap["line_thickness"], 0.0), diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index 015d7ef5..11191390 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -372,6 +372,19 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/qrcodegrid.json") }) + t.Run("when template with signature example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/signature_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("signature", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("signature", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/signaturegrid.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) t.Run("when invalid content is sent, should return an error", func(t *testing.T) { diff --git a/test/maroto/processor/json/signature_template.json b/test/maroto/processor/json/signature_template.json new file mode 100644 index 00000000..d671335f --- /dev/null +++ b/test/maroto/processor/json/signature_template.json @@ -0,0 +1,162 @@ +{ + "builder": { + "debug": true + }, + "pages": { + "template_page": { + "order": 1, + "template_row1": { + "order": 1, + "height": 40, + "cols": [ + { + "size": 2, + "signature": { + "order": 1, + "value": "Signature 1" + } + }, + { + "size": 4, + "signature": { + "order": 1, + "value": "Signature 2", + "props": { + "font_family": "courier" + } + } + }, + { + "size": 6, + "signature": { + "order": 1, + "value": "Signature 3", + "props": { + "font_style": "bold_italic" + } + } + } + ] + }, + "template_row2": { + "order": 2, + "height": 40, + "cols": [ + { + "size": 6, + "signature": { + "order": 1, + "value": "Signature 4", + "props": { + "font_style": "italic" + } + } + }, + { + "size": 4, + "signature": { + "order": 1, + "value": "Signature 5", + "props": { + "font_size": 12 + } + } + }, + { + "size": 2, + "signature": { + "order": 1, + "value": "Signature 6", + "props": { + "font_color": { + "red": 255, + "blue": 0, + "green": 0 + } + } + } + } + ] + }, + "template_row3": { + "order": 3, + "height": 40, + "cols": [ + { + "size": 4, + "signature": { + "order": 1, + "value": "Signature 7", + "props": { + "line_color": { + "red": 255, + "blue": 0, + "green": 0 + } + } + } + }, + { + "size": 4, + "signature": { + "order": 1, + "value": "Signature 8", + "props": { + "line_style": "dashed" + } + } + }, + { + "size": 4, + "signature": { + "order": 1, + "value": "Signature 9", + "props": { + "line_thickness": 0.5 + } + } + } + ] + }, + "template_autorow": { + "order": 4, + "cols": [ + { + "size": 4, + "signature": { + "order": 1, + "value": "Signature 7", + "props": { + "line_color": { + "red": 255, + "blue": 0, + "green": 0 + } + } + } + }, + { + "size": 4, + "signature": { + "order": 1, + "value": "Signature 8", + "props": { + "line_style": "dashed" + } + } + }, + { + "size": 4, + "signature": { + "order": 1, + "value": "Signature 9", + "props": { + "line_thickness": 0.5 + } + } + } + ] + } + } + } +} \ No newline at end of file From 4cfe0e747ebc66c70e255887089c444927d5db47 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 14:31:55 -0300 Subject: [PATCH 112/116] test: validate simplest example build --- pkg/processor/processor_test.go | 15 +++ .../processor/json/simplest_template.json | 91 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 test/maroto/processor/json/simplest_template.json diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index 11191390..56fafa04 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -385,6 +385,21 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/signaturegrid.json") }) + + t.Run("when template with simplest example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/simplest_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("simplest", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("simplest", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/simplest.json") + }) + t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) t.Run("when invalid content is sent, should return an error", func(t *testing.T) { diff --git a/test/maroto/processor/json/simplest_template.json b/test/maroto/processor/json/simplest_template.json new file mode 100644 index 00000000..4377f7c5 --- /dev/null +++ b/test/maroto/processor/json/simplest_template.json @@ -0,0 +1,91 @@ +{ + "pages": { + "template_page": { + "order": 1, + "template_row1": { + "order": 1, + "height": 20, + "cols": [ + { + "size": 4, + "bar_code": { + "order": 1, + "value": "barcode" + } + }, + { + "size": 4, + "matrix_code": { + "order": 1, + "value": "matrixcode" + } + }, + { + "size": 4, + "qr_code": { + "order": 1, + "value": "qrcode" + } + } + ] + }, + "tepmlate_row2": { + "order": 2, + "height": 10, + "cols": [ + { + "size": 12 + } + ] + }, + "template_row3": { + "order": 3, + "height": 20, + "cols": [ + { + "size": 4, + "image": { + "order": 1, + "value": "docs/assets/images/biplane.jpg" + } + }, + { + "size": 4, + "signature": { + "order": 1, + "value": "signature" + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "text" + } + } + ] + }, + "template_row4": { + "order": 4, + "height": 10, + "cols": [ + { + "size": 12 + } + ] + }, + "template_row5": { + "order": 5, + "height": 20, + "cols": [ + { + "size": 12, + "line": { + "order": 1 + } + } + ] + } + } + } +} \ No newline at end of file From f8d61727a2cc130b4aaa5d1f90574c4f8e26ab50 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 16:19:10 -0300 Subject: [PATCH 113/116] test: validate textgrid example build --- pkg/processor/mappers/propsmapper/text.go | 14 +- pkg/processor/processor_test.go | 15 +- .../processor/json/textgrid_template.json | 424 ++++++++++++++++++ 3 files changed, 447 insertions(+), 6 deletions(-) create mode 100644 test/maroto/processor/json/textgrid_template.json diff --git a/pkg/processor/mappers/propsmapper/text.go b/pkg/processor/mappers/propsmapper/text.go index 464a823b..8d89c213 100644 --- a/pkg/processor/mappers/propsmapper/text.go +++ b/pkg/processor/mappers/propsmapper/text.go @@ -1,6 +1,8 @@ package propsmapper -import "fmt" +import ( + "fmt" +) // Text represents properties from a Text inside a cell. type Text struct { @@ -35,8 +37,7 @@ func NewText(signature interface{}) (*Text, error) { if !ok { return nil, fmt.Errorf("ensure text props can be converted to map[string] interface{}") } - - return &Text{ + text := &Text{ Top: *convertFields(signatureMap["top"], -1.0), Left: *convertFields(signatureMap["left"], -1.0), Right: *convertFields(signatureMap["right"], -1.0), @@ -47,6 +48,9 @@ func NewText(signature interface{}) (*Text, error) { BreakLineStrategy: NewBreakLineStrategy(*convertFields(signatureMap["break_line_strategy"], "")), VerticalPadding: *convertFields(signatureMap["vertical_padding"], -1.0), Color: NewColor(signatureMap["color"]), - Hyperlink: *convertFields[*string](signatureMap["hyperlink"], nil), - }, nil + } + if hyperlink := *convertFields(signatureMap["hyperlink"], ""); hyperlink != "" { + text.Hyperlink = &hyperlink + } + return text, nil } diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index 56fafa04..b52bd8cd 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -370,7 +370,7 @@ func TestGenerateTemplate(t *testing.T) { provider, err := processor.GenerateDocument("qrcodegrid", "{}") assert.Nil(t, err) - test.New(t).Assert((*provider).GetStructure()).Equals("examples/qrcodegrid.json") + test.New(t).Assert((*provider).GetStructure()).Equals("examples/qrgrid.json") }) t.Run("when template with signature example is found, should set template", func(t *testing.T) { test.SetupTestDir(t) @@ -399,6 +399,19 @@ func TestGenerateTemplate(t *testing.T) { assert.Nil(t, err) test.New(t).Assert((*provider).GetStructure()).Equals("examples/simplest.json") }) + t.Run("when template with textgrid example is found, should set template", func(t *testing.T) { + test.SetupTestDir(t) + + fixtemplate, _ := processortest.NewFileReader().LoadFile("processor/json/textgrid_template.json") + processor := processor.NewProcessor(repository.NewMemoryStorage(loader.NewLoader()), deserializer.NewJSONDeserializer()) + err := processor.RegisterTemplate("textgrid", string(fixtemplate)) + require.NoError(t, err) + + provider, err := processor.GenerateDocument("textgrid", "{}") + + assert.Nil(t, err) + test.New(t).Assert((*provider).GetStructure()).Equals("examples/textgrid.json") + }) t.Run("when template with invalid field is found, should return an error", func(t *testing.T) { }) diff --git a/test/maroto/processor/json/textgrid_template.json b/test/maroto/processor/json/textgrid_template.json new file mode 100644 index 00000000..8fdf8304 --- /dev/null +++ b/test/maroto/processor/json/textgrid_template.json @@ -0,0 +1,424 @@ +{ + "builder": { + "debug": true + }, + "pages": { + "template_page": { + "order": 1, + "template_row1": { + "order": 1, + "height": 40, + "cols": [ + { + "size": 2, + "text": { + "order": 1, + "value": "Red text", + "props": { + "color": { + "red": 255, + "green": 0, + "blue": 0 + } + } + } + }, + { + "size": 6, + "text": { + "order": 1, + "value": "Green text", + "props": { + "color": { + "red": 0, + "green": 255, + "blue": 0 + } + } + } + }, + { + "size": 4, + "text":{ + "order": 1, + "value": "Blue text", + "props": { + "color": { + "red": 0, + "green": 0, + "blue": 255 + } + } + } + } + ] + }, + "template_row2": { + "order": 2, + "height": 40, + "cols": [ + { + "size": 2, + "text": { + "order": 1, + "value": "Left-aligned text" + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "Centered text", + "props": { + "align": "center" + } + } + + }, + { + "size": 6, + "text": { + "order": 1, + "value": "Right-aligned text", + "props": { + "align": "right" + } + } + } + ] + }, + "template_row3": { + "order": 3, + "height": 10, + "cols": [ + { + "text": { + "order": 1, + "value": "Aligned unindented text" + } + } + ] + }, + "template_row4": { + "order": 4, + "height": 40, + "cols": [ + { + "size": 2, + "text": { + "order": 1, + "value": "Left-aligned text", + "props": { + "top": 3, + "left": 3, + "align": "left" + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "Centered text", + "props": { + "top": 3, + "align": "center" + } + } + }, + { + "size": 6, + "text":{ + "order": 1, + "value": "Right-aligned text", + "props": { + "top": 3, + "right": 3, + "align": "right" + } + } + } + ] + }, + "template_row5": { + "order": 5, + "height": 10, + "cols": [ + { + "text": { + "order": 1, + "value": "Aligned text with indentation" + } + } + ] + }, + "template_row6": { + "order": 6, + "height": 40, + "cols": [ + { + "size": 2, + "text": { + "order": 1, + "value": "This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise.", + "props": { + "align": "left" + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise.", + "props": { + "align": "center" + } + } + }, + { + "size": 6, + "text": { + "order": 1, + "value": "This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise.", + "props": { + "align": "right" + } + } + } + ] + }, + "template_row7": { + "order": 7, + "height": 10, + "cols": [ + { + "text": { + "order": 1, + "value": "Multiline text" + } + } + ] + }, + "template_row8": { + "order": 8, + "height": 40, + "cols": [ + { + "size": 2, + "text": { + "order": 1, + "value": "This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise.", + "props": { + "top": 3, + "left": 3, + "right": 3, + "align": "left", + "break_line_strategy": "dash_strategy" + } + } + + }, + { + "size": 4, + "text": { + "order": 1, + "value": "This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise.", + "props": { + "top": 3, + "left": 3, + "right": 3, + "align": "center" + } + } + }, + { + "size": 6, + "text": { + "order": 1, + "value": "This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise.", + "props": { + "top": 3, + "left": 3, + "right": 3, + "align": "right" + } + } + } + ] + }, + "template_row9": { + "order": 9, + "height": 10, + "cols": [ + { + "text": { + "order": 1, + "value": "Multiline text with indentation" + } + } + ] + }, + "template_row10": { + "order": 10, + "height": 10, + "cols": [ + { + "text": { + "order": 1, + "value": "text with hyperlink", + "props": { + "hyperlink": "https://google.com" + } + } + } + ] + }, + "template_row11": { + "order": 11, + "height": 45, + "cols": [ + { + "size": 2, + "text": { + "order": 1, + "value": "This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise.", + "props": { + "top": 3, + "left": 3, + "right": 3, + "align": "justify", + "break_line_strategy": "dash_strategy" + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise. This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise.", + "props": { + "top": 10, + "left": 3, + "right": 3, + "align": "justify" + } + } + }, + { + "size": 6, + "text": { + "order": 1, + "value": "This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise. This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise.", + "props": { + "top": 10, + "left": 10, + "right": 10, + "align": "justify", + "hyperlink": "https://google.com" + } + } + } + ] + }, + "template_row12": { + "order": 12, + "height": 10, + "cols": [ + { + "text": { + "order": 1, + "value": "Justify-aligned text", + "props": { + "align": "justify" + } + } + } + ] + }, + "template_row13": { + "order": 13, + "cols": [ + { + "size": 2, + "text": { + "order": 1, + "value": "This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise.", + "props": { + "top": 0, + "left": 3, + "right": 3, + "align": "justify", + "break_line_strategy": "dash_strategy" + } + } + }, + { + "size": 4, + "text": { + "order": 1, + "value": "This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise. This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise.", + "props": { + "top": 0, + "left": 3, + "right": 3, + "align": "justify" + } + } + }, + { + "size": 6, + "text": { + "order": 1, + "value": "This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise. This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise. This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise.", + "props": { + "top": 0, + "left": 10, + "right": 10, + "align": "justify", + "hyperlink": "https://google.com" + } + } + } + ] + }, + "template_row14": { + "order": 14, + "cols": [ + { + "size": 12, + "text": { + "order": 1, + "value": "This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise. This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise. This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise.", + "props": { + "left": 3, + "right": 3, + "align": "justify", + "break_line_strategy": "empty_space_strategyt" + } + } + } + ] + }, + "template_row15": { + "order": 15, + "cols": [ + { + "size": 12, + "text": { + "order": 1, + "value": "This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise. This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise. This is a longer sentence that will be broken into multiple lines as it does not fit into the column otherwise.", + "props": { + "left": 3, + "right": 3, + "align": "justify", + "break_line_strategy": "empty_space_strategy", + "vertical_padding": 10 + } + } + } + ] + } + } + } +} \ No newline at end of file From 68e1cccf392d94fb9dfd57b96c57381ee3e16b8e Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 16:59:08 -0300 Subject: [PATCH 114/116] test: fix error in expected structure for autorow example --- test/maroto/examples/autorow.json | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/maroto/examples/autorow.json b/test/maroto/examples/autorow.json index 78bda398..d739323c 100755 --- a/test/maroto/examples/autorow.json +++ b/test/maroto/examples/autorow.json @@ -168,6 +168,21 @@ } ] }, + { + "value": 23.946388888888862, + "type": "row", + "nodes": [ + { + "value": 12, + "type": "col" + } + ] + } + ] + }, + { + "type": "page", + "nodes": [ { "value": 47.5, "type": "row", @@ -204,21 +219,6 @@ } ] }, - { - "value": 0.0030555555555338287, - "type": "row", - "nodes": [ - { - "value": 12, - "type": "col" - } - ] - } - ] - }, - { - "type": "page", - "nodes": [ { "value": 31.666666666666664, "type": "row", @@ -256,7 +256,7 @@ ] }, { - "value": 25.98527777777778, + "value": 187.83083333333335, "type": "row", "nodes": [ { From 1af0abedfcec4bc120088b693ead89ce79c7202e Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 17:15:27 -0300 Subject: [PATCH 115/116] fix: include bottom property in text --- pkg/processor/mappers/propsmapper/text.go | 3 ++ pkg/processor/processorprovider/Maroto.go | 7 +++-- .../processor/json/auto_row_content.json | 4 +++ .../processor/json/auto_row_template.json | 30 +++++++++++++++++-- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/pkg/processor/mappers/propsmapper/text.go b/pkg/processor/mappers/propsmapper/text.go index 8d89c213..8e13a779 100644 --- a/pkg/processor/mappers/propsmapper/text.go +++ b/pkg/processor/mappers/propsmapper/text.go @@ -8,6 +8,8 @@ import ( type Text struct { // Top is the amount of space between the upper cell limit and the text. Top float64 + // Bottom is the amount of space between the lower cell limit and the text. (Used by auto row only) + Bottom float64 // Left is the minimal amount of space between the left cell boundary and the text. Left float64 // Right is the minimal amount of space between the right cell boundary and the text. @@ -41,6 +43,7 @@ func NewText(signature interface{}) (*Text, error) { Top: *convertFields(signatureMap["top"], -1.0), Left: *convertFields(signatureMap["left"], -1.0), Right: *convertFields(signatureMap["right"], -1.0), + Bottom: *convertFields(signatureMap["bottom"], -1.0), Family: *convertFields(signatureMap["family"], ""), Style: NewFontStyle(*convertFields(signatureMap["style"], "")), Size: *convertFields(signatureMap["size"], 0.0), diff --git a/pkg/processor/processorprovider/Maroto.go b/pkg/processor/processorprovider/Maroto.go index a4776278..40beb80e 100644 --- a/pkg/processor/processorprovider/Maroto.go +++ b/pkg/processor/processorprovider/Maroto.go @@ -160,9 +160,10 @@ func (m *Maroto) CreateText(value string, textsProps ...*propsmapper.Text) Provi } return text.New(value, props.Text{ - Top: tProps.Top, Left: tProps.Left, Right: tProps.Right, Family: tProps.Family, Style: fontstyle.Type(tProps.Style), - Size: tProps.Size, Align: align.Type(tProps.Align), BreakLineStrategy: breakline.Strategy(tProps.BreakLineStrategy), - VerticalPadding: tProps.VerticalPadding, Color: (*props.Color)(tProps.Color), Hyperlink: tProps.Hyperlink, + Top: tProps.Top, Bottom: tProps.Bottom, Left: tProps.Left, Right: tProps.Right, Family: tProps.Family, + Style: fontstyle.Type(tProps.Style), Size: tProps.Size, Align: align.Type(tProps.Align), + BreakLineStrategy: breakline.Strategy(tProps.BreakLineStrategy), VerticalPadding: tProps.VerticalPadding, + Color: (*props.Color)(tProps.Color), Hyperlink: tProps.Hyperlink, }) } diff --git a/test/maroto/processor/json/auto_row_content.json b/test/maroto/processor/json/auto_row_content.json index f21566de..c9470dd3 100644 --- a/test/maroto/processor/json/auto_row_content.json +++ b/test/maroto/processor/json/auto_row_content.json @@ -9,6 +9,10 @@ "biplane": "docs/assets/images/biplane.jpg", "intro": "Numa toca no chão vivia um hobbit. Não uma toca nojenta, suja, úmida, \ncheia de pontas de minhocas e um cheiro de limo, nem tam pouco uma toca seca, vazia, arenosa, \nsem nenhum lugar onde se sentar ou onde comer: era uma toca de hobbit, e isso significa conforto.\nEla tinha uma porta perfeitamente redonda feito uma escotilha, pintada de verde, com uma maçaneta\namarela e brilhante de latão exatamente no meio. A porta se abria para um corredor em forma de tubo,\nfeito um túnel: um túnel muito confortável, sem fumaça, de paredes com painéis e assoalhos\nazulejados e acarpetados, com cadeiras enceradas e montes e montes de cabieiros para chapéus e\ncasacos - o hobbit apreciava visitas." }, + "row_with_image2": { + "biplane": "docs/assets/images/biplane.jpg", + "intro": "Numa toca no chão vivia um hobbit. Não uma toca nojenta, suja, úmida, \ncheia de pontas de minhocas e um cheiro de limo, nem tam pouco uma toca seca, vazia, arenosa, \nsem nenhum lugar onde se sentar ou onde comer: era uma toca de hobbit, e isso significa conforto.\nEla tinha uma porta perfeitamente redonda feito uma escotilha, pintada de verde, com uma maçaneta\namarela e brilhante de latão exatamente no meio. A porta se abria para um corredor em forma de tubo,\nfeito um túnel: um túnel muito confortável, sem fumaça, de paredes com painéis e assoalhos\nazulejados e acarpetados, com cadeiras enceradas e montes e montes de cabieiros para chapéus e\ncasacos - o hobbit apreciava visitas." + }, "row_barcode": { "bar_col": "code", "intro": "Numa toca no chão vivia um hobbit. Não uma toca nojenta, suja, úmida, \ncheia de pontas de minhocas e um cheiro de limo, nem tam pouco uma toca seca, vazia, arenosa, \nsem nenhum lugar onde se sentar ou onde comer: era uma toca de hobbit, e isso significa conforto.\nEla tinha uma porta perfeitamente redonda feito uma escotilha, pintada de verde, com uma maçaneta\namarela e brilhante de latão exatamente no meio. A porta se abria para um corredor em forma de tubo,\nfeito um túnel: um túnel muito confortável, sem fumaça, de paredes com painéis e assoalhos\nazulejados e acarpetados, com cadeiras enceradas e montes e montes de cabieiros para chapéus e\ncasacos - o hobbit apreciava visitas." diff --git a/test/maroto/processor/json/auto_row_template.json b/test/maroto/processor/json/auto_row_template.json index 62c5bdea..6edb07c9 100644 --- a/test/maroto/processor/json/auto_row_template.json +++ b/test/maroto/processor/json/auto_row_template.json @@ -46,8 +46,32 @@ } ] }, - "row_barcode": { + "row_with_image2": { "order": 3, + "cols": [ + { + "image": { + "order": 1, + "source_key": "biplane" + }, + "size": 5 + }, + { + "text": { + "order": 1, + "source_key": "intro", + "props": { + "size": 13, + "top": 8, + "bottom": 9 + } + }, + "size": 7 + } + ] + }, + "row_barcode": { + "order": 4, "cols": [ { "bar_code": { @@ -66,7 +90,7 @@ ] }, "row_matrixcode": { - "order": 4, + "order": 5, "cols": [ { "matrix_code": { @@ -85,7 +109,7 @@ ] }, "row_qrcode": { - "order": 5, + "order": 6, "cols": [ { "qr_code": { From 7d8c3c87faf366c69b6d1c77a93da7a30bd65165 Mon Sep 17 00:00:00 2001 From: Fernando-hub527 Date: Thu, 2 Jan 2025 17:28:46 -0300 Subject: [PATCH 116/116] mocks: fix repeating interface names --- internal/providers/gofpdf/builder.go | 4 +- mocks/BuilderProvider.go | 89 ++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 mocks/BuilderProvider.go diff --git a/internal/providers/gofpdf/builder.go b/internal/providers/gofpdf/builder.go index 6aa59f2e..11d821bb 100644 --- a/internal/providers/gofpdf/builder.go +++ b/internal/providers/gofpdf/builder.go @@ -25,8 +25,8 @@ type Dependencies struct { Cfg *entity.Config } -// Builder is the dependencies builder for gofpdf -type Builder interface { +// BuilderProvider is the dependencies builder for gofpdf +type BuilderProvider interface { Build(cfg *entity.Config, cache cache.Cache) *Dependencies } diff --git a/mocks/BuilderProvider.go b/mocks/BuilderProvider.go new file mode 100644 index 00000000..71b0e59d --- /dev/null +++ b/mocks/BuilderProvider.go @@ -0,0 +1,89 @@ +// Code generated by mockery v2.42.0. DO NOT EDIT. + +package mocks + +import ( + cache "github.com/johnfercher/maroto/v2/internal/cache" + entity "github.com/johnfercher/maroto/v2/pkg/core/entity" + + gofpdf "github.com/johnfercher/maroto/v2/internal/providers/gofpdf" + + mock "github.com/stretchr/testify/mock" +) + +// BuilderProvider is an autogenerated mock type for the BuilderProvider type +type BuilderProvider struct { + mock.Mock +} + +type BuilderProvider_Expecter struct { + mock *mock.Mock +} + +func (_m *BuilderProvider) EXPECT() *BuilderProvider_Expecter { + return &BuilderProvider_Expecter{mock: &_m.Mock} +} + +// Build provides a mock function with given fields: cfg, _a1 +func (_m *BuilderProvider) Build(cfg *entity.Config, _a1 cache.Cache) *gofpdf.Dependencies { + ret := _m.Called(cfg, _a1) + + if len(ret) == 0 { + panic("no return value specified for Build") + } + + var r0 *gofpdf.Dependencies + if rf, ok := ret.Get(0).(func(*entity.Config, cache.Cache) *gofpdf.Dependencies); ok { + r0 = rf(cfg, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*gofpdf.Dependencies) + } + } + + return r0 +} + +// BuilderProvider_Build_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Build' +type BuilderProvider_Build_Call struct { + *mock.Call +} + +// Build is a helper method to define mock.On call +// - cfg *entity.Config +// - _a1 cache.Cache +func (_e *BuilderProvider_Expecter) Build(cfg interface{}, _a1 interface{}) *BuilderProvider_Build_Call { + return &BuilderProvider_Build_Call{Call: _e.mock.On("Build", cfg, _a1)} +} + +func (_c *BuilderProvider_Build_Call) Run(run func(cfg *entity.Config, _a1 cache.Cache)) *BuilderProvider_Build_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*entity.Config), args[1].(cache.Cache)) + }) + return _c +} + +func (_c *BuilderProvider_Build_Call) Return(_a0 *gofpdf.Dependencies) *BuilderProvider_Build_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *BuilderProvider_Build_Call) RunAndReturn(run func(*entity.Config, cache.Cache) *gofpdf.Dependencies) *BuilderProvider_Build_Call { + _c.Call.Return(run) + return _c +} + +// NewBuilderProvider creates a new instance of BuilderProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewBuilderProvider(t interface { + mock.TestingT + Cleanup(func()) +}, +) *BuilderProvider { + mock := &BuilderProvider{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +}