-
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add text unit tests and refactor color to use consts and reference (#336
- Loading branch information
1 parent
ac4ec81
commit 2cb4639
Showing
26 changed files
with
350 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,92 @@ | ||
package text_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/johnfercher/maroto/v2/internal/fixture" | ||
"github.com/johnfercher/maroto/v2/mocks" | ||
"github.com/johnfercher/maroto/v2/pkg/components/text" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/johnfercher/maroto/v2/pkg/core/entity" | ||
"github.com/johnfercher/maroto/v2/pkg/test" | ||
) | ||
|
||
func TestNew(t *testing.T) { | ||
// Act | ||
sut := text.New("label") | ||
t.Run("when prop is not sent, should use default", func(t *testing.T) { | ||
// Act | ||
sut := text.New("code") | ||
|
||
// Assert | ||
assert.NotNil(t, sut) | ||
assert.Equal(t, "*text.text", fmt.Sprintf("%T", sut)) | ||
// Assert | ||
test.New(t).Assert(sut.GetStructure()).Equals("new_text_default_prop.json") | ||
}) | ||
t.Run("when prop is sent, should use the provided", func(t *testing.T) { | ||
// Act | ||
sut := text.New("code", fixture.TextProp()) | ||
|
||
// Assert | ||
test.New(t).Assert(sut.GetStructure()).Equals("new_text_custom_prop.json") | ||
}) | ||
} | ||
|
||
func TestNewCol(t *testing.T) { | ||
t.Run("when prop is not sent, should use default", func(t *testing.T) { | ||
// Act | ||
sut := text.NewCol(12, "code") | ||
|
||
// Assert | ||
test.New(t).Assert(sut.GetStructure()).Equals("new_text_col_default_prop.json") | ||
}) | ||
t.Run("when prop is sent, should use the provided", func(t *testing.T) { | ||
// Act | ||
sut := text.NewCol(12, "code", fixture.TextProp()) | ||
|
||
// Assert | ||
test.New(t).Assert(sut.GetStructure()).Equals("new_text_col_custom_prop.json") | ||
}) | ||
} | ||
|
||
func TestNewRow(t *testing.T) { | ||
t.Run("when prop is not sent, should use default", func(t *testing.T) { | ||
// Act | ||
sut := text.NewRow(10, "code") | ||
|
||
// Assert | ||
test.New(t).Assert(sut.GetStructure()).Equals("new_text_row_default_prop.json") | ||
}) | ||
t.Run("when prop is sent, should use the provided", func(t *testing.T) { | ||
// Act | ||
sut := text.NewRow(10, "code", fixture.TextProp()) | ||
|
||
// Assert | ||
test.New(t).Assert(sut.GetStructure()).Equals("new_text_row_custom_prop.json") | ||
}) | ||
} | ||
|
||
func TestText_Render(t *testing.T) { | ||
t.Run("should call provider correctly", func(t *testing.T) { | ||
// Arrange | ||
value := "textValue" | ||
cell := fixture.CellEntity() | ||
prop := fixture.TextProp() | ||
sut := text.New(value, prop) | ||
|
||
provider := &mocks.Provider{} | ||
provider.EXPECT().AddText(value, &cell, &prop) | ||
sut.SetConfig(&entity.Config{}) | ||
|
||
// Act | ||
sut.Render(provider, &cell) | ||
|
||
// Assert | ||
provider.AssertNumberOfCalls(t, "AddText", 1) | ||
}) | ||
} | ||
|
||
func TestText_SetConfig(t *testing.T) { | ||
t.Run("should call correctly", func(t *testing.T) { | ||
// Arrange | ||
sut := text.New("textValue") | ||
|
||
// Act | ||
sut.SetConfig(nil) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.