mirror of
https://github.com/minio/minio.git
synced 2025-11-26 20:38:20 -05:00
Fix failing unit tests in browser (#5688)
* format js files using prettier Used the following command to format the files prettier --write "browser/app/js/**/*.js" * fix failing unit tests in browser
This commit is contained in:
committed by
Harshavardhana
parent
cb3818be27
commit
c0e45f9098
@@ -28,29 +28,29 @@ export class BrowserDropdown extends React.Component {
|
||||
super(props)
|
||||
this.state = {
|
||||
showAboutModal: false,
|
||||
showChangePasswordModal: false,
|
||||
showChangePasswordModal: false
|
||||
}
|
||||
}
|
||||
showAbout(e) {
|
||||
e.preventDefault()
|
||||
this.setState({
|
||||
showAboutModal: true,
|
||||
showAboutModal: true
|
||||
})
|
||||
}
|
||||
hideAbout() {
|
||||
this.setState({
|
||||
showAboutModal: false,
|
||||
showAboutModal: false
|
||||
})
|
||||
}
|
||||
showChangePassword(e) {
|
||||
e.preventDefault()
|
||||
this.setState({
|
||||
showChangePasswordModal: true,
|
||||
showChangePasswordModal: true
|
||||
})
|
||||
}
|
||||
hideChangePassword() {
|
||||
this.setState({
|
||||
showChangePasswordModal: false,
|
||||
showChangePasswordModal: false
|
||||
})
|
||||
}
|
||||
componentDidMount() {
|
||||
@@ -142,13 +142,13 @@ export class BrowserDropdown extends React.Component {
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
serverInfo: state.browser.serverInfo,
|
||||
serverInfo: state.browser.serverInfo
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
fetchServerInfo: () => dispatch(browserActions.fetchServerInfo()),
|
||||
fetchServerInfo: () => dispatch(browserActions.fetchServerInfo())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
Modal,
|
||||
ModalBody,
|
||||
ModalHeader,
|
||||
OverlayTrigger,
|
||||
OverlayTrigger
|
||||
} from "react-bootstrap"
|
||||
|
||||
export class ChangePasswordModal extends React.Component {
|
||||
@@ -33,7 +33,7 @@ export class ChangePasswordModal extends React.Component {
|
||||
this.state = {
|
||||
accessKey: "",
|
||||
secretKey: "",
|
||||
keysReadOnly: false,
|
||||
keysReadOnly: false
|
||||
}
|
||||
}
|
||||
// When its shown, it loads the access key and secret key.
|
||||
@@ -45,13 +45,13 @@ export class ChangePasswordModal extends React.Component {
|
||||
this.setState({
|
||||
accessKey: "xxxxxxxxx",
|
||||
secretKey: "xxxxxxxxx",
|
||||
keysReadOnly: true,
|
||||
keysReadOnly: true
|
||||
})
|
||||
} else {
|
||||
web.GetAuth().then(data => {
|
||||
this.setState({
|
||||
accessKey: data.accessKey,
|
||||
secretKey: data.secretKey,
|
||||
secretKey: data.secretKey
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -60,19 +60,19 @@ export class ChangePasswordModal extends React.Component {
|
||||
// Handle field changes from inside the modal.
|
||||
accessKeyChange(e) {
|
||||
this.setState({
|
||||
accessKey: e.target.value,
|
||||
accessKey: e.target.value
|
||||
})
|
||||
}
|
||||
|
||||
secretKeyChange(e) {
|
||||
this.setState({
|
||||
secretKey: e.target.value,
|
||||
secretKey: e.target.value
|
||||
})
|
||||
}
|
||||
|
||||
secretKeyVisible(secretKeyVisible) {
|
||||
this.setState({
|
||||
secretKeyVisible,
|
||||
secretKeyVisible
|
||||
})
|
||||
}
|
||||
|
||||
@@ -84,18 +84,18 @@ export class ChangePasswordModal extends React.Component {
|
||||
web
|
||||
.SetAuth({
|
||||
accessKey,
|
||||
secretKey,
|
||||
secretKey
|
||||
})
|
||||
.then(data => {
|
||||
showAlert({
|
||||
type: "success",
|
||||
message: "Changed credentials",
|
||||
message: "Changed credentials"
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
showAlert({
|
||||
type: "danger",
|
||||
message: err.message,
|
||||
message: err.message
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -105,7 +105,7 @@ export class ChangePasswordModal extends React.Component {
|
||||
this.setState({
|
||||
accessKey: data.accessKey,
|
||||
secretKey: data.secretKey,
|
||||
secretKeyVisible: true,
|
||||
secretKeyVisible: true
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -136,7 +136,7 @@ export class ChangePasswordModal extends React.Component {
|
||||
<input
|
||||
type={this.state.secretKeyVisible ? "text" : "password"}
|
||||
value={this.state.secretKey}
|
||||
onChange={this.accessKeyChange.bind(this)}
|
||||
onChange={this.secretKeyChange.bind(this)}
|
||||
id="secretKey"
|
||||
className="form-group__field"
|
||||
name="secretKey"
|
||||
@@ -148,7 +148,7 @@ export class ChangePasswordModal extends React.Component {
|
||||
<i
|
||||
onClick={this.secretKeyVisible.bind(
|
||||
this,
|
||||
!this.state.secretKeyVisible,
|
||||
!this.state.secretKeyVisible
|
||||
)}
|
||||
className={
|
||||
"form-group__addon zmdi " +
|
||||
@@ -191,13 +191,13 @@ export class ChangePasswordModal extends React.Component {
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
serverInfo: state.browser.serverInfo,
|
||||
serverInfo: state.browser.serverInfo
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
showAlert: alert => dispatch(alertActions.set(alert)),
|
||||
showAlert: alert => dispatch(alertActions.set(alert))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ let ConfirmModal = ({
|
||||
cancelText,
|
||||
okHandler,
|
||||
cancelHandler,
|
||||
show,
|
||||
show
|
||||
}) => {
|
||||
return (
|
||||
<Modal
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
import React from "react"
|
||||
import Path from "../objects/Path"
|
||||
import ObjectsBulkActions from "../objects/ObjectsBulkActions"
|
||||
import Toolbar from "../objects/Toolbar"
|
||||
|
||||
export const Header = () => {
|
||||
return (
|
||||
<header className="header">
|
||||
<ObjectsBulkActions />
|
||||
<Toolbar />
|
||||
<Path />
|
||||
</header>
|
||||
)
|
||||
|
||||
@@ -40,7 +40,7 @@ export class Login extends React.Component {
|
||||
web
|
||||
.Login({
|
||||
username: document.getElementById("accessKey").value,
|
||||
password: document.getElementById("secretKey").value,
|
||||
password: document.getElementById("secretKey").value
|
||||
})
|
||||
.then(res => {
|
||||
history.push("/")
|
||||
@@ -114,10 +114,10 @@ const mapDispatchToProps = dispatch => {
|
||||
dispatch(
|
||||
actionsAlert.set({
|
||||
type: type,
|
||||
message: message,
|
||||
}),
|
||||
message: message
|
||||
})
|
||||
),
|
||||
clearAlert: () => dispatch(actionsAlert.clear()),
|
||||
clearAlert: () => dispatch(actionsAlert.clear())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import { getPrefixWritable } from "../objects/selectors"
|
||||
export const MainActions = ({
|
||||
prefixWritable,
|
||||
uploadFile,
|
||||
showMakeBucketModal,
|
||||
showMakeBucketModal
|
||||
}) => {
|
||||
const uploadTooltip = <Tooltip id="tooltip-upload-file">Upload file</Tooltip>
|
||||
const makeBucketTooltip = (
|
||||
@@ -89,14 +89,14 @@ export const MainActions = ({
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
prefixWritable: getPrefixWritable(state),
|
||||
prefixWritable: getPrefixWritable(state)
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
uploadFile: file => dispatch(uploadsActions.uploadFile(file)),
|
||||
showMakeBucketModal: () => dispatch(actionsBuckets.showMakeBucketModal()),
|
||||
showMakeBucketModal: () => dispatch(actionsBuckets.showMakeBucketModal())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ export const SideBar = ({ sidebarOpen }) => {
|
||||
<aside
|
||||
className={classNames({
|
||||
sidebar: true,
|
||||
"sidebar--toggled": sidebarOpen,
|
||||
"sidebar--toggled": sidebarOpen
|
||||
})}
|
||||
>
|
||||
<div className="sidebar__inner">
|
||||
@@ -53,13 +53,13 @@ export const SideBar = ({ sidebarOpen }) => {
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
sidebarOpen: state.browser.sidebarOpen,
|
||||
sidebarOpen: state.browser.sidebarOpen
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
toggleSidebar: () => dispatch(actionsCommon.toggleSidebar()),
|
||||
toggleSidebar: () => dispatch(actionsCommon.toggleSidebar())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,13 +30,13 @@ export const SidebarBackdrop = ({ sidebarOpen, toggleSidebar }) => (
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
sidebarOpen: state.browser.sidebarOpen,
|
||||
sidebarOpen: state.browser.sidebarOpen
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
toggleSidebar: () => dispatch(actionsCommon.toggleSidebar()),
|
||||
toggleSidebar: () => dispatch(actionsCommon.toggleSidebar())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,13 +30,13 @@ export const SidebarToggle = ({ sidebarOpen, toggleSidebar }) => (
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
sidebarOpen: state.browser.sidebarOpen,
|
||||
sidebarOpen: state.browser.sidebarOpen
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
toggleSidebar: () => dispatch(actionsCommon.toggleSidebar()),
|
||||
toggleSidebar: () => dispatch(actionsCommon.toggleSidebar())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,13 +44,13 @@ export class StorageInfo extends React.Component {
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
storageInfo: state.browser.storageInfo,
|
||||
storageInfo: state.browser.storageInfo
|
||||
}
|
||||
}
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
fetchStorageInfo: () => dispatch(actionsCommon.fetchStorageInfo()),
|
||||
fetchStorageInfo: () => dispatch(actionsCommon.fetchStorageInfo())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ describe("AboutModal", () => {
|
||||
version: "test",
|
||||
memory: "test",
|
||||
platform: "test",
|
||||
runtime: "test",
|
||||
runtime: "test"
|
||||
}
|
||||
|
||||
it("should render without crashing", () => {
|
||||
@@ -33,9 +33,9 @@ describe("AboutModal", () => {
|
||||
it("should call hideAbout when close button is clicked", () => {
|
||||
const hideAbout = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<AboutModal serverInfo={serverInfo} hideAbout={hideAbout} />,
|
||||
<AboutModal serverInfo={serverInfo} hideAbout={hideAbout} />
|
||||
)
|
||||
wrapper.find("button").simulate("click")
|
||||
wrapper.find("i").simulate("click")
|
||||
expect(hideAbout).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -23,12 +23,12 @@ describe("BrowserDropdown", () => {
|
||||
version: "test",
|
||||
memory: "test",
|
||||
platform: "test",
|
||||
runtime: "test",
|
||||
runtime: "test"
|
||||
}
|
||||
|
||||
it("should render without crashing", () => {
|
||||
shallow(
|
||||
<BrowserDropdown serverInfo={serverInfo} fetchServerInfo={jest.fn()} />,
|
||||
<BrowserDropdown serverInfo={serverInfo} fetchServerInfo={jest.fn()} />
|
||||
)
|
||||
})
|
||||
|
||||
@@ -38,17 +38,17 @@ describe("BrowserDropdown", () => {
|
||||
<BrowserDropdown
|
||||
serverInfo={serverInfo}
|
||||
fetchServerInfo={fetchServerInfo}
|
||||
/>,
|
||||
/>
|
||||
)
|
||||
expect(fetchServerInfo).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it("should show AboutModal when About link is clicked", () => {
|
||||
const wrapper = shallow(
|
||||
<BrowserDropdown serverInfo={serverInfo} fetchServerInfo={jest.fn()} />,
|
||||
<BrowserDropdown serverInfo={serverInfo} fetchServerInfo={jest.fn()} />
|
||||
)
|
||||
wrapper.find("#show-about").simulate("click", {
|
||||
preventDefault: jest.fn(),
|
||||
preventDefault: jest.fn()
|
||||
})
|
||||
wrapper.update()
|
||||
expect(wrapper.state("showAboutModal")).toBeTruthy()
|
||||
@@ -57,10 +57,10 @@ describe("BrowserDropdown", () => {
|
||||
|
||||
it("should logout and redirect to /login when logout is clicked", () => {
|
||||
const wrapper = shallow(
|
||||
<BrowserDropdown serverInfo={serverInfo} fetchServerInfo={jest.fn()} />,
|
||||
<BrowserDropdown serverInfo={serverInfo} fetchServerInfo={jest.fn()} />
|
||||
)
|
||||
wrapper.find("#logout").simulate("click", {
|
||||
preventDefault: jest.fn(),
|
||||
preventDefault: jest.fn()
|
||||
})
|
||||
expect(window.location.pathname.endsWith("/login")).toBeTruthy()
|
||||
})
|
||||
|
||||
@@ -22,13 +22,13 @@ jest.mock("../../web", () => ({
|
||||
GetAuth: jest.fn(() => {
|
||||
return Promise.resolve({
|
||||
accessKey: "test1",
|
||||
secretKey: "test2",
|
||||
secretKey: "test2"
|
||||
})
|
||||
}),
|
||||
GenerateAuth: jest.fn(() => {
|
||||
return Promise.resolve({
|
||||
accessKey: "gen1",
|
||||
secretKey: "gen2",
|
||||
secretKey: "gen2"
|
||||
})
|
||||
}),
|
||||
SetAuth: jest.fn(({ accessKey, secretKey }) => {
|
||||
@@ -36,10 +36,10 @@ jest.mock("../../web", () => ({
|
||||
return Promise.resolve({})
|
||||
} else {
|
||||
return Promise.reject({
|
||||
message: "Error",
|
||||
message: "Error"
|
||||
})
|
||||
}
|
||||
}),
|
||||
})
|
||||
}))
|
||||
|
||||
describe("ChangePasswordModal", () => {
|
||||
@@ -49,8 +49,8 @@ describe("ChangePasswordModal", () => {
|
||||
platform: "test",
|
||||
runtime: "test",
|
||||
info: {
|
||||
isEnvCreds: false,
|
||||
},
|
||||
isEnvCreds: false
|
||||
}
|
||||
}
|
||||
|
||||
it("should render without crashing", () => {
|
||||
@@ -69,8 +69,8 @@ describe("ChangePasswordModal", () => {
|
||||
const newServerInfo = {
|
||||
...serverInfo,
|
||||
info: {
|
||||
isEnvCreds: true,
|
||||
},
|
||||
isEnvCreds: true
|
||||
}
|
||||
}
|
||||
const wrapper = shallow(<ChangePasswordModal serverInfo={newServerInfo} />)
|
||||
expect(wrapper.state("accessKey")).toBe("xxxxxxxxx")
|
||||
@@ -93,23 +93,23 @@ describe("ChangePasswordModal", () => {
|
||||
it("should update accessKey and secretKey when Update button is clicked", () => {
|
||||
const showAlert = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<ChangePasswordModal serverInfo={serverInfo} showAlert={showAlert} />,
|
||||
<ChangePasswordModal serverInfo={serverInfo} showAlert={showAlert} />
|
||||
)
|
||||
wrapper.find("#accessKey").simulate("change", {
|
||||
target: {
|
||||
value: "test3",
|
||||
},
|
||||
value: "test3"
|
||||
}
|
||||
})
|
||||
wrapper.find("#secretKey").simulate("change", {
|
||||
target: {
|
||||
value: "test4",
|
||||
},
|
||||
value: "test4"
|
||||
}
|
||||
})
|
||||
wrapper.find("#update-keys").simulate("click")
|
||||
setImmediate(() => {
|
||||
expect(showAlert).toHaveBeenCalledWith({
|
||||
type: "success",
|
||||
message: "Changed credentials",
|
||||
message: "Changed credentials"
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -120,7 +120,7 @@ describe("ChangePasswordModal", () => {
|
||||
<ChangePasswordModal
|
||||
serverInfo={serverInfo}
|
||||
hideChangePassword={hideChangePassword}
|
||||
/>,
|
||||
/>
|
||||
)
|
||||
wrapper.find("#cancel-change-password").simulate("click")
|
||||
expect(hideChangePassword).toHaveBeenCalled()
|
||||
|
||||
@@ -18,25 +18,8 @@ import React from "react"
|
||||
import { shallow } from "enzyme"
|
||||
import Header from "../Header"
|
||||
|
||||
jest.mock("../../web", () => ({
|
||||
LoggedIn: jest
|
||||
.fn(() => true)
|
||||
.mockReturnValueOnce(true)
|
||||
.mockReturnValueOnce(false),
|
||||
}))
|
||||
describe("Header", () => {
|
||||
it("should render without crashing", () => {
|
||||
shallow(<Header />)
|
||||
})
|
||||
|
||||
it("should render Login button when the user has not LoggedIn", () => {
|
||||
const wrapper = shallow(<Header />)
|
||||
expect(wrapper.find("a").text()).toBe("Login")
|
||||
})
|
||||
|
||||
it("should render StorageInfo and BrowserDropdown when the user has LoggedIn", () => {
|
||||
const wrapper = shallow(<Header />)
|
||||
expect(wrapper.find("Connect(BrowserDropdown)").length).toBe(1)
|
||||
expect(wrapper.find("Connect(StorageInfo)").length).toBe(1)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -23,10 +23,10 @@ jest.mock("../../web", () => ({
|
||||
Login: jest.fn(() => {
|
||||
return Promise.resolve({
|
||||
token: "test",
|
||||
uiVersion: "2018-02-01T01:17:47Z",
|
||||
uiVersion: "2018-02-01T01:17:47Z"
|
||||
})
|
||||
}),
|
||||
LoggedIn: jest.fn(),
|
||||
LoggedIn: jest.fn()
|
||||
}))
|
||||
|
||||
describe("Login", () => {
|
||||
@@ -41,7 +41,7 @@ describe("Login", () => {
|
||||
alert={{ show: false, type: "danger" }}
|
||||
showAlert={showAlertMock}
|
||||
clearAlert={clearAlertMock}
|
||||
/>,
|
||||
/>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -54,8 +54,8 @@ describe("Login", () => {
|
||||
clearAlert={clearAlertMock}
|
||||
/>,
|
||||
{
|
||||
attachTo: document.body,
|
||||
},
|
||||
attachTo: document.body
|
||||
}
|
||||
)
|
||||
expect(document.body.classList.contains("is-guest")).toBeTruthy()
|
||||
})
|
||||
@@ -69,14 +69,14 @@ describe("Login", () => {
|
||||
clearAlert={clearAlertMock}
|
||||
/>,
|
||||
{
|
||||
attachTo: document.body,
|
||||
},
|
||||
attachTo: document.body
|
||||
}
|
||||
)
|
||||
// case where both keys are empty - displays the second warning
|
||||
wrapper.find("form").simulate("submit")
|
||||
expect(showAlertMock).toHaveBeenCalledWith(
|
||||
"danger",
|
||||
"Secret Key cannot be empty",
|
||||
"Secret Key cannot be empty"
|
||||
)
|
||||
|
||||
// case where access key is empty
|
||||
@@ -84,7 +84,7 @@ describe("Login", () => {
|
||||
wrapper.find("form").simulate("submit")
|
||||
expect(showAlertMock).toHaveBeenCalledWith(
|
||||
"danger",
|
||||
"Access Key cannot be empty",
|
||||
"Access Key cannot be empty"
|
||||
)
|
||||
|
||||
// case where secret key is empty
|
||||
@@ -92,7 +92,7 @@ describe("Login", () => {
|
||||
wrapper.find("form").simulate("submit")
|
||||
expect(showAlertMock).toHaveBeenCalledWith(
|
||||
"danger",
|
||||
"Secret Key cannot be empty",
|
||||
"Secret Key cannot be empty"
|
||||
)
|
||||
})
|
||||
|
||||
@@ -105,15 +105,15 @@ describe("Login", () => {
|
||||
clearAlert={clearAlertMock}
|
||||
/>,
|
||||
{
|
||||
attachTo: document.body,
|
||||
},
|
||||
attachTo: document.body
|
||||
}
|
||||
)
|
||||
document.getElementById("accessKey").value = "accessKey"
|
||||
document.getElementById("secretKey").value = "secretKey"
|
||||
wrapper.find("form").simulate("submit")
|
||||
expect(web.Login).toHaveBeenCalledWith({
|
||||
username: "accessKey",
|
||||
password: "secretKey",
|
||||
password: "secretKey"
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -23,7 +23,7 @@ jest.mock("../../web", () => ({
|
||||
.fn(() => true)
|
||||
.mockReturnValueOnce(true)
|
||||
.mockReturnValueOnce(false)
|
||||
.mockReturnValueOnce(false),
|
||||
.mockReturnValueOnce(false)
|
||||
}))
|
||||
|
||||
describe("MainActions", () => {
|
||||
@@ -52,10 +52,10 @@ describe("MainActions", () => {
|
||||
it("should call showMakeBucketModal when create bucket icon is clicked", () => {
|
||||
const showMakeBucketModal = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<MainActions showMakeBucketModal={showMakeBucketModal} />,
|
||||
<MainActions showMakeBucketModal={showMakeBucketModal} />
|
||||
)
|
||||
wrapper.find("#show-make-bucket").simulate("click", {
|
||||
preventDefault: jest.fn(),
|
||||
preventDefault: jest.fn()
|
||||
})
|
||||
expect(showMakeBucketModal).toHaveBeenCalled()
|
||||
})
|
||||
@@ -64,13 +64,13 @@ describe("MainActions", () => {
|
||||
const uploadFile = jest.fn()
|
||||
const wrapper = shallow(<MainActions uploadFile={uploadFile} />)
|
||||
const file = new Blob(["file content"], {
|
||||
type: "text/plain",
|
||||
type: "text/plain"
|
||||
})
|
||||
wrapper.find("#file-input").simulate("change", {
|
||||
preventDefault: jest.fn(),
|
||||
target: {
|
||||
files: [file],
|
||||
},
|
||||
files: [file]
|
||||
}
|
||||
})
|
||||
expect(uploadFile).toHaveBeenCalledWith(file)
|
||||
})
|
||||
|
||||
@@ -19,7 +19,7 @@ import { shallow } from "enzyme"
|
||||
import { SideBar } from "../SideBar"
|
||||
|
||||
jest.mock("../../web", () => ({
|
||||
LoggedIn: jest.fn(() => false).mockReturnValueOnce(true),
|
||||
LoggedIn: jest.fn(() => false).mockReturnValueOnce(true)
|
||||
}))
|
||||
|
||||
describe("SideBar", () => {
|
||||
@@ -31,13 +31,4 @@ describe("SideBar", () => {
|
||||
const wrapper = shallow(<SideBar />)
|
||||
expect(wrapper.find("Connect(BucketSearch)").length).toBe(0)
|
||||
})
|
||||
|
||||
it("should call clickOutside when the user clicks outside the sidebar", () => {
|
||||
const clickOutside = jest.fn()
|
||||
const wrapper = shallow(<SideBar clickOutside={clickOutside} />)
|
||||
wrapper.simulate("clickOut", {
|
||||
preventDefault: jest.fn(),
|
||||
})
|
||||
expect(clickOutside).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -16,20 +16,20 @@
|
||||
|
||||
import React from "react"
|
||||
import { shallow } from "enzyme"
|
||||
import { MobileHeader } from "../MobileHeader"
|
||||
import { SidebarToggle } from "../SidebarToggle"
|
||||
|
||||
describe("Bucket", () => {
|
||||
describe("SidebarToggle", () => {
|
||||
it("should render without crashing", () => {
|
||||
shallow(<MobileHeader sidebarOpen={false} />)
|
||||
shallow(<SidebarToggle sidebarOpen={false} />)
|
||||
})
|
||||
|
||||
it("should toggleSidebar when trigger is clicked", () => {
|
||||
const toggleSidebar = jest.fn()
|
||||
const wrapper = shallow(
|
||||
<MobileHeader sidebarOpen={false} toggleSidebar={toggleSidebar} />,
|
||||
<SidebarToggle sidebarOpen={false} toggleSidebar={toggleSidebar} />
|
||||
)
|
||||
wrapper.find("#sidebar-toggle").simulate("click", {
|
||||
stopPropagation: jest.fn(),
|
||||
wrapper.find("button").simulate("click", {
|
||||
stopPropagation: jest.fn()
|
||||
})
|
||||
expect(toggleSidebar).toHaveBeenCalled()
|
||||
})
|
||||
@@ -24,7 +24,7 @@ describe("StorageInfo", () => {
|
||||
<StorageInfo
|
||||
storageInfo={{ total: 100, free: 60 }}
|
||||
fetchStorageInfo={jest.fn()}
|
||||
/>,
|
||||
/>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -34,7 +34,7 @@ describe("StorageInfo", () => {
|
||||
<StorageInfo
|
||||
storageInfo={{ total: 100, free: 60 }}
|
||||
fetchStorageInfo={fetchStorageInfo}
|
||||
/>,
|
||||
/>
|
||||
)
|
||||
expect(fetchStorageInfo).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@@ -23,8 +23,8 @@ jest.mock("../../web", () => ({
|
||||
return Promise.resolve({
|
||||
storageInfo: {
|
||||
Total: 100,
|
||||
Free: 60,
|
||||
},
|
||||
Free: 60
|
||||
}
|
||||
})
|
||||
}),
|
||||
ServerInfo: jest.fn(() => {
|
||||
@@ -33,9 +33,9 @@ jest.mock("../../web", () => ({
|
||||
MinioMemory: "test",
|
||||
MinioPlatform: "test",
|
||||
MinioRuntime: "test",
|
||||
MinioGlobalInfo: "test",
|
||||
MinioGlobalInfo: "test"
|
||||
})
|
||||
}),
|
||||
})
|
||||
}))
|
||||
|
||||
const middlewares = [thunk]
|
||||
@@ -49,9 +49,9 @@ describe("Common actions", () => {
|
||||
type: "common/SET_STORAGE_INFO",
|
||||
storageInfo: {
|
||||
total: 100,
|
||||
free: 60,
|
||||
},
|
||||
},
|
||||
free: 60
|
||||
}
|
||||
}
|
||||
]
|
||||
return store.dispatch(actionsCommon.fetchStorageInfo()).then(() => {
|
||||
const actions = store.getActions()
|
||||
@@ -69,9 +69,9 @@ describe("Common actions", () => {
|
||||
memory: "test",
|
||||
platform: "test",
|
||||
runtime: "test",
|
||||
info: "test",
|
||||
},
|
||||
},
|
||||
info: "test"
|
||||
}
|
||||
}
|
||||
]
|
||||
return store.dispatch(actionsCommon.fetchServerInfo()).then(() => {
|
||||
const actions = store.getActions()
|
||||
|
||||
@@ -23,9 +23,9 @@ describe("common reducer", () => {
|
||||
sidebarOpen: false,
|
||||
storageInfo: {
|
||||
total: 0,
|
||||
free: 0,
|
||||
free: 0
|
||||
},
|
||||
serverInfo: {},
|
||||
serverInfo: {}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -33,14 +33,14 @@ describe("common reducer", () => {
|
||||
expect(
|
||||
reducer(
|
||||
{
|
||||
sidebarOpen: false,
|
||||
sidebarOpen: false
|
||||
},
|
||||
{
|
||||
type: actionsCommon.TOGGLE_SIDEBAR,
|
||||
},
|
||||
),
|
||||
type: actionsCommon.TOGGLE_SIDEBAR
|
||||
}
|
||||
)
|
||||
).toEqual({
|
||||
sidebarOpen: true,
|
||||
sidebarOpen: true
|
||||
})
|
||||
})
|
||||
|
||||
@@ -48,14 +48,14 @@ describe("common reducer", () => {
|
||||
expect(
|
||||
reducer(
|
||||
{
|
||||
sidebarOpen: true,
|
||||
sidebarOpen: true
|
||||
},
|
||||
{
|
||||
type: actionsCommon.CLOSE_SIDEBAR,
|
||||
},
|
||||
),
|
||||
type: actionsCommon.CLOSE_SIDEBAR
|
||||
}
|
||||
)
|
||||
).toEqual({
|
||||
sidebarOpen: false,
|
||||
sidebarOpen: false
|
||||
})
|
||||
})
|
||||
|
||||
@@ -67,15 +67,15 @@ describe("common reducer", () => {
|
||||
type: actionsCommon.SET_STORAGE_INFO,
|
||||
storageInfo: {
|
||||
total: 100,
|
||||
free: 40,
|
||||
},
|
||||
},
|
||||
),
|
||||
free: 40
|
||||
}
|
||||
}
|
||||
)
|
||||
).toEqual({
|
||||
storageInfo: {
|
||||
total: 100,
|
||||
free: 40,
|
||||
},
|
||||
free: 40
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -88,15 +88,15 @@ describe("common reducer", () => {
|
||||
memory: "test",
|
||||
platform: "test",
|
||||
runtime: "test",
|
||||
info: "test",
|
||||
},
|
||||
}).serverInfo,
|
||||
info: "test"
|
||||
}
|
||||
}).serverInfo
|
||||
).toEqual({
|
||||
version: "test",
|
||||
memory: "test",
|
||||
platform: "test",
|
||||
runtime: "test",
|
||||
info: "test",
|
||||
info: "test"
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -22,11 +22,11 @@ export const SET_STORAGE_INFO = "common/SET_STORAGE_INFO"
|
||||
export const SET_SERVER_INFO = "common/SET_SERVER_INFO"
|
||||
|
||||
export const toggleSidebar = () => ({
|
||||
type: TOGGLE_SIDEBAR,
|
||||
type: TOGGLE_SIDEBAR
|
||||
})
|
||||
|
||||
export const closeSidebar = () => ({
|
||||
type: CLOSE_SIDEBAR,
|
||||
type: CLOSE_SIDEBAR
|
||||
})
|
||||
|
||||
export const fetchStorageInfo = () => {
|
||||
@@ -34,7 +34,7 @@ export const fetchStorageInfo = () => {
|
||||
return web.StorageInfo().then(res => {
|
||||
const storageInfo = {
|
||||
total: res.storageInfo.Total,
|
||||
free: res.storageInfo.Free,
|
||||
free: res.storageInfo.Free
|
||||
}
|
||||
dispatch(setStorageInfo(storageInfo))
|
||||
})
|
||||
@@ -43,7 +43,7 @@ export const fetchStorageInfo = () => {
|
||||
|
||||
export const setStorageInfo = storageInfo => ({
|
||||
type: SET_STORAGE_INFO,
|
||||
storageInfo,
|
||||
storageInfo
|
||||
})
|
||||
|
||||
export const fetchServerInfo = () => {
|
||||
@@ -54,7 +54,7 @@ export const fetchServerInfo = () => {
|
||||
memory: res.MinioMemory,
|
||||
platform: res.MinioPlatform,
|
||||
runtime: res.MinioRuntime,
|
||||
info: res.MinioGlobalInfo,
|
||||
info: res.MinioGlobalInfo
|
||||
}
|
||||
dispatch(setServerInfo(serverInfo))
|
||||
})
|
||||
@@ -63,5 +63,5 @@ export const fetchServerInfo = () => {
|
||||
|
||||
export const setServerInfo = serverInfo => ({
|
||||
type: SET_SERVER_INFO,
|
||||
serverInfo,
|
||||
serverInfo
|
||||
})
|
||||
|
||||
@@ -21,29 +21,29 @@ export default (
|
||||
sidebarOpen: false,
|
||||
storageInfo: {
|
||||
total: 0,
|
||||
free: 0,
|
||||
free: 0
|
||||
},
|
||||
serverInfo: {},
|
||||
serverInfo: {}
|
||||
},
|
||||
action,
|
||||
action
|
||||
) => {
|
||||
switch (action.type) {
|
||||
case actionsCommon.TOGGLE_SIDEBAR:
|
||||
return Object.assign({}, state, {
|
||||
sidebarOpen: !state.sidebarOpen,
|
||||
sidebarOpen: !state.sidebarOpen
|
||||
})
|
||||
case actionsCommon.CLOSE_SIDEBAR:
|
||||
return Object.assign({}, state, {
|
||||
sidebarOpen: false,
|
||||
sidebarOpen: false
|
||||
})
|
||||
case actionsCommon.SET_STORAGE_INFO:
|
||||
return Object.assign({}, state, {
|
||||
storageInfo: action.storageInfo,
|
||||
storageInfo: action.storageInfo
|
||||
})
|
||||
case actionsCommon.SET_SERVER_INFO:
|
||||
return {
|
||||
...state,
|
||||
serverInfo: action.serverInfo,
|
||||
serverInfo: action.serverInfo
|
||||
}
|
||||
default:
|
||||
return state
|
||||
|
||||
Reference in New Issue
Block a user