Added menu item named "Open Test Case Class" to browser class list context menu.
Searches for class named ClassName + Tests and if this class exists then opens a new browser tab and navigates to this class.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CustomNewSystemBrowserTests.st Fri Dec 26 21:02:39 2014 +0100
@@ -0,0 +1,118 @@
+"{ Package: 'jn:refactoring_custom' }"
+
+TestCase subclass:#CustomNewSystemBrowserTests
+ instanceVariableNames:'browser mock menu'
+ classVariableNames:''
+ poolDictionaries:''
+ category:'Interface-Refactoring-Custom-UI-Tests'
+!
+
+!CustomNewSystemBrowserTests methodsFor:'initialization & release'!
+
+setUp
+ super setUp.
+
+ mock := CustomMock new.
+ menu := Menu labels: 'label' values: nil.
+ browser := (mock mockOf: Tools::NewSystemBrowser)
+ compileMockMethod: 'information: aString
+ self objectAttributeAt: #testInformation put: aString';
+ compileMockMethod: 'information
+ ^ self objectAttributeAt: #testInformation';
+ compileMockMethod: 'theSingleSelectedClass: aClass
+ self objectAttributeAt: #testTheSingleSelectedClass put: aClass';
+ compileMockMethod: 'theSingleSelectedClass
+ ^ self objectAttributeAt: #testTheSingleSelectedClass';
+ compileMockMethod: 'createBuffer ^ true';
+ compileMockMethod: 'switchToClass: aClass
+ self objectAttributeAt: #testSwitchToClass put: aClass';
+ compileMockMethod: 'switchToClass
+ ^ self objectAttributeAt: #testSwitchToClass';
+ compileMockMethod: 'selectProtocol: aProtocol
+ self objectAttributeAt: #testSelectProtocol put: aProtocol';
+ compileMockMethod: 'selectProtocol
+ ^ self objectAttributeAt: #testSelectProtocol';
+ yourself.
+
+ "Modified: / 26-12-2014 / 18:42:47 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+!
+
+tearDown
+
+ mock unmockAll.
+
+ super tearDown.
+
+ "Modified: / 26-12-2014 / 19:17:51 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+! !
+
+!CustomNewSystemBrowserTests methodsFor:'tests'!
+
+test_class_menu_extension_navigate_to_test_case_custom_extensions
+ | expectedClass actualClass |
+
+ expectedClass := CustomRBMethodTests.
+ browser theSingleSelectedClass: RBMethod.
+ browser classMenuExtensionNavigateToTestCase: menu.
+ menu lastItem itemValue value. "Call menu item action block"
+ actualClass := browser switchToClass.
+
+ self assert: expectedClass = actualClass.
+ self assert: (browser selectProtocol) == #tests
+
+ "Created: / 26-12-2014 / 18:58:56 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+!
+
+test_class_menu_extension_navigate_to_test_case_found
+ | expectedClass actualClass |
+
+ expectedClass := CustomContextTests.
+ browser theSingleSelectedClass: CustomContext.
+ browser classMenuExtensionNavigateToTestCase: menu.
+ menu lastItem itemValue value. "Call menu item action block"
+ actualClass := browser switchToClass.
+
+ self assert: expectedClass = actualClass.
+ self assert: (browser selectProtocol) == #tests
+
+ "Created: / 26-12-2014 / 18:53:34 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+!
+
+test_class_menu_extension_navigate_to_test_case_not_found
+ | expectedInformation actualInformation |
+
+ expectedInformation := 'Test Case named CustomNewSystemBrowserTestsTests not found'.
+ browser theSingleSelectedClass: CustomNewSystemBrowserTests.
+ browser classMenuExtensionNavigateToTestCase: menu.
+ menu lastItem itemValue value. "Call menu item action block"
+ actualInformation := browser information.
+
+ self assert: expectedInformation = actualInformation
+
+ "Created: / 26-12-2014 / 18:32:23 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+!
+
+test_class_menu_extension_navigate_to_test_case_placed_after_generate
+ | expectedPosition actualPosition foundItem |
+
+ expectedPosition := 3.
+
+ menu := Menu labels: 'Label_01
+Generate
+Label_02' values: nil.
+
+ browser classMenuExtensionNavigateToTestCase: menu.
+ actualPosition := 0.
+ foundItem := false.
+ menu itemsDo: [ :item |
+ foundItem ifFalse: [
+ actualPosition := actualPosition + 1.
+ foundItem := (item label = 'Open Test Case Class').
+ ]
+ ].
+
+ self assert: expectedPosition = actualPosition
+
+ "Created: / 26-12-2014 / 19:01:59 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+! !
+
--- a/abbrev.stc Fri Dec 26 13:59:44 2014 +0100
+++ b/abbrev.stc Fri Dec 26 21:02:39 2014 +0100
@@ -17,6 +17,7 @@
CustomMock CustomMock jn:refactoring_custom 'Interface-Refactoring-Custom-Tests' 0
CustomMockTests CustomMockTests jn:refactoring_custom 'Interface-Refactoring-Custom-Tests' 1
CustomNamespace CustomNamespace jn:refactoring_custom 'Interface-Refactoring-Custom' 0
+CustomNewSystemBrowserTests CustomNewSystemBrowserTests jn:refactoring_custom 'Interface-Refactoring-Custom-UI-Tests' 1
CustomNoneSourceCodeFormatterTests CustomNoneSourceCodeFormatterTests jn:refactoring_custom 'Interface-Refactoring-Custom-Tests' 1
CustomParseTreeRewriter CustomParseTreeRewriter jn:refactoring_custom 'Interface-Refactoring-Custom' 0
CustomParseTreeRewriterTests CustomParseTreeRewriterTests jn:refactoring_custom 'Interface-Refactoring-Custom-Tests' 1
--- a/extensions.st Fri Dec 26 13:59:44 2014 +0100
+++ b/extensions.st Fri Dec 26 21:02:39 2014 +0100
@@ -868,6 +868,52 @@
!Tools::NewSystemBrowser methodsFor:'menus extensions-custom refactorings'!
+classMenuExtensionNavigateToTestCase: aMenu
+ "Adds menu item to class list window and tries to guess test case class
+ name. If test case class exists then opens a new tab with this class selected."
+ <menuextension: #classMenu>
+
+ | item index |
+
+ item := MenuItem label: (resources string: 'Open Test Case Class')
+ itemValue: [
+ | className testClassName testClass |
+
+ className := self theSingleSelectedClass theNonMetaclass name.
+ testClassName := (className, 'Tests') asSymbol.
+ testClass := environment at: testClassName ifAbsent: nil.
+ testClass isNil ifTrue: [
+ | extensionTestClassName |
+
+ "Small hack for my extension test cases"
+ extensionTestClassName := ('Custom', className, 'Tests') asSymbol.
+ testClass := environment at: extensionTestClassName ifAbsent: nil.
+ ].
+
+ testClass notNil ifTrue: [
+ self createBuffer;
+ switchToClass: testClass;
+ selectProtocol: #tests
+ ] ifFalse: [
+ self information: 'Test Case named ', testClassName, ' not found'
+ ].
+ ].
+
+ item enabled: [ self theSingleSelectedClass notNil ].
+
+ index := aMenu indexOfMenuItemForWhich:[:each | each label = 'Generate' ].
+ index ~~ 0 ifTrue:[
+ aMenu addItem:item beforeIndex:index + 1.
+ ] ifFalse:[
+ aMenu addItem:item.
+ ].
+
+ "Created: / 26-12-2014 / 16:54:30 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+ "Modified: / 26-12-2014 / 18:55:18 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+! !
+
+!Tools::NewSystemBrowser methodsFor:'menus extensions-custom refactorings'!
+
codeViewMenuExtensionCustomRefactorings:aMenu
<menuextension: #codeViewMenu>
--- a/jn_refactoring_custom.st Fri Dec 26 13:59:44 2014 +0100
+++ b/jn_refactoring_custom.st Fri Dec 26 21:02:39 2014 +0100
@@ -108,6 +108,7 @@
CustomMock
(CustomMockTests autoload)
CustomNamespace
+ (CustomNewSystemBrowserTests autoload)
(CustomNoneSourceCodeFormatterTests autoload)
CustomParseTreeRewriter
(CustomParseTreeRewriterTests autoload)
@@ -285,6 +286,7 @@
RBAbstractClass isAbstract:
RBAbstractClass programmingLanguage
RBMethod programmingLanguage
+ #'Tools::NewSystemBrowser' classMenuExtensionNavigateToTestCase:
)
! !
--- a/patches/patches.rc Fri Dec 26 13:59:44 2014 +0100
+++ b/patches/patches.rc Fri Dec 26 21:02:39 2014 +0100
@@ -25,7 +25,7 @@
VALUE "LegalCopyright", "My CopyRight or CopyLeft\0"
VALUE "ProductName", "LibraryName\0"
VALUE "ProductVersion", "6.2.5.1478\0"
- VALUE "ProductDate", "Fri, 26 Dec 2014 12:43:23 GMT\0"
+ VALUE "ProductDate", "Fri, 26 Dec 2014 18:18:54 GMT\0"
END
END
--- a/refactoring_custom.rc Fri Dec 26 13:59:44 2014 +0100
+++ b/refactoring_custom.rc Fri Dec 26 21:02:39 2014 +0100
@@ -25,7 +25,7 @@
VALUE "LegalCopyright", "My CopyRight or CopyLeft\0"
VALUE "ProductName", "ProductName\0"
VALUE "ProductVersion", "6.2.5.1478\0"
- VALUE "ProductDate", "Fri, 26 Dec 2014 12:43:22 GMT\0"
+ VALUE "ProductDate", "Fri, 26 Dec 2014 18:18:52 GMT\0"
END
END