Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tests #85

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sqwidget/app/component/core.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ define ['underscore','backbone'], (_, Backbone) ->

register: (el) ->
$this = $(el).addClass('sqwidget')
pkg = el: $this
opts = @getWidgetParams($this)
pkg = el: $this, opts: opts
_.extend(pkg, Backbone.Events)
@registered.push(pkg)
opts = @getWidgetParams($this)

throw new Error("No widget source") unless opts.url

Expand Down Expand Up @@ -39,7 +39,7 @@ define ['underscore','backbone'], (_, Backbone) ->
# 'data-sqwidget-bg-color='#FFF' -> data['bgcolor'] = '#FFF'
#
getWidgetParams: ($el) ->
data = []
data = {}
for key, val of $el.data()
key = key.replace("sqwidget", "").toLowerCase()
data[key || "url" ] = val
Expand Down
10 changes: 9 additions & 1 deletion sqwidget/tests/spec/core.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ define ['chai', 'jquery', 'component/core'], (chai, $, Core) ->
assert = chai.assert
describe 'Core', ->
sqwidget = new Core()
src = $("<div data-sqwidget='/base/widgets/test'></div>'")
src = $("<div data-sqwidget-test='moo' data-sqwidget='/base/widgets/test'></div>'")

describe '#register()', ->
widget = sqwidget.register(src)

it 'should register widget', ->
assert.lengthOf(sqwidget.registered, 1, "Registered module")

it 'should parse params correctly', ->
assert.deepEqual( widget.opts, { test: 'moo', url: '/base/widgets/test' } , "params parsed")

it 'should trigger rendered event', (done) ->
widget.on 'rendered', ->
assert.ok "Triggered event"
assert.equal(src.html(),
'<div class="sqwidget-hello-world"><div>Test Widget</div></div>'
'Rendered correctly'
)
done()