|
8 | 8 | "testing"
|
9 | 9 |
|
10 | 10 | intWidget "fyne.io/fyne/v2/internal/widget"
|
| 11 | + "fyne.io/fyne/v2/lang" |
11 | 12 | "github.com/stretchr/testify/assert"
|
12 | 13 |
|
13 | 14 | "fyne.io/fyne/v2"
|
@@ -97,7 +98,7 @@ func TestEffectiveStartingDir(t *testing.T) {
|
97 | 98 | // make sure we fail over if the specified directory does not exist
|
98 | 99 | dialog.startingLocation, err = storage.ListerForURI(storage.NewFileURI("/some/file/that/does/not/exist"))
|
99 | 100 | if err == nil {
|
100 |
| - t.Errorf("Should have failed to create lister for nonexistant file") |
| 101 | + t.Errorf("Should have failed to create lister for nonexistent file") |
101 | 102 | }
|
102 | 103 | res = dialog.effectiveStartingDir()
|
103 | 104 | expect = home
|
@@ -146,7 +147,7 @@ func TestFileDialogResize(t *testing.T) {
|
146 | 147 | expectedWidth = 600 //since win width only 600
|
147 | 148 | assert.Equal(t, expectedWidth, file.dialog.win.Size().Width) //max, also work
|
148 | 149 | assert.Equal(t, expectedWidth, file.dialog.win.Content.Size().Width+theme.Padding()*2)
|
149 |
| - expectedHeight = 400 //since win heigh only 400 |
| 150 | + expectedHeight = 400 //since win height only 400 |
150 | 151 | assert.Equal(t, expectedHeight, file.dialog.win.Size().Height) //max, also work
|
151 | 152 | assert.Equal(t, expectedHeight, file.dialog.win.Content.Size().Height+theme.Padding()*2)
|
152 | 153 |
|
@@ -183,7 +184,7 @@ func TestShowFileOpen(t *testing.T) {
|
183 | 184 | ui := popup.Content.(*fyne.Container)
|
184 | 185 | //header
|
185 | 186 | title := ui.Objects[1].(*fyne.Container).Objects[1].(*widget.Label)
|
186 |
| - assert.Equal(t, "Open File", title.Text) |
| 187 | + assert.Equal(t, lang.L("Open")+" "+lang.L("File"), title.Text) |
187 | 188 | //optionsbuttons
|
188 | 189 | createNewFolderButton := ui.Objects[1].(*fyne.Container).Objects[0].(*fyne.Container).Objects[0].(*widget.Button)
|
189 | 190 | assert.Equal(t, "", createNewFolderButton.Text)
|
@@ -219,7 +220,7 @@ func TestShowFileOpen(t *testing.T) {
|
219 | 220 | assert.Greater(t, len(objects), 0)
|
220 | 221 |
|
221 | 222 | fileName := test.TempWidgetRenderer(t, objects[0].(fyne.Widget)).Objects()[1].(*fileDialogItem).name
|
222 |
| - assert.Equal(t, "(Parent)", fileName) |
| 223 | + assert.Equal(t, lang.L("(Parent)"), fileName) |
223 | 224 | assert.True(t, open.Disabled())
|
224 | 225 |
|
225 | 226 | var target *fileDialogItem
|
@@ -255,7 +256,7 @@ func TestHiddenFiles(t *testing.T) {
|
255 | 256 | t.Error("Failed to open testdata dir", err)
|
256 | 257 | }
|
257 | 258 |
|
258 |
| - // git does not preserve windows hidden flag so we have to set it. |
| 259 | + // git does not preserve windows hidden flag, so we have to set it. |
259 | 260 | // just an empty function for non windows builds
|
260 | 261 | if err := hideFile(filepath.Join(testDataPath, ".hidden")); err != nil {
|
261 | 262 | t.Error("Failed to hide .hidden", err)
|
@@ -305,7 +306,7 @@ func TestHiddenFiles(t *testing.T) {
|
305 | 306 | target = item
|
306 | 307 | }
|
307 | 308 | }
|
308 |
| - assert.NotNil(t, target, "Failed,.hidden not found in testdata") |
| 309 | + assert.NotNil(t, target, "Failed, .hidden not found in testdata") |
309 | 310 | }
|
310 | 311 |
|
311 | 312 | func TestShowFileSave(t *testing.T) {
|
@@ -335,7 +336,7 @@ func TestShowFileSave(t *testing.T) {
|
335 | 336 | assert.Greater(t, len(objects), 0)
|
336 | 337 |
|
337 | 338 | item := test.TempWidgetRenderer(t, objects[0].(fyne.Widget)).Objects()[1].(*fileDialogItem)
|
338 |
| - assert.Equal(t, "(Parent)", item.name) |
| 339 | + assert.Equal(t, lang.L("(Parent)"), item.name) |
339 | 340 | assert.True(t, save.Disabled())
|
340 | 341 |
|
341 | 342 | abs, _ := filepath.Abs("./testdata/")
|
@@ -450,6 +451,47 @@ func TestFileFilters(t *testing.T) {
|
450 | 451 | assert.Equal(t, 9, count)
|
451 | 452 | }
|
452 | 453 |
|
| 454 | +func TestFileSort(t *testing.T) { |
| 455 | + testDataPath, _ := filepath.Abs("testdata") |
| 456 | + testData := storage.NewFileURI(testDataPath) |
| 457 | + dir, err := storage.ListerForURI(testData) |
| 458 | + if err != nil { |
| 459 | + t.Error("Failed to open testdata dir", err) |
| 460 | + } |
| 461 | + |
| 462 | + win := test.NewTempWindow(t, widget.NewLabel("Content")) |
| 463 | + d := NewFileOpen(func(file fyne.URIReadCloser, err error) { |
| 464 | + }, win) |
| 465 | + d.SetLocation(dir) |
| 466 | + d.Show() |
| 467 | + |
| 468 | + popup := win.Canvas().Overlays().Top().(*widget.PopUp) |
| 469 | + defer win.Canvas().Overlays().Remove(popup) |
| 470 | + assert.NotNil(t, popup) |
| 471 | + |
| 472 | + ui := popup.Content.(*fyne.Container) |
| 473 | + |
| 474 | + files := ui.Objects[0].(*container.Split).Trailing.(*fyne.Container).Objects[1].(*container.Scroll).Content.(*fyne.Container).Objects[0].(*widget.GridWrap) |
| 475 | + objects := test.TempWidgetRenderer(t, files).Objects()[0].(*container.Scroll).Content.(*fyne.Container).Objects |
| 476 | + assert.NotEmpty(t, objects) |
| 477 | + |
| 478 | + binPos := -1 |
| 479 | + capitalPos := -1 |
| 480 | + for i, icon := range objects { |
| 481 | + item := test.TempWidgetRenderer(t, icon.(fyne.Widget)).Objects()[1].(*fileDialogItem) |
| 482 | + switch item.name { |
| 483 | + case "bin": |
| 484 | + binPos = i |
| 485 | + case "Capitalised": |
| 486 | + capitalPos = i |
| 487 | + } |
| 488 | + } |
| 489 | + |
| 490 | + assert.NotEqual(t, -1, binPos, "bin file not found") |
| 491 | + assert.NotEqual(t, -1, capitalPos, "Capitalised.txt file not found") |
| 492 | + assert.Less(t, binPos, capitalPos) |
| 493 | +} |
| 494 | + |
453 | 495 | func TestView(t *testing.T) {
|
454 | 496 | win := test.NewTempWindow(t, widget.NewLabel("Content"))
|
455 | 497 |
|
@@ -633,6 +675,7 @@ func TestViewPreferences(t *testing.T) {
|
633 | 675 | }
|
634 | 676 |
|
635 | 677 | func TestFileFavorites(t *testing.T) {
|
| 678 | + _ = test.NewApp() |
636 | 679 | win := test.NewTempWindow(t, widget.NewLabel("Content"))
|
637 | 680 |
|
638 | 681 | dlg := NewFileOpen(func(reader fyne.URIReadCloser, err error) {
|
|
0 commit comments