@ -18,7 +18,13 @@ import configureStore from "redux-mock-store"
import thunk from "redux-thunk"
import * as actionsObjects from "../actions"
import * as alertActions from "../../alert/actions"
import { minioBrowserPrefix } from "../../constants"
import {
minioBrowserPrefix ,
SORT _BY _NAME ,
SORT _ORDER _ASC ,
SORT _BY _LAST _MODIFIED ,
SORT _ORDER _DESC
} from "../../constants"
import history from "../../history"
jest . mock ( "../../web" , ( ) => ( {
@ -37,8 +43,6 @@ jest.mock("../../web", () => ({
} else {
return Promise . resolve ( {
objects : [ { name : "test1" } , { name : "test2" } ] ,
istruncated : false ,
nextmarker : "test2" ,
writable : false
} )
}
@ -77,17 +81,11 @@ describe("Objects actions", () => {
const expectedActions = [
{
type : "objects/SET_LIST" ,
objects : [ { name : "test1" } , { name : "test2" } ] ,
isTruncated : false ,
marker : "test2"
objects : [ { name : "test1" } , { name : "test2" } ]
}
]
store . dispatch (
actionsObjects . setList (
[ { name : "test1" } , { name : "test2" } ] ,
"test2" ,
false
)
actionsObjects . setList ( [ { name : "test1" } , { name : "test2" } ] )
)
const actions = store . getActions ( )
expect ( actions ) . toEqual ( expectedActions )
@ -98,10 +96,10 @@ describe("Objects actions", () => {
const expectedActions = [
{
type : "objects/SET_SORT_BY" ,
sortBy : "name"
sortBy : SORT _BY _NAME
}
]
store . dispatch ( actionsObjects . setSortBy ( "name" ) )
store . dispatch ( actionsObjects . setSortBy ( SORT _BY _NAME ) )
const actions = store . getActions ( )
expect ( actions ) . toEqual ( expectedActions )
} )
@ -111,10 +109,10 @@ describe("Objects actions", () => {
const expectedActions = [
{
type : "objects/SET_SORT_ORDER" ,
sortOrder : true
sortOrder : SORT _ORDER _ASC
}
]
store . dispatch ( actionsObjects . setSortOrder ( true ) )
store . dispatch ( actionsObjects . setSortOrder ( SORT _ORDER _ASC ) )
const actions = store . getActions ( )
expect ( actions ) . toEqual ( expectedActions )
} )
@ -126,48 +124,28 @@ describe("Objects actions", () => {
} )
const expectedActions = [
{
type : "objects/SET_LIST" ,
objects : [ { name : "test1" } , { name : "test2" } ] ,
marker : "test2" ,
isTruncated : false
type : "objects/RESET_LIST"
} ,
{ listLoading : true , type : "objects/SET_LIST_LOADING" } ,
{
type : "objects/SET_SORT_BY" ,
sortBy : ""
sortBy : SORT _BY _LAST _MODIFIED
} ,
{
type : "objects/SET_SORT_ORDER" ,
sortOrder : false
sortOrder : SORT _ORDER _DESC
} ,
{
type : "objects/SET_PREFIX_WRITABLE" ,
prefixWritable : false
}
]
return store . dispatch ( actionsObjects . fetchObjects ( ) ) . then ( ( ) => {
const actions = store . getActions ( )
expect ( actions ) . toEqual ( expectedActions )
} )
} )
it ( "creates objects/APPEND_LIST after fetching more objects" , ( ) => {
const store = mockStore ( {
buckets : { currentBucket : "bk1" } ,
objects : { currentPrefix : "" }
} )
const expectedActions = [
{
type : "objects/APPEND_LIST" ,
objects : [ { name : "test1" } , { name : "test2" } ] ,
marker : "test2" ,
isTruncated : false
type : "objects/SET_LIST" ,
objects : [ { name : "test2" } , { name : "test1" } ]
} ,
{
type : "objects/SET_PREFIX_WRITABLE" ,
prefixWritable : false
}
} ,
{ listLoading : false , type : "objects/SET_LIST_LOADING" }
]
return store . dispatch ( actionsObjects . fetchObjects ( true ) ) . then ( ( ) => {
return store . dispatch ( actionsObjects . fetchObjects ( ) ) . then ( ( ) => {
const actions = store . getActions ( )
expect ( actions ) . toEqual ( expectedActions )
} )
@ -179,6 +157,10 @@ describe("Objects actions", () => {
objects : { currentPrefix : "" }
} )
const expectedActions = [
{
type : "objects/RESET_LIST"
} ,
{ listLoading : true , type : "objects/SET_LIST_LOADING" } ,
{
type : "alert/SET" ,
alert : {
@ -189,8 +171,9 @@ describe("Objects actions", () => {
}
} ,
{
type : "object/RESET_LIST"
}
type : "objects/RESET_LIST"
} ,
{ listLoading : false , type : "objects/SET_LIST_LOADING" }
]
return store . dispatch ( actionsObjects . fetchObjects ( ) ) . then ( ( ) => {
const actions = store . getActions ( )
@ -213,28 +196,24 @@ describe("Objects actions", () => {
objects : {
list : [ ] ,
sortBy : "" ,
sortOrder : false ,
isTruncated : false ,
marker : ""
sortOrder : SORT _ORDER _ASC
}
} )
const expectedActions = [
{
type : "objects/SET_SORT_BY" ,
sortBy : "name"
sortBy : SORT _BY _NAME
} ,
{
type : "objects/SET_SORT_ORDER" ,
sortOrder : true
sortOrder : SORT _ORDER _ASC
} ,
{
type : "objects/SET_LIST" ,
objects : [ ] ,
isTruncated : false ,
marker : ""
objects : [ ]
}
]
store . dispatch ( actionsObjects . sortObjects ( "name" ) )
store . dispatch ( actionsObjects . sortObjects ( SORT _BY _NAME ) )
const actions = store . getActions ( )
expect ( actions ) . toEqual ( expectedActions )
} )
@ -246,6 +225,10 @@ describe("Objects actions", () => {
} )
const expectedActions = [
{ type : "objects/SET_CURRENT_PREFIX" , prefix : "abc/" } ,
{
type : "objects/RESET_LIST"
} ,
{ listLoading : true , type : "objects/SET_LIST_LOADING" } ,
{ type : "objects/CHECKED_LIST_RESET" }
]
store . dispatch ( actionsObjects . selectPrefix ( "abc/" ) )