Skip to content

Commit

Permalink
Fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Nov 3, 2020
1 parent 466031c commit 69d15cf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
27 changes: 16 additions & 11 deletions internal/ui/editor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (

"fyne.io/fyne"
"fyne.io/fyne/storage"
_ "fyne.io/fyne/test" // load a test application
"fyne.io/fyne/test"

"github.com/stretchr/testify/assert"

"github.com/fyne-io/pixeledit/internal/api"
)

func uriForTestFile(name string) fyne.URI {
Expand Down Expand Up @@ -43,17 +45,15 @@ func testFileWrite(name string) fyne.URIWriteCloser {

func TestEditor_LoadFile(t *testing.T) {
file := testFile("8x8")
e := NewEditor()
e.LoadFile(file)
e := testEditorWithFile(file)

assert.Equal(t, color.RGBA{A: 255}, e.PixelColor(0, 0))
assert.Equal(t, color.RGBA{R: 255, G: 255, B: 255, A: 255}, e.PixelColor(1, 0))
}

func TestEditor_Reset(t *testing.T) {
file := testFile("8x8")
e := NewEditor()
e.LoadFile(file)
e := testEditorWithFile(file)

assert.Equal(t, color.RGBA{A: 255}, e.PixelColor(0, 0))

Expand Down Expand Up @@ -83,9 +83,8 @@ func TestEditor_Save(t *testing.T) {
}
}()

e := NewEditor()
file := testFile("8x8-tmp")
e.LoadFile(file)
e := testEditorWithFile(file)

assert.Equal(t, color.RGBA{A: 255}, e.PixelColor(0, 0))

Expand Down Expand Up @@ -115,17 +114,15 @@ func TestEditor_SetFGColor(t *testing.T) {

func TestEditor_PixelColor(t *testing.T) {
file := testFile("8x8")
e := NewEditor()
e.LoadFile(file)
e := testEditorWithFile(file)

assert.Equal(t, color.RGBA{A: 255}, e.PixelColor(0, 0))
assert.Equal(t, color.RGBA{R: 0, G: 0, B: 0, A: 0}, e.PixelColor(9, 9))
}

func TestEditor_SetPixelColor(t *testing.T) {
file := testFile("8x8")
e := NewEditor()
e.LoadFile(file)
e := testEditorWithFile(file)

assert.Equal(t, color.RGBA{A: 255}, e.PixelColor(0, 0))
col := color.RGBA{R: 255, G: 255, B: 0, A: 128}
Expand Down Expand Up @@ -155,3 +152,11 @@ func TestEditor_isPNG(t *testing.T) {
assert.True(t, e.isPNG("BIG.PNG"))
assert.False(t, e.isPNG("wrong.ping"))
}

func testEditorWithFile(path fyne.URIReadCloser) api.Editor {
e := NewEditor()
e.(*editor).win = test.NewWindow(nil)
e.LoadFile(path)

return e
}
6 changes: 2 additions & 4 deletions internal/ui/palette_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (

func TestDefaultZoom(t *testing.T) {
file := testFile("8x8")
e := NewEditor()
e.LoadFile(file)
e := testEditorWithFile(file)

p := newPalette(e.(*editor))
zoom := p.(*widget.Box).Children[0].(*fyne.Container).Objects[1].(*widget.Box).Children[1].(*widget.Label)
Expand All @@ -21,8 +20,7 @@ func TestDefaultZoom(t *testing.T) {

func TestZoomIn(t *testing.T) {
file := testFile("8x8")
e := NewEditor()
e.LoadFile(file)
e := testEditorWithFile(file)
assert.Equal(t, 1, e.(*editor).zoom)

p := newPalette(e.(*editor))
Expand Down
6 changes: 2 additions & 4 deletions internal/ui/raster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (

func TestInteractiveRaster_MinSize(t *testing.T) {
file := testFile("8x8")
e := NewEditor().(*editor)
e.LoadFile(file)
e := testEditorWithFile(file).(*editor)

rast := newInteractiveRaster(e)
e.drawSurface = rast
Expand All @@ -26,8 +25,7 @@ func TestInteractiveRaster_MinSize(t *testing.T) {

func TestInteractiveRaster_locationForPositon(t *testing.T) {
file := testFile("8x8")
e := NewEditor().(*editor)
e.LoadFile(file)
e := testEditorWithFile(file).(*editor)

r := newInteractiveRaster(e)
x, y := r.locationForPosition(fyne.NewPos(2, 2))
Expand Down
3 changes: 1 addition & 2 deletions internal/ui/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (

func TestStatus(t *testing.T) {
file := testFile("8x8")
e := NewEditor()
e.LoadFile(file)
e := testEditorWithFile(file)

assert.True(t, strings.Contains(e.(*editor).status.Text, "File: 8x8.png"))
assert.True(t, strings.Contains(e.(*editor).status.Text, "Width: 8"))
Expand Down

0 comments on commit 69d15cf

Please sign in to comment.