fix(fe/files): sharings info is not updated
This commit is contained in:
parent
25a2fdad04
commit
ee0fcb5691
4 changed files with 45 additions and 21 deletions
|
@ -1,4 +1,3 @@
|
|||
import { mock, instance, verify, when, anything } from "ts-mockito";
|
||||
import { List } from "immutable";
|
||||
|
||||
import { initMockWorker } from "../../test/helpers";
|
||||
|
@ -39,20 +38,8 @@ describe("FilesPanel", () => {
|
|||
test("chdir", async () => {
|
||||
const { filesPanel, usersCl, filesCl } = initFilesPanel();
|
||||
|
||||
const newSharings = ["mock_sharingfolder1", "mock_sharingfolder2"];
|
||||
const newCwd = List(["newPos", "subFolder"]);
|
||||
|
||||
filesCl.setMock({
|
||||
...filesResps,
|
||||
listSharingsMockResp: {
|
||||
status: 200,
|
||||
statusText: "",
|
||||
data: {
|
||||
sharingDirs: newSharings,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await filesPanel.chdir(newCwd);
|
||||
|
||||
expect(updater().props.filesInfo.dirPath).toEqual(newCwd);
|
||||
|
@ -60,8 +47,31 @@ describe("FilesPanel", () => {
|
|||
expect(updater().props.filesInfo.items).toEqual(
|
||||
List(filesResps.listHomeMockResp.data.metadatas)
|
||||
);
|
||||
});
|
||||
|
||||
test("addSharing", async () => {
|
||||
const { filesPanel, usersCl, filesCl } = initFilesPanel();
|
||||
|
||||
const newSharingPath = List(["newPos", "subFolder"]);
|
||||
const sharingDirs = [newSharingPath.join("/")];
|
||||
|
||||
filesCl.setMock({
|
||||
...filesResps,
|
||||
listSharingsMockResp: {
|
||||
status: 200,
|
||||
statusText: "",
|
||||
data: {
|
||||
sharingDirs: sharingDirs,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await filesPanel.addSharing(newSharingPath);
|
||||
|
||||
|
||||
expect(updater().props.filesInfo.isSharing).toEqual(true);
|
||||
expect(updater().props.sharingsInfo.sharings).toEqual(
|
||||
List(filesResps.listSharingsMockResp.data.sharingDirs)
|
||||
List(sharingDirs)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -128,8 +128,6 @@ export class FilesPanel extends React.Component<Props, State, {}> {
|
|||
}
|
||||
updater().addUploads(fileList);
|
||||
this.props.update(updater().updateUploadingsInfo);
|
||||
// this.props.update(updater().updateFilesInfo);
|
||||
// this.props.update(updater().updateSharingsInfo);
|
||||
};
|
||||
|
||||
onNewFolderNameChange = (ev: React.ChangeEvent<HTMLInputElement>) => {
|
||||
|
@ -308,11 +306,12 @@ export class FilesPanel extends React.Component<Props, State, {}> {
|
|||
alertMsg(this.props.msg.pkg.get("browser.share.add.fail"));
|
||||
} else {
|
||||
updater().setSharing(true);
|
||||
return updater().listSharings();
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
this.props.update(updater().updateFilesInfo);
|
||||
this.props.update(updater().updateSharingsInfo);
|
||||
this.props.update(updater().updateFilesInfo);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -324,11 +323,12 @@ export class FilesPanel extends React.Component<Props, State, {}> {
|
|||
alertMsg(this.props.msg.pkg.get("browser.share.del.fail"));
|
||||
} else {
|
||||
updater().setSharing(false);
|
||||
return updater().listSharings();
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
this.props.update(updater().updateFilesInfo);
|
||||
this.props.update(updater().updateSharingsInfo);
|
||||
this.props.update(updater().updateFilesInfo);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -74,8 +74,8 @@ export class StateMgr extends React.Component<Props, State, {}> {
|
|||
});
|
||||
};
|
||||
|
||||
update = (apply: (prevState: ICoreState) => ICoreState): void => {
|
||||
this.setState(apply(this.state));
|
||||
update = (update: (prevState: ICoreState) => ICoreState): void => {
|
||||
this.setState(update(this.state));
|
||||
};
|
||||
|
||||
render() {
|
||||
|
|
|
@ -63,7 +63,6 @@ export class Updater {
|
|||
this.props.uploadingsInfo.uploadings.forEach((entry) => {
|
||||
Up().addStopped(entry.filePath, entry.uploaded, entry.size);
|
||||
});
|
||||
// this.setUploadings(Up().list());
|
||||
};
|
||||
|
||||
addUploads = (fileList: List<File>) => {
|
||||
|
@ -705,6 +704,21 @@ export class Updater {
|
|||
return resp.status;
|
||||
};
|
||||
|
||||
updateAll = (prevState: ICoreState): ICoreState => {
|
||||
return {
|
||||
filesInfo: { ...prevState.filesInfo, ...this.props.filesInfo },
|
||||
uploadingsInfo: {
|
||||
...prevState.uploadingsInfo,
|
||||
...this.props.uploadingsInfo,
|
||||
},
|
||||
sharingsInfo: { ...prevState.sharingsInfo, ...this.props.sharingsInfo },
|
||||
login: { ...prevState.login, ...this.props.login },
|
||||
admin: { ...prevState.admin, ...this.props.admin },
|
||||
msg: { ...prevState.msg, ...this.props.msg },
|
||||
ui: { ...prevState.ui, ...this.props.ui },
|
||||
};
|
||||
};
|
||||
|
||||
updateFilesInfo = (prevState: ICoreState): ICoreState => {
|
||||
return {
|
||||
...prevState,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue