summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/reducers/tests/quick-open.spec.js
blob: cd91b040bec7381ab28d890510fe823a46119d8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

import update, { initialQuickOpenState } from "../quick-open";
import {
  getQuickOpenEnabled,
  getQuickOpenQuery,
  getQuickOpenType,
} from "../../selectors/quick-open";
import {
  setQuickOpenQuery,
  openQuickOpen,
  closeQuickOpen,
} from "../../actions/quick-open";

describe("quickOpen reducer", () => {
  test("initial state", () => {
    const state = update(undefined, { type: "FAKE" });
    expect(getQuickOpenQuery({ quickOpen: state })).toEqual("");
    expect(getQuickOpenType({ quickOpen: state })).toEqual("sources");
  });

  test("opens the quickOpen modal", () => {
    const state = update(initialQuickOpenState(), openQuickOpen());
    expect(getQuickOpenEnabled({ quickOpen: state })).toEqual(true);
  });

  test("closes the quickOpen modal", () => {
    let state = update(initialQuickOpenState(), openQuickOpen());
    expect(getQuickOpenEnabled({ quickOpen: state })).toEqual(true);
    state = update(initialQuickOpenState(), closeQuickOpen());
    expect(getQuickOpenEnabled({ quickOpen: state })).toEqual(false);
  });

  test("leaves query alone on open if not provided", () => {
    const state = update(initialQuickOpenState(), openQuickOpen());
    expect(getQuickOpenQuery({ quickOpen: state })).toEqual("");
    expect(getQuickOpenType({ quickOpen: state })).toEqual("sources");
  });

  test("set query on open if provided", () => {
    const state = update(initialQuickOpenState(), openQuickOpen("@"));
    expect(getQuickOpenQuery({ quickOpen: state })).toEqual("@");
    expect(getQuickOpenType({ quickOpen: state })).toEqual("functions");
  });

  test("clear query on close", () => {
    const state = update(initialQuickOpenState(), closeQuickOpen());
    expect(getQuickOpenQuery({ quickOpen: state })).toEqual("");
    expect(getQuickOpenType({ quickOpen: state })).toEqual("sources");
  });

  test("sets the query to the provided string", () => {
    const state = update(initialQuickOpenState(), setQuickOpenQuery("test"));
    expect(getQuickOpenQuery({ quickOpen: state })).toEqual("test");
    expect(getQuickOpenType({ quickOpen: state })).toEqual("sources");
  });
});