diff options
Diffstat (limited to 'test/background/completion/TabCompletionUseCase.test.ts')
| -rw-r--r-- | test/background/completion/TabCompletionUseCase.test.ts | 104 | 
1 files changed, 40 insertions, 64 deletions
| diff --git a/test/background/completion/TabCompletionUseCase.test.ts b/test/background/completion/TabCompletionUseCase.test.ts index 319f217..c006b65 100644 --- a/test/background/completion/TabCompletionUseCase.test.ts +++ b/test/background/completion/TabCompletionUseCase.test.ts @@ -3,8 +3,6 @@ import TabRepositoryImpl from "../../../src/background/completion/impl/TabReposi  import { Tab } from "../../../src/background/completion/TabRepository";  import TabPresenter from "../../../src/background/presenters/TabPresenter";  import TabCompletionUseCase from "../../../src/background/completion/TabCompletionUseCase"; -import sinon from "sinon"; -import { expect } from "chai";  import TabFlag from "../../../src/shared/TabFlag";  class MockTabRepository implements TabRepositoryImpl { @@ -98,43 +96,39 @@ describe("TabCompletionUseCase", () => {      tabPresenter = new MockTabPresenter();      sut = new TabCompletionUseCase(tabRepository, tabPresenter); -    sinon.stub(tabPresenter, "getLastSelectedId").returns(Promise.resolve(12)); -    sinon.stub(tabRepository, "getAllTabs").returns( -      Promise.resolve([ -        { -          id: 10, -          index: 0, -          title: "Google", -          url: "https://google.com/", -          faviconUrl: "https://google.com/favicon.ico", -          active: false, -        }, -        { -          id: 11, -          index: 1, -          title: "Yahoo", -          url: "https://yahoo.com/", -          faviconUrl: "https://yahoo.com/favicon.ico", -          active: true, -        }, -        { -          id: 12, -          index: 2, -          title: "Bing", -          url: "https://bing.com/", -          active: false, -        }, -      ]) -    ); +    jest.spyOn(tabPresenter, "getLastSelectedId").mockResolvedValue(12); +    jest.spyOn(tabRepository, "getAllTabs").mockResolvedValue([ +      { +        id: 10, +        index: 0, +        title: "Google", +        url: "https://google.com/", +        faviconUrl: "https://google.com/favicon.ico", +        active: false, +      }, +      { +        id: 11, +        index: 1, +        title: "Yahoo", +        url: "https://yahoo.com/", +        faviconUrl: "https://yahoo.com/favicon.ico", +        active: true, +      }, +      { +        id: 12, +        index: 2, +        title: "Bing", +        url: "https://bing.com/", +        active: false, +      }, +    ]);    });    describe("#queryTabs", () => {      it("returns tab items", async () => { -      sinon -        .stub(tabRepository, "queryTabs") -        .withArgs("", false) -        .returns( -          Promise.resolve([ +      jest.spyOn(tabRepository, "queryTabs").mockImplementation((keyword) => +        Promise.resolve( +          [              {                id: 10,                index: 0, @@ -158,31 +152,13 @@ describe("TabCompletionUseCase", () => {                url: "https://bing.com/",                active: false,              }, -          ]) +          ].filter( +            (item) => item.title.includes(keyword) || item.url.includes(keyword) +          )          ) -        .withArgs("oo", false) -        .returns( -          Promise.resolve([ -            { -              id: 10, -              index: 0, -              title: "Google", -              url: "https://google.com/", -              faviconUrl: "https://google.com/favicon.ico", -              active: false, -            }, -            { -              id: 11, -              index: 1, -              title: "Yahoo", -              url: "https://yahoo.com/", -              faviconUrl: "https://yahoo.com/favicon.ico", -              active: true, -            }, -          ]) -        ); +      ); -      expect(await sut.queryTabs("", false)).to.deep.equal([ +      expect(await sut.queryTabs("", false)).toEqual([          {            index: 1,            title: "Google", @@ -206,7 +182,7 @@ describe("TabCompletionUseCase", () => {          },        ]); -      expect(await sut.queryTabs("oo", false)).to.deep.equal([ +      expect(await sut.queryTabs("oo", false)).toEqual([          {            index: 1,            title: "Google", @@ -225,7 +201,7 @@ describe("TabCompletionUseCase", () => {      });      it("returns a tab by the index", async () => { -      expect(await sut.queryTabs("1", false)).to.deep.equal([ +      expect(await sut.queryTabs("1", false)).toEqual([          {            index: 1,            title: "Google", @@ -235,12 +211,12 @@ describe("TabCompletionUseCase", () => {          },        ]); -      expect(await sut.queryTabs("10", false)).to.be.empty; -      expect(await sut.queryTabs("-1", false)).to.be.empty; +      expect(await sut.queryTabs("10", false)).toHaveLength(0); +      expect(await sut.queryTabs("-1", false)).toHaveLength(0);      });      it("returns the current tab by % flag", async () => { -      expect(await sut.queryTabs("%", false)).to.deep.equal([ +      expect(await sut.queryTabs("%", false)).toEqual([          {            index: 2,            title: "Yahoo", @@ -252,7 +228,7 @@ describe("TabCompletionUseCase", () => {      });      it("returns the current tab by # flag", async () => { -      expect(await sut.queryTabs("#", false)).to.deep.equal([ +      expect(await sut.queryTabs("#", false)).toEqual([          {            index: 3,            title: "Bing", | 
