@ -26,21 +26,21 @@ jest.mock("../../web", () => ({
return Promise . resolve ( {
return Promise . resolve ( {
objects : [
objects : [
{
{
name : "test1" ,
name : "test1"
} ,
} ,
{
{
name : "test2" ,
name : "test2"
} ,
}
] ,
] ,
istruncated : false ,
istruncated : false ,
nextmarker : "test2" ,
nextmarker : "test2" ,
writable : false ,
writable : false
} )
} )
} ) ,
} ) ,
RemoveObject : jest . fn ( ( { bucketName , objects } ) => {
RemoveObject : jest . fn ( ( { bucketName , objects } ) => {
if ( ! bucketName ) {
if ( ! bucketName ) {
return Promise . reject ( {
return Promise . reject ( {
message : "Invalid bucket" ,
message : "Invalid bucket"
} )
} )
}
}
return Promise . resolve ( { } )
return Promise . resolve ( { } )
@ -48,30 +48,30 @@ jest.mock("../../web", () => ({
PresignedGet : jest . fn ( ( { bucket , object } ) => {
PresignedGet : jest . fn ( ( { bucket , object } ) => {
if ( ! bucket ) {
if ( ! bucket ) {
return Promise . reject ( {
return Promise . reject ( {
message : "Invalid bucket" ,
message : "Invalid bucket"
} )
} )
}
}
return Promise . resolve ( {
return Promise . resolve ( {
url : "https://test.com/bk1/pre1/b.txt" ,
url : "https://test.com/bk1/pre1/b.txt"
} )
} )
} ) ,
} ) ,
CreateURLToken : jest
CreateURLToken : jest
. fn ( )
. fn ( )
. mockImplementationOnce ( ( ) => {
. mockImplementationOnce ( ( ) => {
return Promise . resolve ( {
return Promise . resolve ( {
token : "test" ,
token : "test"
} )
} )
} )
} )
. mockImplementationOnce ( ( ) => {
. mockImplementationOnce ( ( ) => {
return Promise . reject ( {
return Promise . reject ( {
message : "Error in creating token" ,
message : "Error in creating token"
} )
} )
} )
} )
. mockImplementationOnce ( ( ) => {
. mockImplementationOnce ( ( ) => {
return Promise . resolve ( {
return Promise . resolve ( {
token : "test" ,
token : "test"
} )
} )
} )
} ) ,
} ) )
} ) )
const middlewares = [ thunk ]
const middlewares = [ thunk ]
@ -85,29 +85,29 @@ describe("Objects actions", () => {
type : "objects/SET_LIST" ,
type : "objects/SET_LIST" ,
objects : [
objects : [
{
{
name : "test1" ,
name : "test1"
} ,
} ,
{
{
name : "test2" ,
name : "test2"
} ,
}
] ,
] ,
isTruncated : false ,
isTruncated : false ,
marker : "test2" ,
marker : "test2"
} ,
}
]
]
store . dispatch (
store . dispatch (
actionsObjects . setList (
actionsObjects . setList (
[
[
{
{
name : "test1" ,
name : "test1"
} ,
} ,
{
{
name : "test2" ,
name : "test2"
} ,
}
] ,
] ,
"test2" ,
"test2" ,
false ,
false
) ,
)
)
)
const actions = store . getActions ( )
const actions = store . getActions ( )
expect ( actions ) . toEqual ( expectedActions )
expect ( actions ) . toEqual ( expectedActions )
@ -118,8 +118,8 @@ describe("Objects actions", () => {
const expectedActions = [
const expectedActions = [
{
{
type : "objects/SET_SORT_BY" ,
type : "objects/SET_SORT_BY" ,
sortBy : "name" ,
sortBy : "name"
} ,
}
]
]
store . dispatch ( actionsObjects . setSortBy ( "name" ) )
store . dispatch ( actionsObjects . setSortBy ( "name" ) )
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -131,8 +131,8 @@ describe("Objects actions", () => {
const expectedActions = [
const expectedActions = [
{
{
type : "objects/SET_SORT_ORDER" ,
type : "objects/SET_SORT_ORDER" ,
sortOrder : true ,
sortOrder : true
} ,
}
]
]
store . dispatch ( actionsObjects . setSortOrder ( true ) )
store . dispatch ( actionsObjects . setSortOrder ( true ) )
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -142,38 +142,38 @@ describe("Objects actions", () => {
it ( "creates objects/SET_LIST after fetching the objects" , ( ) => {
it ( "creates objects/SET_LIST after fetching the objects" , ( ) => {
const store = mockStore ( {
const store = mockStore ( {
buckets : {
buckets : {
currentBucket : "bk1" ,
currentBucket : "bk1"
} ,
} ,
objects : {
objects : {
currentPrefix : "" ,
currentPrefix : ""
} ,
}
} )
} )
const expectedActions = [
const expectedActions = [
{
{
type : "objects/SET_LIST" ,
type : "objects/SET_LIST" ,
objects : [
objects : [
{
{
name : "test1" ,
name : "test1"
} ,
} ,
{
{
name : "test2" ,
name : "test2"
} ,
}
] ,
] ,
marker : "test2" ,
marker : "test2" ,
isTruncated : false ,
isTruncated : false
} ,
} ,
{
{
type : "objects/SET_SORT_BY" ,
type : "objects/SET_SORT_BY" ,
sortBy : "" ,
sortBy : ""
} ,
} ,
{
{
type : "objects/SET_SORT_ORDER" ,
type : "objects/SET_SORT_ORDER" ,
sortOrder : false ,
sortOrder : false
} ,
} ,
{
{
type : "objects/SET_PREFIX_WRITABLE" ,
type : "objects/SET_PREFIX_WRITABLE" ,
prefixWritable : false ,
prefixWritable : false
} ,
}
]
]
return store . dispatch ( actionsObjects . fetchObjects ( ) ) . then ( ( ) => {
return store . dispatch ( actionsObjects . fetchObjects ( ) ) . then ( ( ) => {
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -184,30 +184,30 @@ describe("Objects actions", () => {
it ( "creates objects/APPEND_LIST after fetching more objects" , ( ) => {
it ( "creates objects/APPEND_LIST after fetching more objects" , ( ) => {
const store = mockStore ( {
const store = mockStore ( {
buckets : {
buckets : {
currentBucket : "bk1" ,
currentBucket : "bk1"
} ,
} ,
objects : {
objects : {
currentPrefix : "" ,
currentPrefix : ""
} ,
}
} )
} )
const expectedActions = [
const expectedActions = [
{
{
type : "objects/APPEND_LIST" ,
type : "objects/APPEND_LIST" ,
objects : [
objects : [
{
{
name : "test1" ,
name : "test1"
} ,
} ,
{
{
name : "test2" ,
name : "test2"
} ,
}
] ,
] ,
marker : "test2" ,
marker : "test2" ,
isTruncated : false ,
isTruncated : false
} ,
} ,
{
{
type : "objects/SET_PREFIX_WRITABLE" ,
type : "objects/SET_PREFIX_WRITABLE" ,
prefixWritable : false ,
prefixWritable : false
} ,
}
]
]
return store . dispatch ( actionsObjects . fetchObjects ( true ) ) . then ( ( ) => {
return store . dispatch ( actionsObjects . fetchObjects ( true ) ) . then ( ( ) => {
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -222,24 +222,24 @@ describe("Objects actions", () => {
sortBy : "" ,
sortBy : "" ,
sortOrder : false ,
sortOrder : false ,
isTruncated : false ,
isTruncated : false ,
marker : "" ,
marker : ""
} ,
}
} )
} )
const expectedActions = [
const expectedActions = [
{
{
type : "objects/SET_SORT_BY" ,
type : "objects/SET_SORT_BY" ,
sortBy : "name" ,
sortBy : "name"
} ,
} ,
{
{
type : "objects/SET_SORT_ORDER" ,
type : "objects/SET_SORT_ORDER" ,
sortOrder : true ,
sortOrder : true
} ,
} ,
{
{
type : "objects/SET_LIST" ,
type : "objects/SET_LIST" ,
objects : [ ] ,
objects : [ ] ,
isTruncated : false ,
isTruncated : false ,
marker : "" ,
marker : ""
} ,
}
]
]
store . dispatch ( actionsObjects . sortObjects ( "name" ) )
store . dispatch ( actionsObjects . sortObjects ( "name" ) )
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -249,20 +249,20 @@ describe("Objects actions", () => {
it ( "should update browser url and creates objects/SET_CURRENT_PREFIX and objects/CHECKED_LIST_RESET actions when selectPrefix is called" , ( ) => {
it ( "should update browser url and creates objects/SET_CURRENT_PREFIX and objects/CHECKED_LIST_RESET actions when selectPrefix is called" , ( ) => {
const store = mockStore ( {
const store = mockStore ( {
buckets : {
buckets : {
currentBucket : "test" ,
currentBucket : "test"
} ,
} ,
objects : {
objects : {
currentPrefix : "" ,
currentPrefix : ""
} ,
}
} )
} )
const expectedActions = [
const expectedActions = [
{
{
type : "objects/SET_CURRENT_PREFIX" ,
type : "objects/SET_CURRENT_PREFIX" ,
prefix : "abc/" ,
prefix : "abc/"
} ,
} ,
{
{
type : "objects/CHECKED_LIST_RESET" ,
type : "objects/CHECKED_LIST_RESET"
} ,
}
]
]
store . dispatch ( actionsObjects . selectPrefix ( "abc/" ) )
store . dispatch ( actionsObjects . selectPrefix ( "abc/" ) )
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -275,8 +275,8 @@ describe("Objects actions", () => {
const expectedActions = [
const expectedActions = [
{
{
type : "objects/SET_PREFIX_WRITABLE" ,
type : "objects/SET_PREFIX_WRITABLE" ,
prefixWritable : true ,
prefixWritable : true
} ,
}
]
]
store . dispatch ( actionsObjects . setPrefixWritable ( true ) )
store . dispatch ( actionsObjects . setPrefixWritable ( true ) )
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -288,8 +288,8 @@ describe("Objects actions", () => {
const expectedActions = [
const expectedActions = [
{
{
type : "objects/REMOVE" ,
type : "objects/REMOVE" ,
object : "obj1" ,
object : "obj1"
} ,
}
]
]
store . dispatch ( actionsObjects . removeObject ( "obj1" ) )
store . dispatch ( actionsObjects . removeObject ( "obj1" ) )
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -299,17 +299,17 @@ describe("Objects actions", () => {
it ( "creates objects/REMOVE action when object is deleted" , ( ) => {
it ( "creates objects/REMOVE action when object is deleted" , ( ) => {
const store = mockStore ( {
const store = mockStore ( {
buckets : {
buckets : {
currentBucket : "test" ,
currentBucket : "test"
} ,
} ,
objects : {
objects : {
currentPrefix : "pre1/" ,
currentPrefix : "pre1/"
} ,
}
} )
} )
const expectedActions = [
const expectedActions = [
{
{
type : "objects/REMOVE" ,
type : "objects/REMOVE" ,
object : "obj1" ,
object : "obj1"
} ,
}
]
]
store . dispatch ( actionsObjects . deleteObject ( "obj1" ) ) . then ( ( ) => {
store . dispatch ( actionsObjects . deleteObject ( "obj1" ) ) . then ( ( ) => {
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -320,11 +320,11 @@ describe("Objects actions", () => {
it ( "creates alert/SET action when invalid bucket is provided" , ( ) => {
it ( "creates alert/SET action when invalid bucket is provided" , ( ) => {
const store = mockStore ( {
const store = mockStore ( {
buckets : {
buckets : {
currentBucket : "" ,
currentBucket : ""
} ,
} ,
objects : {
objects : {
currentPrefix : "pre1/" ,
currentPrefix : "pre1/"
} ,
}
} )
} )
const expectedActions = [
const expectedActions = [
{
{
@ -332,9 +332,9 @@ describe("Objects actions", () => {
alert : {
alert : {
type : "danger" ,
type : "danger" ,
message : "Invalid bucket" ,
message : "Invalid bucket" ,
id : 0 ,
id : 0
} ,
}
} ,
}
]
]
return store . dispatch ( actionsObjects . deleteObject ( "obj1" ) ) . then ( ( ) => {
return store . dispatch ( actionsObjects . deleteObject ( "obj1" ) ) . then ( ( ) => {
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -349,8 +349,8 @@ describe("Objects actions", () => {
type : "objects/SET_SHARE_OBJECT" ,
type : "objects/SET_SHARE_OBJECT" ,
show : true ,
show : true ,
object : "b.txt" ,
object : "b.txt" ,
url : "test" ,
url : "test"
} ,
}
]
]
store . dispatch ( actionsObjects . showShareObject ( "b.txt" , "test" ) )
store . dispatch ( actionsObjects . showShareObject ( "b.txt" , "test" ) )
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -364,8 +364,8 @@ describe("Objects actions", () => {
type : "objects/SET_SHARE_OBJECT" ,
type : "objects/SET_SHARE_OBJECT" ,
show : false ,
show : false ,
object : "" ,
object : "" ,
url : "" ,
url : ""
} ,
}
]
]
store . dispatch ( actionsObjects . hideShareObject ( ) )
store . dispatch ( actionsObjects . hideShareObject ( ) )
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -375,27 +375,27 @@ describe("Objects actions", () => {
it ( "creates objects/SET_SHARE_OBJECT when object is shared" , ( ) => {
it ( "creates objects/SET_SHARE_OBJECT when object is shared" , ( ) => {
const store = mockStore ( {
const store = mockStore ( {
buckets : {
buckets : {
currentBucket : "bk1" ,
currentBucket : "bk1"
} ,
} ,
objects : {
objects : {
currentPrefix : "pre1/" ,
currentPrefix : "pre1/"
} ,
}
} )
} )
const expectedActions = [
const expectedActions = [
{
{
type : "objects/SET_SHARE_OBJECT" ,
type : "objects/SET_SHARE_OBJECT" ,
show : true ,
show : true ,
object : "a.txt" ,
object : "a.txt" ,
url : "https://test.com/bk1/pre1/b.txt" ,
url : "https://test.com/bk1/pre1/b.txt"
} ,
} ,
{
{
type : "alert/SET" ,
type : "alert/SET" ,
alert : {
alert : {
type : "success" ,
type : "success" ,
message : "Object shared. Expires in 1 days 0 hours 0 minutes" ,
message : "Object shared. Expires in 1 days 0 hours 0 minutes" ,
id : alertActions . alertId ,
id : alertActions . alertId
} ,
}
} ,
}
]
]
return store
return store
. dispatch ( actionsObjects . shareObject ( "a.txt" , 1 , 0 , 0 ) )
. dispatch ( actionsObjects . shareObject ( "a.txt" , 1 , 0 , 0 ) )
@ -408,11 +408,11 @@ describe("Objects actions", () => {
it ( "creates alert/SET when shareObject is failed" , ( ) => {
it ( "creates alert/SET when shareObject is failed" , ( ) => {
const store = mockStore ( {
const store = mockStore ( {
buckets : {
buckets : {
currentBucket : "" ,
currentBucket : ""
} ,
} ,
objects : {
objects : {
currentPrefix : "pre1/" ,
currentPrefix : "pre1/"
} ,
}
} )
} )
const expectedActions = [
const expectedActions = [
{
{
@ -420,9 +420,9 @@ describe("Objects actions", () => {
alert : {
alert : {
type : "danger" ,
type : "danger" ,
message : "Invalid bucket" ,
message : "Invalid bucket" ,
id : alertActions . alertId ,
id : alertActions . alertId
} ,
}
} ,
}
]
]
return store
return store
. dispatch ( actionsObjects . shareObject ( "a.txt" , 1 , 0 , 0 ) )
. dispatch ( actionsObjects . shareObject ( "a.txt" , 1 , 0 , 0 ) )
@ -438,15 +438,15 @@ describe("Objects actions", () => {
Object . defineProperty ( window , "location" , {
Object . defineProperty ( window , "location" , {
set ( url ) {
set ( url ) {
setLocation ( url )
setLocation ( url )
} ,
}
} )
} )
const store = mockStore ( {
const store = mockStore ( {
buckets : {
buckets : {
currentBucket : "bk1" ,
currentBucket : "bk1"
} ,
} ,
objects : {
objects : {
currentPrefix : "pre1/" ,
currentPrefix : "pre1/"
} ,
}
} )
} )
store . dispatch ( actionsObjects . downloadObject ( "obj1" ) )
store . dispatch ( actionsObjects . downloadObject ( "obj1" ) )
const url = ` ${
const url = ` ${
@ -460,21 +460,21 @@ describe("Objects actions", () => {
Object . defineProperty ( window , "location" , {
Object . defineProperty ( window , "location" , {
set ( url ) {
set ( url ) {
setLocation ( url )
setLocation ( url )
} ,
}
} )
} )
const store = mockStore ( {
const store = mockStore ( {
buckets : {
buckets : {
currentBucket : "bk1" ,
currentBucket : "bk1"
} ,
} ,
objects : {
objects : {
currentPrefix : "pre1/" ,
currentPrefix : "pre1/"
} ,
}
} )
} )
return store . dispatch ( actionsObjects . downloadObject ( "obj1" ) ) . then ( ( ) => {
return store . dispatch ( actionsObjects . downloadObject ( "obj1" ) ) . then ( ( ) => {
const url = ` ${
const url = ` ${
window . location . origin
window . location . origin
} $ { minioBrowserPrefix } / download / bk1 / $ { encodeURI (
} $ { minioBrowserPrefix } / download / bk1 / $ { encodeURI (
"pre1/obj1" ,
"pre1/obj1"
) } ? token = test `
) } ? token = test `
expect ( setLocation ) . toHaveBeenCalledWith ( url )
expect ( setLocation ) . toHaveBeenCalledWith ( url )
} )
} )
@ -483,11 +483,11 @@ describe("Objects actions", () => {
it ( "create alert/SET action when CreateUrlToken fails" , ( ) => {
it ( "create alert/SET action when CreateUrlToken fails" , ( ) => {
const store = mockStore ( {
const store = mockStore ( {
buckets : {
buckets : {
currentBucket : "bk1" ,
currentBucket : "bk1"
} ,
} ,
objects : {
objects : {
currentPrefix : "pre1/" ,
currentPrefix : "pre1/"
} ,
}
} )
} )
const expectedActions = [
const expectedActions = [
{
{
@ -495,9 +495,9 @@ describe("Objects actions", () => {
alert : {
alert : {
type : "danger" ,
type : "danger" ,
message : "Error in creating token" ,
message : "Error in creating token" ,
id : alertActions . alertId ,
id : alertActions . alertId
} ,
}
} ,
}
]
]
return store . dispatch ( actionsObjects . downloadObject ( "obj1" ) ) . then ( ( ) => {
return store . dispatch ( actionsObjects . downloadObject ( "obj1" ) ) . then ( ( ) => {
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -511,8 +511,8 @@ describe("Objects actions", () => {
const expectedActions = [
const expectedActions = [
{
{
type : "objects/CHECKED_LIST_ADD" ,
type : "objects/CHECKED_LIST_ADD" ,
object : "obj1" ,
object : "obj1"
} ,
}
]
]
store . dispatch ( actionsObjects . checkObject ( "obj1" ) )
store . dispatch ( actionsObjects . checkObject ( "obj1" ) )
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -524,8 +524,8 @@ describe("Objects actions", () => {
const expectedActions = [
const expectedActions = [
{
{
type : "objects/CHECKED_LIST_REMOVE" ,
type : "objects/CHECKED_LIST_REMOVE" ,
object : "obj1" ,
object : "obj1"
} ,
}
]
]
store . dispatch ( actionsObjects . uncheckObject ( "obj1" ) )
store . dispatch ( actionsObjects . uncheckObject ( "obj1" ) )
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -536,8 +536,8 @@ describe("Objects actions", () => {
const store = mockStore ( )
const store = mockStore ( )
const expectedActions = [
const expectedActions = [
{
{
type : "objects/CHECKED_LIST_RESET" ,
type : "objects/CHECKED_LIST_RESET"
} ,
}
]
]
store . dispatch ( actionsObjects . resetCheckedList ( ) )
store . dispatch ( actionsObjects . resetCheckedList ( ) )
const actions = store . getActions ( )
const actions = store . getActions ( )
@ -549,18 +549,18 @@ describe("Objects actions", () => {
const send = jest . fn ( )
const send = jest . fn ( )
const xhrMockClass = ( ) => ( {
const xhrMockClass = ( ) => ( {
open : open ,
open : open ,
send : send ,
send : send
} )
} )
window . XMLHttpRequest = jest . fn ( ) . mockImplementation ( xhrMockClass )
window . XMLHttpRequest = jest . fn ( ) . mockImplementation ( xhrMockClass )
const store = mockStore ( {
const store = mockStore ( {
buckets : {
buckets : {
currentBucket : "bk1" ,
currentBucket : "bk1"
} ,
} ,
objects : {
objects : {
currentPrefix : "pre1/" ,
currentPrefix : "pre1/" ,
checkedList : [ "obj1" ] ,
checkedList : [ "obj1" ]
} ,
}
} )
} )
return store . dispatch ( actionsObjects . downloadCheckedObjects ( ) ) . then ( ( ) => {
return store . dispatch ( actionsObjects . downloadCheckedObjects ( ) ) . then ( ( ) => {
const requestUrl = ` ${
const requestUrl = ` ${
@ -571,8 +571,8 @@ describe("Objects actions", () => {
JSON . stringify ( {
JSON . stringify ( {
bucketName : "bk1" ,
bucketName : "bk1" ,
prefix : "pre1/" ,
prefix : "pre1/" ,
objects : [ "obj1" ] ,
objects : [ "obj1" ]
} ) ,
} )
)
)
} )
} )
} )
} )