-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
pr05 Typescript #3: Migrate client/utils folder #3553
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
Open
clairep94
wants to merge
67
commits into
processing:develop
Choose a base branch
from
clairep94:pr05/migrate_client_utils_folder
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,466
−511
Open
Changes from 40 commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
a52d312
apiClient: update extension to ts
clairep94 2480bd1
apiClient: add axios instance type
clairep94 87adc72
device: update extension to ts
clairep94 9efdd25
device: add test
clairep94 462524c
eslint: remove prefer-default-export rule
clairep94 8010af7
device.ts: add edgecase test and refactor
clairep94 cb9ddc5
metaKey.js: update extention to ts
clairep94 f7282c2
metaKey: update to use isMac() -- due to navigator.platform being dep…
clairep94 411eb4a
useKeyDownHandler: refactor to use isMac()
clairep94 e7eaa2c
language-utils.js: update ext to ts
clairep94 53962db
language-utils.ts: add test
clairep94 3efc164
language-utils: add types, passes typecheck
clairep94 fa6d69f
language-utils: refactor for clarity & disable eslint noplusplus rule
clairep94 75b35a3
formatDate: update ext to ts
clairep94 b7fb7a0
formatDate.js: add test
clairep94 2440d6f
formatDate.js: add types and refactor
clairep94 0a9af47
consoleUtils: update extension to ts
clairep94 5302f54
consoleUtils: add tests and bare minimum type
clairep94 2638c32
consoleUtils.ts: add jsdocs and return type
clairep94 723cac3
dispatcher.js: update extention to ts --no-verify
clairep94 e0cb6c7
dispatcher: add unit test
clairep94 0aab549
dispatcher.ts: update with types
clairep94 60f8a6e
dispatcher.ts: add jsdocs
clairep94 04ca29a
remove jsdocs on internal functions to retain git history?
clairep94 e91000f
evaluateExpression: update ext to ts --no-verify
clairep94 0713173
evaluateExpression: add unit test
clairep94 16d84e1
evaluateExpression: add tests
clairep94 6957124
reduxFormUtils: update ext to ts --no-verify
clairep94 97754db
reduxFormUtils: add unit test, no-verify
clairep94 ed0c6f0
reduxFormUtils: delete unused dom-onlyprops function
clairep94 0b223df
reduxFormUtils: add types and jsdocs
clairep94 a52372d
getConfig.js: change to ts, no-verify
clairep94 de6fc10
getConfig.ts: remove circular logic for env check and add types
clairep94 8061e09
migrate getConfig.test to ts
clairep94 058d155
update tests for get config after typing
clairep94 34f0735
add parseStringToType util
clairep94 c6c7d40
update parsers and update useages of getConfig
clairep94 2362807
update formatDate to ts, fix type errors
clairep94 1f5614c
Merge branch 'develop' into pr05/migrate_client_utils_folder
clairep94 8febdcb
Merge branch 'develop' into pr05/migrate_client_utils_folder
clairep94 a9d954f
turn on no-underscore-dangle warning
clairep94 50eab48
getConfig: underscore-dangle stylefix for internal function
clairep94 87d9c0d
evaluateExpression: underscore-dangle stylefix for internal function
clairep94 e387df2
parseString: fix to address nullish check
clairep94 c4af496
device: simplify check for isMac()
clairep94 c67d841
evaluateExpression: address comments
clairep94 589318b
.prettierrc: remove hardcoded babel as parser setting to allow typesc…
clairep94 5f2d878
dispatcher: remove old comments
clairep94 7421ef9
lint-fix after removing prettier hardcoded parser babel
clairep94 5de3876
formatDate: update to named export and update format function to form…
clairep94 2cc486a
remove prettier/prettier eslint error ignore
clairep94 c92d53e
language-utils: update to named export
clairep94 0418d8c
apiClient: update to named export and update instances of importing
clairep94 7173d5d
getConfig: update to named export and update instances of import
clairep94 02428a0
turn underscore dangle to warn in ts only
clairep94 15cabf8
dispatcher: update to use enum
clairep94 bbeac90
getConfig: update to have failOnNotFound option to fail on compiler
clairep94 fcc9a4a
getConfig: handle instances of useage where should throw error in pro…
clairep94 919ab3b
getConfig: cleanup new optional property names
clairep94 de0f4da
cleanup unused import
clairep94 482fb18
reduxFormUtils: address comments for double partial
clairep94 640a0bb
evaluateExpression: update to named export
clairep94 8b3fee5
language-utils: remove check for navigatory == type of undefined
clairep94 6de4d6d
move isTestEnvironemnt to its own module for better testability
clairep94 0ad638f
getConfig: wip update to remove superfluous fail in test env option
clairep94 c832736
fix test
clairep94 9fe530a
Merge branch 'develop' into pr05/migrate_client_utils_folder
clairep94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
khanniie marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. tried my best with this test, I'm not 100% sure how the line offset works, so I didn't test its calculation, just that it should be a number in the tupple that's returned |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { getAllScriptOffsets, startTag } from './consoleUtils'; | ||
|
||
describe('getAllScriptOffsets', () => { | ||
// not sure how the line offset calculations have been formulated | ||
it('returns an empty array when no scripts are found', () => { | ||
const html = '<html><body><h1>No scripts here</h1></body></html>'; | ||
expect(getAllScriptOffsets(html)).toEqual([]); | ||
}); | ||
|
||
it('detects a single external script with @fs- path', () => { | ||
const html = ` | ||
<html> | ||
<head> | ||
<script src="${startTag}my-script.js"></script> | ||
</head> | ||
</html> | ||
`; | ||
const result = getAllScriptOffsets(html); | ||
expect(result.every(([offset, _]) => typeof offset === 'number')).toBe( | ||
true | ||
); | ||
expect(result.map(([_, name]) => name)).toEqual(['my-script']); | ||
}); | ||
|
||
it('detects multiple external scripts with @fs- paths', () => { | ||
const html = ` | ||
<script src="${startTag}one.js"></script> | ||
<script src="${startTag}two.js"></script> | ||
`; | ||
const result = getAllScriptOffsets(html); | ||
expect(result.every(([offset, _]) => typeof offset === 'number')).toBe( | ||
true | ||
); | ||
expect(result.map(([_, name]) => name)).toEqual(['one', 'two']); | ||
}); | ||
|
||
it('detects embedded scripts with crossorigin attribute', () => { | ||
const html = ` | ||
<html> | ||
<head> | ||
<script crossorigin=""></script> | ||
</head> | ||
</html> | ||
`; | ||
const result = getAllScriptOffsets(html); | ||
expect(result.every(([offset, _]) => typeof offset === 'number')).toBe( | ||
true | ||
); | ||
expect(result.map(([_, name]) => name)).toEqual(['index.html']); | ||
}); | ||
|
||
it('detects both @fs- scripts and embedded scripts together, ordering embedded scripts last', () => { | ||
const html = ` | ||
<script src="${startTag}abc.js"></script> | ||
<script crossorigin=""></script> | ||
<script src="${startTag}xyz.js"></script> | ||
`; | ||
const result = getAllScriptOffsets(html); | ||
expect(result.every(([offset, _]) => typeof offset === 'number')).toBe( | ||
true | ||
); | ||
expect(result.map(([_, name]) => name)).toEqual([ | ||
'abc', | ||
'xyz', | ||
'index.html' | ||
]); | ||
}); | ||
|
||
it('handles scripts with varying whitespace and newlines', () => { | ||
const html = ` | ||
<script src="${startTag}some-script.js"> | ||
</script> | ||
<script crossorigin=""> | ||
</script> | ||
`; | ||
const result = getAllScriptOffsets(html); | ||
expect(result.every(([offset, _]) => typeof offset === 'number')).toBe( | ||
true | ||
); | ||
expect(result.map(([_, name]) => name)).toEqual([ | ||
'some-script', | ||
'index.html' | ||
]); | ||
}); | ||
}); |
11 changes: 9 additions & 2 deletions
11
client/utils/consoleUtils.js → client/utils/consoleUtils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { isMac } from './device'; | ||
|
||
describe('isMac', () => { | ||
const originalUserAgent = navigator.userAgent; | ||
|
||
afterEach(() => { | ||
// Restore the original userAgent after each test | ||
Object.defineProperty(navigator, 'userAgent', { | ||
value: originalUserAgent, | ||
configurable: true | ||
}); | ||
}); | ||
|
||
it('returns true when userAgent contains "Mac"', () => { | ||
Object.defineProperty(navigator, 'userAgent', { | ||
value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)', | ||
configurable: true | ||
}); | ||
expect(isMac()).toBe(true); | ||
}); | ||
|
||
it('returns false when userAgent does not contain "Mac"', () => { | ||
Object.defineProperty(navigator, 'userAgent', { | ||
value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', | ||
configurable: true | ||
}); | ||
expect(isMac()).toBe(false); | ||
}); | ||
|
||
it('returns false when navigator agent is null', () => { | ||
Object.defineProperty(navigator, 'userAgent', { | ||
value: null, | ||
configurable: true | ||
}); | ||
expect(isMac()).toBe(false); | ||
}); | ||
|
||
it('returns false when navigator agent is undefined', () => { | ||
Object.defineProperty(navigator, 'userAgent', { | ||
value: undefined, | ||
configurable: true | ||
}); | ||
expect(isMac()).toBe(false); | ||
}); | ||
}); |
khanniie marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Checks if the user's OS is macOS based on the `navigator.userAgent` string. | ||
* This is the preferred method over `navigator.platform`, which is now deprecated: | ||
* - see https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform | ||
*/ | ||
export function isMac(): boolean { | ||
return typeof navigator?.userAgent === 'string' | ||
khanniie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
? navigator.userAgent.toLowerCase().includes('mac') | ||
: false; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.