Skip to content

Commit

Permalink
Merge pull request #126 from johnfercher/dev
Browse files Browse the repository at this point in the history
Release/20-12-2019.2
  • Loading branch information
johnfercher authored Dec 20, 2019
2 parents b40e86a + 73e20ce commit 5386d9c
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 2 deletions.
Binary file modified internal/examples/pdfs/sample1.pdf
Binary file not shown.
4 changes: 3 additions & 1 deletion internal/examples/sample1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ func main() {
})
})

m.TableList(headerSmall, smallContent)
m.TableList(headerSmall, smallContent, props.TableList{
Line: true,
})

m.Row(15, func() {
m.Col(func() {
Expand Down
7 changes: 7 additions & 0 deletions internal/tablelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ type MarotoGridPart interface {

// Helpers
GetCurrentOffset() float64

// Outside Col/Row Components
Line(spaceHeight float64)
}

// TableList is the abstraction to create a table with header and contents
Expand Down Expand Up @@ -109,6 +112,10 @@ func (s *tableList) Create(header []string, contents [][]string, prop ...props.T
})
}
})

if tableProp.Line {
s.pdf.Line(1.0)
}
}
}

Expand Down
59 changes: 59 additions & 0 deletions internal/tablelist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/johnfercher/maroto/internal"
"github.com/johnfercher/maroto/internal/mocks"
"github.com/johnfercher/maroto/pkg/consts"
"github.com/johnfercher/maroto/pkg/props"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"testing"
Expand Down Expand Up @@ -90,6 +91,42 @@ func TestTableList_Create_Happy(t *testing.T) {

marotoGrid := &mocks.Maroto{}
marotoGrid.On("Row", mock.Anything, mock.Anything).Return(nil)
marotoGrid.On("Line", mock.Anything).Return(nil)

sut := internal.NewTableList(text, font)
sut.BindGrid(marotoGrid)

headers, contents := getContents()

// Act
sut.Create(headers, contents, props.TableList{
Line: true,
})

// Assert
text.AssertNotCalled(t, "GetLinesQuantity")
text.AssertNumberOfCalls(t, "GetLinesQuantity", 84)

font.AssertCalled(t, "GetFont")
font.AssertNumberOfCalls(t, "GetFont", 21)

marotoGrid.AssertCalled(t, "Row", mock.Anything, mock.Anything)
marotoGrid.AssertNumberOfCalls(t, "Row", 22)
marotoGrid.AssertNumberOfCalls(t, "Line", 20)
}

func TestTableList_Create_Happy_Without_Line(t *testing.T) {
// Arrange
text := &mocks.Text{}
text.On("GetLinesQuantity", mock.Anything, mock.Anything, mock.Anything).Return(1)

font := &mocks.Font{}
font.On("GetFont").Return(consts.Arial, consts.Bold, 1.0)
font.On("GetScaleFactor").Return(1.5)

marotoGrid := &mocks.Maroto{}
marotoGrid.On("Row", mock.Anything, mock.Anything).Return(nil)
marotoGrid.On("Line", mock.Anything).Return(nil)

sut := internal.NewTableList(text, font)
sut.BindGrid(marotoGrid)
Expand All @@ -108,6 +145,28 @@ func TestTableList_Create_Happy(t *testing.T) {

marotoGrid.AssertCalled(t, "Row", mock.Anything, mock.Anything)
marotoGrid.AssertNumberOfCalls(t, "Row", 22)
marotoGrid.AssertNumberOfCalls(t, "Line", 0)
}

func TestTableList_Create_WhenContentIsEmptyWithLine(t *testing.T) {
// Arrange
text := &mocks.Text{}
text.On("GetLinesQuantity", mock.Anything, mock.Anything, mock.Anything).Return(1)
sut := internal.NewTableList(text, nil)

marotoGrid := mocks.Maroto{}
marotoGrid.On("Line", mock.Anything).Return(nil)

headers, _ := getContents()

// Act
sut.Create(headers, [][]string{}, props.TableList{
Line: true,
})

// Assert
text.AssertNotCalled(t, "GetLinesQuantity")
marotoGrid.AssertNotCalled(t, "Line")
}

func getContents() ([]string, [][]string) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/pdf/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ func ExamplePdfMaroto_TableList() {
// 1 Row of header
// 2 Rows of contents
// Each row have 2 columns
m.TableList(headers, contents)
m.TableList(headers, contents, props.TableList{
Line: false,
})

// Do more things and save...
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/props/prop.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ type TableList struct {
Align consts.Align
// HeaderContentSpace is the space between the header and the contents
HeaderContentSpace float64
// Line adds a line after every content-row to separate rows. The line's spaceHeight is set to 1.0
Line bool
}

// MakeValid from Rect means will make the properties from a rectangle reliable to fit inside a cell
Expand Down

0 comments on commit 5386d9c

Please sign in to comment.