Use promise syntax with Helper.getContent

Fix
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12198#note_37143217
This commit is contained in:
Eric Eastwood 2017-08-10 14:01:32 -05:00
parent f1e1113bf4
commit ecb7c534f6
3 changed files with 13 additions and 12 deletions

View file

@ -42,19 +42,20 @@ const RepoSidebar = {
file.loading = false;
} else {
Service.url = file.url;
// I need to refactor this to do the `then` here.
// Not a callback. For now this is good enough.
// it works.
Helper.getContent(file, () => {
file.loading = false;
Helper.scrollTabsRight();
});
Helper.getContent(file)
.then(() => {
file.loading = false;
Helper.scrollTabsRight();
})
.catch(Helper.loadingError);
}
},
goToPreviousDirectoryClicked(prevURL) {
Service.url = prevURL;
Helper.getContent(null, () => Helper.scrollTabsRight());
Helper.getContent(null)
.then(() => Helper.scrollTabsRight())
.catch(Helper.loadingError);
},
},
};

View file

@ -135,14 +135,13 @@ const RepoHelper = {
return isRoot;
},
getContent(treeOrFile, cb) {
getContent(treeOrFile) {
let file = treeOrFile;
// const loadingData = RepoHelper.setLoading(true);
return Service.getContent()
.then((response) => {
const data = response.data;
// RepoHelper.setLoading(false, loadingData);
if (cb) cb();
Store.isTree = RepoHelper.isTree(data);
if (!Store.isTree) {
if (!file) file = data;

View file

@ -64,9 +64,10 @@ describe('RepoSidebar', () => {
describe('methods', () => {
describe('fileClicked', () => {
it('should fetch data for new file', () => {
spyOn(Helper, 'getContent');
spyOn(Helper, 'getContent').and.callThrough();
const file1 = {
id: 0,
url: '',
};
RepoStore.files = [file1];
RepoStore.isRoot = true;
@ -74,7 +75,7 @@ describe('RepoSidebar', () => {
vm.fileClicked(file1);
expect(Helper.getContent).toHaveBeenCalledWith(file1, jasmine.any(Function));
expect(Helper.getContent).toHaveBeenCalledWith(file1);
});
it('should hide files in directory if already open', () => {