summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/node/store/ui.test.js
blob: 8b4315a465fe0d5a61f876d79078ea1ec0b7f146 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const expect = require("expect");

const actions = require("devtools/client/webconsole/actions/index");
const {
  setupStore,
  getFirstMessage,
  getLastMessage,
} = require("devtools/client/webconsole/test/node/helpers");
const {
  stubPackets,
  stubPreparedMessages,
} = require("devtools/client/webconsole/test/node/fixtures/stubs/index");

describe("Testing UI", () => {
  let store;

  beforeEach(() => {
    store = setupStore();
  });

  describe("Toggle sidebar", () => {
    it("sidebar is toggled on and off", () => {
      const packet = stubPackets.get("inspect({a: 1})");
      const message = stubPreparedMessages.get("inspect({a: 1})");
      store.dispatch(actions.messagesAdd([packet]));

      const { actorID } = message.parameters[0];
      const messageId = getFirstMessage(store.getState()).id;
      store.dispatch(actions.showMessageObjectInSidebar(actorID, messageId));

      expect(store.getState().ui.sidebarVisible).toEqual(true);
      store.dispatch(actions.sidebarClose());
      expect(store.getState().ui.sidebarVisible).toEqual(false);
    });
  });

  describe("Hide sidebar on clear", () => {
    it("sidebar is hidden on clear", () => {
      const packet = stubPackets.get("inspect({a: 1})");
      const message = stubPreparedMessages.get("inspect({a: 1})");
      store.dispatch(actions.messagesAdd([packet]));

      const { actorID } = message.parameters[0];
      const messageId = getFirstMessage(store.getState()).id;
      store.dispatch(actions.showMessageObjectInSidebar(actorID, messageId));

      expect(store.getState().ui.sidebarVisible).toEqual(true);
      store.dispatch(actions.messagesClear());
      expect(store.getState().ui.sidebarVisible).toEqual(false);
      store.dispatch(actions.messagesClear());
      expect(store.getState().ui.sidebarVisible).toEqual(false);
    });
  });

  describe("Show object in sidebar", () => {
    it("sidebar is shown with correct object", () => {
      const packet = stubPackets.get("inspect({a: 1})");
      const message = stubPreparedMessages.get("inspect({a: 1})");
      store.dispatch(actions.messagesAdd([packet]));

      const { actorID } = message.parameters[0];
      const messageId = getFirstMessage(store.getState()).id;
      store.dispatch(actions.showMessageObjectInSidebar(actorID, messageId));

      expect(store.getState().ui.sidebarVisible).toEqual(true);
      expect(store.getState().ui.frontInSidebar).toEqual(message.parameters[0]);
    });

    it("sidebar is not updated for the same object", () => {
      const packet = stubPackets.get("inspect({a: 1})");
      const message = stubPreparedMessages.get("inspect({a: 1})");
      store.dispatch(actions.messagesAdd([packet]));

      const { actorID } = message.parameters[0];
      const messageId = getFirstMessage(store.getState()).id;
      store.dispatch(actions.showMessageObjectInSidebar(actorID, messageId));

      expect(store.getState().ui.sidebarVisible).toEqual(true);
      expect(store.getState().ui.frontInSidebar).toEqual(message.parameters[0]);
      const state = store.getState().ui;

      store.dispatch(actions.showMessageObjectInSidebar(actorID, messageId));
      expect(store.getState().ui).toEqual(state);
    });

    it("sidebar shown and updated for new object", () => {
      const packet = stubPackets.get("inspect({a: 1})");
      const message = stubPreparedMessages.get("inspect({a: 1})");
      store.dispatch(actions.messagesAdd([packet]));

      const { actorID } = message.parameters[0];
      const messageId = getFirstMessage(store.getState()).id;
      store.dispatch(actions.showMessageObjectInSidebar(actorID, messageId));

      expect(store.getState().ui.sidebarVisible).toEqual(true);
      expect(store.getState().ui.frontInSidebar).toEqual(message.parameters[0]);

      const newPacket = stubPackets.get("new Date(0)");
      const newMessage = stubPreparedMessages.get("new Date(0)");
      store.dispatch(actions.messagesAdd([newPacket]));

      const newActorID = newMessage.parameters[0].actorID;
      const newMessageId = getLastMessage(store.getState()).id;
      store.dispatch(
        actions.showMessageObjectInSidebar(newActorID, newMessageId)
      );

      expect(store.getState().ui.sidebarVisible).toEqual(true);
      expect(store.getState().ui.frontInSidebar).toEqual(
        newMessage.parameters[0]
      );
    });
  });
});