Some words about what I've learned. As TWM move / resize windows, it's better to create a World dedicated to the tests, so you don't see all your windows moving while testing (and if you use Autotest note that tests are run as soon as you save a method, quite fun :).
So in TWM have a look at WMInANewWorldTestCase>>setUp and some of its subclasses like: - WMInANewWorldTestCase |_ WMWithTwoBrowsersAndTwoWorkspacesTest>>setUp
|_ TWMBarWithTwoBrowsersAndTwoWorkspacesTest>>setUp If I merge the setUps: testWorld := PasteUpMorph new
initAsTestWorld: WorldState new; yourself. testWorld bounds: (0@0 extent: 200@200).
windowManager := TilingWM forWorld: testWorld. browser1 := self newBrowserIn: testWorld.
browser2 := self newBrowserIn: testWorld. workspace1 := self newWorkspaceIn: testWorld.
workspace2 := self newWorkspaceIn: testWorld. Then it should be easier to understand something like: WMWithTwoBrowsersAndTwoWorkspacesTest>>testTileVisibleWindowsShouldPlaceThemInTwoColumnsAndRows windowManager tileVisibleWindows.
self assert: (0@0 extent: 100@100) equals: workspace2 bounds. self assert: (100@0 extent: 100@100) equals: workspace1 bounds.
self assert: (0@100 extent: 100@100) equals: browser2 bounds. self assert: (100@100 extent: 100@100) equals: browser1 bounds.
or WMWithTwoBrowsersAndTwoWorkspacesTest>>testTileLastUsedWindowsShouldTileOnlyLastTwoWindowsUsed workspace1 activate.
browser2 activate. workspace2 activate. browser1 activate.
browser1 minimize. windowManager tileLastUsedWindows.. self assert: (0@0 extent: 200@100) equals: browser1 bounds.
self assert: (0@100 extent: 200@100) equals: workspace2 bounds. Another example: WMWithAnOBBrowserAndDockingBarsTest>>setUp super setUp. obbrowser := self newWindowFor: #OBSystemBrowser.
taskBar := TaskbarMorph new openInWorld: testWorld;
adhereToEdge: #bottom. leftBar := DockingBarMorph new
adhereToLeft; width: 25; openInWorld: testWorld.
Note that in Core there's no OB, so tests are expected to fail: WMWithAnOBBrowserAndDockingBarsTest>>expectedFailures
^ (Smalltalk at: #OBSystemBrowser ifAbsent: nil) ifNil: [self class testSelectors]
ifNotNil: [#()] Now if I want to test the content of a window / morph, I use methods you can find in Morph, protocol submorphs-accessing.
For example I want to find the menu that have a given icon. Here's an helper: TWMBarWithTwoBrowsersAndTwoWorkspacesTest>>menuWithIcon: aForm ^ self twmBar dock
findDeepSubmorphThat: [:aMorph| (aMorph isKindOf: MenuItemMorph) and:[aMorph icon = aForm]]
ifAbsent: [nil]. so I can test that the Other Tools menu in TWMBar have an entry named "New TestRunner":
TWMBarWithTwoBrowsersAndTwoWorkspacesTest>>testOtherToolsMenuShouldContainsEntryForOpeningSUnitTestRunner self assertMenuWithIcon: twmBar otherToolsMenuIcon containsItemNamed: 'New TestRunner'.
I can also check that clicking on a given entry do the action I want. For example, if I have a Browser browsing class String, there should be an entry in the Browsers menu. If minimized, when I click on it, the Browser should be placed on top and expanded:
TWMBarWithTwoBrowsersAndTwoWorkspacesTest>>testClickOnBrowserTwoMenuItemWhenMinimizedShouldActivateIt |menuItem|
browser2 minimize. workspace1 activate. menuItem := self itemNamed: 'String' fromMenuWithIcon: twmBar browsersMenuIcon.
menuItem target perform: (menuItem selector). self assert: browser2 equals: SystemWindow topWindow.
self assert: (windowManager visibleWindows includes: browser2). Finally, if you use some settings, it's better to backup them in the setUp and restore them in the tearDown, so you keep your Settings while testing them :)
WMWithTwoBrowsersAndTwoWorkspacesTest >>setUp ...... backupNumberOfWindowsSetting := TilingWM numberOfLastUsedWindows.
TilingWM numberOfLastUsedWindows: 2. WMWithTwoBrowsersAndTwoWorkspacesTest>>tearDown .....
TilingWM numberOfLastUsedWindows: backupNumberOfWindowsSetting. Ideas welcome :) Laurent Laffont - @lolgzs Pharo Smalltalk Screencasts: http://www.pharocasts.com/ Blog: http://magaloma.blogspot.com/
Developer group: http://cara74.seasidehosting.st
|
Free forum by Nabble | Edit this page |