Skip to content

Commit

Permalink
fix: fix broken navigation when using <FpjsProvider />
Browse files Browse the repository at this point in the history
  • Loading branch information
TheUnderScorer committed Oct 25, 2022
1 parent 3aabdba commit e518cbc
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
39 changes: 37 additions & 2 deletions __tests__/with-environment.test.tsx
@@ -1,7 +1,9 @@
import React, { FunctionComponent } from 'react'
import { render } from '@testing-library/react'

import { act, render } from '@testing-library/react'
import { WithEnvironment } from '../src/components/with-environment'
import { Link, MemoryRouter, Route, Routes } from 'react-router-dom'
import userEvent from '@testing-library/user-event'
import { actWait } from './helpers'

describe('WithEnvironment', () => {
it('enhances provided element with `env` prop', () => {
Expand All @@ -27,4 +29,37 @@ describe('WithEnvironment', () => {

expect(container.innerHTML).toContain('hello')
})

it('should not break navigation', async () => {
const Home = () => (
<Link to='/test' id='test'>
Go to test
</Link>
)

const App = () => {
return (
<MemoryRouter>
<Routes>
<Route path='/' element={<Home />} />
<Route path='/test' element={<div>Test page</div>} />
</Routes>
</MemoryRouter>
)
}

const { container } = render(
<WithEnvironment>
<App />
</WithEnvironment>
)

act(() => {
userEvent.click(container.querySelector('#test')!)
})

await actWait(250)

expect(container.innerHTML).toContain('Test page')
})
})
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -58,8 +58,8 @@
"@semantic-release/npm": "9.0.1",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/preact": "^3.2.2",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/react": "^13.4.0",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^27.4.0",
"@types/react": "^17.0.39",
Expand All @@ -84,6 +84,7 @@
"prettier": "^2.7.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.4.2",
"rollup": "^2.75.7",
"rollup-plugin-dts": "^4.2.2",
"rollup-plugin-license": "^2.8.1",
Expand Down
6 changes: 1 addition & 5 deletions src/components/with-environment.tsx
@@ -1,4 +1,4 @@
import { Component, cloneElement } from 'react'
import { cloneElement, Component } from 'react'

import { getEnvironment } from '../get-env'
import { type DetectEnvParams } from '../detect-env'
Expand Down Expand Up @@ -44,10 +44,6 @@ class WithEnvironment extends Component<WithEnvironmentProps> {
// passes the `env` down as a prop
return cloneElement(this.props.children, { env: this.detectedEnv })
}

shouldComponentUpdate() {
return false
}
}

export { WithEnvironment }
20 changes: 20 additions & 0 deletions yarn.lock
Expand Up @@ -1217,6 +1217,11 @@
dependencies:
"@octokit/openapi-types" "^12.4.0"

"@remix-run/router@1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@remix-run/router/-/router-1.0.2.tgz#1c17eadb2fa77f80a796ad5ea9bf108e6993ef06"
integrity sha512-GRSOFhJzjGN+d4sKHTMSvNeUPoZiDHWmRnXfzaxrqe7dE/Nzlc8BiMSJdLDESZlndM7jIUrZ/F4yWqVYlI0rwQ==

"@rollup/plugin-json@^4.1.0":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@rollup/plugin-json/-/plugin-json-4.1.0.tgz#54e09867ae6963c593844d8bd7a9c718294496f3"
Expand Down Expand Up @@ -6667,6 +6672,21 @@ react-is@^17.0.1:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==

react-router-dom@^6.4.2:
version "6.4.2"
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.4.2.tgz#115b37d501d6d8ac870683694978c51c43e6c0d2"
integrity sha512-yM1kjoTkpfjgczPrcyWrp+OuQMyB1WleICiiGfstnQYo/S8hPEEnVjr/RdmlH6yKK4Tnj1UGXFSa7uwAtmDoLQ==
dependencies:
"@remix-run/router" "1.0.2"
react-router "6.4.2"

react-router@6.4.2:
version "6.4.2"
resolved "https://registry.yarnpkg.com/react-router/-/react-router-6.4.2.tgz#300628ee9ed81b8ef1597b5cb98b474efe9779b8"
integrity sha512-Rb0BAX9KHhVzT1OKhMvCDMw776aTYM0DtkxqUBP8dNBom3mPXlfNs76JNGK8wKJ1IZEY1+WGj+cvZxHVk/GiKw==
dependencies:
"@remix-run/router" "1.0.2"

react@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
Expand Down

0 comments on commit e518cbc

Please sign in to comment.