Skip to content

Commit

Permalink
test: make test coverage to 100% (#84)
Browse files Browse the repository at this point in the history
* Add more tests to make test coverage to 100%

* test: added test expectations with static expectations for ANSI 256 and TrueColor

* Revert "test: added test expectations with static expectations for ANSI 256 and TrueColor"

This reverts commit c6fbbca.

* Revert "Revert "test: added test expectations with static expectations for ANSI 256 and TrueColor""

This reverts commit a4826b8.

* test: fixed environment dependent test results

* test: attempt to fix term color test

* test: added matchers for ANSI16 terminals

* test: added assertion for ASCII

* test: fixed assertion for ASCII

* test: removed unused variable

Co-authored-by: Ani Channarasappa <git@ani.dev>
  • Loading branch information
SnkSynthesis and achannarasappa committed Feb 10, 2021
1 parent c5341f2 commit f7b002a
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 16 deletions.
48 changes: 34 additions & 14 deletions internal/ui/component/summary/summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,40 @@ func removeFormatting(text string) string {

var _ = Describe("Summary", func() {

It("should render a summary", func() {
m := NewModel()
m.Summary = position.PositionSummary{
Value: 10000,
Cost: 1000,
Change: 9000,
DayChange: 100.0,
ChangePercent: 1000.0,
DayChangePercent: 10.0,
}
Expect(removeFormatting(m.View())).To(Equal(strings.Join([]string{
"Day: ↑ 100.00 (10.00%) • Change: ↑ 9000.00 (1000.00%) • Value: 10000.00",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
}, "\n")))
When("the change is positive", func() {
It("should render a summary with up arrow", func() {
m := NewModel()
m.Summary = position.PositionSummary{
Value: 10000,
Cost: 1000,
Change: 9000,
DayChange: 100.0,
ChangePercent: 1000.0,
DayChangePercent: 10.0,
}
Expect(removeFormatting(m.View())).To(Equal(strings.Join([]string{
"Day: ↑ 100.00 (10.00%) • Change: ↑ 9000.00 (1000.00%) • Value: 10000.00",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
}, "\n")))
})
})

When("the change is negative", func() {
It("should render a summary with down arrow", func() {
m := NewModel()
m.Summary = position.PositionSummary{
Value: 1000,
Cost: 10000,
Change: -9000,
DayChange: -100.0,
ChangePercent: -1000.0,
DayChangePercent: -10.0,
}
Expect(removeFormatting(m.View())).To(Equal(strings.Join([]string{
"Day: ↓ -100.00 (-10.00%) • Change: ↓ -9000.00 (-1000.00%) • Value: 1000.00",
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
}, "\n")))
})
})

When("no quotes are set", func() {
Expand Down
50 changes: 48 additions & 2 deletions internal/ui/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,62 @@ var _ = Describe("Util", func() {
Expect(output).To(Equal("12.56"))
})
})
Describe("ValueText", func() {
When("value is <= 0.0", func() {
It("should return an empty string", func() {
output := ValueText(0.0)
Expect(output).To(ContainSubstring(""))
})
})
It("should generate text for values", func() {
output := ValueText(435.32)
expectedOutput := NewStyle("#d4d4d4", "", false)("435.32")
Expect(output).To(Equal(expectedOutput))
})
})
Describe("NewStyle", func() {
It("should generate text with a background and foreground color", func() {
inputStyleFn := NewStyle("#ffffff", "#000000", false)
output := inputStyleFn("test")
Expect(output).To(ContainSubstring("test\x1b[0m"))
expectedASCII := "\x1b[;mtest\x1b[0m"
expectedANSI16Color := "\x1b[97;40mtest\x1b[0m"
expectedANSI256Color := "\x1b[38;5;231;48;5;16mtest\x1b[0m"
expectedTrueColor := "\x1b[38;2;255;255;255;48;2;0;0;0mtest\x1b[0m"
Expect(output).To(SatisfyAny(Equal(expectedASCII), Equal(expectedANSI16Color), Equal(expectedANSI256Color), Equal(expectedTrueColor)))
})
It("should generate text with bold styling", func() {
inputStyleFn := NewStyle("#ffffff", "#000000", true)
output := inputStyleFn("test")
Expect(output).To(ContainSubstring("test\x1b[0m"))
expectedASCII := "\x1b[;;1mtest\x1b[0m"
expectedANSI16Color := "\x1b[97;40;1mtest\x1b[0m"
expectedANSI256Color := "\x1b[38;5;231;48;5;16;1mtest\x1b[0m"
expectedTrueColor := "\x1b[38;2;255;255;255;48;2;0;0;0;1mtest\x1b[0m"
Expect(output).To(SatisfyAny(Equal(expectedASCII), Equal(expectedANSI16Color), Equal(expectedANSI256Color), Equal(expectedTrueColor)))
})
})
Describe("NewStyleFromGradient", func() {
inputGradientFn := NewStyleFromGradient("#ffffff", "#000000")
When("the percent given is 100%", func() {
It("should generate text with the gradient of two colors relative to the percentage given", func() {
inputStyleFn := inputGradientFn(100)
output := inputStyleFn("test")
expectedASCII := "test"
expectedANSI16Color := "\x1b[30mtest\x1b[0m"
expectedANSI256Color := "\x1b[38;5;16mtest\x1b[0m"
expectedTrueColor := "\x1b[38;2;0;0;0mtest\x1b[0m"
Expect(output).To(SatisfyAny(Equal(expectedASCII), Equal(expectedANSI16Color), Equal(expectedANSI256Color), Equal(expectedTrueColor)))
})
})
When("the percent given is 1%", func() {
It("should generate text with the gradient of two colors relative to the percentage given", func() {
inputStyleFn := inputGradientFn(1)
output := inputStyleFn("test")
expectedASCII := "test"
expectedANSI16Color := "\x1b[37mtest\x1b[0m"
expectedANSI256Color := "\x1b[38;5;188mtest\x1b[0m"
expectedTrueColor := "\x1b[38;2;230;230;230mtest\x1b[0m"
Expect(output).To(SatisfyAny(Equal(expectedASCII), Equal(expectedANSI16Color), Equal(expectedANSI256Color), Equal(expectedTrueColor)))
})
})
})
})

0 comments on commit f7b002a

Please sign in to comment.