Skip to content

Commit

Permalink
Mock file choosers when testing so features don't have to deal with t…
Browse files Browse the repository at this point in the history
…hem. Change file chooser to AWT, since it looks more native. Deal with user clicking Cancel on file chooser. [#4]
  • Loading branch information
marnen committed Nov 18, 2009
1 parent fe7d4a7 commit f496b60
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 41 deletions.
8 changes: 3 additions & 5 deletions features/file_menu.feature
Expand Up @@ -3,9 +3,7 @@ Feature: File menu
I should have commands on the File menu
So I can easily work with my files

Scenario: New brings up a file creation dialog
Scenario: New
Given the frame "Document-1" is visible
And I click the menu "File/New"
And the file chooser "New" is visible
And the file chooser "New" is the container
When I click the button "Cancel"
When I click the menu "File/New"
Then I should see the frame "Document-2"
19 changes: 0 additions & 19 deletions features/step_definitions/file_chooser_steps.rb

This file was deleted.

2 changes: 2 additions & 0 deletions features/support/env.rb
Expand Up @@ -6,6 +6,8 @@
puts "It takes a while for the scenarios to begin executing, so please be patient..."

$NO_MAC_MENUBAR = true # disable Mac-style menu bars so Swinger can drive the menus
$MOCK_FILE_CHOOSERS = true # don't bring up file chooser dialogs
# TODO: put those global variables in a config object or something
require path + '/../../src/main'
sleep(1)

Expand Down
11 changes: 0 additions & 11 deletions features/support/file_chooser_helper.rb

This file was deleted.

18 changes: 12 additions & 6 deletions src/document/document_controller.rb
Expand Up @@ -10,15 +10,21 @@ class DocumentController < ApplicationController
set_close_action :exit

def file_new_menu_item_action_performed
self.class.create_instance.open
instance = self.class.create_instance
instance.open unless instance.nil?
end

def self.create_instance
# Perhaps we should have this be AWT except in the test environment. It's got a better file chooser than Swing.
dialog = javax.swing.JFileChooser.new
dialog.dialog_title = _('New')
dialog.show_dialog(nil, _('Create'))
file = dialog.selected_file
if $MOCK_FILE_CHOOSERS
else
dialog = java.awt.FileDialog.new(nil, _('New'), java.awt.FileDialog::SAVE)
dialog.show
if dialog.file.nil?
# User cancelled without selecting a file
return nil
end
filename = dialog.directory + dialog.file
end

@@count += 1
super
Expand Down

0 comments on commit f496b60

Please sign in to comment.