diff options
-rw-r--r-- | test/static/filterContainsSpec.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/static/filterContainsSpec.js b/test/static/filterContainsSpec.js new file mode 100644 index 0000000..f6db514 --- /dev/null +++ b/test/static/filterContainsSpec.js @@ -0,0 +1,60 @@ +describe("Awesomplete.FILTER_CONTAINS", function () { + + subject(function () { return Awesomplete.FILTER_CONTAINS }); + + it("is a function", function () { + expect(this.subject).toEqual(jasmine.any(Function)); + }); + + describe("search in a plain string", function () { + it("matches at the start", function () { + expect(this.subject("Hello world", "Hello")).toBe(true); + }); + + it("matches in the middle", function () { + expect(this.subject("Ticket to the moon", "to the")).toBe(true); + }); + + it("matches at the end", function () { + expect(this.subject("This is the end", "end")).toBe(true); + }); + + it("performs case insensitive match", function () { + expect(this.subject("Hey You", "HEY YOU")).toBe(true); + }); + + it("ignores whitespaces around the search value", function () { + expect(this.subject("Watch this", " Watch ")).toBe(true); + }); + + it("does not match if substring is not found", function () { + expect(this.subject("No", "way")).toBe(false); + }); + }); + + describe("search in string with special RegExp chars", function () { + it("matches at the start", function () { + expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", "[^j(a)v?a-")).toBe(true); + }); + + it("matches in the middle", function () { + expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", "sc|ri\\p+t*")).toBe(true); + }); + + it("matches at the end", function () { + expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", "{.$}")).toBe(true); + }); + + it("performs case insensitive match", function () { + expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", "[^J(A)V?A-SC|RI\\P+T*]{.$}")).toBe(true); + }); + + it("ignores whitespaces around the search value", function () { + expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", " [^j(a)v?a- ")).toBe(true); + }); + + it("does not match if substring is not found", function () { + expect(this.subject("[^j(a)v?a-sc|ri\\p+t*]{.$}", "no way")).toBe(false); + }); + }); +}); |