Permalink
Please sign in to comment.
Browse files
added testing with testem, added ability to emojify a string
- Loading branch information...
Showing
with
179 additions
and 31 deletions.
- +4 −0 .bowerrc
- +2 −0 .gitignore
- +0 −1 Gruntfile.js
- +51 −30 emojify.js
- +3 −0 package.json
- +21 −0 testem.json
- +51 −0 tests/dom_test.coffee
- +5 −0 tests/setup.js
- +40 −0 tests/string_test.coffee
- +2 −0 tests/tests.coffee
4
.bowerrc
@@ -0,0 +1,4 @@ | ||
+{ | ||
+ "directory": "/vendor/", | ||
+ "json" : "bower.json" | ||
+} |
2
.gitignore
@@ -1,2 +1,4 @@ | ||
node_modules | ||
css | ||
+vendor | ||
+tests.browserified.js |
1
Gruntfile.js
81
emojify.js
3
package.json
21
testem.json
@@ -0,0 +1,21 @@ | ||
+{ | ||
+ "framework": "jasmine", | ||
+ "before_tests": "browserify tests/tests.coffee -o tests.browserified.js -t coffeeify", | ||
+ "src_files": [ | ||
+ "emojify.js", | ||
+ "tests/**/*.coffee", | ||
+ "tests/**/*.js" | ||
+ ], | ||
+ "serve_files": [ | ||
+ "emojify.js", | ||
+ "vendor/sinon/lib/sinon.js", | ||
+ "vendor/sinon/lib/sinon/match.js", | ||
+ "vendor/sinon/lib/sinon/call.js", | ||
+ "vendor/sinon/lib/sinon/spy.js", | ||
+ "vendor/sinon/lib/sinon/mock.js", | ||
+ "vendor/sinon/lib/sinon/stub.js", | ||
+ "vendor/chai/chai.js", | ||
+ "tests/setup.js", | ||
+ "tests.browserified.js" | ||
+ ] | ||
+} |
51
tests/dom_test.coffee
@@ -0,0 +1,51 @@ | ||
+describe 'emojify on DOM nodes', -> | ||
+ beforeEach -> | ||
+ @el = document.createElement("DIV") | ||
+ | ||
+ describe 'with variations of spacing around 2char smileys', -> | ||
+ it 'works with no spacing around :)', -> | ||
+ @el.innerHTML = ":)" | ||
+ result = emojify.run(@el) | ||
+ assert.equal '<img title=":blush:" class="emoji" src="images/emoji/blush.png" align="absmiddle"></img>', @el.innerHTML | ||
+ | ||
+ it 'works with spacing before :)', -> | ||
+ @el.innerHTML = " :)" | ||
+ result = emojify.run(@el) | ||
+ assert.equal ' <img title=":blush:" class="emoji" src="images/emoji/blush.png" align="absmiddle"></img>', @el.innerHTML | ||
+ | ||
+ it 'works with spacing after :)', -> | ||
+ @el.innerHTML = ":) " | ||
+ result = emojify.run(@el) | ||
+ assert.equal '<img title=":blush:" class="emoji" src="images/emoji/blush.png" align="absmiddle"></img> ', @el.innerHTML | ||
+ | ||
+ it 'works with spacing before and after :)', -> | ||
+ @el.innerHTML = " :) " | ||
+ result = emojify.run(@el) | ||
+ assert.equal ' <img title=":blush:" class="emoji" src="images/emoji/blush.png" align="absmiddle"></img> ', @el.innerHTML | ||
+ | ||
+ describe 'with multiple emoji beside each other', -> | ||
+ it 'works with multiple :emoji: style', -> | ||
+ @el.innerHTML = ":railway_car::railway_car:" | ||
+ emojify.run(@el) | ||
+ assert.equal '<img title=":railway_car:" class="emoji" src="images/emoji/railway_car.png" align="absmiddle"></img><img title=":railway_car:" class="emoji" src="images/emoji/railway_car.png" align="absmiddle"></img>', @el.innerHTML | ||
+ | ||
+ describe 'isolated cases', -> | ||
+ it ':)', -> | ||
+ @el.innerHTML = ":)" | ||
+ emojify.run(@el) | ||
+ assert.equal '<img title=":blush:" class="emoji" src="images/emoji/blush.png" align="absmiddle"></img>', @el.innerHTML | ||
+ | ||
+ it ':D', -> | ||
+ @el.innerHTML = ":D" | ||
+ emojify.run(@el) | ||
+ assert.equal '<img title=":smiley:" class="emoji" src="images/emoji/smiley.png" align="absmiddle"></img>', @el.innerHTML | ||
+ | ||
+ it ':P', -> | ||
+ @el.innerHTML = ":P" | ||
+ emojify.run(@el) | ||
+ assert.equal '<img title=":stuck_out_tongue_winking_eye:" class="emoji" src="images/emoji/stuck_out_tongue_winking_eye.png" align="absmiddle"></img>', @el.innerHTML | ||
+ | ||
+ it '>:P', -> | ||
+ @el.innerHTML = ">:P" | ||
+ emojify.run(@el) | ||
+ assert.equal '><img title=":stuck_out_tongue_winking_eye:" class="emoji" src="images/emoji/stuck_out_tongue_winking_eye.png" align="absmiddle"></img>', @el.innerHTML |
5
tests/setup.js
@@ -0,0 +1,5 @@ | ||
+expect = chai.expect; | ||
+assert = chai.assert; | ||
+spy = sinon.spy; | ||
+mock = sinon.mock; | ||
+stub = sinon.stub; |
40
tests/string_test.coffee
@@ -0,0 +1,40 @@ | ||
+describe 'emojify used with flat strings', -> | ||
+ | ||
+ describe 'with variations of spacing around 2char smileys', -> | ||
+ it 'works with no spacing around :)', -> | ||
+ el = "<div>:)</div>" | ||
+ result = emojify.run(el) | ||
+ assert.equal '<div><img title=\'&58;blush&58;\' class=\'emoji\' src=\'images/emoji/blush.png\' align=\'absmiddle\' /></div>', result | ||
+ | ||
+ it 'works with spacing before :)', -> | ||
+ el = "<div> :)</div>" | ||
+ result = emojify.run(el) | ||
+ assert.equal '<div> <img title=\'&58;blush&58;\' class=\'emoji\' src=\'images/emoji/blush.png\' align=\'absmiddle\' /></div>', result | ||
+ | ||
+ it 'works with spacing after :)', -> | ||
+ el = "<div>:) </div>" | ||
+ result = emojify.run(el) | ||
+ assert.equal '<div><img title=\'&58;blush&58;\' class=\'emoji\' src=\'images/emoji/blush.png\' align=\'absmiddle\' /> </div>', result | ||
+ | ||
+ it 'works with spacing before and after :)', -> | ||
+ el = "<div> :) </div>" | ||
+ result = emojify.run(el) | ||
+ assert.equal '<div> <img title=\'&58;blush&58;\' class=\'emoji\' src=\'images/emoji/blush.png\' align=\'absmiddle\' /> </div>', result | ||
+ | ||
+ describe 'with multiple emoji beside each other', -> | ||
+ it 'works with multiple :emoji: style', -> | ||
+ el = "<div>:railway_car::railway_car:</div>" | ||
+ result = emojify.run(el) | ||
+ assert.equal '<div><img title=\'&58;railway_car&58;\' class=\'emoji\' src=\'images/emoji/railway_car.png\' align=\'absmiddle\' /><img title=\'&58;railway_car&58;\' class=\'emoji\' src=\'images/emoji/railway_car.png\' align=\'absmiddle\' /></div>', result | ||
+ | ||
+ it 'works with multiple :) style', -> | ||
+ el = "<div>:):P</div>" | ||
+ result = emojify.run(el) | ||
+ assert.equal '<div><img title=\'&58;blush&58;\' class=\'emoji\' src=\'images/emoji/blush.png\' align=\'absmiddle\' /><img title=\'&58;stuck_out_tongue_winking_eye&58;\' class=\'emoji\' src=\'images/emoji/stuck_out_tongue_winking_eye.png\' align=\'absmiddle\' /></div>', result | ||
+ | ||
+ | ||
+ describe 'isolated cases', -> | ||
+ it ':neckbeard:', -> | ||
+ el = "<div>:neckbeard:</div>" | ||
+ result = emojify.run(el) | ||
+ assert.equal '<div><img title=\'&58;neckbeard&58;\' class=\'emoji\' src=\'images/emoji/neckbeard.png\' align=\'absmiddle\' /></div>', result |
2
tests/tests.coffee
@@ -0,0 +1,2 @@ | ||
+require('./dom_test.coffee') | ||
+require('./string_test.coffee') |
0 comments on commit
36e6fe5