Skip to content

Commit

Permalink
Update steps and features to work better with file choosers. [#2, #4]
Browse files Browse the repository at this point in the history
  • Loading branch information
marnen committed Nov 18, 2009
1 parent 80ab17d commit 9c104bc
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
4 changes: 2 additions & 2 deletions features/document/table.feature
Expand Up @@ -4,13 +4,13 @@ Feature: Table in document
So I can easily work with my data

Scenario: Table is present in new document
Given I have a new document
Given I have a new document called "Document-1"
And the frame "Document-1" is the container
Then it should contain a table
And the table should not be empty

Scenario: Table is editable
Given I have a new document
Given I have a new document called "Document-1"
And the frame "Document-1" is the container
When I change the cell at row 3 and column 2 to "new value"
Then I should see "new value" in the table
Expand Down
3 changes: 3 additions & 0 deletions features/file_menu.feature
Expand Up @@ -6,4 +6,7 @@ Feature: File menu
Scenario: New
Given the frame "Document-1" is visible
When I click the menu "File/New"
Given the file chooser "New" is visible
When I select the file "Document-2"
And I click the button "OK"
Then I should see the frame "Document-2"
4 changes: 2 additions & 2 deletions features/step_definitions/document_steps.rb
@@ -1,5 +1,5 @@
Given /^I have a new document$/ do
DocumentController.create_instance.open
Given /^I have a new document called "([^\"]*)"$/ do |name|
DocumentController.create_instance(name).open
end

Then /^it should contain a table$/ do
Expand Down
25 changes: 25 additions & 0 deletions features/step_definitions/file_chooser_steps.rb
@@ -0,0 +1,25 @@
Given t(/^the file chooser "([^\"]*)" is visible$/) do |name|
container.set dialog(name, nil)
end

Given t(/^the file chooser "([^\"]*)" is the container$/) do |name|
container.set dialog(name, nil)
end

When t(/^I select the file "([^\"]*)"$/) do |name|
When %Q(I fill the text field "#1" with "#{name}")
end

When t(/^I close the file chooser "([^\"]*)"$/) do |name|
dialog(name, nil).close
end

Then t(/^I should (not )*see the file chooser "([^\"]*)"$/) do |negation, name|
if negation
expect_timeout(:id => "ComponentOperator.WaitComponentTimeout") do
dialog(name, nil)
end
else
dialog(name, nil).visible?.should be_true
end
end
34 changes: 18 additions & 16 deletions src/document/document_controller.rb
Expand Up @@ -14,27 +14,29 @@ def file_new_menu_item_action_performed
instance.open unless instance.nil?
end

def self.create_instance
# TODO: put all this dialog code somewhere else!
if $MOCK_FILE_CHOOSERS
filename = javax.swing.JOptionPane.show_input_dialog(nil, _('Enter file path:'), _('New'), javax.swing.JOptionPane::QUESTION_MESSAGE)
if filename.nil?
return nil
def self.create_instance(filename = nil)
if filename.nil?
# TODO: put all this dialog code somewhere else!
if $MOCK_FILE_CHOOSERS
filename = javax.swing.JOptionPane.show_input_dialog(nil, _('Enter file path:'), _('New'), javax.swing.JOptionPane::QUESTION_MESSAGE)
if filename.nil?
return nil
else
filename = File.expand_path filename
end
else
filename = File.expand_path filename
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
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
super()
end

protected
Expand Down

0 comments on commit 9c104bc

Please sign in to comment.