-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Android - Error attempting to download an attachment #25742
Changes from all commits
c4e0203
56209d2
91378e2
57e582f
27381e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import CONST from '../../src/CONST'; | ||
import DateUtils from '../../src/libs/DateUtils'; | ||
import * as FileUtils from '../../src/libs/fileDownload/FileUtils'; | ||
|
||
|
@@ -26,13 +27,13 @@ describe('FileUtils', () => { | |
it('should append current time to the end of the file name', () => { | ||
const actualFileName = FileUtils.appendTimeToFileName('image.jpg'); | ||
const expectedFileName = `image-${DateUtils.getDBTime()}.jpg`; | ||
expect(actualFileName).toEqual(expectedFileName); | ||
expect(actualFileName).toEqual(expectedFileName.replace(CONST.REGEX.ILLEGAL_FILENAME_CHARACTERS, '_')); | ||
Comment on lines
29
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that the test is using part of the same logic as the implementation, specifically the A more robust approach would be to test against a static expectation, as shown below: it('should append current time to the end of the file name', () => {
const fixedTime = '2023-08-25 13:56:12.119';
jest.spyOn(DateUtils, 'getDBTime').mockReturnValue(fixedTime);
const actualFileName = FileUtils.appendTimeToFileName('image.jpg');
const expectedFileName = 'image-2023-08-25 13_56_12.119.jpg'; // Static expectation
expect(actualFileName).toEqual(expectedFileName);
}); In this revised version, the expected file name is hardcoded, and a mock ensures that the time appended to the file name is known and fixed. This makes the test more robust and reliable. By removing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for suggestions. Agree to use static values in automated test. I also had this in mind but we used dynamic value - |
||
}); | ||
|
||
it('should append current time to the end of the file name without extension', () => { | ||
const actualFileName = FileUtils.appendTimeToFileName('image'); | ||
const expectedFileName = `image-${DateUtils.getDBTime()}`; | ||
expect(actualFileName).toEqual(expectedFileName); | ||
expect(actualFileName).toEqual(expectedFileName.replace(CONST.REGEX.ILLEGAL_FILENAME_CHARACTERS, '_')); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using the list operator
[]
for single characters in Regex, as it's more concise and doesn't require as many escape sequences:This makes the code cleaner and aligns with common practices for handling individual characters.