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:
Kanagaraj M
2018-03-23 00:55:56 +05:30
committed by Harshavardhana
parent cb3818be27
commit c0e45f9098
95 changed files with 839 additions and 890 deletions

View File

@@ -20,13 +20,13 @@ import { ShareObjectModal } from "../ShareObjectModal"
import {
SHARE_OBJECT_EXPIRY_DAYS,
SHARE_OBJECT_EXPIRY_HOURS,
SHARE_OBJECT_EXPIRY_MINUTES,
SHARE_OBJECT_EXPIRY_MINUTES
} from "../../constants"
jest.mock("../../web", () => ({
LoggedIn: jest.fn(() => {
return true
}),
})
}))
describe("ShareObjectModal", () => {
@@ -35,7 +35,7 @@ describe("ShareObjectModal", () => {
<ShareObjectModal
object={{ name: "obj1" }}
shareObjectDetails={{ show: true, object: "obj1", url: "test" }}
/>,
/>
)
})
@@ -46,7 +46,7 @@ describe("ShareObjectModal", () => {
object={{ name: "obj1" }}
shareObjectDetails={{ show: true, object: "obj1", url: "test" }}
hideShareObject={hideShareObject}
/>,
/>
)
wrapper
.find("button")
@@ -60,13 +60,13 @@ describe("ShareObjectModal", () => {
<ShareObjectModal
object={{ name: "obj1" }}
shareObjectDetails={{ show: true, object: "obj1", url: "test" }}
/>,
/>
)
expect(
wrapper
.find("input")
.first()
.prop("value"),
.prop("value")
).toBe(`${window.location.protocol}//test`)
})
@@ -79,7 +79,7 @@ describe("ShareObjectModal", () => {
shareObjectDetails={{ show: true, object: "obj1", url: "test" }}
hideShareObject={hideShareObject}
showCopyAlert={showCopyAlert}
/>,
/>
)
wrapper.find("CopyToClipboard").prop("onCopy")()
expect(showCopyAlert).toHaveBeenCalledWith("Link copied to clipboard!")
@@ -89,40 +89,40 @@ describe("ShareObjectModal", () => {
describe("Update expiry values", () => {
const props = {
object: {
name: "obj1",
name: "obj1"
},
shareObjectDetails: {
show: true,
object: "obj1",
url: "test",
},
url: "test"
}
}
it("should have default expiry values", () => {
const wrapper = shallow(<ShareObjectModal {...props} />)
expect(wrapper.state("expiry")).toEqual({
days: SHARE_OBJECT_EXPIRY_DAYS,
hours: SHARE_OBJECT_EXPIRY_HOURS,
minutes: SHARE_OBJECT_EXPIRY_MINUTES,
minutes: SHARE_OBJECT_EXPIRY_MINUTES
})
})
it("should not allow any increments when days is already max", () => {
const shareObject = jest.fn()
const wrapper = shallow(
<ShareObjectModal {...props} shareObject={shareObject} />,
<ShareObjectModal {...props} shareObject={shareObject} />
)
wrapper.setState({
expiry: {
days: 7,
hours: 0,
minutes: 0,
},
minutes: 0
}
})
wrapper.find("#increase-hours").simulate("click")
expect(wrapper.state("expiry")).toEqual({
days: 7,
hours: 0,
minutes: 0,
minutes: 0
})
expect(shareObject).not.toHaveBeenCalled()
})
@@ -130,14 +130,14 @@ describe("ShareObjectModal", () => {
it("should not allow expiry values less than minimum value", () => {
const shareObject = jest.fn()
const wrapper = shallow(
<ShareObjectModal {...props} shareObject={shareObject} />,
<ShareObjectModal {...props} shareObject={shareObject} />
)
wrapper.setState({
expiry: {
days: 5,
hours: 0,
minutes: 0,
},
minutes: 0
}
})
wrapper.find("#decrease-hours").simulate("click")
expect(wrapper.state("expiry").hours).toBe(0)
@@ -149,14 +149,14 @@ describe("ShareObjectModal", () => {
it("should not allow expiry values more than maximum value", () => {
const shareObject = jest.fn()
const wrapper = shallow(
<ShareObjectModal {...props} shareObject={shareObject} />,
<ShareObjectModal {...props} shareObject={shareObject} />
)
wrapper.setState({
expiry: {
days: 1,
hours: 23,
minutes: 59,
},
minutes: 59
}
})
wrapper.find("#increase-hours").simulate("click")
expect(wrapper.state("expiry").hours).toBe(23)
@@ -168,20 +168,20 @@ describe("ShareObjectModal", () => {
it("should set hours and minutes to 0 when days reaches max", () => {
const shareObject = jest.fn()
const wrapper = shallow(
<ShareObjectModal {...props} shareObject={shareObject} />,
<ShareObjectModal {...props} shareObject={shareObject} />
)
wrapper.setState({
expiry: {
days: 6,
hours: 5,
minutes: 30,
},
minutes: 30
}
})
wrapper.find("#increase-days").simulate("click")
expect(wrapper.state("expiry")).toEqual({
days: 7,
hours: 0,
minutes: 0,
minutes: 0
})
expect(shareObject).toHaveBeenCalled()
})
@@ -189,20 +189,20 @@ describe("ShareObjectModal", () => {
it("should set days to MAX when all of them becomes 0", () => {
const shareObject = jest.fn()
const wrapper = shallow(
<ShareObjectModal {...props} shareObject={shareObject} />,
<ShareObjectModal {...props} shareObject={shareObject} />
)
wrapper.setState({
expiry: {
days: 0,
hours: 1,
minutes: 0,
},
minutes: 0
}
})
wrapper.find("#decrease-hours").simulate("click")
expect(wrapper.state("expiry")).toEqual({
days: 7,
hours: 0,
minutes: 0,
minutes: 0
})
expect(shareObject).toHaveBeenCalledWith("obj1", 7, 0, 0)
})