summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/actions/tests/setProjectDirectoryRoot.spec.js
blob: b8d2fb2906eb00661e81ad9b40eebad6fd1fbaea (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* 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/>. */

// @flow

import {
  createStore,
  selectors,
  actions,
  makeSource,
} from "../../utils/test-head";

const {
  getProjectDirectoryRoot,
  getProjectDirectoryRootName,
  getDisplayedSources,
} = selectors;

describe("setProjectDirectoryRoot", () => {
  it("should set domain directory as root", async () => {
    const { dispatch, getState, cx } = createStore();
    dispatch(actions.setProjectDirectoryRoot(cx, "example.com", "foo"));
    expect(getProjectDirectoryRoot(getState())).toBe("example.com");
  });

  it("should set a directory as root directory", async () => {
    const { dispatch, getState, cx } = createStore();
    dispatch(actions.setProjectDirectoryRoot(cx, "/example.com/foo", "foo"));
    expect(getProjectDirectoryRoot(getState())).toBe("/example.com/foo");
  });

  it("should add to the directory ", () => {
    const { dispatch, getState, cx } = createStore();
    dispatch(actions.setProjectDirectoryRoot(cx, "/example.com/foo", "foo"));
    dispatch(actions.setProjectDirectoryRoot(cx, "/foo/bar", "foo"));
    expect(getProjectDirectoryRoot(getState())).toBe("/example.com/foo/bar");
  });

  it("should update the directory ", () => {
    const { dispatch, getState, cx } = createStore();
    dispatch(actions.setProjectDirectoryRoot(cx, "/example.com/foo", "foo"));
    dispatch(actions.clearProjectDirectoryRoot(cx));
    dispatch(actions.setProjectDirectoryRoot(cx, "/example.com/bar", "foo"));
    expect(getProjectDirectoryRoot(getState())).toBe("/example.com/bar");
  });

  it("should filter sources", async () => {
    const store = createStore({
      getSourceActorBreakableLines: async () => [],
    });
    const { dispatch, getState, cx } = store;
    await dispatch(actions.newGeneratedSource(makeSource("js/scopes.js")));
    await dispatch(actions.newGeneratedSource(makeSource("lib/vendor.js")));

    dispatch(
      actions.setProjectDirectoryRoot(cx, "localhost:8000/examples/js", "foo")
    );

    const filteredSourcesByThread = getDisplayedSources(getState());
    const filteredSources = (Object.values(
      filteredSourcesByThread.FakeThread
    ): any)[0];

    expect(filteredSources.url).toEqual(
      "http://localhost:8000/examples/js/scopes.js"
    );

    expect(filteredSources.relativeUrl).toEqual("scopes.js");
  });

  it("should update the child directory ", () => {
    const { dispatch, getState, cx } = createStore({
      getSourceActorBreakableLines: async () => [],
    });
    dispatch(actions.setProjectDirectoryRoot(cx, "example.com", "foo"));
    dispatch(actions.setProjectDirectoryRoot(cx, "example.com/foo/bar", "foo"));
    expect(getProjectDirectoryRoot(getState())).toBe("example.com/foo/bar");
  });

  it("should update the child directory when domain name is Webpack://", () => {
    const { dispatch, getState, cx } = createStore({
      getSourceActorBreakableLines: async () => [],
    });
    dispatch(actions.setProjectDirectoryRoot(cx, "webpack://", "foo"));
    dispatch(actions.setProjectDirectoryRoot(cx, "webpack:///app", "foo"));
    expect(getProjectDirectoryRoot(getState())).toBe("webpack:///app");
  });

  it("should set the name of the root directory", () => {
    const { dispatch, getState, cx } = createStore();
    dispatch(actions.setProjectDirectoryRoot(cx, "foo", "example.com"));
    expect(getProjectDirectoryRootName(getState())).toBe("example.com");
  });
});