Skip to content

Instantly share code, notes, and snippets.

@shiwano
Created March 11, 2014 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiwano/9486432 to your computer and use it in GitHub Desktop.
Save shiwano/9486432 to your computer and use it in GitHub Desktop.
Titanium サンプル
Globals = Alloy.Globals
SceneController = require 'common/controllers/scene'
class exports.Controller extends SceneController
name: Globals.Consts.Scenes.Start
events:
'click startButton': 'moveToHome'
'click optionButton': 'moveToOption'
initialize: ->
Globals.musicManager.play 'start'
moveToHome: ->
Globals.musicManager.stop()
Globals.Util.initializeModels()
Globals.sceneManager.moveTo Globals.Consts.Scenes.Home
moveToOption: ->
Globals.sceneManager.moveTo Globals.Consts.Scenes.Option
exports.controller = new exports.Controller($, arguments[0] or {}) unless GRUNT_ENV?
helper = require('../../../test_helper')
Globals = Alloy.Globals
describe 'StartSceneController', ->
beforeEach ->
helper.beforeEach false
@subject = Globals.Util.createController 'start/scene'
afterEach ->
helper.afterEach()
describe '#initialize', ->
it 'should play "start" music', ->
expect(Globals.musicManager.name).to.be.equal 'start'
describe '#moveToHome', ->
beforeEach ->
sinon.spy Globals.Util, 'initializeModels'
sinon.spy Globals.musicManager, 'stop'
@subject.moveToHome()
afterEach ->
Globals.Util.initializeModels.restore()
Globals.musicManager.stop.restore()
it 'should initialize models', ->
expect(Globals.Util.initializeModels.called).to.be.ok
it 'should stop music', ->
expect(Globals.musicManager.stop.called).to.be.ok
it 'should move to home scene', ->
expect(Globals.sceneManager.currentScene.name).to.be.equal Globals.Consts.Scenes.Home
describe '#moveToOption', ->
beforeEach ->
@subject.moveToOption()
it 'should move to option scene', ->
expect(Globals.sceneManager.currentScene.name).to.be.equal Globals.Consts.Scenes.Option
'#title':
top: 64
font:
fontSize: 32
fontFamily: 'M+ 2p'
'#startButton':
width: 192
height: 64
'#optionButton':
width: 160
height: 48
bottom: 8
font:
fontSize: 14
fontFamily: 'M+ 2p'
<Alloy>
<View class="container">
<View class="header">
<Label class="sceneName">タイトル</Label>
</View>
<Label id="title" class="label">ああああ</Label>
<Button id="startButton" class="button">ゲームスタート</Button>
<Button id="optionButton" class="button">オプション</Button>
</View>
</Alloy>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment