Fix warning for unsaved work on beforeUnload
Review Request #8635 — Created Jan. 19, 2017 and submitted
Information | |
---|---|
khp | |
Review Board | |
master | |
4084 | |
3df832f... | |
Reviewers | |
reviewboard, students | |
Previously, when editing a review or comments as a user without
edit rights, warning users about losing unsaved work did not get
displayed.Now the ReviewRequestEditorView's beforeUnload event handler does
not check a user's edit rights and only checks to see if any
fields are being edited at the moment.New unit tests testing the onBeforeUnload event handler has been
added.
Ran JS unit tests.
Check that ReviewDialogView for both edit and non-edit privileged users are
warned before unloading.
Description | From | Last Updated |
---|---|---|
Did you run the JS unit tests or just the python unit tests? |
|
|
If we leave this and the corresponding decr() we should not need to add/remove the event handler for onBeforeUnload. It … |
|
|
This whole function should be unnecessary. See my other comments about the editCount stuff. |
|
|
Single quotes. This is an ES6 file (.es6.js instead of .js) so we can use const here instead of var. |
|
|
All declared variables in a function should be declared in a single var statement at the top of the function. |
|
|
Single quotes for strings. |
|
|
Why do we have to add/remove the handler if we are checking the edit count? |
|
|
Single quotes. |
|
|
Can your unit tests set or assert the editable states for these as well? Make sure that now (and in … |
|
|
When you have to escape a quote, you can instead use double quotes for the string. |
|
|
This is an internal function, so t should be _onBeforeUnload. |
|
|
Can you move the var declaration outside the if to the top of the function? We can still assign it … |
|
|
These 4 tests deal with a combination of states that could probably better be described with one more nested describe(). … |
|
|
To help make unit tests more readable, try breaking these into blocks, where each block makes a change and then … |
|
|
Start this comment with /** so it gets properly interpreted as documentation. A lot of the other comments in older … |
|
|
Dedent the description of the return value 4 spaces. |
|
|
We format multi-line comments like: /* * The components in ReviewablePageView ... * many fields ... * ... */ Please … |
|
|
type: editabe |
|
|
Add a period at the end. |
|
|
Add a period at the end. |
|
-
-
-
reviewboard/static/rb/js/views/reviewDialogView.es6.js (Diff revision 1) If we leave this and the corresponding decr() we should not need to add/remove the event handler for onBeforeUnload. It should only need to be registered once.
-
reviewboard/static/rb/js/views/reviewDialogView.es6.js (Diff revision 1) This whole function should be unnecessary. See my other comments about the editCount stuff.
-
reviewboard/static/rb/js/views/reviewDialogView.es6.js (Diff revision 1) Single quotes.
This is an ES6 file (
.es6.js
instead of.js
) so we can useconst
here instead ofvar
. -
reviewboard/static/rb/js/views/reviewDialogView.es6.js (Diff revision 1) All declared variables in a function should be declared in a single
var
statement at the top of the function. -
-
reviewboard/static/rb/js/views/reviewDialogView.es6.js (Diff revision 1) Why do we have to add/remove the handler if we are checking the edit count?
-
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 2 (+15 -3) |

-
Tool: PEP8 Style Checker Ignored Files: reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js reviewboard/static/rb/js/views/reviewRequestEditorView.js Tool: Pyflakes Ignored Files: reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js reviewboard/static/rb/js/views/reviewRequestEditorView.js
Change Summary:
Update Description and Testing Done
Description: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Testing Done: |
|
-
-
reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js (Diff revision 2) Can your unit tests set or assert the
editable
states for these as well? Make sure that now (and in the future) the code does the right thing when editable/not editable? -
reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js (Diff revision 2) When you have to escape a quote, you can instead use double quotes for the string.
Change Summary:
Moved the handler to be an instance method to be better testable.
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 3 (+44 -22) |

-
Tool: PEP8 Style Checker Ignored Files: reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js reviewboard/static/rb/js/views/reviewRequestEditorView.js Tool: Pyflakes Ignored Files: reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js reviewboard/static/rb/js/views/reviewRequestEditorView.js
Change Summary:
Updated according to comments; formatting + unit tests
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 4 (+73 -22) |

-
Tool: PEP8 Style Checker Ignored Files: reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js reviewboard/static/rb/js/views/reviewRequestEditorView.js Tool: Pyflakes Ignored Files: reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js reviewboard/static/rb/js/views/reviewRequestEditorView.js
-
A few tiny nitpicks. This looks good to me!
-
reviewboard/static/rb/js/views/reviewRequestEditorView.js (Diff revision 4) This is an internal function, so t should be
_onBeforeUnload
. -
reviewboard/static/rb/js/views/reviewRequestEditorView.js (Diff revision 4) Can you move the
var
declaration outside theif
to the top of the function? We can still assign it within theif
.Also, do you mind changing this to single quotes while you're here?
-
-
reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js (Diff revision 4) These 4 tests deal with a combination of states that could probably better be described with one more nested
describe()
. I'd have one for the editable state. So:describe('editable=true', { ... }) describe('editable=false', { ... })
Each of those can then set the initial state in a
beforeEach()
, ensuring each test within has the correct starting state and that the initial state's assertions have passed.This ensures that all tests are set up correctly, helps show the real "meat" of the tests and how they differ from each other, and ensures future tests in here are consistent (especially if changes are made to any of this logic down the road).
-
reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js (Diff revision 4) To help make unit tests more readable, try breaking these into blocks, where each block makes a change and then tests it. Comments help as well.
So for instance, I'd put a blank line between the
expect(editor.get('editable', true)).toBe(true);
and theview.model.incr('editCount')
, since we started testing a new thing there.Also, I don't know that the unit test should be providing a default for these
get()
calls. It should be testing state in these, not influencing state. This would cover up a bug whereeditable
gets set asundefined
.Same comments apply below.
Change Summary:
Updated with responses to comments.
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 5 (+84 -22) |

-
Tool: Pyflakes Ignored Files: reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js reviewboard/static/rb/js/views/reviewRequestEditorView.js Tool: PEP8 Style Checker Ignored Files: reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js reviewboard/static/rb/js/views/reviewRequestEditorView.js
-
-
reviewboard/static/rb/js/views/reviewRequestEditorView.js (Diff revision 5) Start this comment with
/**
so it gets properly interpreted as documentation. A lot of the other comments in older code don't (yet) do this, but we're moving towards it. -
reviewboard/static/rb/js/views/reviewRequestEditorView.js (Diff revision 5) Dedent the description of the return value 4 spaces.
-
reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js (Diff revision 5) We format multi-line comments like:
/* * The components in ReviewablePageView ... * many fields ... * ... */
Please also capitalize the first letter of "ReviewablePageView" and "ReviewRequestEditorView" herein.
-
reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js (Diff revision 5) type: editabe
Change Summary:
Fixed formatting on comments
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 6 (+86 -22) |

-
Tool: Pyflakes Ignored Files: reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js reviewboard/static/rb/js/views/reviewRequestEditorView.js Tool: PEP8 Style Checker Ignored Files: reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js reviewboard/static/rb/js/views/reviewRequestEditorView.js
-
Just a couple trivial things:
-
reviewboard/static/rb/js/views/reviewRequestEditorView.js (Diff revision 6) Add a period at the end.
-
reviewboard/static/rb/js/views/reviewRequestEditorView.js (Diff revision 6) Add a period at the end.
Change Summary:
Added a couple of periods in to comments
Commit: |
|
||||
---|---|---|---|---|---|
Diff: |
Revision 7 (+86 -22) |

-
Tool: PEP8 Style Checker Ignored Files: reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js reviewboard/static/rb/js/views/reviewRequestEditorView.js Tool: Pyflakes Ignored Files: reviewboard/static/rb/js/views/tests/reviewRequestEditorViewTests.js reviewboard/static/rb/js/views/reviewRequestEditorView.js