Beispiel #1
0
            it("should allow icon extensions to return a string for the icon", function () {
                var extensionCalls = 0,
                    rendered = PreactTestUtils.renderIntoDocument(FileTreeView._fileNode({
                        name: "afile.js",
                        entry: Immutable.Map(),
                        parentPath: "/foo/",
                        extensions: Immutable.fromJS({
                            icons: [function (data) {
                                extensionCalls++;
                                return "<ins>ICON</ins>";
                            }]
                        })
                    }));

                expect(extensionCalls).toBe(1);

                var a = findRenderedDOMComponentWithTag(rendered, "a");
                expect(a.children[0].textContent).toBe("");
                expect(a.children[2].textContent).toBe("afile");
                expect(a.children[3].textContent).toBe(".js");

                var $a = $(Preact.findDOMNode(a)),
                    $ins = $a.find("ins");

                expect($ins.text()).toBe("ICON");
            });
Beispiel #2
0
            it("should re-render as needed", function () {
                var props = {
                    name      : "afile.js",
                    entry     : Immutable.Map(),
                    parentPath: "/foo/",
                    extensions: Immutable.Map()
                };

                var rendered = PreactTestUtils.renderIntoDocument(FileTreeView._fileNode(props));

                var newProps = _.clone(props);
                expect(rendered.shouldComponentUpdate(newProps)).toBe(false);

                newProps = _.clone(props);
                newProps.entry = Immutable.Map({
                    selected: true
                });
                expect(rendered.shouldComponentUpdate(newProps)).toBe(true);

                newProps = _.clone(props);
                newProps.forceRender = true;
                expect(rendered.shouldComponentUpdate(newProps)).toBe(true);

                newProps = _.clone(props);
                newProps.extensions = Immutable.Map({
                    addClasses: Immutable.List()
                });
                expect(rendered.shouldComponentUpdate(newProps)).toBe(true);
            });
Beispiel #3
0
            it("should call icon extensions to replace the default icon", function () {
                var extensionCalls = 0,
                    rendered = PreactTestUtils.renderIntoDocument(FileTreeView._fileNode({
                        name: "afile.js",
                        entry: Immutable.Map(),
                        parentPath: "/foo/",
                        extensions: Immutable.fromJS({
                            icons: [function (data) {
                                extensionCalls++;
                                expect(data.name).toBe("afile.js");
                                expect(data.isFile).toBe(true);
                                expect(data.fullPath).toBe("/foo/afile.js");
                                return Preact.DOM.ins({}, "ICON");
                            }]
                        })
                    }));

                expect(extensionCalls).toBe(1);

                var a = findRenderedDOMComponentWithTag(rendered, "a");
                expect(a.children[0].textContent).toBe("");
                expect(a.children[1].textContent).toBe("ICON");
                expect(a.children[2].textContent).toBe("afile");
                expect(a.children[3].textContent).toBe(".js");
            });
Beispiel #4
0
 it("should render a rename component", function () {
     var rendered = PreactTestUtils.renderIntoDocument(FileTreeView._fileNode({
         name: "afile.js",
         entry: Immutable.Map({
             rename: true
         })
     }));
     var input = findRenderedDOMComponentWithTag(rendered, "input");
     expect(input.value).toBe("afile.js");
 });
Beispiel #5
0
 it("should create a component with the right information", function () {
     var rendered = PreactTestUtils.renderIntoDocument(FileTreeView._fileNode({
         name: "afile.js",
         entry: Immutable.Map()
     }));
     var a = findRenderedDOMComponentWithTag(rendered, "a");
     expect(a.children[0].textContent).toBe("");
     expect(a.children[1].textContent).toBe(" ");
     expect(a.children[2].textContent).toBe("afile");
     expect(a.children[3].textContent).toBe(".js");
 });
Beispiel #6
0
 it("should set context on a node by right click", function () {
     var actions = jasmine.createSpyObj("actions", ["setContext"]);
     var rendered = PreactTestUtils.renderIntoDocument(FileTreeView._fileNode({
         name: "afile.js",
         entry: Immutable.Map(),
         actions: actions,
         parentPath: "/foo/"
     }));
     var node = Preact.findDOMNode(rendered);
     PreactTestUtils.Simulate.mouseDown(node, {
         button: 2
     });
     expect(actions.setContext).toHaveBeenCalledWith("/foo/afile.js");
 });
Beispiel #7
0
 it("should not set context on a node by control click on Windows", function () {
     var actions = jasmine.createSpyObj("actions", ["setContext"]);
     var rendered = PreactTestUtils.renderIntoDocument(FileTreeView._fileNode({
         name: "afile.js",
         entry: Immutable.Map(),
         actions: actions,
         parentPath: "/foo/",
         platform: "win"
     }));
     var node = Preact.findDOMNode(rendered);
     PreactTestUtils.Simulate.mouseDown(node, {
         button: 0,
         ctrlKey: true
     });
     expect(actions.setContext).not.toHaveBeenCalled();
 });
Beispiel #8
0
            it("should call addClass extensions", function () {
                var extensionCalls = 0,
                    rendered = PreactTestUtils.renderIntoDocument(FileTreeView._fileNode({
                        name: "afile.js",
                        entry: Immutable.Map(),
                        parentPath: "/foo/",
                        extensions: Immutable.fromJS({
                            addClass: [function (data) {
                                extensionCalls++;
                                expect(data.name).toBe("afile.js");
                                expect(data.isFile).toBe(true);
                                expect(data.fullPath).toBe("/foo/afile.js");
                                return "new";
                            }, function (data) {
                                return "classes are cool";
                            }]
                        })
                    }));

                expect(extensionCalls).toBe(1);

                var li = findRenderedDOMComponentWithTag(rendered, "li");
                expect(li.className).toBe("jstree-leaf new classes are cool");
            });