Skip to content

Commit 4ed6104

Browse files
authored
Merge pull request #4 from jordanmontt/feature/editing-ui-testing-chapter
Feature/editing UI testing chapter
2 parents d20378a + 4b60e16 commit 4ed6104

File tree

2 files changed

+83
-49
lines changed

2 files changed

+83
-49
lines changed

Chapters/UITesting/UITesting.pillar

Lines changed: 83 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ To help you understand the different possibilities of testing that you can engag
2828
- ""Widget Developers."" Widget developers are concerned about the logic and working of a given widget is a given back-end.
2929

3030
%+UI elements under test.>file://figures/UI.png|width=75|label=fig:UI+
31-
We will focus on the first role because it is simpler.
31+
We will focus on the first role.
3232
For the reader interested in the second role, the class ==SpAbstractBackendForTest== is a good starting place.
3333

3434
!!! Spec user perspective
@@ -39,74 +39,108 @@ Inversely when the user interface components change, we should ensure that the m
3939

4040
!!!! Example
4141

42-
%Figure @*fig:UI* shows the little application that we use in our example.
42+
We will test a simple spec application. The model for this application can be any class.
43+
It shows in a tree presenter all the subclasses of the model. Also, has a text presenter that shows the definition string for the selected class.
44+
Finally, has a string morph and a button. When the button is
45+
pressed, the colour of the morph changes randomly.
4346

44-
Here is a simple example: Imagine we have the following requirements.
45-
- Click the button should add an element to the list.
46-
- Select an element in the list should populate the form.
47-
- Changing values in the form should change the objects in the list.
47+
+A Spec application.>file://figures/example_spec_application.jpg|width=75|label=fig:SpecApp+
4848

49-
Such requirements are in fact the ones of the Pharo Launcher configuration list.
50-
We convert such requirements into tests as follows:
49+
!!!! Spec user test 1: the tool should be initialized correctly
5150

52-
!!!! Spec user test 1: triggering a button action
51+
The tool will be instantiated with a model.
52+
In this case, we will use ==Object== because it is the root of almost all classes.
53+
So, when we instantiate the spec application of the figure above, all the sub presenters of the application must show the data of the model.
54+
55+
[[[
56+
testInitialization
57+
58+
| model |
59+
model := String.
60+
spApplication := ClassVisualizerPresenter on: model.
61+
self assert: spApplication model equals: model.
62+
self
63+
assert: spApplication textPresenter text
64+
equals: model classDefinitions first definitionString.
65+
self
66+
assert: spApplication morphPresenter morph contents
67+
equals: model name
68+
]]]
5369

54-
Here we specify that clicking the button should add an element to the list.
55-
The message ==launchConfigurations== is returning the list of configurations exposed by the launcher.
56-
Therefore we store the number of list items, then we access the add button of the presenter (here named image)
57-
and we click this button sending the message ==click==.
58-
And we verify that the length of the list has increased by one.
70+
71+
!!!! Spec user test 2: when selecting a new item in the tree presenter the text presenter and the morph should change
72+
73+
The tree presenter shows a tree of classes.
74+
When a class of the tree presenter is selected, the text presenter should change according to the definition of the new selected class.
75+
The morph must change as well.
5976

6077
[[[
61-
testClickAddButtonCreatesNewLaunchConfiguration
62-
63-
| old |
64-
old := image launchConfigurations size.
65-
editor addButton click.
66-
self assert: image launchConfigurations size equals: old + 1
78+
testSelectItemOnTreePresenter
79+
80+
"As we have initialized the tree with Object as its roots. The class OrderedCollection is a subclass of Object. We would simulate that a user selectes OrderedCollection from the tree presenter."
81+
82+
spApplication := ClassVisualizerPresenter on: Object.
83+
spApplication hierarchyTreePresenter selectItem: OrderedCollection.
84+
self
85+
assert: spApplication hierarchyTreePresenter selectedItem
86+
equals: OrderedCollection.
87+
self
88+
assert: spApplication textPresenter text
89+
equals: OrderedCollection classDefinitions first definitionString.
90+
self
91+
assert: spApplication morphPresenter morph contents
92+
equals: OrderedCollection name
6793
]]]
6894

6995

70-
!!!! Spec user test 2: changing text input
71-
The following test verifies that a selection of an element in the list should populate the form.
72-
The method ==clickItem:== simulates the selection of the element of index passed as argument.
96+
!!!! Spec user test 3: triggering the button action
97+
98+
The action of the colour button changes the colour of the morph randomly.
99+
When the button is clicked the morph must change its colour.
73100

74101
[[[
75-
testClickOnLaunchConfigurationListItemSetsFormName
76-
| name |
77-
name := 'test'.
78-
image addLaunchConfiguration: (PhLaunchConfiguration named: name).
79-
editor refreshList.
80-
81-
editor configurationList clickItem: 3.
82-
self assert: editor form nameInput text equals: name
102+
testButtonChangesMorph
103+
104+
| previousColor |
105+
spApplication := ClassVisualizerPresenter on: Object.
106+
previousColor := spApplication morphPresenter morph color.
107+
spApplication colorButton click.
108+
self
109+
deny: spApplication morphPresenter morph color
110+
equals: previousColor
83111
]]]
84112

85113

114+
!!!! Spec user test 4: the text presenter should not be editable
86115

87-
!!!! Spec user test 3: checking list item displayed value
88-
Changing values in the form should change the objects in the list.
89-
This test selects the second item of the list so that the form displays the values
90-
of such item.
91-
Then the name displayed in the form editor is changed to a new text.
92-
And using the message ==displayValueAt:==, it verifies that the displayed value of a given list item (here the second 2, the currently displayed in the form)
93-
is actually the new entered text.
116+
For this application, we only want that the text presenter shows the class definition.
117+
We do not want the user to be able to edit it.
94118

95119
[[[
96-
testEditConfigurationNameUpdatesListItem
97-
| newName |
98-
newName := 'some name'.
99-
editor configurationList clickItem: 2.
100-
editor form nameInput text: newName.
101-
102-
self
103-
assert: (editor configurationList displayValueAt: 2)
104-
equals: newName
120+
testTextPresenterIsNotEditable
121+
122+
spApplication := ClassVisualizerPresenter on: Object.
123+
self deny: spApplication textPresenter isEditable
105124
]]]
106125

107126

108-
These examples of tests show that key actions such as clicking on a button, changing text, selecting
109-
a given list elements can be used to verify the expected behavior of the user interface.
127+
!!!! Spec user test 5: the window is built correctly
128+
129+
Here, we will test that the title and the initial extent of the window are correct.
130+
Also, we will test if the window were built correctly.
131+
132+
[[[
133+
testInitializeWindow
134+
135+
| window |
136+
spApplication := ClassVisualizerPresenter on: Object.
137+
window := spApplication openWithSpec.
138+
self assert: window isBuilt.
139+
self assert: window title equals: ClassVisualizerPresenter title.
140+
self assert: window initialExtent equals: 600 @ 400.
141+
window close
142+
]]]
143+
110144

111145
!!!! Known limitations and conclusion
112146

40.4 KB
Loading

0 commit comments

Comments
 (0)