From 131b8789133be9552f970ea9a9caffeb51376d2e Mon Sep 17 00:00:00 2001 From: Delmer Reed Date: Tue, 10 Jul 2018 15:41:13 -0400 Subject: [PATCH] Add hosts switcher links test --- .../hosts/utils/hostsSwitcherLinks.test.ts | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 ui/test/hosts/utils/hostsSwitcherLinks.test.ts diff --git a/ui/test/hosts/utils/hostsSwitcherLinks.test.ts b/ui/test/hosts/utils/hostsSwitcherLinks.test.ts new file mode 100644 index 0000000000..acb20e7e10 --- /dev/null +++ b/ui/test/hosts/utils/hostsSwitcherLinks.test.ts @@ -0,0 +1,82 @@ +import { + loadHostsLinks, + updateActiveHostLink, +} from 'src/hosts/utils/hostsSwitcherLinks' +import {source} from 'test/resources' +import {HostNames} from 'src/types/hosts' + +describe('hosts.utils.hostsSwitcherLinks', () => { + describe('loadHostLinks', () => { + const socure = {...source, id: '897'} + + const hostNames: HostNames = { + 'zelda.local': { + name: 'zelda.local', + }, + 'gannon.local': { + name: 'gannon.local', + }, + } + + const getHostsAJAX = async () => hostNames + + it('can load host links for a given source', async () => { + const actualLinks = await loadHostsLinks(socure, getHostsAJAX) + + const expectedLinks = { + links: [ + { + key: 'zelda.local', + text: 'zelda.local', + to: '/sources/897/hosts/zelda.local', + }, + { + key: 'gannon.local', + text: 'gannon.local', + to: '/sources/897/hosts/gannon.local', + }, + ], + active: null, + } + + expect(actualLinks).toEqual(expectedLinks) + }) + }) + + describe('updateActiveHostLink', () => { + const link1 = { + key: 'korok.local', + text: 'korok.local', + to: '/sources/897/hosts/korok.local', + } + + const link2 = { + key: 'deku.local', + text: 'deku.local', + to: '/sources/897/hosts/deku.local', + } + + const activeLink = { + key: 'robbie.local', + text: 'robbie.local', + to: '/sources/897/hosts/robbie.local', + } + + const activeHostName = { + name: 'robbie.local', + } + + const links = [link1, activeLink, link2] + + it('can set the active host link', () => { + const loadedLinks = { + links, + active: null, + } + const actualLinks = updateActiveHostLink(loadedLinks, activeHostName) + const expectedLinks = {links, active: activeLink} + + expect(actualLinks).toEqual(expectedLinks) + }) + }) +})