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

@@ -29,10 +29,10 @@ describe("AbortConfirmModal", () => {
<AbortConfirmModal
uploads={{
"a-b/-test1": { size: 100, loaded: 50, name: "test1" },
"a-b/-test2": { size: 100, loaded: 50, name: "test2" },
"a-b/-test2": { size: 100, loaded: 50, name: "test2" }
}}
abort={abort}
/>,
/>
)
wrapper.instance().abortUploads()
expect(abort.mock.calls.length).toBe(2)

View File

@@ -27,10 +27,10 @@ describe("Dropzone", () => {
const uploadFile = jest.fn()
const wrapper = shallow(<Dropzone uploadFile={uploadFile} />)
const file1 = new Blob(["file content1"], {
type: "text/plain",
type: "text/plain"
})
const file2 = new Blob(["file content2"], {
type: "text/plain",
type: "text/plain"
})
wrapper.first().prop("onDrop")([file1, file2])
expect(uploadFile.mock.calls).toEqual([[file1], [file2]])

View File

@@ -37,7 +37,7 @@ describe("UploadModal", () => {
const wrapper = shallow(
<UploadModal
uploads={{ "a-b/-test": { size: 100, loaded: 50, name: "test" } }}
/>,
/>
)
expect(wrapper.find("ProgressBar").length).toBe(1)
})
@@ -48,7 +48,7 @@ describe("UploadModal", () => {
<UploadModal
uploads={{ "a-b/-test": { size: 100, loaded: 50, name: "test" } }}
showAbortModal={showAbortModal}
/>,
/>
)
wrapper.find("button").simulate("click")
expect(showAbortModal).toHaveBeenCalled()

View File

@@ -29,8 +29,8 @@ describe("Uploads actions", () => {
type: "uploads/ADD",
slug: "a-b-c",
size: 100,
name: "test",
},
name: "test"
}
]
store.dispatch(uploadsActions.add("a-b-c", 100, "test"))
const actions = store.getActions()
@@ -43,8 +43,8 @@ describe("Uploads actions", () => {
{
type: "uploads/UPDATE_PROGRESS",
slug: "a-b-c",
loaded: 50,
},
loaded: 50
}
]
store.dispatch(uploadsActions.updateProgress("a-b-c", 50))
const actions = store.getActions()
@@ -56,8 +56,8 @@ describe("Uploads actions", () => {
const expectedActions = [
{
type: "uploads/STOP",
slug: "a-b-c",
},
slug: "a-b-c"
}
]
store.dispatch(uploadsActions.stop("a-b-c"))
const actions = store.getActions()
@@ -69,8 +69,8 @@ describe("Uploads actions", () => {
const expectedActions = [
{
type: "uploads/SHOW_ABORT_MODAL",
show: true,
},
show: true
}
]
store.dispatch(uploadsActions.showAbortModal())
const actions = store.getActions()
@@ -79,15 +79,15 @@ describe("Uploads actions", () => {
describe("uploadFile", () => {
const file = new Blob(["file content"], {
type: "text/plain",
type: "text/plain"
})
file.name = "file1"
it("creates alerts/SET action when currentBucket is not present", () => {
const store = mockStore({
buckets: {
currentBucket: "",
},
currentBucket: ""
}
})
const expectedActions = [
{
@@ -95,12 +95,12 @@ describe("Uploads actions", () => {
alert: {
id: 0,
type: "danger",
message: "Please choose a bucket before trying to upload files.",
},
},
message: "Please choose a bucket before trying to upload files."
}
}
]
const file = new Blob(["file content"], {
type: "text/plain",
type: "text/plain"
})
store.dispatch(uploadsActions.uploadFile(file))
const actions = store.getActions()
@@ -110,19 +110,19 @@ describe("Uploads actions", () => {
it("creates uploads/ADD action before uploading the file", () => {
const store = mockStore({
buckets: {
currentBucket: "test1",
currentBucket: "test1"
},
objects: {
currentPrefix: "pre1/",
},
currentPrefix: "pre1/"
}
})
const expectedActions = [
{
type: "uploads/ADD",
slug: "test1-pre1/-file1",
size: file.size,
name: file.name,
},
name: file.name
}
]
store.dispatch(uploadsActions.uploadFile(file))
const actions = store.getActions()
@@ -137,23 +137,23 @@ describe("Uploads actions", () => {
send: send,
setRequestHeader: jest.fn(),
upload: {
addEventListener: jest.fn(),
},
addEventListener: jest.fn()
}
})
window.XMLHttpRequest = jest.fn().mockImplementation(xhrMockClass)
const store = mockStore({
buckets: {
currentBucket: "test1",
currentBucket: "test1"
},
objects: {
currentPrefix: "pre1/",
},
currentPrefix: "pre1/"
}
})
store.dispatch(uploadsActions.uploadFile(file))
expect(open).toHaveBeenCalledWith(
"PUT",
"https://localhost:8080/upload/test1/pre1/file1",
true,
true
)
expect(send).toHaveBeenCalledWith(file)
})
@@ -164,12 +164,12 @@ describe("Uploads actions", () => {
const expectedActions = [
{
type: "uploads/STOP",
slug: "a-b/-c",
slug: "a-b/-c"
},
{
type: "uploads/SHOW_ABORT_MODAL",
show: false,
},
show: false
}
]
store.dispatch(uploadsActions.abortUpload("a-b/-c"))
const actions = store.getActions()

View File

@@ -22,7 +22,7 @@ describe("uploads reducer", () => {
const initialState = reducer(undefined, {})
expect(initialState).toEqual({
files: {},
showAbortModal: false,
showAbortModal: false
})
})
@@ -31,14 +31,14 @@ describe("uploads reducer", () => {
type: actions.ADD,
slug: "a-b-c",
size: 100,
name: "test",
name: "test"
})
expect(newState.files).toEqual({
"a-b-c": {
loaded: 0,
size: 100,
name: "test",
},
name: "test"
}
})
})
@@ -49,22 +49,22 @@ describe("uploads reducer", () => {
"a-b-c": {
loaded: 0,
size: 100,
name: "test",
},
},
name: "test"
}
}
},
{
type: actions.UPDATE_PROGRESS,
slug: "a-b-c",
loaded: 50,
},
loaded: 50
}
)
expect(newState.files).toEqual({
"a-b-c": {
loaded: 50,
size: 100,
name: "test",
},
name: "test"
}
})
})
@@ -75,38 +75,38 @@ describe("uploads reducer", () => {
"a-b-c": {
loaded: 70,
size: 100,
name: "test1",
name: "test1"
},
"x-y-z": {
loaded: 50,
size: 100,
name: "test2",
},
},
name: "test2"
}
}
},
{
type: actions.STOP,
slug: "a-b-c",
},
slug: "a-b-c"
}
)
expect(newState.files).toEqual({
"x-y-z": {
loaded: 50,
size: 100,
name: "test2",
},
name: "test2"
}
})
})
it("should handle SHOW_ABORT_MODAL", () => {
const newState = reducer(
{
showAbortModal: false,
showAbortModal: false
},
{
type: actions.SHOW_ABORT_MODAL,
show: true,
},
show: true
}
)
expect(newState.showAbortModal).toBeTruthy()
})