Permalink
Browse files

Extend demo app to support multiple samples, add acceptance test

  • Loading branch information...
1 parent 060d206 commit fbd779f01943a8ca993814a46a441e3b826d43a9 @seanhotw seanhotw committed Oct 15, 2012
View
@@ -66,6 +66,7 @@ def viewDidLoad
end
````
+- UIActionSheet via `action_sheet`
- UIActivityIndicatorView via `activity_indicator`
- UIButton via `button`
- UIDatePicker via `date_picker`
View
@@ -1,5 +1,7 @@
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
+ return true if RUBYMOTION_ENV == 'test'
+
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@window.rootViewController = UINavigationController.alloc.initWithRootViewController(SimpleViewController.alloc.init)
@window.rootViewController.wantsFullScreenLayout = true
@@ -1,27 +1,44 @@
class SimpleViewController < UIViewController
include SimpleView::Layout
+ DEFAULT_CELL_ID = 'DefaultCellId'
+
def viewDidLoad
- SimpleView::Styles.define :square,
- width: 20,
- height: 20
+ super
+
+ @demos = [
+ {caption: 'View Anchoring', controller: ViewAnchoringController}
+ ]
setup view, controller: self do
- controller.title = "SimpleView Demo"
+ controller.title = 'Demo'
- rect styles: :square, backgroundColor: "#000", top: 0, left: 0, bottom: 0, right: 0
+ table_view delegate: controller, dataSource: controller, top: 0, left: 0, bottom: 0, right: 0 do
+ view.registerClass UITableViewCell, forCellReuseIdentifier: DEFAULT_CELL_ID
+ end
+ end
+ end
- rect styles: :square, backgroundColor: "#990000", top: 0, left: 0
- rect styles: :square, backgroundColor: "#993300", top: 0
- rect styles: :square, backgroundColor: "#CC9900", top: 0, right: 0
+ # UITableView dataSource and delegate
- rect styles: :square, backgroundColor: "#006600", left: 0
- rect styles: :square, backgroundColor: "#336666"
- rect styles: :square, backgroundColor: "#0033FF", right: 0
+ def numberOfSectionsInTableView tableView
+ 1
+ end
- rect styles: :square, backgroundColor: "#000099", bottom: 0, left: 0
- rect styles: :square, backgroundColor: "#660099", bottom: 0
- rect styles: :square, backgroundColor: "#990066", bottom: 0, right: 0
- end
+ def tableView tableView, numberOfRowsInSection: section
+ @demos.size
+ end
+
+ def tableView tableView, cellForRowAtIndexPath: indexPath
+ cell = tableView.dequeueReusableCellWithIdentifier DEFAULT_CELL_ID
+ cell.textLabel.text = @demos[indexPath.row][:caption]
+ cell
+ end
+
+ def tableView tableView, didSelectRowAtIndexPath: indexPath
+ tableView.deselectRowAtIndexPath indexPath, animated: true
+
+ controller = @demos[indexPath.row][:controller].alloc.init
+ navigationController.pushViewController controller, animated: true
end
end
@@ -0,0 +1,27 @@
+class ViewAnchoringController < UIViewController
+ include SimpleView::Layout
+
+ def viewDidLoad
+ SimpleView::Styles.define :square,
+ width: 20,
+ height: 20
+
+ setup view, controller: self do
+ controller.title = "View Anchoring"
+
+ rect name: 'fill', styles: :square, backgroundColor: "#000", top: 0, left: 0, bottom: 0, right: 0
+
+ rect name: 'tl', styles: :square, backgroundColor: "#990000", top: 0, left: 0
+ rect name: 'tc', styles: :square, backgroundColor: "#993300", top: 0
+ rect name: 'tr', styles: :square, backgroundColor: "#CC9900", top: 0, right: 0
+
+ rect name: 'ml', styles: :square, backgroundColor: "#006600", left: 0
+ rect name: 'mc', styles: :square, backgroundColor: "#336666"
+ rect name: 'mr', styles: :square, backgroundColor: "#0033FF", right: 0
+
+ rect name: 'bl', styles: :square, backgroundColor: "#000099", bottom: 0, left: 0
+ rect name: 'bc', styles: :square, backgroundColor: "#660099", bottom: 0
+ rect name: 'br', styles: :square, backgroundColor: "#990066", bottom: 0, right: 0
+ end
+ end
+end
@@ -0,0 +1,82 @@
+describe 'ViewAnchoringController' do
+ tests ViewAnchoringController
+
+ BLOCK_SIZE = 20
+
+ it "should have a view anchored to the four sides of the parent view" do
+ view = controller.view.find('fill')
+ view.frame.should == controller.view.bounds
+ end
+
+ it "should have a view anchored to top left corner" do
+ view = controller.view.find('tl')
+ view.frame.origin.x.should == 0
+ view.frame.origin.y.should == 0
+ view.frame.size.width.should == BLOCK_SIZE
+ view.frame.size.height.should == BLOCK_SIZE
+ end
+
+ it "should have a view anchored to top and centered" do
+ view = controller.view.find('tc')
+ view.center.x.should == controller.view.bounds.size.width / 2
+ view.frame.origin.y.should == 0
+ view.frame.size.width.should == BLOCK_SIZE
+ view.frame.size.height.should == BLOCK_SIZE
+ end
+
+ it "should have a view anchored to top right corner" do
+ view = controller.view.find('tr')
+ view.frame.origin.x.should == controller.view.bounds.size.width - BLOCK_SIZE
+ view.frame.origin.y.should == 0
+ view.frame.size.width.should == BLOCK_SIZE
+ view.frame.size.height.should == BLOCK_SIZE
+ end
+
+ it "should have a view anchored to middle left corner" do
+ view = controller.view.find('ml')
+ view.frame.origin.x.should == 0
+ view.center.y.should == controller.view.bounds.size.height / 2
+ view.frame.size.width.should == BLOCK_SIZE
+ view.frame.size.height.should == BLOCK_SIZE
+ end
+
+ it "should have a view anchored to middle and centered" do
+ view = controller.view.find('mc')
+ view.center.x.should == controller.view.bounds.size.width / 2
+ view.center.y.should == controller.view.bounds.size.height / 2
+ view.frame.size.width.should == BLOCK_SIZE
+ view.frame.size.height.should == BLOCK_SIZE
+ end
+
+ it "should have a view anchored to middle right corner" do
+ view = controller.view.find('mr')
+ view.frame.origin.x.should == controller.view.bounds.size.width - BLOCK_SIZE
+ view.center.y.should == controller.view.bounds.size.height / 2
+ view.frame.size.width.should == BLOCK_SIZE
+ view.frame.size.height.should == BLOCK_SIZE
+ end
+
+ it "should have a view anchored to bottom left corner" do
+ view = controller.view.find('bl')
+ view.frame.origin.x.should == 0
+ view.frame.origin.y.should == controller.view.bounds.size.height - BLOCK_SIZE
+ view.frame.size.width.should == BLOCK_SIZE
+ view.frame.size.height.should == BLOCK_SIZE
+ end
+
+ it "should have a view anchored to bottom and centered" do
+ view = controller.view.find('bc')
+ view.center.x.should == controller.view.bounds.size.width / 2
+ view.frame.origin.y.should == controller.view.bounds.size.height - BLOCK_SIZE
+ view.frame.size.width.should == BLOCK_SIZE
+ view.frame.size.height.should == BLOCK_SIZE
+ end
+
+ it "should have a view anchored to bottom right corner" do
+ view = controller.view.find('br')
+ view.frame.origin.x.should == controller.view.bounds.size.width - BLOCK_SIZE
+ view.frame.origin.y.should == controller.view.bounds.size.height - BLOCK_SIZE
+ view.frame.size.width.should == BLOCK_SIZE
+ view.frame.size.height.should == BLOCK_SIZE
+ end
+end

0 comments on commit fbd779f

Please sign in to comment.