Skip to content
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

Chore: Add util tests and fix file tests #709

Merged
merged 1 commit into from
Mar 13, 2018

Conversation

tonyjin
Copy link
Contributor

@tonyjin tonyjin commented Mar 8, 2018

  • Move hostname check to Browser function so we can test isBoxWebApp()
  • Fix incorrect file.canDownload() tests, they were missing brackets
  • Add missing peer dependency
  • Clean up package.json and run yarn upgrade

@boxcla
Copy link

boxcla commented Mar 8, 2018

Verified that @tonyjin has signed the CLA. Thanks for the pull request!

src/lib/util.js Outdated
@@ -901,5 +902,6 @@ export function isValidFileId(fileId) {
* @return {boolean} Is Preview running in the Box WebApp
*/
export function isBoxWebApp() {
return (window.location.hostname || '').indexOf('app.box.com') !== -1;
const boxHostnameRegex = /(app|ent)\.(box\.com|boxcn\.net|boxenterprise\.net)/;
return !!Browser.getHostname().match(boxHostnameRegex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use regex.test here since you are returning a boolean?

*
* @return {string} Window hostname
*/
static getHostname() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit out of place in this file to me. There is a few instances of window.location in the codebase, maybe create a Url class and we can refactor?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's nothing else needed for URL related stuff, maybe just add it to util since it's being used in a few places?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specifically moved this here (instead of including in util.js) so I could test isBoxWebApp() without refactoring util to a class with all static functions or adding Babel Rewire. I'll move this to a new URL class per Daniel's recommendation.

- Move hostname check to Browser function so we can test `isBoxWebApp()`
- Fix incorrect `file.canDownload()` tests, they were missing brackets
- Add missing peer dependency
- Clean up package.json and run `yarn upgrade`
@tonyjin tonyjin merged commit 1102077 into box:master Mar 13, 2018
@tonyjin tonyjin deleted the add-fix-tests-2 branch March 13, 2018 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants