Conversation
apps/files/js/filelist.js
Outdated
| if (!force && currentDir === targetDir) { | ||
| return; | ||
| } | ||
| if(this._currentDirectory && currentDir === targetDir) { |
There was a problem hiding this comment.
it seems this is what the previous if statement is doing.
Note that there is a force attribute to let callers force a refresh. With your approach this would break.
Did you have a look if it is possible to add this check much earlier, maybe inside app.js ?
There was a problem hiding this comment.
@PVince81 ,
I had a look, it's not possible to do this at a previous state.
There was a problem hiding this comment.
Have a look in FileList._onUrlChanged. Try adding the check there instead.
|
@PVince81 , |
apps/files/js/filelist.js
Outdated
| _onUrlChanged: function(e) { | ||
| if (e && _.isString(e.dir)) { | ||
| var currentDir = this.getCurrentDirectory(); | ||
| if(this._currentDirectory && currentDir === e.dir) { |
There was a problem hiding this comment.
Yes, looks better. Does it work ?
Also, why did you add this._currentDirectory in the check ? What's the purpose ?
There was a problem hiding this comment.
Yes, this works now as well.
The this._currentDirectory check is there because we wouldn't want to skip file loading at the root directory ( '/' ).
There was a problem hiding this comment.
if we are at root directory OR home page the initialised values of currentDir and e.dir turn out to be same, hence the file-loading doesn't complete at the root page.
To solve this, I introduced the check.
There was a problem hiding this comment.
Ah, I see. That makes sense. Please add a comment in the code to clarify this.
So basically this._currentDirectory is null/empty when the file list is first initialized
There was a problem hiding this comment.
Exactly.
Adding a comment.
|
Now curious if some unit test will fail. Would be good to have a JS unit test for that case too. |
|
@PVince81 , |
The case you just fixed here. Add the following tests for FileList:
I'll first let you look at the "fileListSpec.js" file to find existing tests you could based this on. |
|
@PVince81 , |
| var currentDir = this.getCurrentDirectory(); | ||
| // this._currentDirectory is NULL when fileList is first initialised | ||
| if(this._currentDirectory && currentDir === e.dir) { | ||
| if( (this._currentDirectory || this.$el.find('#dir').val()) && currentDir === e.dir) { |
There was a problem hiding this comment.
no, don't use the old crappy '#dir' element. This should be the same value like this.getCurrentDirectory() already.
There was a problem hiding this comment.
This is neccesary, otherwise the first test fails
in the test, this._currentDirectory remains null for some reason.
There was a problem hiding this comment.
Then we should rather fix the test instead. Maybe something is missing in the test initialization.
There was a problem hiding this comment.
should I remove this then and look into why it's not initialised?
apps/files/tests/js/filelistSpec.js
Outdated
|
|
||
| beforeEach(function() { | ||
| if (fileList) { | ||
| fileList.destroy(); |
There was a problem hiding this comment.
You don't need to destroy here, remove this. The afterEach in a higher level at the top of the file already takes care of this.
apps/files/tests/js/filelistSpec.js
Outdated
| if (fileList) { | ||
| fileList.destroy(); | ||
| } | ||
| fileList = new OCA.Files.FileList($('#app-content-files'), { |
There was a problem hiding this comment.
also no need to create, the very first beforeEach does that already.
apps/files/tests/js/filelistSpec.js
Outdated
| fileListStub.restore(); | ||
| }) | ||
| it('File list must be refreshed', function() { | ||
| console.log(fileList.getCurrentDirectory()); |
| it('File list must be refreshed', function() { | ||
| console.log(fileList.getCurrentDirectory()); | ||
| $('#app-content-files').trigger(new $.Event('urlChanged', {dir: '/'})); | ||
| expect(fileListStub.notCalled).toEqual(false); |
There was a problem hiding this comment.
use fileListStub.calledOnce here, it's better
There was a problem hiding this comment.
should that be called exactly once?
There was a problem hiding this comment.
Yes. Enforcing exactly once is also a good practice.
Just in case future bugs would make it be called multiple times...
| testMountType(123, 'external-root', 'external', 'external'); | ||
| }); | ||
| }); | ||
| describe('file list should not refresh if url does not change', function() { |
There was a problem hiding this comment.
You only need one describe block to group your two tests.
describe('file list url refresh tests', function() {
beforeEach(...);
afterEach(...);
it('does not reload the file list if path in url does not change', ...);
it('refreshes the file list after list creation', ...);
});|
@PVince81 , Thanks. |
|
@butonic , |
|
@noveens I looked into it and it seems that it's more complicated than I thought. We can't easily get rid of '#dir' at this point. So I'm willing to accept the PR as it is, with the '#dir' check inside the event handler, for now. If you also agree, feel free to merge this directly as the tests pass 👍 |
apps/files/tests/js/filelistSpec.js
Outdated
| }); | ||
| afterEach(function() { | ||
| fileListStub.restore(); | ||
| }) |
There was a problem hiding this comment.
one more thing: missing semicolon here.
If you run jshint/jslint on JS files it will tell you that. Maybe your IDE has an option for this.
|
@PVince81 , Thanks. |
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
Fixes #15520
Fixes #26318
The filelist is refreshed if and only if the directory is changed and not otherwise.
Related Issue
#15520
#26318
Motivation and Context
How Has This Been Tested?
Tested at all directories.
Types of changes
Checklist: