From 566ac78b8b85308ac07bbf9ffcbdd2ac4029f40d Mon Sep 17 00:00:00 2001 From: Kaan Kabalak Date: Fri, 16 Feb 2018 19:45:32 -0800 Subject: [PATCH] Add missing unit tests for PR #5499 (#5527) Part of #5410 --- .../app/js/browser/__tests__/Header.test.js | 25 +++++++++++++++ .../js/browser/__tests__/MainContent.test.js | 25 +++++++++++++++ .../app/js/browser/__tests__/SideBar.test.js | 7 ++++- .../objects/__tests__/ObjectContainer.test.js | 31 +++++++++++++++++++ ...ObjetctItem.test.js => ObjectItem.test.js} | 0 .../objects/__tests__/ObjectsHeader.test.js | 20 ++++++++++++ .../__tests__/ObjectsListContainer.test.js | 7 +++++ .../objects/__tests__/ObjectsSection.test.js | 25 +++++++++++++++ 8 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 browser/app/js/browser/__tests__/Header.test.js create mode 100644 browser/app/js/browser/__tests__/MainContent.test.js create mode 100644 browser/app/js/objects/__tests__/ObjectContainer.test.js rename browser/app/js/objects/__tests__/{ObjetctItem.test.js => ObjectItem.test.js} (100%) create mode 100644 browser/app/js/objects/__tests__/ObjectsSection.test.js diff --git a/browser/app/js/browser/__tests__/Header.test.js b/browser/app/js/browser/__tests__/Header.test.js new file mode 100644 index 000000000..a48357361 --- /dev/null +++ b/browser/app/js/browser/__tests__/Header.test.js @@ -0,0 +1,25 @@ +/* + * Minio Cloud Storage (C) 2018 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from "react" +import { shallow } from "enzyme" +import Header from "../Header" + +describe("Header", () => { + it("should render without crashing", () => { + shallow(
) + }) +}) diff --git a/browser/app/js/browser/__tests__/MainContent.test.js b/browser/app/js/browser/__tests__/MainContent.test.js new file mode 100644 index 000000000..92c212c84 --- /dev/null +++ b/browser/app/js/browser/__tests__/MainContent.test.js @@ -0,0 +1,25 @@ +/* + * Minio Cloud Storage (C) 2018 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from "react" +import { shallow } from "enzyme" +import MainContent from "../MainContent" + +describe("MainContent", () => { + it("should render without crashing", () => { + shallow() + }) +}) diff --git a/browser/app/js/browser/__tests__/SideBar.test.js b/browser/app/js/browser/__tests__/SideBar.test.js index f1020de29..45d3897e5 100644 --- a/browser/app/js/browser/__tests__/SideBar.test.js +++ b/browser/app/js/browser/__tests__/SideBar.test.js @@ -23,5 +23,10 @@ describe("SideBar", () => { shallow() }) - // ClickOutHandler test to be added when corresponding function is added + it("should call clickOutside when the user clicks outside the sidebar", () => { + const clickOutside = jest.fn() + const wrapper = shallow() + wrapper.simulate("clickOut", { preventDefault: jest.fn() }) + expect(clickOutside).toHaveBeenCalled() + }) }) diff --git a/browser/app/js/objects/__tests__/ObjectContainer.test.js b/browser/app/js/objects/__tests__/ObjectContainer.test.js new file mode 100644 index 000000000..67d7cc074 --- /dev/null +++ b/browser/app/js/objects/__tests__/ObjectContainer.test.js @@ -0,0 +1,31 @@ +/* + * Minio Cloud Storage (C) 2018 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from "react" +import { shallow } from "enzyme" +import { ObjectContainer } from "../ObjectContainer" + +describe("ObjectContainer", () => { + it("should render without crashing", () => { + shallow() + }) + + it("should render ObjectItem with props", () => { + const wrapper = shallow() + expect(wrapper.find("ObjectItem").length).toBe(1) + expect(wrapper.find("ObjectItem").prop("name")).toBe("test1.jpg") + }) +}) diff --git a/browser/app/js/objects/__tests__/ObjetctItem.test.js b/browser/app/js/objects/__tests__/ObjectItem.test.js similarity index 100% rename from browser/app/js/objects/__tests__/ObjetctItem.test.js rename to browser/app/js/objects/__tests__/ObjectItem.test.js diff --git a/browser/app/js/objects/__tests__/ObjectsHeader.test.js b/browser/app/js/objects/__tests__/ObjectsHeader.test.js index 4bf6c8485..dfc86f632 100644 --- a/browser/app/js/objects/__tests__/ObjectsHeader.test.js +++ b/browser/app/js/objects/__tests__/ObjectsHeader.test.js @@ -48,6 +48,26 @@ describe("ObjectsHeader", () => { ).toBeTruthy() }) + it("should render size column with desc class when objects are sorted by size", () => { + const sortObjects = jest.fn() + const wrapper = shallow( + + ) + expect( + wrapper.find("#sort-by-size i").hasClass("fa-sort-amount-desc") + ).toBeTruthy() + }) + + it("should render last modified column with desc class when objects are sorted by last modified", () => { + const sortObjects = jest.fn() + const wrapper = shallow( + + ) + expect( + wrapper.find("#sort-by-last-modified i").hasClass("fa-sort-numeric-desc") + ).toBeTruthy() + }) + it("should call sortObjects when a column is clicked", () => { const sortObjects = jest.fn() const wrapper = shallow() diff --git a/browser/app/js/objects/__tests__/ObjectsListContainer.test.js b/browser/app/js/objects/__tests__/ObjectsListContainer.test.js index 63f736dc5..dbc009e03 100644 --- a/browser/app/js/objects/__tests__/ObjectsListContainer.test.js +++ b/browser/app/js/objects/__tests__/ObjectsListContainer.test.js @@ -36,4 +36,11 @@ describe("ObjectsList", () => { { name: "test2.jpg" } ]) }) + + it("should show the loading indicator at the bottom if there are more elements to display", () => { + const wrapper = shallow( + + ) + expect(wrapper.find(".text-center").prop("style")).toHaveProperty("display", "block") + }) }) diff --git a/browser/app/js/objects/__tests__/ObjectsSection.test.js b/browser/app/js/objects/__tests__/ObjectsSection.test.js new file mode 100644 index 000000000..817be33fa --- /dev/null +++ b/browser/app/js/objects/__tests__/ObjectsSection.test.js @@ -0,0 +1,25 @@ +/* + * Minio Cloud Storage (C) 2018 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from "react" +import { shallow } from "enzyme" +import { ObjectsSection } from "../ObjectsSection" + +describe("ObjectsSection", () => { + it("should render without crashing", () => { + shallow() + }) +})