Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
okcoker committed Jan 27, 2014
1 parent bf916b7 commit 3d7d4ac
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Taggle.js
=========

Form-ready delicious style tagging.
Form-ready dependency-less delicious-style tagging.

[Demo & Docs](http://sean.is/poppin/tags/)

Expand Down
83 changes: 82 additions & 1 deletion test/taggle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,40 @@
});

describe('Option callbacks', function() {
var onTagAddSpy = sinon.spy();
var onTagRemoveSpy = sinon.spy();

before(function() {
this.instance = new Taggle(this.container, {
onTagAdd: onTagAddSpy,
onTagRemove: onTagRemoveSpy
});
});

describe('onTagAdd()', function() {
it('should be called after a tag has been added', function() {
expect(onTagAddSpy).to.not.have.been.called;
this.instance.add('one');
console.log(onTagAddSpy.getCall());
expect(onTagAddSpy).to.have.been.called;
expect(onTagAddSpy.getCall(0).args[0]).to.not.be.ok;
expect(onTagAddSpy.getCall(0).args[1]).to.equal('one');
});
});

describe('onTagRemove()', function() {
it('should be called after a tag has been added', function() {
expect(onTagRemoveSpy).to.not.have.been.called;
this.instance.remove('one');
expect(onTagRemoveSpy).to.have.been.called;
expect(onTagRemoveSpy.getCall(0).args[0]).to.not.be.ok;
expect(onTagRemoveSpy.getCall(0).args[1]).to.equal('one');
});
});
});

describe('Methods', function() {
before(function() {
beforeEach(function() {
this.instance = new Taggle(this.container, {
tags: ['zero', 'one', 'two', 'three']
});
Expand All @@ -78,6 +107,58 @@
it('getInput() should return the container\'s text input', function() {
expect(this.instance.getInput()).to.equal(this.instance.getContainer().querySelector('input[type="text"]'));
});

describe('add()', function() {
it('should add a new tag from a string argument', function() {
expect(this.instance.getTagElements().length).to.equal(4);
this.instance.add('four');
this.instance.add(3);
this.instance.add(true);
this.instance.add(false);
this.instance.add([]);
this.instance.add([2]);
this.instance.add('');
expect(this.instance.getTagElements().length).to.equal(5);
});

it('should add new tags from an array of strings', function() {
expect(this.instance.getTagElements().length).to.equal(4);
this.instance.add(['four', 'five', 4, true, undefined]);
this.instance.add(['', Array, false]);
expect(this.instance.getTagElements().length).to.equal(6);
});
});

describe('remove()', function() {
beforeEach(function() {
this.instance = new Taggle(this.container, {
tags: ['zero', 'one', 'two', 'three', 'four', 'three']
});
});

it('should remove the most recent occurance of the tag if it exists', function() {
expect(this.instance.getTagElements().length).to.equal(6);
this.instance.remove('four');
this.instance.remove('five');
this.instance.remove(3);
this.instance.remove(false, true);
this.instance.remove('');
expect(this.instance.getTagElements().length).to.equal(5);
expect(this.instance.getTagValues().length).to.equal(5);
expect(this.instance.getTagValues()[4]).to.equal(this.instance.getTagValues()[3]);
});

it('should remove all occurances of a string if the second argument is true', function() {
expect(this.instance.getTagElements().length).to.equal(6);
this.instance.remove('three', true);
this.instance.remove('five', true);
this.instance.remove(2, true);
this.instance.remove('', true);
expect(this.instance.getTagElements().length).to.equal(4);
expect(this.instance.getTagValues().length).to.equal(4);
expect(this.instance.getTagValues()[3]).to.equal('four');
});
});
});
});

Expand Down

0 comments on commit 3d7d4ac

Please sign in to comment.