Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnferchermeli committed Mar 28, 2020
1 parent 89803ff commit bcff61d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
Binary file modified internal/examples/pdfs/sample1.pdf
Binary file not shown.
7 changes: 3 additions & 4 deletions pkg/pdf/pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,11 @@ func (s *PdfMaroto) GetCurrentOffset() float64 {
// SetPageMargins overrides default margins (10,10,10)
// the new page margin will affect all PDF pages
func (s *PdfMaroto) SetPageMargins(left, top, right float64) {
if top <= 10 {
s.Pdf.SetMargins(left, top, right)
} else {
if top > 10 {
s.marginTop = top - 10
s.Pdf.SetMargins(left, 10, right)
}

s.Pdf.SetMargins(left, 10.0, right)
}

// GetPageMargins returns the set page margins. Comes in order of Left, Top, Right, Bottom
Expand Down
22 changes: 14 additions & 8 deletions pkg/pdf/pdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1780,17 +1780,24 @@ func TestPdfMaroto_SetPageMargins(t *testing.T) {
cases := []struct {
name string
act func(m pdf.Maroto)
assert func(t *testing.T, left, top, right float64)
assert func(t *testing.T, m *mocks.Pdf)
}{
{
"Set page margins should override default",
"Set page margins should override default, top greater than 10",
func(m pdf.Maroto) {
m.SetPageMargins(12.3, 19.3, 0.0)
},
func(t *testing.T, left, top, right float64) {
assert.Equal(t, 12.3, left)
assert.Equal(t, 19.3, top)
assert.Equal(t, 0.0, right)
func(t *testing.T, m *mocks.Pdf) {
m.AssertCalled(t, "SetMargins", 12.3, 10.0, 0.0)
},
},
{
"Set page margins should override default, top less than 10",
func(m pdf.Maroto) {
m.SetPageMargins(12.3, 9.0, 0.0)
},
func(t *testing.T, m *mocks.Pdf) {
m.AssertCalled(t, "SetMargins", 12.3, 10.0, 0.0)
},
},
}
Expand All @@ -1805,8 +1812,7 @@ func TestPdfMaroto_SetPageMargins(t *testing.T) {
c.act(m)

// Assert
left, top, right, _ := m.GetPageMargins()
c.assert(t, left, top, right)
c.assert(t, pdf)
}
}

Expand Down

0 comments on commit bcff61d

Please sign in to comment.