Skip to content

Conversation

@jamchoi
Copy link

@jamchoi jamchoi commented Apr 23, 2025

Description

Add comprehensive unit tests for utility functions in client/app/utils/index.js.

More Details

This test suite covers all four exported utility functions: randomString, setCsrfToken, getPusher, and renderContent.

randomString

  • Verifies format, length, and randomness across multiple invocations.

setCsrfToken

  • Mocks DOM meta tag insertion.
  • Tests correct setting of Axios header.
  • Handles missing tag and token overwrite behavior.

getPusher

  • Mocks window.Pusher and DOM meta tags.
  • Ensures proper configuration via meta tag values.
  • Tests edge cases where meta tags or Pusher are missing.

renderContent

  • Validates sanitization of malicious HTML input.
  • Handles React elements with prop overrides.
  • Preserves non-string content like objects and nulls.
  • Tests fragments, cloning behavior, and safe handling of undefined inputs.

Corresponding Issue

Attempted to complete #2128

Screenshots


Reviewing this pull request? Check out our Code Review Practices guide if you haven't already!

Created unit test cases for each of the four functions mentioned in the github issue.
@jamchoi jamchoi added the tests label Apr 23, 2025
@jamchoi jamchoi self-assigned this Apr 23, 2025
@welcome
Copy link

welcome bot commented Apr 23, 2025

Thank you for opening this pull request with us! Be sure to follow our Pull Request Practices. Let us know if you have any questions on Slack.

@julianguyen julianguyen self-requested a review April 23, 2025 22:08
@julianguyen
Copy link
Member

I'm seeing there are linting errors, if you scroll down here to your failing job:

/home/circleci/ifmeorg/ifme/client/app/utils/__tests__/utils.test.js
    2:1   error  `./index` import should occur after import of `react-dom/server`  import/order
    2:23  error  Unable to resolve path to module './index'                        import/no-unresolved
    2:23  error  Missing file extension for "./index"                              import/extensions
   21:31  error  Unary operator '++' used                                          no-plusplus
  100:25  error  Strings must use singlequote                                      quotes
  109:23  error  Missing an explicit type attribute for button                     react/button-has-type
  109:23  error  JSX not allowed in files with extension '.js'                     react/jsx-filename-extension
  139:69  error  Do not use Array index in keys                                    react/no-array-index-key

@julianguyen
Copy link
Member

Any updates here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants