Skip to content

Commit

Permalink
added few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdugne committed May 2, 2020
1 parent d2ce688 commit 61b3c14
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 36 deletions.
13 changes: 4 additions & 9 deletions cherry/core/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ local App = {
verticalPanel = 'cherry/assets/images/gui/panels/panel.vertical.png',
greenGem = 'cherry/assets/images/gui/items/gem.green.png'
},
colors = {
'#7f00ff',
'#ff00ff'
},
-----------------------------------------
xGravity = 0,
yGravity = 0,
Expand Down Expand Up @@ -102,15 +106,6 @@ local function applyOptions(_options)
App.screens = screens
App.images = images

App.colors =
_.defaults(
App.colors or {},
{
'#7f00ff',
'#ff00ff'
}
)

----------------------------------------------------------------------------

_G.IOS = system.getInfo('platformName') == 'iPhone OS'
Expand Down
2 changes: 1 addition & 1 deletion cherry/main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--------------------------------------------------------------------------------
_G.CHERRY_VERSION = '3.5.0'
_G.CHERRY_VERSION = '3.6.0'
--------------------------------------------------------------------------------
-- debug
require 'cherry.libs.logger'
Expand Down
4 changes: 2 additions & 2 deletions docs/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env variables are placed within `App.env`.
- `SHOW_TOUCHABLES = false`
- `SOUND_OFF = false`

Override them in your `App:start(options)`
Override them in your `App.start(options)`

```lua
{options = {env = {"SOUND_OFF": true}}}
Expand Down Expand Up @@ -48,5 +48,5 @@ then require your `env` to set the chosen one in your start options:

```lua
local env = require 'src/env.lua'
App:start({env = env.PRODUCTION})
App.start({env = env.PRODUCTION})
```
2 changes: 1 addition & 1 deletion docs/push-notifications.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# push notifications

to subscribe to push notifications from FCM, add the list of topics within `App:start(options)`:
to subscribe to push notifications from FCM, add the list of topics within `App.start(options)`:

```lua
options = {pushSubscriptions = {'news', 'quest'}}
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ require 'src.app'

```lua
-- src/app.lua
App:start({
App.start({
name = 'YourGame',
version = '1.0',
})
Expand Down Expand Up @@ -229,7 +229,7 @@ You may use Cherry or a part of it in a free or commercial game or app, providin

##### waiting for the doc, read the code

- Look in app.App to see what you may override with `App:start(options)`
- Look in app.App to see what you may override with `App.start(options)`
- Look in engine.Game to see what you may override with `Game:YourStuff()`

##### core
Expand Down
128 changes: 107 additions & 21 deletions test/spec/core/app.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
require('cherry.main')
local App = require('cherry.core.app')
local deviceNotification = require('cherry.extensions.device-notifications')

describe(
'[App]',
function()
it(
'should instanciate an App',
function()
App:start()
App.start()
end
)

it(
'should accept few options',
function()
App:start(
App.start(
{
name = 'Demo',
version = '2.6.0'
Expand All @@ -26,7 +27,7 @@ describe(
it(
'should test gpgs',
function()
App:start(
App.start(
{
useGPGS = true
}
Expand All @@ -37,7 +38,7 @@ describe(
it(
'should open a view directly',
function()
App:start(
App.start(
{
ENV = 'development'
}
Expand All @@ -48,7 +49,7 @@ describe(
it(
'should start as production',
function()
App:start(
App.start(
{
ENV = 'production'
}
Expand All @@ -60,30 +61,115 @@ describe(
'should start as iOS',
function()
system.switchPlatform('iPhone OS')
App:start()
App.start()
system.switchPlatform('Android')
end
)

it(
'should use default colors',
function()
local colors = App.colors
App.start()
assert.are.same(App.colors, colors)
end
)

it(
'should override colors',
function()
App:start(
local customColors = {
'#DA1D38',
'#ffe35b',
'#8E84F8'
}

App.start(
{
colors = customColors
}
)

assert.are.same(App.colors, customColors)
end
)

it(
'should extend App.env',
function()
local customEnv = {
plop = 'plup'
}

App.start(
{
env = customEnv
}
)

assert.are.same(
App.env,
{
SHOW_TOUCHABLES = false,
SOUND_OFF = false,
name = 'cherry-default-env',
plop = customEnv.plop
}
)
end
)

it(
'should extend App.images',
function()
local customImages = {
plop = 'path/to/custom/img.png'
}

App.start(
{
images = customImages
}
)

assert.are.same(
App.images,
{
blurBG = 'cherry/assets/images/overlay-blur.png',
greenGem = 'cherry/assets/images/gui/items/gem.green.png',
heart = 'cherry/assets/images/gui/items/heart.png',
heartLeft = 'cherry/assets/images/gui/items/heart-left.png',
heartRight = 'cherry/assets/images/gui/items/heart-right.png',
star = 'cherry/assets/images/gui/items/star.icon.png',
step = 'cherry/assets/images/gui/buttons/empty.png',
verticalPanel = 'cherry/assets/images/gui/panels/panel.vertical.png',
plop = customImages.plop
}
)
end
)

it(
'should extend App.screens',
function()
local customScreens = {
screen1 = 'SCREEN1.scene'
}

App.start(
{
colors = {
'DA1D38', -- #DA1D38
'ffe35b', -- #ffe35b
'8E84F8' -- #8E84F8
}
screens = customScreens
}
)

assert.are.same(
App.colors,
App.screens,
{
'DA1D38',
'ffe35b',
'8E84F8'
HEADPHONES = 'headphones',
HOME = 'home',
LEADERBOARD = 'leaderboard',
PLAYGROUND = 'playground',
screen1 = customScreens.screen1
}
)
end
Expand All @@ -92,7 +178,7 @@ describe(
it(
'should listen key events',
function()
App:start()
App.start()

Runtime:dispatchEvent(
{
Expand All @@ -107,17 +193,17 @@ describe(
it(
'should send device notifications',
function()
App:start()
App.start()
assert.are.equal(#App.deviceNotifications, 0)

App:deviceNotification('plop', 10, 'test.plop')
deviceNotification('plop', 10, 'test.plop')
assert.are.equal(table.count(App.deviceNotifications), 1)

-- should cancel previous one and add a new one
App:deviceNotification('plop', 10, 'test.plop')
deviceNotification('plop', 10, 'test.plop')
assert.are.equal(table.count(App.deviceNotifications), 1)

App:deviceNotification('plop!', 10, 'test.other.plop')
deviceNotification('plop!', 10, 'test.other.plop')
assert.are.equal(table.count(App.deviceNotifications), 2)
_G.log(App.deviceNotifications)
end
Expand Down
1 change: 1 addition & 0 deletions test/spec/core/user.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe(
sound = true,
soundVolume = 1
},
sync = true,
tutorial = false,
currentUser = 1,
users = {
Expand Down

0 comments on commit 61b3c14

Please sign in to comment.