diff options
Diffstat (limited to 'test/shared/settings')
-rw-r--r-- | test/shared/settings/Blacklist.test.ts | 83 | ||||
-rw-r--r-- | test/shared/settings/Key.test.ts | 95 | ||||
-rw-r--r-- | test/shared/settings/Keymaps.test.ts | 13 | ||||
-rw-r--r-- | test/shared/settings/Properties.test.ts | 5 | ||||
-rw-r--r-- | test/shared/settings/Search.test.ts | 15 | ||||
-rw-r--r-- | test/shared/settings/Settings.test.ts | 15 |
6 files changed, 110 insertions, 116 deletions
diff --git a/test/shared/settings/Blacklist.test.ts b/test/shared/settings/Blacklist.test.ts index 1ccb32a..af7b946 100644 --- a/test/shared/settings/Blacklist.test.ts +++ b/test/shared/settings/Blacklist.test.ts @@ -1,15 +1,14 @@ import Blacklist, { BlacklistItem, } from "../../../src/shared/settings/Blacklist"; -import { expect } from "chai"; import Key from "../../../src/shared/settings/Key"; describe("BlacklistItem", () => { describe("#fromJSON", () => { it("parses string pattern", () => { const item = BlacklistItem.fromJSON("example.com"); - expect(item.pattern).to.equal("example.com"); - expect(item.partial).to.be.false; + expect(item.pattern).toEqual("example.com"); + expect(item.partial).toBeFalsy; }); it("parses partial blacklist item", () => { @@ -17,56 +16,56 @@ describe("BlacklistItem", () => { url: "example.com", keys: ["j", "k"], }); - expect(item.pattern).to.equal("example.com"); - expect(item.partial).to.be.true; - expect(item.keys).to.deep.equal(["j", "k"]); + expect(item.pattern).toEqual("example.com"); + expect(item.partial).toBeTruthy; + expect(item.keys).toEqual(["j", "k"]); }); }); describe("#matches", () => { it('matches by "*"', () => { const item = BlacklistItem.fromJSON("*"); - expect(item.matches(new URL("https://github.com/abc"))).to.be.true; + expect(item.matches(new URL("https://github.com/abc"))).toBeTruthy; }); it("matches by hostname", () => { const item = BlacklistItem.fromJSON("github.com"); - expect(item.matches(new URL("https://github.com"))).to.be.true; - expect(item.matches(new URL("https://gist.github.com"))).to.be.false; - expect(item.matches(new URL("https://github.com/ueokande"))).to.be.true; - expect(item.matches(new URL("https://github.org"))).to.be.false; - expect(item.matches(new URL("https://google.com/search?q=github.org"))).to - .be.false; + expect(item.matches(new URL("https://github.com"))).toBeTruthy; + expect(item.matches(new URL("https://gist.github.com"))).toBeFalsy; + expect(item.matches(new URL("https://github.com/ueokande"))).toBeTruthy; + expect(item.matches(new URL("https://github.org"))).toBeFalsy; + expect(item.matches(new URL("https://google.com/search?q=github.org"))) + .toBeFalsy; }); it("matches by hostname with wildcard", () => { const item = BlacklistItem.fromJSON("*.github.com"); - expect(item.matches(new URL("https://github.com"))).to.be.false; - expect(item.matches(new URL("https://gist.github.com"))).to.be.true; + expect(item.matches(new URL("https://github.com"))).toBeFalsy; + expect(item.matches(new URL("https://gist.github.com"))).toBeTruthy; }); it("matches by path", () => { const item = BlacklistItem.fromJSON("github.com/abc"); - expect(item.matches(new URL("https://github.com/abc"))).to.be.true; - expect(item.matches(new URL("https://github.com/abcdef"))).to.be.false; - expect(item.matches(new URL("https://gist.github.com/abc"))).to.be.false; + expect(item.matches(new URL("https://github.com/abc"))).toBeTruthy; + expect(item.matches(new URL("https://github.com/abcdef"))).toBeFalsy; + expect(item.matches(new URL("https://gist.github.com/abc"))).toBeFalsy; }); it("matches by path with wildcard", () => { const item = BlacklistItem.fromJSON("github.com/abc*"); - expect(item.matches(new URL("https://github.com/abc"))).to.be.true; - expect(item.matches(new URL("https://github.com/abcdef"))).to.be.true; - expect(item.matches(new URL("https://gist.github.com/abc"))).to.be.false; + expect(item.matches(new URL("https://github.com/abc"))).toBeTruthy; + expect(item.matches(new URL("https://github.com/abcdef"))).toBeTruthy; + expect(item.matches(new URL("https://gist.github.com/abc"))).toBeFalsy; }); it("matches address and port", () => { const item = BlacklistItem.fromJSON("127.0.0.1:8888"); - expect(item.matches(new URL("http://127.0.0.1:8888/"))).to.be.true; - expect(item.matches(new URL("http://127.0.0.1:8888/hello"))).to.be.true; + expect(item.matches(new URL("http://127.0.0.1:8888/"))).toBeTruthy; + expect(item.matches(new URL("http://127.0.0.1:8888/hello"))).toBeTruthy; }); it("matches with partial blacklist", () => { @@ -75,8 +74,8 @@ describe("BlacklistItem", () => { keys: ["j", "k"], }); - expect(item.matches(new URL("https://google.com"))).to.be.true; - expect(item.matches(new URL("https://yahoo.com"))).to.be.false; + expect(item.matches(new URL("https://google.com"))).toBeTruthy; + expect(item.matches(new URL("https://yahoo.com"))).toBeFalsy; }); }); @@ -89,22 +88,22 @@ describe("BlacklistItem", () => { expect( item.includeKey(new URL("http://google.com/maps"), Key.fromMapKey("j")) - ).to.be.true; + ).toBeTruthy; expect( item.includeKey( new URL("http://google.com/maps"), Key.fromMapKey("<C-U>") ) - ).to.be.true; + ).toBeTruthy; expect( item.includeKey(new URL("http://google.com/maps"), Key.fromMapKey("z")) - ).to.be.false; + ).toBeFalsy; expect( item.includeKey(new URL("http://google.com/maps"), Key.fromMapKey("u")) - ).to.be.false; + ).toBeFalsy; expect( item.includeKey(new URL("http://maps.google.com/"), Key.fromMapKey("j")) - ).to.be.false; + ).toBeFalsy; }); }); }); @@ -113,7 +112,7 @@ describe("Blacklist", () => { describe("#fromJSON", () => { it("parses string list", () => { const blacklist = Blacklist.fromJSON(["example.com", "example.org"]); - expect(blacklist.toJSON()).to.deep.equals(["example.com", "example.org"]); + expect(blacklist.toJSON()).toEqual(["example.com", "example.org"]); }); it("parses mixed blacklist", () => { @@ -121,7 +120,7 @@ describe("Blacklist", () => { { url: "example.com", keys: ["j", "k"] }, "example.org", ]); - expect(blacklist.toJSON()).to.deep.equals([ + expect(blacklist.toJSON()).toEqual([ { url: "example.com", keys: ["j", "k"] }, "example.org", ]); @@ -129,7 +128,7 @@ describe("Blacklist", () => { it("parses empty blacklist", () => { const blacklist = Blacklist.fromJSON([]); - expect(blacklist.toJSON()).to.deep.equals([]); + expect(blacklist.toJSON()).toEqual([]); }); }); @@ -137,12 +136,12 @@ describe("Blacklist", () => { it("matches a url with entire blacklist", () => { const blacklist = Blacklist.fromJSON(["google.com", "*.github.com"]); expect(blacklist.includesEntireBlacklist(new URL("https://google.com"))) - .to.be.true; + .toBeTruthy; expect(blacklist.includesEntireBlacklist(new URL("https://github.com"))) - .to.be.false; + .toBeFalsy; expect( blacklist.includesEntireBlacklist(new URL("https://gist.github.com")) - ).to.be.true; + ).toBeTruthy; }); it("does not matches with partial blacklist", () => { @@ -151,9 +150,9 @@ describe("Blacklist", () => { { url: "yahoo.com", keys: ["j", "k"] }, ]); expect(blacklist.includesEntireBlacklist(new URL("https://google.com"))) - .to.be.true; - expect(blacklist.includesEntireBlacklist(new URL("https://yahoo.com"))).to - .be.false; + .toBeTruthy; + expect(blacklist.includesEntireBlacklist(new URL("https://yahoo.com"))) + .toBeFalsy; }); }); @@ -166,13 +165,13 @@ describe("Blacklist", () => { expect( blacklist.includeKey(new URL("https://google.com"), Key.fromMapKey("j")) - ).to.be.false; + ).toBeFalsy; expect( blacklist.includeKey(new URL("https://github.com"), Key.fromMapKey("j")) - ).to.be.true; + ).toBeTruthy; expect( blacklist.includeKey(new URL("https://github.com"), Key.fromMapKey("a")) - ).to.be.false; + ).toBeFalsy; }); }); }); diff --git a/test/shared/settings/Key.test.ts b/test/shared/settings/Key.test.ts index 47af1d9..8ad9265 100644 --- a/test/shared/settings/Key.test.ts +++ b/test/shared/settings/Key.test.ts @@ -1,89 +1,88 @@ -import { expect } from "chai"; import Key from "../../../src/shared/settings/Key"; describe("Key", () => { describe("fromMapKey", () => { it("return for X", () => { const key = Key.fromMapKey("x"); - expect(key.key).to.equal("x"); - expect(key.shift).to.be.false; - expect(key.ctrl).to.be.false; - expect(key.alt).to.be.false; - expect(key.meta).to.be.false; + expect(key.key).toEqual("x"); + expect(key.shift).toBeFalsy; + expect(key.ctrl).toBeFalsy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeFalsy; }); it("return for Shift+X", () => { const key = Key.fromMapKey("X"); - expect(key.key).to.equal("X"); - expect(key.shift).to.be.true; - expect(key.ctrl).to.be.false; - expect(key.alt).to.be.false; - expect(key.meta).to.be.false; + expect(key.key).toEqual("X"); + expect(key.shift).toBeTruthy; + expect(key.ctrl).toBeFalsy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeFalsy; }); it("return for Ctrl+X", () => { const key = Key.fromMapKey("<C-X>"); - expect(key.key).to.equal("x"); - expect(key.shift).to.be.false; - expect(key.ctrl).to.be.true; - expect(key.alt).to.be.false; - expect(key.meta).to.be.false; + expect(key.key).toEqual("x"); + expect(key.shift).toBeFalsy; + expect(key.ctrl).toBeTruthy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeFalsy; }); it("returns for Ctrl+Meta+X", () => { const key = Key.fromMapKey("<C-M-X>"); - expect(key.key).to.equal("x"); - expect(key.shift).to.be.false; - expect(key.ctrl).to.be.true; - expect(key.alt).to.be.false; - expect(key.meta).to.be.true; + expect(key.key).toEqual("x"); + expect(key.shift).toBeFalsy; + expect(key.ctrl).toBeTruthy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeTruthy; }); it("returns for Ctrl+Shift+x", () => { const key = Key.fromMapKey("<C-S-x>"); - expect(key.key).to.equal("X"); - expect(key.shift).to.be.true; - expect(key.ctrl).to.be.true; - expect(key.alt).to.be.false; - expect(key.meta).to.be.false; + expect(key.key).toEqual("X"); + expect(key.shift).toBeTruthy; + expect(key.ctrl).toBeTruthy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeFalsy; }); it("returns for Shift+Esc", () => { const key = Key.fromMapKey("<S-Esc>"); - expect(key.key).to.equal("Esc"); - expect(key.shift).to.be.true; - expect(key.ctrl).to.be.false; - expect(key.alt).to.be.false; - expect(key.meta).to.be.false; + expect(key.key).toEqual("Esc"); + expect(key.shift).toBeTruthy; + expect(key.ctrl).toBeFalsy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeFalsy; }); it("returns for Ctrl+Esc", () => { const key = Key.fromMapKey("<C-Esc>"); - expect(key.key).to.equal("Esc"); - expect(key.shift).to.be.false; - expect(key.ctrl).to.be.true; - expect(key.alt).to.be.false; - expect(key.meta).to.be.false; + expect(key.key).toEqual("Esc"); + expect(key.shift).toBeFalsy; + expect(key.ctrl).toBeTruthy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeFalsy; }); it("returns for Ctrl+Esc", () => { const key = Key.fromMapKey("<C-Space>"); - expect(key.key).to.equal("Space"); - expect(key.shift).to.be.false; - expect(key.ctrl).to.be.true; - expect(key.alt).to.be.false; - expect(key.meta).to.be.false; + expect(key.key).toEqual("Space"); + expect(key.shift).toBeFalsy; + expect(key.ctrl).toBeTruthy; + expect(key.alt).toBeFalsy; + expect(key.meta).toBeFalsy; }); }); describe("idDigit", () => { it("returns true if the key is a digit", () => { - expect(new Key({ key: "0" }).isDigit()).to.be.true; - expect(new Key({ key: "9" }).isDigit()).to.be.true; - expect(new Key({ key: "9", alt: true }).isDigit()).to.be.false; + expect(new Key({ key: "0" }).isDigit()).toBeTruthy; + expect(new Key({ key: "9" }).isDigit()).toBeTruthy; + expect(new Key({ key: "9", alt: true }).isDigit()).toBeFalsy; - expect(new Key({ key: "a" }).isDigit()).to.be.false; - expect(new Key({ key: "0" }).isDigit()).to.be.false; + expect(new Key({ key: "a" }).isDigit()).toBeFalsy; + expect(new Key({ key: "0" }).isDigit()).toBeFalsy; }); }); @@ -105,7 +104,7 @@ describe("Key", () => { meta: false, }) ) - ).to.be.true; + ).toBeTruthy; expect( new Key({ @@ -123,7 +122,7 @@ describe("Key", () => { meta: false, }) ) - ).to.be.false; + ).toBeFalsy; }); }); }); diff --git a/test/shared/settings/Keymaps.test.ts b/test/shared/settings/Keymaps.test.ts index 264684d..850e327 100644 --- a/test/shared/settings/Keymaps.test.ts +++ b/test/shared/settings/Keymaps.test.ts @@ -1,11 +1,10 @@ import Keymaps from "../../../src/shared/settings/Keymaps"; -import { expect } from "chai"; describe("Keymaps", () => { describe("#valueOf", () => { it("returns empty object by empty settings", () => { const keymaps = Keymaps.fromJSON({}).toJSON(); - expect(keymaps).to.be.empty; + expect(keymaps).toEqual({}); }); it("returns keymaps by valid settings", () => { @@ -14,11 +13,11 @@ describe("Keymaps", () => { j: { type: "scroll.vertically", count: 1 }, }).toJSON(); - expect(keymaps["k"]).to.deep.equal({ + expect(keymaps["k"]).toEqual({ type: "scroll.vertically", count: -1, }); - expect(keymaps["j"]).to.deep.equal({ + expect(keymaps["j"]).toEqual({ type: "scroll.vertically", count: 1, }); @@ -29,7 +28,7 @@ describe("Keymaps", () => { Keymaps.fromJSON({ k: { type: "invalid.operation" }, }) - ).to.throw(TypeError); + ).toThrow(TypeError); }); }); @@ -48,7 +47,7 @@ describe("Keymaps", () => { const entries = keymaps .entries() .sort(([name1], [name2]) => name1.localeCompare(name2)); - expect(entries).deep.equals([ + expect(entries).toEqual([ ["j", { type: "scroll.vertically", count: 1 }], ["k", { type: "scroll.vertically", count: -1 }], ["n", { type: "find.next" }], @@ -70,7 +69,7 @@ describe("Keymaps", () => { const entries = keymaps .entries() .sort(([name1], [name2]) => name1.localeCompare(name2)); - expect(entries).deep.equals([ + expect(entries).toEqual([ ["j", { type: "find.prev" }], ["k", { type: "scroll.vertically", count: -1 }], ["n", { type: "find.next" }], diff --git a/test/shared/settings/Properties.test.ts b/test/shared/settings/Properties.test.ts index 647cb1c..1161b48 100644 --- a/test/shared/settings/Properties.test.ts +++ b/test/shared/settings/Properties.test.ts @@ -1,12 +1,11 @@ import Properties from "../../../src/shared/settings/Properties"; -import { expect } from "chai"; import ColorScheme from "../../../src/shared/ColorScheme"; describe("Properties", () => { describe("#propertiesValueOf", () => { it("returns with default properties by empty settings", () => { const props = Properties.fromJSON({}); - expect(props).to.deep.equal({ + expect(props).toEqual({ hintchars: "abcdefghijklmnopqrstuvwxyz", smoothscroll: false, complete: "sbh", @@ -22,7 +21,7 @@ describe("Properties", () => { colorscheme: ColorScheme.System, }); - expect(props).to.deep.equal({ + expect(props).toEqual({ hintchars: "abcdefgh", smoothscroll: false, complete: "sbh", diff --git a/test/shared/settings/Search.test.ts b/test/shared/settings/Search.test.ts index 1feb14b..5d2f8d5 100644 --- a/test/shared/settings/Search.test.ts +++ b/test/shared/settings/Search.test.ts @@ -1,5 +1,4 @@ import Search from "../../../src/shared/settings/Search"; -import { expect } from "chai"; describe("Search", () => { it("returns search settings by valid settings", () => { @@ -11,12 +10,12 @@ describe("Search", () => { }, }); - expect(search.defaultEngine).to.equal("google"); - expect(search.engines).to.deep.equals({ + expect(search.defaultEngine).toEqual("google"); + expect(search.engines).toEqual({ google: "https://google.com/search?q={}", yahoo: "https://search.yahoo.com/search?p={}", }); - expect(search.toJSON()).to.deep.equal({ + expect(search.toJSON()).toEqual({ default: "google", engines: { google: "https://google.com/search?q={}", @@ -34,7 +33,7 @@ describe("Search", () => { yahoo: "https://search.yahoo.com/search?p={}", }, }) - ).to.throw(TypeError); + ).toThrow(TypeError); expect(() => Search.fromJSON({ default: "g o o g l e", @@ -42,7 +41,7 @@ describe("Search", () => { "g o o g l e": "https://google.com/search?q={}", }, }) - ).to.throw(TypeError); + ).toThrow(TypeError); expect(() => Search.fromJSON({ default: "google", @@ -50,7 +49,7 @@ describe("Search", () => { google: "https://google.com/search", }, }) - ).to.throw(TypeError); + ).toThrow(TypeError); expect(() => Search.fromJSON({ default: "google", @@ -58,6 +57,6 @@ describe("Search", () => { google: "https://google.com/search?q={}&r={}", }, }) - ).to.throw(TypeError); + ).toThrow(TypeError); }); }); diff --git a/test/shared/settings/Settings.test.ts b/test/shared/settings/Settings.test.ts index 951c9cd..49a5d0b 100644 --- a/test/shared/settings/Settings.test.ts +++ b/test/shared/settings/Settings.test.ts @@ -1,5 +1,4 @@ import Settings from "../../../src/shared/settings/Settings"; -import { expect } from "chai"; describe("Settings", () => { describe("#valueOf", () => { @@ -21,7 +20,7 @@ describe("Settings", () => { search: x.search.toJSON(), properties: x.properties.toJSON(), blacklist: x.blacklist.toJSON(), - }).to.deep.equal({ + }).toEqual({ keymaps: {}, search: { default: "google", @@ -41,15 +40,15 @@ describe("Settings", () => { it("sets default settings", () => { const value = Settings.fromJSON({}); - expect(value.keymaps.toJSON()).to.not.be.empty; - expect(value.properties.toJSON()).to.not.be.empty; - expect(value.search.defaultEngine).to.be.a("string"); - expect(value.search.engines).to.be.an("object"); - expect(value.blacklist.toJSON()).to.be.empty; + expect(value.keymaps.toJSON()).not.toEqual({}); + expect(value.properties.toJSON()).not.toEqual({}); + expect(typeof value.search.defaultEngine).toEqual("string"); + expect(typeof value.search.engines).toEqual("object"); + expect(value.blacklist.toJSON()).toHaveLength(0); }); it("throws a TypeError with an unknown field", () => { - expect(() => Settings.fromJSON({ name: "alice" })).to.throw(TypeError); + expect(() => Settings.fromJSON({ name: "alice" })).toThrow(TypeError); }); }); }); |