Add tests for RB.UploadAttachmentView
Review Request #10941 — Created March 7, 2020 and submitted
This patch adds unit tests for
RB.UploadAttachmentView
. The recent refactoring
of the view led to some regressions that were not caught until the changes were
already landed. With unit tests, we can help reduce the likelihood of this
happening in the future.
New tests:
-Cancel
button has the correct state when the dialog is initialized
-Cancel
button closes the dialog when clicked
-Upload
button has the correct state when the dialog is initialized
-Upload
button has the correct state when a file is uploaded and when it is
removed
-Upload
button sends request to create a file attachment when clicked
- the dialog is populated with the right information when updating a file
attachment
Description | From | Last Updated |
---|---|---|
If this function is empty, could we remove it? |
bui1 | |
Change this to UploadAttachmentView instances |
bui1 | |
Remove the blank line |
bui1 | |
Turn to Cancel Button instead. Both David and Christian stress that test descriptions should be as clear as possible so … |
bui1 | |
Turn this to Upload Button |
bui1 | |
Minor code styling issue to fix, just need to line up the line like this below spyOn(dialog, 'updateUploadButtonEnabledState') .and.callThrough(); |
bui1 | |
Maybe change this to Disabled by default until a file is uploaded to make it clear it is disabled by … |
bui1 | |
Since expect(dialog.updateUploadButtonEnabledState).toHaveBeenCalled(); is being called more than once in this test function, maybe be more specific with how many times … |
bui1 | |
This should be rb/views/UploadAttachmentView (class capitalization). |
chipx86 | |
For ES6 JavaScript, the last item in a list or object should have a trailing comma. |
chipx86 | |
When using let or const, we should list one variable per statement. So: let dialog; let $caption; let $attachmentHistory; Alphabetical … |
chipx86 | |
Blank line between these. Though, it'd probably make more sense to move dialog = null into the conditional. |
chipx86 | |
Only one test needs this, so it should move into that test. |
chipx86 | |
Since this is a precondition sanity-check for test setup, it should move into beforeEach() |
chipx86 | |
One per statement. |
chipx86 | |
Multi-line comments should be in the form of: /* * ... * ... */ Each comment should also have proper … |
chipx86 | |
Single quotes are preferable so long as content doesn't need to use a single quote. |
chipx86 | |
Similarly, this should move into beforeEach(). |
chipx86 | |
This is going to result in something like Blah blah blah blah This really sounds more like two tests. I'd … |
chipx86 | |
This should use single quotes. |
chipx86 | |
I'd suggest chaining the statements: $path .val('') .trigger('change'); Same with similar code paths below. |
chipx86 | |
This statement exceeds the max line length limit. You should wrap at .toHave..... |
chipx86 | |
This should use single quotes. |
chipx86 | |
This statement exceeds the max line length limit. |
chipx86 | |
This statement exceeds the max line length limit. Also, the context for this test is "Buttons -> Upload", so we … |
chipx86 | |
Can you inverse the types of quotes: '[name="caption"] is more consistent with our standards. |
chipx86 |
- Change Summary:
-
Fix spies and add more tests
- Commit:
-
79140d5c1836d7a336ff1414ad5562992c1faf4e781f4680da2c41b734eb1f2dfef48de4ddf0c247
Checks run (2 succeeded)
- Change Summary:
-
Fix review request fields & remove WIP tag
- Summary:
-
[WIP] Add tests for RB.UploadAttachmentViewAdd tests for RB.UploadAttachmentView
- Description:
-
~ This patch adds unit tests for
RB.UploadAttachmentView
. The recent refactoring of the view led to some regressions that were not caught until the changes were already landed. With unit tests, we can help reduce the likelihood of this happening in the future.~ This patch adds unit tests for
RB.UploadAttachmentView
. The recent refactoring+ of the view led to some regressions that were not caught until the changes were + already landed. With unit tests, we can help reduce the likelihood of this + happening in the future. - Testing Done:
-
~ New tests
~ New tests:
+ - Cancel
button has the correct state when the dialog is initialized+ - Cancel
button closes the dialog when clicked+ - Upload
button has the correct state when the dialog is initialized+ - Upload
button has the correct state when a file is uploaded and when it is+ removed + - Upload
button sends request to create a file attachment when clicked+ - the dialog is populated with the right information when updating a file + attachment - Commit:
-
781f4680da2c41b734eb1f2dfef48de4ddf0c247721f1ad7cab13be851b9e26efbf79aa01f597ba9
Checks run (2 succeeded)
-
Just some minor things to address but otherwise the test contents itself are solid :)
-
-
-
-
Turn to
Cancel Button
instead.Both David and Christian stress that test descriptions should be as clear as possible so it's easier to traverse through errors when the entire suite runs.
-
-
Minor code styling issue to fix, just need to line up the line like this below
spyOn(dialog, 'updateUploadButtonEnabledState') .and.callThrough();
-
Maybe change this to
Disabled by default until a file is uploaded
to make it clear it is disabled by default -
Since
expect(dialog.updateUploadButtonEnabledState).toHaveBeenCalled();
is being called more than once in this test function, maybe be more specific with how many times this is being called.expect(dialog.updateUploadButtonEnabledState).toHaveBeenCalledTimes(1);
or instead at the very end of the function,
expect(dialog.updateUploadButtonEnabledState).toHaveBeenCalledTimes(2);
-
I'm kind of unclear on what this test is supposed to do. Correct me with I'm wrong.
- Show a dialog with preloaded information
- Check if caption and history has been updated based on this preloaded information?
Initially at first I thought this test would check if the caption got updated to a new value different from the preloaded one or the content of the dialog changes and we check if the history got incremented by one.
- Change Summary:
-
Fix issues from review
- Commit:
-
721f1ad7cab13be851b9e26efbf79aa01f597ba96a631b1b126147584a38139b2f5e5798747d59c5
Checks run (2 succeeded)
-
-
-
-
When using
let
orconst
, we should list one variable per statement. So:let dialog; let $caption; let $attachmentHistory;
Alphabetical order is always appreciated.
-
Blank line between these.
Though, it'd probably make more sense to move
dialog = null
into the conditional. -
-
-
-
Multi-line comments should be in the form of:
/* * ... * ... */
Each comment should also have proper sentence capitalization and punctuation.
-
-
-
This is going to result in something like
Blah blah blah blah
This really sounds more like two tests. I'd have one that tests just setting the file and asserts around that, and a second that sets things up by setting the file and then tests the removal case.
-
-
I'd suggest chaining the statements:
$path .val('') .trigger('change');
Same with similar code paths below.
-
-
-
-
This statement exceeds the max line length limit.
Also, the context for this test is "Buttons -> Upload", so we can get rid of the "Clicking upload ...". Maybe just make this "Uploads the file attachment".
-
spyOn(view, '_someFunc').and.callThrough();
, a view should be rendered afterwards. ForspyOn(RB.SomeView.prototype, '_someFunc').and.callThrough();
the view should be rendered before the spy is created.$testsScratch
to make sure the dialog is actually being attached to the DOM.$path.trigger('change')
, declare a event = $.Event('change'); and pass that in totrigger
ortriggerHandler
instead? Not sure if that'll workI know its not a finished review request yet but also changing
dlg
todialog
will help out too as I didn't get that abbreviation right away.