Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding new specs and organizing them a bit

  • Loading branch information...
commit 8e8ec691e32916a4be70282fdaeaeace057d96af 1 parent 30b6a73
Fabio M. Costa authored
2  Source/Meio.Autocomplete.Cache.js
View
@@ -11,7 +11,7 @@ requires:
license: MIT-style license
-provides: [Meio.Autocomplete.Cache]
+provides: [Meio.Autocomplete.Cache, Meio.Autocomplete.FakeCache]
...
*/
1  Specs/unit/index.html
View
@@ -35,6 +35,7 @@
</script>
<script>
+ jasmine.include('../../Specs/unit/meio/Meio.Autocomplete.Cache.js', true);
jasmine.include('../../Specs/unit/meio/Meio.Autocomplete.js', true);
</script>
76 Specs/unit/meio/Meio.Autocomplete.Cache.js
View
@@ -0,0 +1,76 @@
+describe('Meio.Autocomplete.Cache', function() {
+ describe('initialized with default options', function() {
+ beforeEach(function() {
+ this.cache = new Meio.Autocomplete.Cache();
+ });
+
+ it('should initialize empty', function(){
+ expect(this.cache.getLength()).toEqual(0);
+ });
+ });
+
+ describe('initialized with maxLength 2', function() {
+ beforeEach(function() {
+ this.cache = new Meio.Autocomplete.Cache(2);
+ });
+
+ it('should remove the last item if included more than the defined maxlength', function() {
+ this.cache.set('a', 1);
+ expect(this.cache.getLength()).toEqual(1);
+ this.cache.set('b', 2);
+ this.cache.set('c', 3);
+ expect(this.cache.getLength()).toEqual(2);
+ expect(this.cache.get('a')).toBeNull();
+ expect(this.cache.has('a')).toEqual(false);
+ expect(this.cache.has('b')).toEqual(true);
+ expect(this.cache.get('c')).toEqual(3);
+ });
+
+ describe('the refresh method', function() {
+ beforeEach(function() {
+ this.cache.get('a', 3);
+ this.cache.refresh();
+ });
+ it('should clean both the cache object and the pos array', function() {
+ expect(this.cache.pos).toEqual([]);
+ expect(this.cache.cache).toEqual({});
+ });
+ });
+
+ describe('the setMaxLength method', function() {
+ beforeEach(function() {
+ this.cache.setMaxLength(1);
+ this.cache.set('a', 3);
+ this.cache.set('b', 3);
+ });
+ it('should obey its maxLength restriction', function() {
+ expect(this.cache.getLength()).toBe(1);
+ });
+ });
+
+ });
+});
+
+describe('Meio.Autocomplete.FakeCache', function() {
+ beforeEach(function() {
+ this.cache = new Meio.Autocomplete.FakeCache();
+ });
+
+ it('should initialize empty', function(){
+ expect(this.cache.getLength()).toEqual(0);
+ });
+
+ it('should never cache anything', function(){
+ this.cache.set('c', 3);
+ expect('c' in this.cache.cache).toBeFalsy();
+ });
+
+ it('should always return itself on set', function() {
+ expect(this.cache.set('a')).toBe(this.cache);
+ });
+
+ it('should always return null on get', function() {
+ this.cache.set('a', 3);
+ expect(this.cache.get('a')).toBe(null);
+ });
+});
96 Specs/unit/meio/Meio.Autocomplete.js
View
@@ -1,64 +1,42 @@
-var cache;
-
-describe('Meio.Autocomplete.Cache', function(){
-
- it('should initialize empty', function(){
- cache = new Meio.Autocomplete.Cache();
- expect(cache.getLength()).toEqual(0);
- });
-
- it('should remove the last item if included more than the defined maxlength', function(){
- cache = new Meio.Autocomplete.Cache(2);
- cache.set('a', 1);
- expect(cache.getLength()).toEqual(1);
- cache.set('b', 2);
- cache.set('c', 3);
- expect(cache.getLength()).toEqual(2);
- expect(cache.get('a')).toBeNull();
- expect(cache.has('a')).toEqual(false);
- expect(cache.has('b')).toEqual(true);
- expect(cache.get('c')).toEqual(3);
- });
-
-});
-
-
-var url;
-
describe('Meio.Autocomplete.Data.Request.URL', function(){
-
- it('should initialize a crude url', function(){
- url = new Meio.Autocomplete.Data.Request.URL('/url/', {max: 10, extraParams: {name: 'a', value: 1}});
- expect(url.url).toContain('limit=1');
- expect(url.url).toContain('a=1');
- });
-
- it('should change the value of the url accoring to the dinamic extra params passed', function(){
- var input = new Element('input', {'name': 'input', 'value': 5});
- var i = 0;
- url = new Meio.Autocomplete.Data.Request.URL('/url/', {max: 16, extraParams: [
- {name: 'a', value: 1},
- {name: 'i', value: function(){ return ++i; }},
- input
- ]
- });
- expect(url.url).toNotContain('i=1');
- expect(url.url).toNotContain('input=5');
- expect(url.evaluate()).toContain('i=1');
- expect(url.evaluate()).toContain('i=2');
- expect(url.evaluate()).toContain('input=5');
- input.set('value', 20);
- expect(url.evaluate()).toContain('input=20');
- expect(url.evaluate()).toContain('limit=16');
- });
-
- it('should just include the q parameter', function(){
- url = new Meio.Autocomplete.Data.Request.URL('/url/', {max: null});
- expect(url.url).toNotContain('undefined');
- expect(url.evaluate()).toContain('q=');
- expect(url.evaluate()).toNotContain('&');
- });
+ beforeEach(function() {
+ this.url = new Meio.Autocomplete.Data.Request.URL('/url/', {
+ max: 10, extraParams: {name: 'a', value: 1}});
+ });
+
+ it('should initialize a crude url', function(){
+ expect(this.url.url).toContain('limit=1');
+ expect(this.url.url).toContain('a=1');
+ });
+
+ it('should change the value of the url accoring to the dinamic extra params passed', function() {
+ var input = new Element('input', {name: 'input', value: 5});
+ var i = 0;
+ this.url = new Meio.Autocomplete.Data.Request.URL('/url/', {
+ max: 16,
+ extraParams: [
+ {name: 'a', value: 1},
+ {name: 'i', value: function() { return ++i; }},
+ input
+ ]
+ });
+ expect(this.url.url).toNotContain('i=1');
+ expect(this.url.url).toNotContain('input=5');
+ expect(this.url.evaluate()).toContain('i=1');
+ expect(this.url.evaluate()).toContain('i=2');
+ expect(this.url.evaluate()).toContain('input=5');
+ input.set('value', 20);
+ expect(this.url.evaluate()).toContain('input=20');
+ expect(this.url.evaluate()).toContain('limit=16');
+ });
+
+ it('should just include the q parameter', function(){
+ this.url = new Meio.Autocomplete.Data.Request.URL('/url/', {max: null});
+ expect(this.url.url).toNotContain('undefined');
+ expect(this.url.evaluate()).toContain('q=');
+ expect(this.url.evaluate()).toNotContain('&');
+ });
});
Please sign in to comment.
Something went wrong with that request. Please try again.