Skip to content

Commit 80a558b

Browse files
committed
Add example
1 parent cf05f62 commit 80a558b

4 files changed

Lines changed: 231 additions & 0 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
Class {
2+
#name : 'ExReqExampleTODOApplication',
3+
#superclass : 'SpPresenter',
4+
#instVars : [
5+
'tasks',
6+
'listPresenter',
7+
'addButton',
8+
'stateButton'
9+
],
10+
#category : 'ExecutableRequirements-Examples-Example-TODO',
11+
#package : 'ExecutableRequirements-Examples',
12+
#tag : 'Example-TODO'
13+
}
14+
15+
{ #category : 'as yet unclassified' }
16+
ExReqExampleTODOApplication >> actionAddTask [
17+
18+
| dialog |
19+
dialog := SpRequestDialog new.
20+
dialog
21+
title: 'Create new task';
22+
label: 'Enter the text here:';
23+
text: '';
24+
acceptLabel: 'OK';
25+
cancelLabel: 'Cancel';
26+
onAccept: [
27+
| task |
28+
task := ExReqExampleTODOTask new
29+
text: dialog text;
30+
yourself.
31+
tasks add: task.
32+
listPresenter items: tasks.
33+
listPresenter selectItem: task ];
34+
onCancel: [ ].
35+
dialog openModal
36+
]
37+
38+
{ #category : 'as yet unclassified' }
39+
ExReqExampleTODOApplication >> actionChangeState [
40+
41+
| selected |
42+
selected := self selectedTask.
43+
listPresenter selectedItem state = #TODO
44+
ifTrue: [ selected isDone ]
45+
ifFalse: [ selected isTodo ].
46+
listPresenter updateList.
47+
listPresenter selectItem: selected
48+
]
49+
50+
{ #category : 'initialization - deprecated' }
51+
ExReqExampleTODOApplication >> defaultLayout [
52+
53+
^ SpBoxLayout newVertical
54+
spacing: 4;
55+
add: addButton expand: false;
56+
add: listPresenter;
57+
add: stateButton expand: false;
58+
yourself
59+
]
60+
61+
{ #category : 'initialization - deprecated' }
62+
ExReqExampleTODOApplication >> initializePresenter [
63+
64+
tasks := OrderedCollection new.
65+
addButton := SpButtonPresenter new
66+
label: 'Add new task';
67+
action: [ self actionAddTask ];
68+
yourself.
69+
stateButton := SpButtonPresenter new
70+
label: 'Change state of selected task';
71+
enabled: false;
72+
action: [ self actionChangeState ];
73+
yourself.
74+
listPresenter := SpListPresenter new
75+
whenSelectionChangedDo: [ :sel |
76+
stateButton enabled: sel isNotNil ];
77+
display: [ :task | task text ];
78+
displayIcon: [ :task |
79+
task state = #DONE
80+
ifTrue: [
81+
Smalltalk ui icons iconNamed: #checkboxSelected ]
82+
ifFalse: [
83+
Smalltalk ui icons iconNamed:
84+
#checkboxUnselected ] ];
85+
yourself
86+
]
87+
88+
{ #category : 'as yet unclassified' }
89+
ExReqExampleTODOApplication >> selectedTask [
90+
91+
^ listPresenter selectedItem
92+
]
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
Class {
2+
#name : 'ExReqExampleTODORequirements',
3+
#superclass : 'Object',
4+
#category : 'ExecutableRequirements-Examples-Example-TODO',
5+
#package : 'ExecutableRequirements-Examples',
6+
#tag : 'Example-TODO'
7+
}
8+
9+
{ #category : 'tests' }
10+
ExReqExampleTODORequirements >> todoReq1 [
11+
12+
<ExReqTODO>
13+
^ ExReqRequirement new
14+
title: 'Task model';
15+
description: 'A task is composed of:
16+
- a text (String)
17+
- a state (Enum: TODO, DONE)';
18+
addVerification: [ :verify |
19+
verify
20+
addStepOnAST:
21+
(ExReqExampleTODOTask >> #title:) ast
22+
withPrecondition: [ :obj :arguments | arguments first isString ] ];
23+
addVerification: [ :verify |
24+
verify
25+
addStepOnAST:
26+
(ExReqExampleTODOTask >> #state) ast
27+
withPrecondition: [ :obj | obj state = #DONE ] ];
28+
addVerification: [ :verify |
29+
verify
30+
addStepOnAST:
31+
(ExReqExampleTODOTask >> #state) ast
32+
withPrecondition: [ :obj | obj state = #TODO ] ];
33+
yourself
34+
]
35+
36+
{ #category : 'tests' }
37+
ExReqExampleTODORequirements >> todoReq2 [
38+
39+
<ExReqTODO>
40+
^ ExReqRequirement new
41+
title: 'Task creation';
42+
description:
43+
'A user can create a Task, for this, it provide a text. By default the task has a state TODO.';
44+
addVerification: [ :verify |
45+
verify
46+
addStepOnAST:
47+
(ExReqExampleTODOApplication >> #actionAddTask) ast
48+
withPrecondition: [ :obj | obj tasks size = 0 ]
49+
withPostcondition: [ :obj | obj tasks size = 1 ] ];
50+
addVerification: [ :verify |
51+
verify
52+
addStepOnAST:
53+
(ExReqExampleTODOApplication >> #actionAddTask) ast
54+
withPostcondition: [ :obj | obj tasks first state = #TODO ] ];
55+
yourself
56+
]
57+
58+
{ #category : 'tests' }
59+
ExReqExampleTODORequirements >> todoReq3 [
60+
61+
<ExReqTODO>
62+
^ ExReqRequirement new
63+
title: 'Tasks list';
64+
description: 'The application display all tasks and their states.';
65+
addVerification: [ :verify |
66+
verify addStepOnAST:
67+
(ExReqExampleTODOApplication >> #initializePresenter) ast ];
68+
yourself
69+
]
70+
71+
{ #category : 'tests' }
72+
ExReqExampleTODORequirements >> todoReq4 [
73+
74+
<ExReqTODO>
75+
^ ExReqRequirement new
76+
title: 'Change task state';
77+
description:
78+
'A user can change the state of task from TODO to DONE and form DONE to TODO in case of mistake.';
79+
addVerification: [ :verify |
80+
verify addStepOnAST:
81+
(ExReqExampleTODOApplication >> #actionChangeState) ast withPrecondition: [ :obj | obj selectedTask state = #TODO ] withPostcondition: [ :obj | obj selectedTask state = #DONE ] ];
82+
addVerification: [ :verify |
83+
verify addStepOnAST:
84+
(ExReqExampleTODOApplication >> #actionChangeState) ast withPrecondition: [ :obj | obj selectedTask state = #DONE ] withPostcondition: [ :obj | obj selectedTask state = #TODO ] ];
85+
yourself
86+
]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
Class {
2+
#name : 'ExReqExampleTODOTask',
3+
#superclass : 'Object',
4+
#instVars : [
5+
'text',
6+
'state'
7+
],
8+
#category : 'ExecutableRequirements-Examples-Example-TODO',
9+
#package : 'ExecutableRequirements-Examples',
10+
#tag : 'Example-TODO'
11+
}
12+
13+
{ #category : 'as yet unclassified' }
14+
ExReqExampleTODOTask >> actionAddTask [
15+
]
16+
17+
{ #category : 'testing' }
18+
ExReqExampleTODOTask >> initialize [
19+
20+
super initialize.
21+
self isTodo
22+
]
23+
24+
{ #category : 'testing' }
25+
ExReqExampleTODOTask >> isDone [
26+
27+
state := #DONE
28+
]
29+
30+
{ #category : 'testing' }
31+
ExReqExampleTODOTask >> isTodo [
32+
33+
state := #TODO
34+
]
35+
36+
{ #category : 'accessing' }
37+
ExReqExampleTODOTask >> state [
38+
39+
^ state
40+
]
41+
42+
{ #category : 'accessing' }
43+
ExReqExampleTODOTask >> text [
44+
45+
^ text
46+
]
47+
48+
{ #category : 'accessing' }
49+
ExReqExampleTODOTask >> text: anObject [
50+
51+
text := anObject
52+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Package { #name : 'ExecutableRequirements-Examples' }

0 commit comments

Comments
 (0)