Skip to content

Commit

Permalink
fix: validator link on homepage in custom mode (#859)
Browse files Browse the repository at this point in the history
The link shown when selecting a validator on the homepage was
incorrectly crafted. This was broken by the react-router refactor a
while back. Tests have been updated to check that the url.
  • Loading branch information
ckniffen authored Oct 30, 2023
1 parent 89603f3 commit fa7f9d8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
11 changes: 7 additions & 4 deletions src/containers/Ledgers/Ledgers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getAction, getCategory } from '../shared/components/Transaction'
import { TransactionActionIcon } from '../shared/components/TransactionActionIcon/TransactionActionIcon'
import { Legend } from './Legend'
import { RouteLink } from '../shared/routing'
import { LEDGER_ROUTE, TRANSACTION_ROUTE } from '../App/routes'
import { LEDGER_ROUTE, TRANSACTION_ROUTE, VALIDATOR_ROUTE } from '../App/routes'

class Ledgers extends Component {
constructor(props) {
Expand Down Expand Up @@ -71,13 +71,16 @@ class Ledgers extends Component {
renderSelected = () => {
const { validators, selected } = this.state
const v = validators[selected] || {}
const url = `/validators/${selected}`
return (
<div className="selected-validator">
{v.domain && <DomainLink domain={v.domain} />}
<a className="pubkey" href={url}>
<RouteLink
to={VALIDATOR_ROUTE}
params={{ identifier: selected }}
className="pubkey"
>
{selected}
</a>
</RouteLink>
</div>
)
}
Expand Down
21 changes: 14 additions & 7 deletions src/containers/Ledgers/test/LedgersPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ describe('Ledgers Page container', () => {
let client
const middlewares = [thunk]
const mockStore = configureMockStore(middlewares)
const createWrapper = (props = { network: 'main' }) => {
const createWrapper = (props = { network: 'main', path: '/' }) => {
const store = mockStore({ ...initialState })

return mount(
<Provider store={store}>
<SocketContext.Provider value={client}>
<NetworkContext.Provider value={props.network}>
<QuickHarness i18n={i18n}>
<QuickHarness i18n={i18n} initialEntries={[props.path]}>
<Ledgers msg={props.msg} />
</QuickHarness>
</NetworkContext.Provider>
Expand Down Expand Up @@ -200,11 +200,11 @@ describe('Ledgers Page container', () => {
validations.first().simulate('mouseLeave')
expect(wrapper.find('.tooltip').length).toBe(0)
validations.first().simulate('focus')
expect(wrapper.find('.selected-validator .pubkey').length).toBe(0)
expect(wrapper.find('.selected-validator a.pubkey').length).toBe(0)
validations.first().simulate('click') // set selected
expect(wrapper.find('.selected-validator .pubkey').length).toBe(1)
expect(wrapper.find('.selected-validator a.pubkey').length).toBe(1)
validations.first().simulate('click') // unset selected
expect(wrapper.find('.selected-validator .pubkey').length).toBe(0)
expect(wrapper.find('.selected-validator a.pubkey').length).toBe(0)

wrapper.unmount()

Expand Down Expand Up @@ -235,7 +235,10 @@ describe('Ledgers Page container', () => {
},
)

const wrapper = createWrapper({ network: customNetwork })
const wrapper = createWrapper({
network: customNetwork,
path: '/my.custom.com',
})

expect(wrapper.find('.ledger').length).toBe(0)
expect(wrapper.find('.validation').length).toBe(0)
Expand Down Expand Up @@ -289,7 +292,11 @@ describe('Ledgers Page container', () => {
validations.first().simulate('focus')
expect(wrapper.find('.selected-validator .pubkey').length).toBe(0)
validations.first().simulate('click') // set selected
expect(wrapper.find('.selected-validator .pubkey').length).toBe(1)
expect(wrapper.find('.selected-validator a.pubkey').length).toBe(1)
expect(wrapper.find('.selected-validator a.pubkey')).toHaveProp(
'href',
'/validators/n9KaxgJv69FucW5kkiaMhCqS6sAR1wUVxpZaZmLGVXxAcAse9YhR',
)
validations.first().simulate('click') // unset selected
expect(wrapper.find('.selected-validator .pubkey').length).toBe(0)

Expand Down

0 comments on commit fa7f9d8

Please sign in to comment.