Fix warning for unsaved work on beforeUnload
Review Request #8635 — Created Jan. 19, 2017 and submitted
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? |
brennie | |
If we leave this and the corresponding decr() we should not need to add/remove the event handler for onBeforeUnload. It … |
brennie | |
This whole function should be unnecessary. See my other comments about the editCount stuff. |
brennie | |
Single quotes. This is an ES6 file (.es6.js instead of .js) so we can use const here instead of var. |
brennie | |
All declared variables in a function should be declared in a single var statement at the top of the function. |
brennie | |
Single quotes for strings. |
brennie | |
Why do we have to add/remove the handler if we are checking the edit count? |
brennie | |
Single quotes. |
brennie | |
Can your unit tests set or assert the editable states for these as well? Make sure that now (and in … |
chipx86 | |
When you have to escape a quote, you can instead use double quotes for the string. |
chipx86 | |
This is an internal function, so t should be _onBeforeUnload. |
brennie | |
Can you move the var declaration outside the if to the top of the function? We can still assign it … |
brennie | |
These 4 tests deal with a combination of states that could probably better be described with one more nested describe(). … |
chipx86 | |
To help make unit tests more readable, try breaking these into blocks, where each block makes a change and then … |
chipx86 | |
Start this comment with /** so it gets properly interpreted as documentation. A lot of the other comments in older … |
david | |
Dedent the description of the return value 4 spaces. |
david | |
We format multi-line comments like: /* * The components in ReviewablePageView ... * many fields ... * ... */ Please … |
david | |
type: editabe |
david | |
Add a period at the end. |
david | |
Add a period at the end. |
david |
-
-
-
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.
-
-
Single quotes.
This is an ES6 file (
.es6.js
instead of.js
) so we can useconst
here instead ofvar
. -
All declared variables in a function should be declared in a single
var
statement at the top of the function. -
-
-
-
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:
-
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. ~ The ReviewDialogView now adds its own beforeUnload event handler
~ New unit tests testing the onBeforeUnload event handler has been
- that checks the Top and Bottom comment views to see if either are - dirty, and if so, issue a warning when a beforeUnload event is - fired. This handler is added and removed when the dialog is opened - and closed, respectively. - - New unit tests testing the onBeforeUnload event handlers have been
added. - Testing Done:
-
Ran JS unit tests.
~ Check that dirty fields in ReviewRequestEditorView and ~ Check that ReviewDialogView for both edit and non-edit privileged users are - ReviewDialogView for both edit and non-edit privileged users are warned before unloading.
- Change Summary:
-
Moved the handler to be an instance method to be better testable.
- Commit:
-
596efa49010c5f5adbf6132e385668cce966fd59011c1974ac8ee74b7e3af3cbcb9ed64b1561da4b
-
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:
-
011c1974ac8ee74b7e3af3cbcb9ed64b1561da4b13c030e70766208727f5bb7fc9758694b33a8e7d
-
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
-
-
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).
-
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:
-
13c030e70766208727f5bb7fc9758694b33a8e7d386cbbd64f67fd3e3808a48bcd498d82cf4a85b6
-
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
-
-
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. -
-
We format multi-line comments like:
/* * The components in ReviewablePageView ... * many fields ... * ... */
Please also capitalize the first letter of "ReviewablePageView" and "ReviewRequestEditorView" herein.
-
- Change Summary:
-
Fixed formatting on comments
- Commit:
-
386cbbd64f67fd3e3808a48bcd498d82cf4a85b6570acad1862521745fa1f8861abae4f1e40f755f
-
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
- Change Summary:
-
Added a couple of periods in to comments
- Commit:
-
570acad1862521745fa1f8861abae4f1e40f755f3df832f7c117ba71e93437f8e3841c8f9cef21c6
-
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