Skip to content

Commit

Permalink
Bottom margin
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfercher committed May 28, 2024
1 parent 4f712fd commit c79ebb7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 28 deletions.
89 changes: 61 additions & 28 deletions internal/providers/gofpdf/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package gofpdf_test

import (
"fmt"

Check failure on line 4 in internal/providers/gofpdf/builder_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)

Check failure on line 4 in internal/providers/gofpdf/builder_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
"testing"

"github.com/johnfercher/maroto/v2/internal/fixture"
"github.com/johnfercher/maroto/v2/internal/providers/gofpdf"
"github.com/johnfercher/maroto/v2/pkg/consts/fontfamily"
"github.com/johnfercher/maroto/v2/pkg/core/entity"
"testing"

Check failure on line 8 in internal/providers/gofpdf/builder_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)

Check failure on line 8 in internal/providers/gofpdf/builder_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)

"github.com/johnfercher/maroto/v2/internal/providers/gofpdf"
"github.com/stretchr/testify/assert"
)

Expand All @@ -21,32 +21,65 @@ func TestNewBuilder(t *testing.T) {
}

func TestBuilder_Build(t *testing.T) {
// Arrange
sut := gofpdf.NewBuilder()
font := fixture.FontProp()
cfg := &entity.Config{
Dimensions: &entity.Dimensions{
Width: 100,
Height: 200,
},
Margins: &entity.Margins{
Left: 10,
Top: 10,
Right: 10,
Bottom: 10,
},
DefaultFont: &font,
CustomFonts: []*entity.CustomFont{
{
Family: fontfamily.Arial,
t.Run("when DisableAutoPageBreak true, should build correctly", func(t *testing.T) {
// Arrange
sut := gofpdf.NewBuilder()
font := fixture.FontProp()
cfg := &entity.Config{
Dimensions: &entity.Dimensions{
Width: 100,
Height: 200,
},
Margins: &entity.Margins{
Left: 10,
Top: 10,
Right: 10,
Bottom: 10,
},
DefaultFont: &font,
CustomFonts: []*entity.CustomFont{
{
Family: fontfamily.Arial,
},
},
},
DisableAutoPageBreak: true,
}
DisableAutoPageBreak: true,
}

// Act
dep := sut.Build(cfg, nil)
// Act
dep := sut.Build(cfg, nil)

// Assert
assert.NotNil(t, dep)
})
t.Run("when DisableAutoPageBreak false, should build correctly", func(t *testing.T) {
// Arrange
sut := gofpdf.NewBuilder()
font := fixture.FontProp()
cfg := &entity.Config{
Dimensions: &entity.Dimensions{
Width: 100,
Height: 200,
},
Margins: &entity.Margins{
Left: 10,
Top: 10,
Right: 10,
Bottom: 10,
},
DefaultFont: &font,
CustomFonts: []*entity.CustomFont{
{
Family: fontfamily.Arial,
},
},
DisableAutoPageBreak: false,
}

// Act
dep := sut.Build(cfg, nil)

// Assert
assert.NotNil(t, dep)
})

Check failure on line 84 in internal/providers/gofpdf/builder_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)

Check failure on line 84 in internal/providers/gofpdf/builder_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
// Assert
assert.NotNil(t, dep)
}
4 changes: 4 additions & 0 deletions pkg/config/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (b *CfgBuilder) WithDimensions(width float64, height float64) Builder {
return b
}

// WithLeftMargin customize margin.
func (b *CfgBuilder) WithLeftMargin(left float64) Builder {
if left < pagesize.MinLeftMargin {
return b
Expand All @@ -126,6 +127,7 @@ func (b *CfgBuilder) WithLeftMargin(left float64) Builder {
return b
}

// WithTopMargin customize margin.
func (b *CfgBuilder) WithTopMargin(top float64) Builder {
if top < pagesize.MinTopMargin {
return b
Expand All @@ -135,6 +137,7 @@ func (b *CfgBuilder) WithTopMargin(top float64) Builder {
return b
}

// WithRightMargin customize margin.
func (b *CfgBuilder) WithRightMargin(right float64) Builder {
if right < pagesize.MinRightMargin {
return b
Expand All @@ -144,6 +147,7 @@ func (b *CfgBuilder) WithRightMargin(right float64) Builder {
return b
}

// WithBottomMargin customize margin.
func (b *CfgBuilder) WithBottomMargin(bottom float64) Builder {
if bottom < pagesize.MinBottomMargin {
return b
Expand Down

0 comments on commit c79ebb7

Please sign in to comment.