Skip to content

Commit

Permalink
test(storybook): add PeerBandwidthTable.stories.js (#2095)
Browse files Browse the repository at this point in the history
* chore: add PeerBandwidthTable.stories.js

* chore: resolve lint failures

* Update src/status/PeerBandwidthTable.stories.js

Co-authored-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>

* Update src/status/PeerBandwidthTable.stories.js

Co-authored-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>

* Update src/status/PeerBandwidthTable.js

Co-authored-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>

* test: lint fix

---------

Co-authored-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
  • Loading branch information
SgtPooki and whizzzkid authored Jul 7, 2023
1 parent 5cd8d28 commit c969c5e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/status/PeerBandwidthTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export class PeerBandwidthTable extends Component {

getSorter ({ field, direction }) {
return (a, b) => {
if (a.bw[field].gt(b.bw[field])) return direction
if (a.bw[field].lt(b.bw[field])) return -direction
return 0
return a.bw[field] - b.bw[field]
}
}

Expand Down
70 changes: 70 additions & 0 deletions src/status/PeerBandwidthTable.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React from 'react'
import PeerBandwidthTableComponent from './PeerBandwidthTable.js'
import { Provider } from 'redux-bundler-react'
import { composeBundlesRaw } from 'redux-bundler'

const defaultState = {
peerBandwidthPeers: [
{
id: 'peer1',
bw: {
rateIn: 1000,
rateOut: 500,
totalIn: 10000,
totalOut: 5000
}
},
{
id: 'peer2',
bw: {
rateIn: 10,
rateOut: 5,
totalIn: 10000,
totalOut: 5000
}
}
],
peerLocations: {
peer1: {
country_name: 'United States',
country_code: 'US'
},
peer2: {
country_name: 'Canada',
country_code: 'CA'
}
}
}

const getStore = composeBundlesRaw({
name: 'peerBandwidth',
selectPeerBandwidthPeers: state => state.peerBandwidth.peerBandwidthPeers,
selectPeerLocations: state => state.peerBandwidth.peerLocations,
reducer: (state, { type, payload }) => state ?? defaultState
})
const store = getStore({ peerBandwidth: defaultState })

/**
* @type {import('@storybook/react').Meta}
*/
export default {
title: 'Status/PeerBandwidthTable',
component: PeerBandwidthTableComponent,
decorators: [
(Story) => (
<Provider store={store}>
<Story/>
</Provider>
)
]
}

/**
* @type {import('@storybook/react').StoryObj}
*/
export const PeerBandwidthTable = {
args: {
peerBandwidthPeers: defaultState.peerBandwidthPeers,
peerLocations: defaultState.peerLocations
}
}

0 comments on commit c969c5e

Please sign in to comment.