Add test for updating dashboard name link
parent
e86f157ed1
commit
a1b3927f73
|
@ -26,7 +26,7 @@ import {millisecondTimeRange} from 'src/dashboards/utils/time'
|
|||
import {getDeep} from 'src/utils/wrappers'
|
||||
import {
|
||||
updateActiveDashboardLink,
|
||||
updateDashboadLinkName,
|
||||
updateDashboardLinkName,
|
||||
} from 'src/dashboards/utils/dashboardSwitcherLinks'
|
||||
|
||||
// APIs
|
||||
|
@ -448,10 +448,10 @@ class DashboardPage extends Component<Props, State> {
|
|||
this.updateLinkName()
|
||||
}
|
||||
|
||||
private updateLinkName = () => {
|
||||
private updateLinkName(): void {
|
||||
this.setState((prevState, props) => ({
|
||||
...prevState,
|
||||
dashboardLinks: updateDashboadLinkName(
|
||||
dashboardLinks: updateDashboardLinkName(
|
||||
prevState.dashboardLinks,
|
||||
props.dashboard
|
||||
),
|
||||
|
|
|
@ -36,7 +36,7 @@ export const updateActiveDashboardLink = (
|
|||
return {...dashboardLinks, active}
|
||||
}
|
||||
|
||||
export const updateDashboadLinkName = (
|
||||
export const updateDashboardLinkName = (
|
||||
dashboardLinks: DashboardSwitcherLinks,
|
||||
dashboard: Dashboard
|
||||
): DashboardSwitcherLinks => {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
linksFromDashboards,
|
||||
updateActiveDashboardLink,
|
||||
updateDashboardLinkName,
|
||||
} from 'src/dashboards/utils/dashboardSwitcherLinks'
|
||||
import {dashboard, source} from 'test/resources'
|
||||
|
||||
|
@ -34,6 +35,18 @@ describe('dashboards.utils.dashboardSwitcherLinks', () => {
|
|||
})
|
||||
})
|
||||
|
||||
const link1 = {
|
||||
key: '9001',
|
||||
text: 'Low Dash',
|
||||
to: '/sources/897/dashboards/9001',
|
||||
}
|
||||
|
||||
const link2 = {
|
||||
key: '2282',
|
||||
text: 'Other Dash',
|
||||
to: '/sources/897/dashboards/2282',
|
||||
}
|
||||
|
||||
describe('updateActiveDashboardLink', () => {
|
||||
const activeDashboard = {
|
||||
...dashboard,
|
||||
|
@ -47,18 +60,6 @@ describe('dashboards.utils.dashboardSwitcherLinks', () => {
|
|||
to: '/sources/897/dashboards/123',
|
||||
}
|
||||
|
||||
const link1 = {
|
||||
key: '9001',
|
||||
text: 'Low Dash',
|
||||
to: '/sources/897/dashboards/9001',
|
||||
}
|
||||
|
||||
const link2 = {
|
||||
key: '2282',
|
||||
text: 'Low Dash',
|
||||
to: '/sources/897/dashboards/2282',
|
||||
}
|
||||
|
||||
const links = [link1, activeLink, link2]
|
||||
it('can set the active link', () => {
|
||||
const loadedLinks = {links, active: null}
|
||||
|
@ -79,4 +80,70 @@ describe('dashboards.utils.dashboardSwitcherLinks', () => {
|
|||
expect(actualLinks).toEqual(expectedLinks)
|
||||
})
|
||||
})
|
||||
|
||||
describe('updateDashboardLinkName', () => {
|
||||
const staleDashboard = {
|
||||
...dashboard,
|
||||
id: 3000,
|
||||
name: 'Stale Dashboard Name',
|
||||
}
|
||||
|
||||
const staleLink = {
|
||||
key: '3000',
|
||||
text: 'Stale Dashboard Name',
|
||||
to: '/sources/897/dashboards/3000',
|
||||
}
|
||||
|
||||
const links = [link1, staleLink, link2]
|
||||
const updatedDashboard = {...staleDashboard, name: 'New Dashboard Name'}
|
||||
|
||||
const dashboardLinks = {
|
||||
links,
|
||||
active: link1,
|
||||
}
|
||||
|
||||
it('can update the name of a provided dashboard', () => {
|
||||
const actualDashLinks = updateDashboardLinkName(
|
||||
dashboardLinks,
|
||||
updatedDashboard
|
||||
)
|
||||
|
||||
const expectedDashlinks = {
|
||||
links: [
|
||||
link1,
|
||||
{
|
||||
key: '3000',
|
||||
text: 'New Dashboard Name',
|
||||
to: '/sources/897/dashboards/3000',
|
||||
},
|
||||
link2,
|
||||
],
|
||||
active: link1,
|
||||
}
|
||||
|
||||
expect(actualDashLinks).toEqual(expectedDashlinks)
|
||||
})
|
||||
|
||||
it('can update name for active link', () => {
|
||||
const linksWithStaleActive = {...dashboardLinks, active: staleLink}
|
||||
const actualLinks = updateDashboardLinkName(
|
||||
linksWithStaleActive,
|
||||
updatedDashboard
|
||||
)
|
||||
|
||||
const renamedLink = {
|
||||
key: '3000',
|
||||
text: 'New Dashboard Name',
|
||||
to: '/sources/897/dashboards/3000',
|
||||
}
|
||||
|
||||
const expectedDashlinks = {
|
||||
links: [link1, renamedLink, link2],
|
||||
active: renamedLink,
|
||||
}
|
||||
|
||||
expect(actualLinks).toEqual(expectedDashlinks)
|
||||
expect(actualLinks.active).toBe(actualLinks.links[1])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue