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}
|
||||
onCancel={onCancel}
|
||||
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 CreateNewFolderRoundedIcon from '@material-ui/icons/CreateNewFolderRounded';
|
||||
import GetAppRoundedIcon from '@material-ui/icons/GetAppRounded';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import gettext from 'sources/gettext';
|
||||
import clsx from 'clsx';
|
||||
import { FormFooterMessage, InputSelectNonSearch, InputText, MESSAGE_TYPE } from '../../../../../static/js/components/FormComponents';
|
||||
@ -307,7 +306,9 @@ export class FileManagerUtils {
|
||||
}
|
||||
|
||||
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', {
|
||||
trans_id: this.transId,
|
||||
}), {view: view})
|
||||
@ -401,7 +402,7 @@ ConfirmFile.propTypes = {
|
||||
onNo: PropTypes.func
|
||||
};
|
||||
|
||||
export default function FileManager({params, closeModal, onOK, onCancel}) {
|
||||
export default function FileManager({params, closeModal, onOK, onCancel, sharedStorages=[]}) {
|
||||
const classes = useStyles();
|
||||
const modalClasses = useModalStyles();
|
||||
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}/>}
|
||||
<Box className={classes.toolbar}>
|
||||
<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
|
||||
name="menu-shared-storage" ref={sharedSRef} onClick={toggleMenu} className={classes.sharedStorage}/>
|
||||
: <></>
|
||||
}
|
||||
<PgIconButton title={gettext('Home')} onClick={async ()=>{
|
||||
await openDir(fmUtilsObj.config?.options?.homedir, selectedSS);
|
||||
@ -762,30 +762,33 @@ export default function FileManager({params, closeModal, onOK, onCancel}) {
|
||||
await openDir(fmUtilsObj.currPath, selectedSS);
|
||||
}}>{gettext('Show Hidden Files')}</PgMenuItem>
|
||||
</PgMenu>
|
||||
<PgMenu
|
||||
anchorRef={sharedSRef}
|
||||
open={openMenuName=='menu-shared-storage'}
|
||||
onClose={onMenuClose}
|
||||
label={gettext(`${selectedSS}`)}
|
||||
>
|
||||
<PgMenuItem hasCheck value="my_storage" checked={selectedSS == MY_STORAGE}
|
||||
onClick={async (option)=> {
|
||||
option.keepOpen = false;
|
||||
await changeDir(option.value);
|
||||
}}><FolderIcon className={classes.sharedIcon}/><Box className={classes.storageName}>{gettext('My Storage')}</Box></PgMenuItem>
|
||||
{
|
||||
sharedStorages.length > 0 &&
|
||||
<PgMenu
|
||||
anchorRef={sharedSRef}
|
||||
open={openMenuName=='menu-shared-storage'}
|
||||
onClose={onMenuClose}
|
||||
label={gettext(`${selectedSS}`)}
|
||||
>
|
||||
<PgMenuItem hasCheck value="my_storage" checked={selectedSS == MY_STORAGE} datalabel={'my_storage'}
|
||||
onClick={async (option)=> {
|
||||
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)=> {
|
||||
return (
|
||||
<PgMenuItem key={ss} hasCheck value={ss} checked={selectedSS == ss}
|
||||
onClick={async(option)=> {
|
||||
option.keepOpen = false;
|
||||
await changeDir(option.value);
|
||||
}}><FolderSharedIcon className={classes.sharedIcon}/><Box className={classes.storageName}>{gettext(ss)}</Box></PgMenuItem>);
|
||||
})
|
||||
}
|
||||
{
|
||||
sharedStorages.map((ss)=> {
|
||||
return (
|
||||
<PgMenuItem key={ss} hasCheck value={ss} checked={selectedSS == ss} datalabel={ss}
|
||||
onClick={async(option)=> {
|
||||
option.keepOpen = false;
|
||||
await changeDir(option.value);
|
||||
}}><FolderSharedIcon className={classes.sharedIcon}/><Box className={classes.storageName}>{gettext(ss)}</Box></PgMenuItem>);
|
||||
})
|
||||
}
|
||||
|
||||
</PgMenu>
|
||||
</PgMenu>
|
||||
}
|
||||
</Box>
|
||||
<Box flexGrow="1" display="flex" flexDirection="column" position="relative" overflow="hidden">
|
||||
{showUploader &&
|
||||
@ -848,4 +851,5 @@ FileManager.propTypes = {
|
||||
closeModal: PropTypes.func,
|
||||
onOK: PropTypes.func,
|
||||
onCancel: PropTypes.func,
|
||||
sharedStorages: PropTypes.array,
|
||||
};
|
||||
|
@ -104,7 +104,7 @@ export const PgMenuItem = applyStatics(MenuItem)(({hasCheck=false, checked=false
|
||||
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}>
|
||||
{hasCheck && <CheckIcon className={classes.checkIcon} style={checked ? {} : {visibility: 'hidden'}} />}
|
||||
{children}
|
||||
@ -120,6 +120,7 @@ PgMenuItem.propTypes = {
|
||||
children: CustomPropTypes.children,
|
||||
closeOnCheck: PropTypes.bool,
|
||||
onClick: PropTypes.func,
|
||||
dataLabel: PropTypes.string,
|
||||
};
|
||||
|
||||
export function usePgMenuGroup() {
|
||||
|
@ -67,7 +67,8 @@ const configData = {
|
||||
'platform_type': 'darwin',
|
||||
'show_volumes': true,
|
||||
'homedir': '/home/',
|
||||
'last_selected_format': '*'
|
||||
'last_selected_format': '*',
|
||||
'storage_folder': ''
|
||||
},
|
||||
'security': {
|
||||
'uploadPolicy': '',
|
||||
@ -85,6 +86,8 @@ const configData = {
|
||||
}
|
||||
};
|
||||
|
||||
const sharedStorageConfig = ['Shared Storage'];
|
||||
|
||||
const params={
|
||||
dialog_type: 'select_file',
|
||||
};
|
||||
@ -123,6 +126,7 @@ describe('FileManger', ()=>{
|
||||
closeModal={closeModal}
|
||||
onOK={onOK}
|
||||
onCancel={onCancel}
|
||||
sharedStorages={sharedStorageConfig}
|
||||
{...props}
|
||||
/>
|
||||
</Theme>);
|
||||
@ -150,6 +154,32 @@ describe('FileManger', ()=>{
|
||||
}, 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', ()=>{
|
||||
it('Filename', ()=>{
|
||||
expect(getComparator({columnKey: 'Filename', direction: 'ASC'})({Filename:'a'}, {Filename:'b'})).toBe(-1);
|
||||
@ -257,7 +287,7 @@ describe('FileManagerUtils', ()=>{
|
||||
});
|
||||
|
||||
it('addFolder', async ()=>{
|
||||
let res = await fmObj.addFolder({Filename: 'newfolder'});
|
||||
let res = await fmObj.addFolder({Filename: 'newfolder', 'storage_folder': 'my_storage'});
|
||||
expect(res).toEqual({
|
||||
Filename: 'newfolder',
|
||||
Path: '/home/newfolder',
|
||||
@ -279,10 +309,10 @@ describe('FileManagerUtils', ()=>{
|
||||
|
||||
it('deleteItem', async ()=>{
|
||||
let row = {Filename: 'newfolder', Path: '/home/newfolder'};
|
||||
let path = await fmObj.deleteItem(row);
|
||||
let path = await fmObj.deleteItem(row, '');
|
||||
expect(path).toBe('/home/newfolder');
|
||||
|
||||
path = await fmObj.deleteItem(row, 'file1');
|
||||
path = await fmObj.deleteItem(row, '', 'file1');
|
||||
expect(path).toBe('/home/newfolder/file1');
|
||||
});
|
||||
|
||||
@ -317,7 +347,7 @@ describe('FileManagerUtils', ()=>{
|
||||
|
||||
it('downloadFile', async ()=>{
|
||||
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);
|
||||
expect(pgUtils.downloadBlob).toHaveBeenCalledWith('blobdata', 'newfile1');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user