-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49503f7
commit a64095f
Showing
15 changed files
with
276 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ return { | |
-- the .lua extension) | ||
['exclude'] = { | ||
'mocks', | ||
'spec' | ||
'mocks', | ||
'tprint' | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
expose('[setting up tests Globals]', function() | ||
require('tprint') | ||
|
||
_G.sleep = function(n) | ||
local t = os.clock() | ||
while os.clock() - t <= n do | ||
-- nothing | ||
end | ||
end | ||
|
||
_G.display = require('mocks.display') | ||
_G.transition = require('mocks.transition') | ||
_G.App = require('mocks.app') | ||
_G.network = require('mocks.network') | ||
_G.http = require('mocks.http') | ||
|
||
_G.easing = {} | ||
_G.timer = {performWithDelay = function(time, func) func() end} | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
local App = { | ||
display = display.newGroup(), | ||
start = function () end, | ||
start = function () end, | ||
width = 640, | ||
height = 1280, | ||
} | ||
|
||
return App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
local http = { | ||
post = function (url, data, next, _type) | ||
end | ||
} | ||
|
||
return http |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
local network = { | ||
request = function (url, method, next, params) | ||
end | ||
} | ||
|
||
return network |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
local analytics = require 'analytics' | ||
|
||
describe('[analytics]', function() | ||
it('> should set _G.analyticsParams', function() | ||
analytics.init('plop', 'plup', 'plip', 'ploup', 'plep') | ||
assert.are.equal( _G.analyticsParams.version, 'plop') | ||
assert.are.equal( _G.analyticsParams.trackingId, 'plup') | ||
assert.are.equal( _G.analyticsParams.profileId, 'plip') | ||
assert.are.equal( _G.analyticsParams.AppName, 'ploup') | ||
assert.are.equal( _G.analyticsParams.AppVersion, 'plep') | ||
end) | ||
|
||
it('> should post a page view', function() | ||
stub(_G.http, 'post') | ||
|
||
analytics.init('plop', 'plup', 'plip', 'ploup', 'plep') | ||
analytics.pageview('page') | ||
|
||
assert.stub(_G.http.post).was.called(1) | ||
assert.stub(_G.http.post).was.called_with( | ||
'http://www.google-analytics.com/collect', | ||
'v=plop&tid=plup&cid=plip&t=Appview&an=ploup&av=plep&cd=page', | ||
nil, | ||
'urlencoded' | ||
) | ||
end) | ||
|
||
it('> should post an event', function() | ||
stub(_G.http, 'post') | ||
|
||
analytics.init('plop', 'plup', 'plip', 'ploup', 'plep') | ||
analytics.event('cat', 'act', 'lab') | ||
|
||
assert.stub(_G.http.post).was.called(1) | ||
assert.stub(_G.http.post).was.called_with( | ||
'http://www.google-analytics.com/collect', | ||
'v=plop&tid=plup&cid=plip&t=event&an=ploup&ec=cat&ea=act&el=lab', | ||
nil, | ||
'urlencoded' | ||
) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
local animation = require 'animation' | ||
|
||
describe('[animation]', function() | ||
it('> rotateBackAndForth', function() | ||
local foo = display.newImage(App.display) | ||
assert.are.equal(foo.rotation, 0) | ||
|
||
foo.onCompleteCounts = 0 | ||
animation.rotateBackAndForth(foo, 45, 200) | ||
assert.are.equal(foo.rotation, 45) | ||
|
||
foo.rotation = 0 | ||
foo.onCompleteCounts = 1 | ||
animation.rotateBackAndForth(foo, 45, 200) | ||
assert.are.equal(foo.rotation, 0) | ||
end) | ||
|
||
it('> easeDisplay', function() | ||
local foo = display.newImage(App.display) | ||
foo.xScale = 0 | ||
foo.yScale = 0 | ||
|
||
animation.easeDisplay(foo) | ||
assert.are.equal(foo.xScale, 1) | ||
assert.are.equal(foo.yScale, 1) | ||
|
||
animation.easeDisplay(foo, 2) | ||
assert.are.equal(foo.xScale, 2) | ||
assert.are.equal(foo.yScale, 2) | ||
end) | ||
|
||
it('> bounce', function() | ||
local foo = display.newImage(App.display) | ||
foo.xScale = 0 | ||
foo.yScale = 0 | ||
|
||
animation.bounce(foo) | ||
assert.are.equal(foo.xScale, 1) | ||
assert.are.equal(foo.yScale, 1) | ||
|
||
animation.bounce(foo, 2) | ||
assert.are.equal(foo.xScale, 2) | ||
assert.are.equal(foo.yScale, 2) | ||
end) | ||
|
||
it('> grow', function() | ||
local foo = display.newImage(App.display) | ||
local action = spy.new(function() end) | ||
|
||
animation.grow(foo, 0, 350, action) | ||
|
||
assert.are.equal(foo.xScale, 1) | ||
assert.are.equal(foo.yScale, 1) | ||
assert.spy(action).was.called(1) | ||
end) | ||
|
||
it('> easeHide', function() | ||
local foo = display.newImage(App.display) | ||
local action = spy.new(function() end) | ||
|
||
animation.easeHide(foo, action) | ||
|
||
assert.are.equal(foo.xScale, 0.01) | ||
assert.are.equal(foo.yScale, 0.01) | ||
assert.spy(action).was.called(1) | ||
end) | ||
|
||
it('> fadeIn', function() | ||
local foo = display.newImage(App.display) | ||
foo.alpha = 0 | ||
|
||
animation.fadeIn(foo) | ||
|
||
assert.are.equal(foo.alpha, 1) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,117 @@ | ||
local gesture = require 'gesture' | ||
|
||
describe('[gesture]', function() | ||
it('> onTouch', function() | ||
local foo = display.newImage(App.display) | ||
local action = spy.new(function() end) | ||
describe('[onTouch]', function() | ||
it('> phase.began: action is not called, opacity becomes 0.8', function() | ||
local foo = display.newImage(App.display) | ||
local action = spy.new(function() end) | ||
assert.are.equal(foo.alpha, 1) | ||
|
||
gesture.onTouch(foo, action) | ||
gesture.onTouch(foo, action) | ||
|
||
foo:dispatchEvent({ | ||
name = 'touch', | ||
phase = 'ended' | ||
}) | ||
foo:dispatchEvent({ | ||
name = 'touch', | ||
phase = 'began' | ||
}) | ||
|
||
assert.spy(action).was.called(1) | ||
end) | ||
assert.are.equal(foo.alpha, 0.8) | ||
assert.spy(action).was.called(0) | ||
end) | ||
|
||
it('> phase.ended: action is called, opacity is back to 1', function() | ||
local foo = display.newImage(App.display) | ||
local action = spy.new(function() end) | ||
|
||
gesture.onTouch(foo, action) | ||
|
||
foo:dispatchEvent({ | ||
name = 'touch', | ||
phase = 'ended' | ||
}) | ||
|
||
assert.spy(action).was.called(1) | ||
assert.are.equal(foo.alpha, 1) | ||
end) | ||
|
||
it('> should override previous action', function() | ||
local foo = display.newImage(App.display) | ||
local action1 = spy.new(function() end) | ||
local action2 = spy.new(function() end) | ||
|
||
gesture.onTouch(foo, action1) | ||
gesture.onTouch(foo, action2) | ||
|
||
foo:dispatchEvent({ | ||
name = 'touch', | ||
phase = 'ended' | ||
}) | ||
|
||
assert.spy(action1).was.called(0) | ||
assert.spy(action2).was.called(1) | ||
end) | ||
end) | ||
|
||
describe('[onTap]', function() | ||
it('> phase.began: action is called', function() | ||
local foo = display.newImage(App.display) | ||
local action = spy.new(function() end) | ||
|
||
gesture.onTap(foo, action) | ||
|
||
foo:dispatchEvent({ | ||
name = 'touch', | ||
phase = 'began' | ||
}) | ||
|
||
assert.spy(action).was.called(1) | ||
end) | ||
|
||
it('> phase.ended: action is not called', function() | ||
local foo = display.newImage(App.display) | ||
local action = spy.new(function() end) | ||
|
||
gesture.onTap(foo, action) | ||
|
||
foo:dispatchEvent({ | ||
name = 'touch', | ||
phase = 'ended' | ||
}) | ||
|
||
assert.spy(action).was.called(0) | ||
end) | ||
|
||
it('> should override previous action', function() | ||
local foo = display.newImage(App.display) | ||
local action1 = spy.new(function() end) | ||
local action2 = spy.new(function() end) | ||
|
||
gesture.onTap(foo, action1) | ||
gesture.onTap(foo, action2) | ||
|
||
foo:dispatchEvent({ | ||
name = 'touch', | ||
phase = 'began' | ||
}) | ||
|
||
assert.spy(action1).was.called(0) | ||
assert.spy(action2).was.called(1) | ||
end) | ||
end) | ||
|
||
describe('[disabledTouch]', function() | ||
it('> phase.began: action is called', function() | ||
local foo = display.newImage(App.display) | ||
local action = spy.new(function() end) | ||
|
||
gesture.onTap(foo, action) | ||
gesture.disabledTouch(foo) | ||
|
||
foo:dispatchEvent({ | ||
name = 'touch', | ||
phase = 'began' | ||
}) | ||
|
||
assert.spy(action).was.called(0) | ||
end) | ||
end) | ||
end) |