Add missing unit tests to JavaScript and React components (#5505)
Add the missing unit tests login, bucket listing, and bucket searching functionalities.master
parent
feb726dd98
commit
ead6337eab
@ -0,0 +1,34 @@ |
||||
/* |
||||
* 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, mount } from "enzyme" |
||||
import Alert from "../Alert" |
||||
|
||||
describe("Alert", () => { |
||||
it("should render without crashing", () => { |
||||
shallow(<Alert />) |
||||
}) |
||||
|
||||
it("should call onDismiss when close button is clicked", () => { |
||||
const onDismiss = jest.fn() |
||||
const wrapper = mount( |
||||
<Alert show={true} type="danger" message="test" onDismiss={onDismiss}/> |
||||
) |
||||
wrapper.find("button").simulate("click", { preventDefault: jest.fn() }) |
||||
expect(onDismiss).toHaveBeenCalled() |
||||
}) |
||||
}) |
@ -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 App from "../App" |
||||
|
||||
describe("App", () => { |
||||
it("should render without crashing", () => { |
||||
shallow(<App match={ {url: "/minio"} }/>) |
||||
}) |
||||
}) |
@ -0,0 +1,29 @@ |
||||
/* |
||||
* 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 Browser from "../Browser" |
||||
import configureStore from "redux-mock-store" |
||||
|
||||
const mockStore = configureStore() |
||||
|
||||
describe("Browser", () => { |
||||
it("should render without crashing", () => { |
||||
const store = mockStore() |
||||
shallow(<Browser store={store}/>) |
||||
}) |
||||
}) |
@ -0,0 +1,52 @@ |
||||
/* |
||||
* 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 BucketContainer from "../BucketContainer" |
||||
import configureStore from "redux-mock-store" |
||||
|
||||
const mockStore = configureStore() |
||||
|
||||
describe("BucketContainer", () => { |
||||
let store |
||||
beforeEach(() => { |
||||
store = mockStore({ |
||||
buckets: { |
||||
currentBucket: "Test" |
||||
} |
||||
}) |
||||
store.dispatch = jest.fn() |
||||
}) |
||||
|
||||
it("should render without crashing", () => { |
||||
shallow(<BucketContainer store={store}/>) |
||||
}) |
||||
|
||||
it('maps state and dispatch to props', () => { |
||||
const wrapper = shallow(<BucketContainer store={store}/>) |
||||
expect(wrapper.props()).toEqual(expect.objectContaining({ |
||||
isActive: expect.any(Boolean), |
||||
selectBucket: expect.any(Function) |
||||
})) |
||||
}) |
||||
|
||||
it('maps selectBucket to dispatch action', () => { |
||||
const wrapper = shallow(<BucketContainer store={store}/>) |
||||
wrapper.props().selectBucket() |
||||
expect(store.dispatch).toHaveBeenCalled() |
||||
}) |
||||
}) |
@ -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 Host from "../Host" |
||||
|
||||
describe("Host", () => { |
||||
it("should render without crashing", () => { |
||||
shallow(<Host />) |
||||
}) |
||||
}) |
@ -0,0 +1,99 @@ |
||||
/* |
||||
* 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, mount } from "enzyme" |
||||
import { Login } from "../Login" |
||||
import web from "../../web" |
||||
|
||||
jest.mock('../../web', () => ({ |
||||
Login: jest.fn(() => { |
||||
return Promise.resolve({ token: "test", uiVersion: "2018-02-01T01:17:47Z" }) |
||||
}), |
||||
LoggedIn: jest.fn() |
||||
})) |
||||
|
||||
describe("Login", () => { |
||||
const dispatchMock = jest.fn() |
||||
const showAlertMock = jest.fn() |
||||
const clearAlertMock = jest.fn() |
||||
|
||||
it("should render without crashing", () => { |
||||
shallow(<Login
|
||||
dispatch={dispatchMock}
|
||||
alert={{ show: false, type: "danger"}} |
||||
showAlert={showAlertMock} |
||||
clearAlert={clearAlertMock} |
||||
/>) |
||||
}) |
||||
|
||||
it("should initially have the is-guest class", () => { |
||||
const wrapper = shallow( |
||||
<Login
|
||||
dispatch={dispatchMock}
|
||||
alert={{ show: false, type: "danger"}} |
||||
showAlert={showAlertMock} |
||||
clearAlert={clearAlertMock} |
||||
/>, |
||||
{ attachTo: document.body } |
||||
) |
||||
expect(document.body.classList.contains("is-guest")).toBeTruthy() |
||||
}) |
||||
|
||||
it("should throw an alert if the keys are empty in login form", () => { |
||||
const wrapper = mount( |
||||
<Login
|
||||
dispatch={dispatchMock}
|
||||
alert={{ show: false, type: "danger"}} |
||||
showAlert={showAlertMock} |
||||
clearAlert={clearAlertMock} |
||||
/>, |
||||
{ 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") |
||||
|
||||
// case where access key is empty
|
||||
document.getElementById("secretKey").value = "secretKey" |
||||
wrapper.find("form").simulate("submit") |
||||
expect(showAlertMock).toHaveBeenCalledWith("danger", "Access Key cannot be empty") |
||||
|
||||
// case where secret key is empty
|
||||
document.getElementById("accessKey").value = "accessKey" |
||||
wrapper.find("form").simulate("submit") |
||||
expect(showAlertMock).toHaveBeenCalledWith("danger", "Secret Key cannot be empty") |
||||
}) |
||||
|
||||
it("should call web.Login with correct arguments if both keys are entered", () => { |
||||
const wrapper = mount( |
||||
<Login
|
||||
dispatch={dispatchMock}
|
||||
alert={{ show: false, type: "danger"}} |
||||
showAlert={showAlertMock} |
||||
clearAlert={clearAlertMock} |
||||
/>, |
||||
{ 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" |
||||
}) |
||||
}) |
||||
}) |
@ -0,0 +1,27 @@ |
||||
/* |
||||
* 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 { SideBar } from "../SideBar" |
||||
|
||||
describe("SideBar", () => { |
||||
it("should render without crashing", () => { |
||||
shallow(<SideBar />) |
||||
}) |
||||
|
||||
// ClickOutHandler test to be added when corresponding function is added
|
||||
}) |
@ -0,0 +1 @@ |
||||
module.exports = 'test-file-stub'; |
Loading…
Reference in new issue