Skip to content

Commit 7cb65d8

Browse files
committed
Add more unit tests and minor adjustments.
1 parent 2aa11fb commit 7cb65d8

File tree

2 files changed

+234
-2
lines changed

2 files changed

+234
-2
lines changed

specs/chrome/common-spec.js

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,3 +632,235 @@ describe('common.isEffective', function() {
632632
expect(common.isEffective({ key: 'value' })).toBeTruthy();
633633
});
634634
});
635+
636+
describe('common.setDefaultValues', function() {
637+
it('should set root hash', function() {
638+
expect({}.toString.call(common.setDefaultValues())).toEqual('[object Object]');
639+
});
640+
641+
it('should set attributes hash', function() {
642+
expect({}.toString.call(common.setDefaultValues().attributes)).toEqual('[object Object]');
643+
});
644+
645+
it('should set attributes letter to camel case', function() {
646+
expect(common.setDefaultValues().attributes.letter).toEqual(LETTERS.CAMEL);
647+
});
648+
649+
it('should set attributes letter to input value', function() {
650+
expect(common.setDefaultValues({ attributes: { letter: LETTERS.NATURAL } }).
651+
attributes.letter).not.toEqual(LETTERS.CAMEL);
652+
});
653+
654+
it('should set attributes indent to false', function() {
655+
expect(common.setDefaultValues().attributes.indent).toBeFalsy();
656+
});
657+
658+
it('should set attributes indent to input value', function() {
659+
expect(common.setDefaultValues({ attributes: { indent: true } }).
660+
attributes.indent).toBeTruthy();
661+
});
662+
663+
it('should set attributes separator to breakline', function() {
664+
expect(common.setDefaultValues().attributes.separator).toEqual('\n');
665+
});
666+
667+
it('should set attributes separator to input value', function() {
668+
expect(common.setDefaultValues({ attributes: { separator: 'a' } }).
669+
attributes.separator).toEqual('a');
670+
});
671+
672+
it('should set copyright hash', function() {
673+
expect({}.toString.call(common.setDefaultValues().copyright)).toEqual('[object Object]');
674+
});
675+
676+
it('should set copyright claimant to empty string', function() {
677+
expect(common.setDefaultValues().copyright.claimant).toEqual('');
678+
});
679+
680+
it('should set copyright claimant to input value', function() {
681+
expect(common.setDefaultValues({ copyright: { claimant: 'a' } }).
682+
copyright.claimant).toEqual('a');
683+
});
684+
685+
it('should set copyright year to this year', function() {
686+
expect(common.setDefaultValues().copyright.year).toEqual(new Date().getFullYear());
687+
});
688+
689+
it('should set copyright year to input value', function() {
690+
expect(common.setDefaultValues({ copyright: { year: 3000 } }).
691+
copyright.year).toEqual(3000);
692+
});
693+
694+
it('should set fill hash', function() {
695+
expect({}.toString.call(common.setDefaultValues().fill)).toEqual('[object Object]');
696+
});
697+
698+
it('should set fill separator to empty string', function() {
699+
expect(common.setDefaultValues().fill.separator).toEqual('');
700+
});
701+
702+
it('should set fill separator to input value', function() {
703+
expect(common.setDefaultValues({ fill: { separator: 'a' } }).
704+
fill.separator).toEqual('a');
705+
});
706+
707+
it('should set model hash', function() {
708+
expect({}.toString.call(common.setDefaultValues().model)).toEqual('[object Object]');
709+
});
710+
711+
it('should set model include to false', function() {
712+
expect(common.setDefaultValues().model.include).toBeFalsy();
713+
});
714+
715+
it('should set model include to input value', function() {
716+
expect(common.setDefaultValues({ model: { include: true } }).
717+
model.include).toBeTruthy();
718+
});
719+
720+
it('should set model name to empty string', function() {
721+
expect(common.setDefaultValues().model.name).toEqual('');
722+
});
723+
724+
it('should set model name to input value', function() {
725+
expect(common.setDefaultValues({ model: { name: 'a' } }).
726+
model.name).toEqual('a');
727+
});
728+
729+
it('should set model namespace to empty string', function() {
730+
expect(common.setDefaultValues().model.namespace).toEqual('');
731+
});
732+
733+
it('should set model namespace to input value', function() {
734+
expect(common.setDefaultValues({ model: { namespace: 'a' } }).
735+
model.namespace).toEqual('a');
736+
});
737+
738+
it('should set model target to empty string', function() {
739+
expect(common.setDefaultValues().model.target).toEqual('');
740+
});
741+
742+
it('should set model target to input value', function() {
743+
expect(common.setDefaultValues({ model: { target: 'a' } }).
744+
model.target).toEqual('a');
745+
});
746+
747+
it('should set nodes hash', function() {
748+
expect({}.toString.call(common.setDefaultValues().model)).toEqual('[object Object]');
749+
});
750+
751+
it('should set nodes angular to false', function() {
752+
expect(common.setDefaultValues().nodes.angular).toBeFalsy();
753+
});
754+
755+
it('should set nodes angular to input value', function() {
756+
expect(common.setDefaultValues({ nodes: { angular: true } }).
757+
nodes.angular).toBeTruthy();
758+
});
759+
760+
it('should set nodes root to default value', function() {
761+
expect(common.setDefaultValues().nodes.root).toEqual('body');
762+
});
763+
764+
it('should set nodes root to input value', function() {
765+
expect(common.setDefaultValues({ nodes: { root: 'a' } }).
766+
nodes.root).toEqual('a');
767+
});
768+
769+
it('should set nodes selector to default value', function() {
770+
expect(common.setDefaultValues().nodes.selector).toEqual('a,button,input,select,textarea');
771+
});
772+
773+
it('should set nodes selector to input value', function() {
774+
expect(common.setDefaultValues({ nodes: { selector: 'a' } }).
775+
nodes.selector).toEqual('a');
776+
});
777+
778+
it('should set nodes visibility to all', function() {
779+
expect(common.setDefaultValues().nodes.visibility).toEqual(VISIBILITIES.ALL);
780+
});
781+
782+
it('should set nodes visibility to input value', function() {
783+
expect(common.setDefaultValues({ nodes: { visiblity: VISIBILITIES.HIDDEN } }).
784+
nodes.visibility).not.toEqual(VISIBILITIES.ALL);
785+
});
786+
787+
it('should set operations hash', function() {
788+
expect({}.toString.call(common.setDefaultValues().operations)).toEqual('[object Object]');
789+
});
790+
791+
it('should set operations extras hash', function() {
792+
expect({}.toString.call(common.setDefaultValues().operations.extras)).
793+
toEqual('[object Object]');
794+
});
795+
796+
it('should set operation extras fill to default value', function() {
797+
expect(common.setDefaultValues().operations.extras.fill).toEqual(1);
798+
});
799+
800+
it('should set operations extras fill to input value', function() {
801+
expect(common.setDefaultValues({ operations: { extras: { fill: 0 } } }).
802+
operations.extras.fill).toEqual(0);
803+
});
804+
805+
it('should set operation extras fill.submit to default value', function() {
806+
expect(common.setDefaultValues().operations.extras['fill.submit']).toEqual(1);
807+
});
808+
809+
it('should set operations extras fill.submit to input value', function() {
810+
expect(common.setDefaultValues({ operations: { extras: { 'fill.submit': 0 } } }).
811+
operations.extras['fill.submit']).toEqual(0);
812+
});
813+
814+
it('should set operation extras submit to default value', function() {
815+
expect(common.setDefaultValues().operations.extras.submit).toEqual(1);
816+
});
817+
818+
it('should set operations extras submit to input value', function() {
819+
expect(common.setDefaultValues({ operations: { extras: { submit: 0 } } }).
820+
operations.extras.submit).toEqual(0);
821+
});
822+
823+
it('should set operation extras verify.loaded to default value', function() {
824+
expect(common.setDefaultValues().operations.extras['verify.loaded']).toEqual(1);
825+
});
826+
827+
it('should set operations extras verify.loaded to input value', function() {
828+
expect(common.setDefaultValues({ operations: { extras: { 'verify.loaded': 0 } } }).
829+
operations.extras['verify.loaded']).toEqual(0);
830+
});
831+
832+
it('should set operation extras verify.url to default value', function() {
833+
expect(common.setDefaultValues().operations.extras['verify.url']).toEqual(1);
834+
});
835+
836+
it('should set operations extras verify.url to input value', function() {
837+
expect(common.setDefaultValues({ operations: { extras: { 'verify.url': 0 } } }).
838+
operations.extras['verify.url']).toEqual(0);
839+
});
840+
841+
it('should set operations letter to camel case', function() {
842+
expect(common.setDefaultValues().operations.letter).toEqual(LETTERS.CAMEL);
843+
});
844+
845+
it('should set operations letter to input value', function() {
846+
expect(common.setDefaultValues({ operations: { letter: LETTERS.NATURAL } }).
847+
operations.letter).not.toEqual(LETTERS.CAMEL);
848+
});
849+
850+
it('should set operations separator to breakline', function() {
851+
expect(common.setDefaultValues().operations.separator).toEqual('\n');
852+
});
853+
854+
it('should set operations separator to input value', function() {
855+
expect(common.setDefaultValues({ operations: { separator: 'a' } }).
856+
operations.separator).toEqual('a');
857+
});
858+
859+
it('should set timeout to default value', function() {
860+
expect(common.setDefaultValues().timeout).toEqual(15);
861+
});
862+
863+
it('should set timeout to input value', function() {
864+
expect(common.setDefaultValues({ timeout: 10000 }).timeout).toEqual(10000);
865+
});
866+
});

src/chrome/assets/js/common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var LETTERS = { LOWER: 2, CAMEL: 3, NATURAL: 4, PROPER: 5, UPPER: 6 };
2-
var VISIBILITIES = { HIDDEN: 1, VISIBLE: 2, ALL: 3 };
1+
window.LETTERS = { LOWER: 2, CAMEL: 3, NATURAL: 4, PROPER: 5, UPPER: 6 };
2+
window.VISIBILITIES = { HIDDEN: 1, VISIBLE: 2, ALL: 3 };
33

44
/**
55
* Faster array filtration based on predicate function.

0 commit comments

Comments
 (0)