mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fixed jasmine test cases.
This commit is contained in:
parent
17f18e795f
commit
79de2ad571
@ -74,6 +74,7 @@ export default class FileManagerModule {
|
|||||||
closeModal={closeModal}
|
closeModal={closeModal}
|
||||||
onCancel={onCancel}
|
onCancel={onCancel}
|
||||||
onOK={onOK}
|
onOK={onOK}
|
||||||
|
sharedStorages={this.pgAdmin.server_mode == 'True' ? this.pgAdmin.shared_storage: []}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}, {
|
}, {
|
||||||
|
@ -21,7 +21,6 @@ import MoreHorizRoundedIcon from '@material-ui/icons/MoreHorizRounded';
|
|||||||
import SyncRoundedIcon from '@material-ui/icons/SyncRounded';
|
import SyncRoundedIcon from '@material-ui/icons/SyncRounded';
|
||||||
import CreateNewFolderRoundedIcon from '@material-ui/icons/CreateNewFolderRounded';
|
import CreateNewFolderRoundedIcon from '@material-ui/icons/CreateNewFolderRounded';
|
||||||
import GetAppRoundedIcon from '@material-ui/icons/GetAppRounded';
|
import GetAppRoundedIcon from '@material-ui/icons/GetAppRounded';
|
||||||
import pgAdmin from 'sources/pgadmin';
|
|
||||||
import gettext from 'sources/gettext';
|
import gettext from 'sources/gettext';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import { FormFooterMessage, InputSelectNonSearch, InputText, MESSAGE_TYPE } from '../../../../../static/js/components/FormComponents';
|
import { FormFooterMessage, InputSelectNonSearch, InputText, MESSAGE_TYPE } from '../../../../../static/js/components/FormComponents';
|
||||||
@ -307,7 +306,9 @@ export class FileManagerUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setDialogView(view) {
|
setDialogView(view) {
|
||||||
this.config.options.defaultViewMode = view;
|
if(this.config.options != undefined)
|
||||||
|
this.config.options.defaultViewMode = view;
|
||||||
|
|
||||||
this.api.post(url_for('file_manager.save_file_dialog_view', {
|
this.api.post(url_for('file_manager.save_file_dialog_view', {
|
||||||
trans_id: this.transId,
|
trans_id: this.transId,
|
||||||
}), {view: view})
|
}), {view: view})
|
||||||
@ -401,7 +402,7 @@ ConfirmFile.propTypes = {
|
|||||||
onNo: PropTypes.func
|
onNo: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function FileManager({params, closeModal, onOK, onCancel}) {
|
export default function FileManager({params, closeModal, onOK, onCancel, sharedStorages=[]}) {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const modalClasses = useModalStyles();
|
const modalClasses = useModalStyles();
|
||||||
const apiObj = useMemo(()=>getApiInstance(), []);
|
const apiObj = useMemo(()=>getApiInstance(), []);
|
||||||
@ -696,10 +697,9 @@ export default function FileManager({params, closeModal, onOK, onCancel}) {
|
|||||||
{Boolean(confirmText) && <ConfirmFile text={confirmText} onNo={()=>setConfirmFile([null, null])} onYes={onConfirmYes}/>}
|
{Boolean(confirmText) && <ConfirmFile text={confirmText} onNo={()=>setConfirmFile([null, null])} onYes={onConfirmYes}/>}
|
||||||
<Box className={classes.toolbar}>
|
<Box className={classes.toolbar}>
|
||||||
<PgButtonGroup size="small" style={{flexGrow: 1}}>
|
<PgButtonGroup size="small" style={{flexGrow: 1}}>
|
||||||
{ pgAdmin.server_mode == 'True' && pgAdmin.shared_storage.length > 0?
|
{ sharedStorages.length > 0 &&
|
||||||
<PgIconButton title={ selectedSS == MY_STORAGE ? gettext('My Storage') :gettext(selectedSS)} icon={ selectedSS == MY_STORAGE ? <><FolderIcon/><KeyboardArrowDownIcon style={{marginLeft: '-10px'}} /></> : <><FolderSharedIcon /><KeyboardArrowDownIcon style={{marginLeft: '-10px'}} /></>} splitButton
|
<PgIconButton title={ selectedSS == MY_STORAGE ? gettext('My Storage') :gettext(selectedSS)} icon={ selectedSS == MY_STORAGE ? <><FolderIcon/><KeyboardArrowDownIcon style={{marginLeft: '-10px'}} /></> : <><FolderSharedIcon /><KeyboardArrowDownIcon style={{marginLeft: '-10px'}} /></>} splitButton
|
||||||
name="menu-shared-storage" ref={sharedSRef} onClick={toggleMenu} className={classes.sharedStorage}/>
|
name="menu-shared-storage" ref={sharedSRef} onClick={toggleMenu} className={classes.sharedStorage}/>
|
||||||
: <></>
|
|
||||||
}
|
}
|
||||||
<PgIconButton title={gettext('Home')} onClick={async ()=>{
|
<PgIconButton title={gettext('Home')} onClick={async ()=>{
|
||||||
await openDir(fmUtilsObj.config?.options?.homedir, selectedSS);
|
await openDir(fmUtilsObj.config?.options?.homedir, selectedSS);
|
||||||
@ -762,30 +762,33 @@ export default function FileManager({params, closeModal, onOK, onCancel}) {
|
|||||||
await openDir(fmUtilsObj.currPath, selectedSS);
|
await openDir(fmUtilsObj.currPath, selectedSS);
|
||||||
}}>{gettext('Show Hidden Files')}</PgMenuItem>
|
}}>{gettext('Show Hidden Files')}</PgMenuItem>
|
||||||
</PgMenu>
|
</PgMenu>
|
||||||
<PgMenu
|
{
|
||||||
anchorRef={sharedSRef}
|
sharedStorages.length > 0 &&
|
||||||
open={openMenuName=='menu-shared-storage'}
|
<PgMenu
|
||||||
onClose={onMenuClose}
|
anchorRef={sharedSRef}
|
||||||
label={gettext(`${selectedSS}`)}
|
open={openMenuName=='menu-shared-storage'}
|
||||||
>
|
onClose={onMenuClose}
|
||||||
<PgMenuItem hasCheck value="my_storage" checked={selectedSS == MY_STORAGE}
|
label={gettext(`${selectedSS}`)}
|
||||||
onClick={async (option)=> {
|
>
|
||||||
option.keepOpen = false;
|
<PgMenuItem hasCheck value="my_storage" checked={selectedSS == MY_STORAGE} datalabel={'my_storage'}
|
||||||
await changeDir(option.value);
|
onClick={async (option)=> {
|
||||||
}}><FolderIcon className={classes.sharedIcon}/><Box className={classes.storageName}>{gettext('My Storage')}</Box></PgMenuItem>
|
option.keepOpen = false;
|
||||||
|
await changeDir(option.value);
|
||||||
|
}}><FolderIcon className={classes.sharedIcon}/><Box className={classes.storageName}>{gettext('My Storage')}</Box></PgMenuItem>
|
||||||
|
|
||||||
{
|
{
|
||||||
pgAdmin.shared_storage.map((ss)=> {
|
sharedStorages.map((ss)=> {
|
||||||
return (
|
return (
|
||||||
<PgMenuItem key={ss} hasCheck value={ss} checked={selectedSS == ss}
|
<PgMenuItem key={ss} hasCheck value={ss} checked={selectedSS == ss} datalabel={ss}
|
||||||
onClick={async(option)=> {
|
onClick={async(option)=> {
|
||||||
option.keepOpen = false;
|
option.keepOpen = false;
|
||||||
await changeDir(option.value);
|
await changeDir(option.value);
|
||||||
}}><FolderSharedIcon className={classes.sharedIcon}/><Box className={classes.storageName}>{gettext(ss)}</Box></PgMenuItem>);
|
}}><FolderSharedIcon className={classes.sharedIcon}/><Box className={classes.storageName}>{gettext(ss)}</Box></PgMenuItem>);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
</PgMenu>
|
</PgMenu>
|
||||||
|
}
|
||||||
</Box>
|
</Box>
|
||||||
<Box flexGrow="1" display="flex" flexDirection="column" position="relative" overflow="hidden">
|
<Box flexGrow="1" display="flex" flexDirection="column" position="relative" overflow="hidden">
|
||||||
{showUploader &&
|
{showUploader &&
|
||||||
@ -848,4 +851,5 @@ FileManager.propTypes = {
|
|||||||
closeModal: PropTypes.func,
|
closeModal: PropTypes.func,
|
||||||
onOK: PropTypes.func,
|
onOK: PropTypes.func,
|
||||||
onCancel: PropTypes.func,
|
onCancel: PropTypes.func,
|
||||||
|
sharedStorages: PropTypes.array,
|
||||||
};
|
};
|
||||||
|
@ -104,7 +104,7 @@ export const PgMenuItem = applyStatics(MenuItem)(({hasCheck=false, checked=false
|
|||||||
props.onClick(e);
|
props.onClick(e);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const dataLabel = typeof(children) == 'string' ? children : undefined;
|
const dataLabel = typeof(children) == 'string' ? children : props.datalabel;
|
||||||
return <MenuItem {...props} onClick={onClick} data-label={dataLabel} data-checked={checked}>
|
return <MenuItem {...props} onClick={onClick} data-label={dataLabel} data-checked={checked}>
|
||||||
{hasCheck && <CheckIcon className={classes.checkIcon} style={checked ? {} : {visibility: 'hidden'}} />}
|
{hasCheck && <CheckIcon className={classes.checkIcon} style={checked ? {} : {visibility: 'hidden'}} />}
|
||||||
{children}
|
{children}
|
||||||
@ -120,6 +120,7 @@ PgMenuItem.propTypes = {
|
|||||||
children: CustomPropTypes.children,
|
children: CustomPropTypes.children,
|
||||||
closeOnCheck: PropTypes.bool,
|
closeOnCheck: PropTypes.bool,
|
||||||
onClick: PropTypes.func,
|
onClick: PropTypes.func,
|
||||||
|
dataLabel: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function usePgMenuGroup() {
|
export function usePgMenuGroup() {
|
||||||
|
@ -67,7 +67,8 @@ const configData = {
|
|||||||
'platform_type': 'darwin',
|
'platform_type': 'darwin',
|
||||||
'show_volumes': true,
|
'show_volumes': true,
|
||||||
'homedir': '/home/',
|
'homedir': '/home/',
|
||||||
'last_selected_format': '*'
|
'last_selected_format': '*',
|
||||||
|
'storage_folder': ''
|
||||||
},
|
},
|
||||||
'security': {
|
'security': {
|
||||||
'uploadPolicy': '',
|
'uploadPolicy': '',
|
||||||
@ -85,6 +86,8 @@ const configData = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sharedStorageConfig = ['Shared Storage'];
|
||||||
|
|
||||||
const params={
|
const params={
|
||||||
dialog_type: 'select_file',
|
dialog_type: 'select_file',
|
||||||
};
|
};
|
||||||
@ -123,6 +126,7 @@ describe('FileManger', ()=>{
|
|||||||
closeModal={closeModal}
|
closeModal={closeModal}
|
||||||
onOK={onOK}
|
onOK={onOK}
|
||||||
onCancel={onCancel}
|
onCancel={onCancel}
|
||||||
|
sharedStorages={sharedStorageConfig}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</Theme>);
|
</Theme>);
|
||||||
@ -150,6 +154,32 @@ describe('FileManger', ()=>{
|
|||||||
}, 0);
|
}, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Change Shared Storage', (done)=>{
|
||||||
|
networkMock.onPost('/file_manager/init').reply(200, {'data': configData});
|
||||||
|
let ctrl = ctrlMount({});
|
||||||
|
setTimeout(()=>{
|
||||||
|
ctrl.update();
|
||||||
|
ctrl.find('button[name="menu-shared-storage"]').simulate('click');
|
||||||
|
ctrl.find('Memo(MenuItem)[data-label="Shared Storage"]').simulate('click');
|
||||||
|
ctrl.update();
|
||||||
|
expect(ctrl.find('Shared Storage').length).toBe(0);
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Change Storage to My Storage', (done)=>{
|
||||||
|
networkMock.onPost('/file_manager/init').reply(200, {'data': configData});
|
||||||
|
let ctrl = ctrlMount({});
|
||||||
|
setTimeout(()=>{
|
||||||
|
ctrl.update();
|
||||||
|
ctrl.find('button[name="menu-shared-storage"]').simulate('click');
|
||||||
|
ctrl.find('Memo(MenuItem)[data-label="my_storage"]').simulate('click');
|
||||||
|
ctrl.update();
|
||||||
|
expect(ctrl.find('my_storage').length).toBe(0);
|
||||||
|
done();
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
describe('getComparator', ()=>{
|
describe('getComparator', ()=>{
|
||||||
it('Filename', ()=>{
|
it('Filename', ()=>{
|
||||||
expect(getComparator({columnKey: 'Filename', direction: 'ASC'})({Filename:'a'}, {Filename:'b'})).toBe(-1);
|
expect(getComparator({columnKey: 'Filename', direction: 'ASC'})({Filename:'a'}, {Filename:'b'})).toBe(-1);
|
||||||
@ -257,7 +287,7 @@ describe('FileManagerUtils', ()=>{
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('addFolder', async ()=>{
|
it('addFolder', async ()=>{
|
||||||
let res = await fmObj.addFolder({Filename: 'newfolder'});
|
let res = await fmObj.addFolder({Filename: 'newfolder', 'storage_folder': 'my_storage'});
|
||||||
expect(res).toEqual({
|
expect(res).toEqual({
|
||||||
Filename: 'newfolder',
|
Filename: 'newfolder',
|
||||||
Path: '/home/newfolder',
|
Path: '/home/newfolder',
|
||||||
@ -279,10 +309,10 @@ describe('FileManagerUtils', ()=>{
|
|||||||
|
|
||||||
it('deleteItem', async ()=>{
|
it('deleteItem', async ()=>{
|
||||||
let row = {Filename: 'newfolder', Path: '/home/newfolder'};
|
let row = {Filename: 'newfolder', Path: '/home/newfolder'};
|
||||||
let path = await fmObj.deleteItem(row);
|
let path = await fmObj.deleteItem(row, '');
|
||||||
expect(path).toBe('/home/newfolder');
|
expect(path).toBe('/home/newfolder');
|
||||||
|
|
||||||
path = await fmObj.deleteItem(row, 'file1');
|
path = await fmObj.deleteItem(row, '', 'file1');
|
||||||
expect(path).toBe('/home/newfolder/file1');
|
expect(path).toBe('/home/newfolder/file1');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -317,7 +347,7 @@ describe('FileManagerUtils', ()=>{
|
|||||||
|
|
||||||
it('downloadFile', async ()=>{
|
it('downloadFile', async ()=>{
|
||||||
spyOn(pgUtils, 'downloadBlob');
|
spyOn(pgUtils, 'downloadBlob');
|
||||||
let row = {Filename: 'newfile1', Path: '/home/newfile1'};
|
let row = {Filename: 'newfile1', Path: '/home/newfile1', 'storage_folder': 'my_storage'};
|
||||||
await fmObj.downloadFile(row);
|
await fmObj.downloadFile(row);
|
||||||
expect(pgUtils.downloadBlob).toHaveBeenCalledWith('blobdata', 'newfile1');
|
expect(pgUtils.downloadBlob).toHaveBeenCalledWith('blobdata', 'newfile1');
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user