nobbie-wx-preview 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+
2
+ require 'rubygems'
3
+ require_gem 'nobbie-wx-preview'
4
+ require_all_in_directory [File.dirname(__FILE__), 'suite'].join(File::SEPARATOR)
5
+
6
+ APPLICATION_UNDER_TEST = TestApp.new
@@ -0,0 +1,144 @@
1
+ require 'rubygems'
2
+ require 'wx'
3
+ require 'wx_sugar'
4
+
5
+ include Wx
6
+
7
+ class TestFrame < Frame
8
+ def initialize(*args)
9
+ super
10
+
11
+ #todo: sort out all this :minsize => true stuff out .. need some way to specify defaults
12
+
13
+ panel = add(Panel, :proportion => 1)
14
+ panel.arrange_vertically(:padding => 4)
15
+
16
+ test_notebook = name('test_notebook', panel.add(Notebook, :minsize => true, :proportion => 2))
17
+
18
+ test_notebook.add_page(name('type', test_notebook.add(Panel) {|p| p.arrange_vertically
19
+ listen(:text, name('text_ctrl', p.add(TextCtrl[:value => 'text_ctrl'], :minsize => true)), :update)
20
+ listen(:text, name('readonly_text_ctrl', p.add(TextCtrl[:value => 'readonly_text_ctrl', :style => TE_READONLY], :minsize => true)), :update)
21
+ listen(:text, disable(name('disabled_text_ctrl', p.add(TextCtrl[:value => 'disabled_text_ctrl'], :minsize => true))), :update)
22
+
23
+ listen(:text, name('combo_box', p.add(ComboBox[:value => 'combo_box'], :minsize => true)), :update)
24
+ readonly_combo_box = name('readonly_combo_box', p.add(ComboBox[:style => CB_READONLY], :minsize => true))
25
+ readonly_combo_box.append('readonly_combo_box')
26
+ readonly_combo_box.selection = 0
27
+ listen(:text, readonly_combo_box, :update)
28
+ listen(:text, disable(name('disabled_combo_box', p.add(ComboBox[:value => 'disabled_combo_box'], :minsize => true))), :update)
29
+ }), 'type')
30
+
31
+ test_notebook.add_page(name('click', test_notebook.add(Panel, :minsize => true) {|p| p.arrange_vertically
32
+ listen(:button, name('button', p.add(Button[:label => 'regular_button'], :minsize => true)), :update)
33
+ listen(:button, name('labelled_button_name', p.add(Button[:label => 'labelled_button'], :minsize => true)), :update)
34
+ listen(:button, disable(name('disabled_button', p.add(Button[:label => 'disabled_button'], :minsize => true))), :update)
35
+ name('static_text', p.add(StaticText[:label => 'static_text'], :minsize => true))
36
+ }), 'click')
37
+
38
+ test_notebook.add_page(name('selection', test_notebook.add(Panel) {|p| p.arrange_vertically
39
+ notebook = name('notebook', p.add(Notebook, :minsize => true))
40
+ notebook.add_page(name('notebook_page1', notebook.add(Panel)), 'notebook_page1')
41
+ notebook.add_page(name('notebook_page2', notebook.add(Panel)), 'notebook_page2')
42
+ notebook.evt_notebook_page_changing(notebook.get_id()) {|e| update(e) }
43
+
44
+ disabled_notebook = disable(name('disabled_notebook', p.add(Notebook, :minsize => true)))
45
+ disabled_notebook.add_page(name('disabled_notebook_page1', disabled_notebook.add(Panel)), 'disabled_notebook_page1')
46
+ disabled_notebook.add_page(name('disabled_notebook_page2', disabled_notebook.add(Panel)), 'disabled_notebook_page2')
47
+ disabled_notebook.evt_notebook_page_changing(disabled_notebook.get_id()) {|e| update(e) }
48
+
49
+ #todo: make me have a visible name on screen
50
+ combo_box_with_items = name('combo_box_with_items', p.add(ComboBox, :minsize => true))
51
+ combo_box_with_items.append('combo_box_item')
52
+ listen(:combobox, combo_box_with_items, :update)
53
+
54
+ disabled_combo_box_with_items = disable(name('disabled_combo_box_with_items', p.add(ComboBox, :minsize => true)))
55
+ disabled_combo_box_with_items.append('disabled_combo_box_item1')
56
+ disabled_combo_box_with_items.append('disabled_combo_box_item2')
57
+ listen(:combobox, disabled_combo_box_with_items, :update)
58
+
59
+ list_box_with_items = name('list_box_with_items', p.add(ListBox, :minsize => true))
60
+ list_box_with_items.append('list_box_item')
61
+ listen(:listbox, list_box_with_items, :update)
62
+
63
+ disabled_list_box_with_items = disable(name('disabled_list_box_with_items', p.add(ListBox, :minsize => true)))
64
+ disabled_list_box_with_items.append('disabled_list_box_item1')
65
+ disabled_list_box_with_items.append('disabled_list_box_item2')
66
+ listen(:listbox, disabled_list_box_with_items, :update)
67
+
68
+ choice_with_items = name('choice_with_items', p.add(Choice, :minsize => true))
69
+ choice_with_items.append('choice_item')
70
+ listen(:choice, choice_with_items, :update)
71
+
72
+ disabled_choice_with_items = disable(name('disabled_choice_with_items', p.add(Choice, :minsize => true)))
73
+ disabled_choice_with_items.append('disabled_choice_item1')
74
+ disabled_choice_with_items.append('disabled_choice_item2')
75
+ listen(:choice, disabled_choice_with_items, :update)
76
+
77
+ }), 'selection')
78
+
79
+ test_notebook.add_page(name('choose', test_notebook.add(Panel) {|p| p.arrange_vertically
80
+ #todo: make me have a visible name on screen
81
+ listen(:radiobutton, name('radio_button', p.add(RadioButton, :minsize => true)), :update)
82
+
83
+ #todo: make me have a visible name on screen
84
+ listen(:radiobutton, disable(name('disabled_radio_button', p.add(RadioButton, :minsize => true))), :update)
85
+
86
+ #todo: make me have a visible name on screen
87
+ listen(:checkbox, name('check_box', p.add(CheckBox, :minsize => true)), :update)
88
+
89
+ #todo: make me have a visible name on screen
90
+ listen(:checkbox, disable(name('disabled_check_box', p.add(CheckBox, :minsize => true))), :update)
91
+
92
+ }), 'choose')
93
+
94
+ @log = name('log', panel.add(TextCtrl[:style => TE_READONLY | TE_MULTILINE], :minsize => true, :proportion => 1))
95
+
96
+ menu_bar = MenuBar.new
97
+ file_menu = Menu.new
98
+
99
+ #todo: remove these crappy id's ... there must be a nice sugary way to build menu's
100
+ file_new = file_menu.append(101, "&New...\tCtrl+N")
101
+ file_disabled = file_menu.append(102, "&disabled")
102
+
103
+ menu_bar.append(file_menu, '&File')
104
+ set_menu_bar(menu_bar)
105
+
106
+ #todo: make disable() handle menus ...
107
+ menu_bar.enable(102, false)
108
+
109
+ #todo: make update() handle menus ...
110
+ listen(:menu, @file_new) {|e| log('file_new') }
111
+ end
112
+
113
+ def on_init
114
+ self.update
115
+ end
116
+
117
+ private
118
+
119
+ def name(name, component)
120
+ component.name = name
121
+ component
122
+ end
123
+
124
+ def disable(component)
125
+ component.disable
126
+ component
127
+ end
128
+
129
+ def log(text)
130
+ @log.append_text(text)
131
+ end
132
+
133
+ def update(e)
134
+ @log.append_text("#{e.event_object.name}: #{e.string}\n")
135
+ end
136
+ end
137
+
138
+ class TestApp < App
139
+ def on_init
140
+ TestFrame.new(nil, :title => 'test', :size => [1024, 768]).show
141
+ end
142
+ end
143
+
144
+ TestApp.new.main_loop if __FILE__ == $0
@@ -0,0 +1,46 @@
1
+ module NobbieTestCase
2
+ include Nobbie::Wx
3
+
4
+ def setup
5
+ puts "\n[Started: #{name}]"
6
+ begin
7
+ select_tab_for_test
8
+ rescue ValueNotFoundException
9
+ #ok - this test doesn't have its own tab'
10
+ end
11
+ end
12
+
13
+ def teardown
14
+ puts "\n[Finished: #{name}]"
15
+ end
16
+
17
+ def select_tab_for_test
18
+ clear_events
19
+ tab = self.class.name.gsub('Test', '').downcase
20
+ selection(:in => 'test_notebook').choose tab
21
+ assert_equal tab, selection(:in => 'test_notebook').selected_value
22
+ end
23
+
24
+ def text(component)
25
+ component.nil? ? nil : component.value
26
+ end
27
+
28
+ def clear_events
29
+ log.clear
30
+ end
31
+
32
+ def assert_exception(e)
33
+ assert_raise e do yield end
34
+ assert_events
35
+ end
36
+
37
+ def assert_events(expected_items=[])
38
+ expected_items = [expected_items] unless expected_items.is_a?(Array)
39
+ actual_items = text(log).split("\n")
40
+ assert_equal expected_items, actual_items
41
+ end
42
+
43
+ def log
44
+ component 'log'
45
+ end
46
+ end
@@ -0,0 +1,52 @@
1
+ class TestChoose < Test::Unit::TestCase
2
+ include NobbieTestCase
3
+
4
+ #todo: rename file to choosable
5
+ #todo: should be TestChoosable
6
+ def test_choose_with_radio_button
7
+ assert !choosable('radio_button').chosen?
8
+ choosable('radio_button').choose
9
+ assert choosable('radio_button').chosen?
10
+ assert_events 'radio_button: '
11
+ end
12
+
13
+ def test_choose_with_check_box
14
+ assert !choosable('check_box').chosen?
15
+ choosable('check_box').choose
16
+ assert choosable('check_box').chosen?
17
+ assert_events 'check_box: '
18
+ end
19
+
20
+ def test_choose_with_component_disabled_radio_button
21
+ assert_exception ComponentDisabledException do choosable('disabled_radio_button').choose end
22
+ end
23
+
24
+ def test_choose_with_component_disabled_check_box
25
+ assert_exception ComponentDisabledException do choosable('disabled_check_box').choose end
26
+ end
27
+
28
+ def test_choose_with_unsupported_operation_for_component
29
+ assert_exception UnsupportedOperationForComponentException do choosable('button').choose end
30
+ end
31
+
32
+ def test_choose_with_component_not_found
33
+ assert_exception ComponentNotFoundException do choosable('missing').choose end
34
+ end
35
+
36
+ def test_chosen_with_unsupported_operation_for_component
37
+ assert_exception UnsupportedOperationForComponentException do choosable('button').chosen? end
38
+ end
39
+
40
+ def test_chosen_with_component_not_found
41
+ assert_exception ComponentNotFoundException do choosable('missing').chosen? end
42
+ end
43
+
44
+ def test_chosen_with_component_disabled_radio_button
45
+ assert !choosable('disabled_radio_button').chosen?
46
+ end
47
+
48
+ def test_chosen_with_component_disabled_check_box
49
+ assert !choosable('disabled_check_box').chosen?
50
+ end
51
+ end
52
+
@@ -0,0 +1,28 @@
1
+ class TestClick < Test::Unit::TestCase
2
+ include NobbieTestCase
3
+
4
+ def test_click_with_named_button
5
+ click 'button'
6
+ #todo: improve event detail
7
+ assert_events 'button: '
8
+ end
9
+
10
+ def test_click_with_labelled_button
11
+ click 'labelled_button'
12
+ #todo: improve event detail
13
+ assert_events 'labelled_button_name: '
14
+ end
15
+
16
+ def test_click_with_component_not_found
17
+ assert_exception ComponentNotFoundException do click 'missing' end
18
+ end
19
+
20
+ def test_click_with_component_disabled
21
+ assert_exception ComponentDisabledException do click 'disabled_button' end
22
+ end
23
+
24
+ def test_click_with_unsupported_operation_for_component
25
+ assert_exception UnsupportedOperationForComponentException do click 'static_text' end
26
+ end
27
+ end
28
+
@@ -0,0 +1,13 @@
1
+ class TestEnabled < Test::Unit::TestCase
2
+ include NobbieTestCase
3
+
4
+ def test_enabled
5
+ assert enabled?('text_ctrl')
6
+ assert !enabled?('disabled_text_ctrl')
7
+ end
8
+
9
+ def test_enabled_with_component_not_found
10
+ assert_exception ComponentNotFoundException do enabled?('missing') end
11
+ end
12
+ end
13
+
@@ -0,0 +1,22 @@
1
+ class TestLauncher < Test::Unit::TestCase
2
+
3
+ def test_application_under_test_is_not_defined
4
+ begin
5
+ Nobbie::Wx::ApplicationLauncher.module_eval('def get_application; raise NameError.new; end;')
6
+ Nobbie::Wx::ApplicationLauncher.new
7
+ fail
8
+ rescue RuntimeError => e
9
+ assert_equal Nobbie::Wx::ApplicationLauncher::AUT_NOT_DEFINED, e.message
10
+ end
11
+ end
12
+
13
+ def test_application_under_test_is_not_a_wx_app
14
+ begin
15
+ Nobbie::Wx::ApplicationLauncher.module_eval('def get_application; String.new; end;')
16
+ Nobbie::Wx::ApplicationLauncher.new
17
+ fail
18
+ rescue RuntimeError => e
19
+ assert_equal Nobbie::Wx::ApplicationLauncher::AUT_NOT_WX_APP, e.message
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ class UserPathBuilder
2
+ def find_component
3
+ "something"
4
+ end
5
+ end
6
+
7
+ class TestOperations < Test::Unit::TestCase
8
+
9
+ def test_coerce_path
10
+ assert_path component('text_ctrl')
11
+ assert_path component(:in => 'text_ctrl')
12
+ assert_path component(in_('text_ctrl'))
13
+ assert_path component(Nobbie::Wx::ElementPathBuilder.new('text_ctrl'))
14
+ assert_path component(UserPathBuilder.new)
15
+ assert_path component(:text_ctrl)
16
+ begin
17
+ component(Hash.new)
18
+ fail
19
+ rescue RuntimeError => e
20
+ assert_equal 'Unable to coerce path: ', e.message
21
+ end
22
+ end
23
+
24
+ def assert_path(path)
25
+ assert_not_nil path
26
+ end
27
+ end
@@ -0,0 +1,107 @@
1
+ class TestSelection < Test::Unit::TestCase
2
+ include NobbieTestCase
3
+
4
+ def test_choose_with_notebook_page
5
+ assert_equal 'notebook_page1', selection('notebook').selected_value
6
+ selection('notebook').choose 'notebook_page2'
7
+ assert_equal 'notebook_page2', selection('notebook').selected_value
8
+ #todo: improve event detail
9
+ assert_events 'notebook: '
10
+ end
11
+
12
+ def test_choose_with_menu_item
13
+ selection('&File').choose '&New...'
14
+ #todo: improve event detail
15
+ assert_events 'file_new'
16
+ end
17
+
18
+ def test_choose_with_combo_box
19
+ assert_equal '', selection('combo_box_with_items').selected_value
20
+ selection('combo_box_with_items').choose 'combo_box_item'
21
+ assert_equal 'combo_box_item', selection('combo_box_with_items').selected_value
22
+ assert_events 'combo_box_with_items: '
23
+ end
24
+
25
+ def test_choose_with_list_box
26
+ assert_equal '', selection('list_box_with_items').selected_value
27
+ selection('list_box_with_items').choose 'list_box_item'
28
+ assert_equal 'list_box_item', selection('list_box_with_items').selected_value
29
+ assert_events 'list_box_with_items: list_box_item'
30
+ end
31
+
32
+ def test_choose_with_choice
33
+ assert_equal '', selection('choice_with_items').selected_value
34
+ selection('choice_with_items').choose 'choice_item'
35
+ assert_equal 'choice_item', selection('choice_with_items').selected_value
36
+ assert_events 'choice_with_items: choice_item'
37
+ end
38
+
39
+ #not found
40
+
41
+ def test_choose_with_value_not_found_notebook
42
+ assert_exception ValueNotFoundException do selection('notebook').choose 'missing' end
43
+ end
44
+
45
+ def test_choose_with_value_not_found_menu
46
+ assert_exception ValueNotFoundException do selection('&File').choose 'missing' end
47
+ end
48
+
49
+ def test_choose_with_value_not_found_list_box
50
+ assert_exception ValueNotFoundException do selection('list_box_with_items').choose 'missing' end
51
+ end
52
+
53
+ def test_choose_with_value_not_found_combo_box
54
+ assert_exception ValueNotFoundException do selection('combo_box_with_items').choose 'missing' end
55
+ end
56
+
57
+ def test_choose_with_value_not_found_combo_box
58
+ assert_exception ValueNotFoundException do selection('choice_with_items').choose 'missing' end
59
+ end
60
+
61
+ #disabled
62
+
63
+ def test_choose_with_component_disabled_menu
64
+ assert_exception ComponentDisabledException do selection('&File').choose '&disabled' end
65
+ end
66
+
67
+ def test_choose_with_component_disabled_notebook
68
+ assert_equal 'disabled_notebook_page1', selection('disabled_notebook').selected_value
69
+ assert_exception ComponentDisabledException do selection('disabled_notebook').choose 'disabled_notebook_page2' end
70
+ assert_equal 'disabled_notebook_page1', selection('disabled_notebook').selected_value
71
+ end
72
+
73
+ def test_choose_with_component_disabled_list_box
74
+ assert_exception ComponentDisabledException do selection('disabled_list_box_with_items').choose 'disabled_list_box_item2' end
75
+ end
76
+
77
+ def test_choose_with_component_disabled_combo_box
78
+ assert_exception ComponentDisabledException do selection('disabled_combo_box_with_items').choose 'disabled_combo_box_item2' end
79
+ end
80
+
81
+ def test_choose_with_component_disabled_choice
82
+ assert_exception ComponentDisabledException do selection('disabled_choice_with_items').choose 'disabled_choice_item2' end
83
+ end
84
+
85
+ #not found etc ...
86
+
87
+ def test_choose_with_component_not_found
88
+ assert_exception ComponentNotFoundException do selection('missing').choose 'missing' end
89
+ end
90
+
91
+ def test_choose_with_unsupported_operation_for_component
92
+ assert_exception UnsupportedOperationForComponentException do selection('button').choose 'value' end
93
+ end
94
+
95
+ def test_selected_value_unsupported_operation_for_menu
96
+ assert_exception UnsupportedOperationForComponentException do selection('&File').selected_value end
97
+ end
98
+
99
+ def test_selected_value_with_unsupported_operation_for_component
100
+ assert_exception UnsupportedOperationForComponentException do selection('button').selected_value end
101
+ end
102
+
103
+ def test_selected_value_component_not_found
104
+ assert_exception ComponentNotFoundException do selection('missing').selected_value end
105
+ end
106
+ end
107
+