diff --git a/internal/ui/editor_test.go b/internal/ui/editor_test.go index cde6580..7307cb9 100644 --- a/internal/ui/editor_test.go +++ b/internal/ui/editor_test.go @@ -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 { @@ -43,8 +45,7 @@ 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)) @@ -52,8 +53,7 @@ func TestEditor_LoadFile(t *testing.T) { 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)) @@ -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)) @@ -115,8 +114,7 @@ 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)) @@ -124,8 +122,7 @@ func TestEditor_PixelColor(t *testing.T) { 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} @@ -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 +} diff --git a/internal/ui/palette_test.go b/internal/ui/palette_test.go index 5ddd121..fdc5f7c 100644 --- a/internal/ui/palette_test.go +++ b/internal/ui/palette_test.go @@ -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) @@ -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)) diff --git a/internal/ui/raster_test.go b/internal/ui/raster_test.go index 632cadd..1fa1f52 100644 --- a/internal/ui/raster_test.go +++ b/internal/ui/raster_test.go @@ -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 @@ -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)) diff --git a/internal/ui/status_test.go b/internal/ui/status_test.go index f04ec1f..71145f5 100644 --- a/internal/ui/status_test.go +++ b/internal/ui/status_test.go @@ -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"))