Skip to content

Commit

Permalink
Improve col tests (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfercher authored Oct 10, 2023
1 parent f907ea7 commit 0cecd01
Show file tree
Hide file tree
Showing 37 changed files with 865 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ always when a new page appear, in this case, a header may have many rows, lines
* With `go get`:

```bash
go get github.com/johnfercher/maroto/v2/[email protected].38
go get github.com/johnfercher/maroto/v2/[email protected].39
```


Expand Down
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go#template-engines) [![Branch](https://img.shields.io/badge/V2-Branch-pink)](https://github.com/johnfercher/maroto/tree/v2) [![Roadmap](https://img.shields.io/badge/V2-Roadmap-purple)](https://github.com/users/johnfercher/projects/1) [![Discussion](https://img.shields.io/badge/V2-Discussion-blue)](https://github.com/johnfercher/maroto/issues/257) [![Release Notes](https://img.shields.io/badge/Release-Notes-cyan)](https://github.com/johnfercher/maroto/releases) [![Visits Badge](https://badges.pufler.dev/visits/johnfercher/maroto)](https://badges.pufler.dev)

#### Maroto`v2.0.0-alpha.38`is here! Try out:
#### Maroto`v2.0.0-alpha.39`is here! Try out:

* Installation with`go get`:

```bash
go get github.com/johnfercher/maroto/v2/[email protected].38
go get github.com/johnfercher/maroto/v2/[email protected].39
```

The public API was completely redesigned with the aim of enhancing the
Expand Down
7 changes: 7 additions & 0 deletions pkg/components/col/col.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ func (c *col) GetStructure() *node.Node[core.Structure] {
Details: c.style.ToMap(),
}

if c.isMax {
if len(str.Details) == 0 {
str.Details = make(map[string]interface{})
}
str.Details["is_max"] = true
}

node := node.New(str)

for _, c := range c.components {
Expand Down
62 changes: 54 additions & 8 deletions pkg/components/col/col_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
package col_test

import (
"fmt"
"testing"

"github.com/johnfercher/maroto/v2/internal/fixture"
"github.com/johnfercher/maroto/v2/mocks"
"github.com/johnfercher/maroto/v2/pkg/components/code"
"github.com/johnfercher/maroto/v2/pkg/core/entity"
"github.com/johnfercher/maroto/v2/pkg/props"
"github.com/johnfercher/maroto/v2/pkg/test"
"github.com/stretchr/testify/assert"

"github.com/johnfercher/maroto/v2/pkg/components/col"

"github.com/stretchr/testify/assert"
)

func TestNew(t *testing.T) {
// Act
c := col.New()
t.Run("when size is not defined, should use is as max", func(t *testing.T) {
// Act
c := col.New()

// Assert
test.New(t).Assert(c.GetStructure()).Equals("components/cols/new_zero_size.json")
})
t.Run("when size is defined, should use not use max", func(t *testing.T) {
// Act
c := col.New(12)

// Assert
test.New(t).Assert(c.GetStructure()).Equals("components/cols/new_defined_size.json")
})
t.Run("when has component, should retrieve components", func(t *testing.T) {
// Act
c := col.New(12).Add(code.NewQr("code"))

// Assert
assert.NotNil(t, c)
assert.Equal(t, "*col.col", fmt.Sprintf("%T", c))
// Assert
test.New(t).Assert(c.GetStructure()).Equals("components/cols/new_with_components.json")
})
}

func TestCol_GetSize(t *testing.T) {
Expand All @@ -43,3 +61,31 @@ func TestCol_GetSize(t *testing.T) {
assert.Equal(t, 14, size)
})
}

func TestCol_Render(t *testing.T) {
t.Run("should call provider correctly", func(t *testing.T) {
// Arrange
cfg := &entity.Config{}
cell := fixture.CellEntity()
style := &props.Cell{}

provider := &mocks.Provider{}
provider.EXPECT().CreateCol(cell.Width, cell.Height, cfg, style)

component := &mocks.Component{}
component.EXPECT().Render(provider, &cell)
component.EXPECT().SetConfig(cfg)

sut := col.New(12).Add(component)
sut.WithStyle(style)
sut.SetConfig(cfg)

// Act
sut.Render(provider, cell, true)

// Assert
provider.AssertNumberOfCalls(t, "CreateCol", 1)
component.AssertNumberOfCalls(t, "Render", 1)
component.AssertNumberOfCalls(t, "SetConfig", 1)
})
}
3 changes: 3 additions & 0 deletions test/maroto/components/codes/new_bar_row_custom_prop.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"value": "code",
Expand Down
3 changes: 3 additions & 0 deletions test/maroto/components/codes/new_bar_row_default_prop.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"value": "code",
Expand Down
3 changes: 3 additions & 0 deletions test/maroto/components/codes/new_matrix_row_custom_prop.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"value": "code",
Expand Down
3 changes: 3 additions & 0 deletions test/maroto/components/codes/new_matrix_row_default_prop.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"value": "code",
Expand Down
3 changes: 3 additions & 0 deletions test/maroto/components/codes/new_qr_row_custom_prop.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"value": "code",
Expand Down
3 changes: 3 additions & 0 deletions test/maroto/components/codes/new_qr_row_default_prop.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"value": "code",
Expand Down
4 changes: 4 additions & 0 deletions test/maroto/components/cols/new_defined_size.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"value": 12,
"type": "col"
}
13 changes: 13 additions & 0 deletions test/maroto/components/cols/new_with_components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"value": 12,
"type": "col",
"nodes": [
{
"value": "code",
"type": "qrcode",
"details": {
"prop_percent": 100
}
}
]
}
7 changes: 7 additions & 0 deletions test/maroto/components/cols/new_zero_size.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"value": "AQID",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"value": "AQID",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"value": "path",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"value": "path",
Expand Down
3 changes: 3 additions & 0 deletions test/maroto/components/lines/new_line_row_custom_prop.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"type": "lineStyle",
Expand Down
3 changes: 3 additions & 0 deletions test/maroto/components/lines/new_line_row_default_prop.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"type": "lineStyle",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"value": "signature",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"value": "signature",
Expand Down
3 changes: 3 additions & 0 deletions test/maroto/components/texts/new_text_row_custom_prop.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"value": "code",
Expand Down
3 changes: 3 additions & 0 deletions test/maroto/components/texts/new_text_row_default_prop.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"value": 0,
"type": "col",
"details": {
"is_max": true
},
"nodes": [
{
"value": "code",
Expand Down
Loading

0 comments on commit 0cecd01

Please sign in to comment.