import React from 'react'; import { shallow } from 'enzyme'; import { ServerStatus } from 'generated-sources'; import { clusterBrokersPath, clusterTopicsPath } from 'lib/paths'; import ClusterWidget from '../ClusterWidget'; import { offlineCluster, onlineCluster } from './fixtures'; describe('ClusterWidget', () => { describe('when cluster is online', () => { it('renders with correct tag', () => { const tag = shallow().find( '.tag' ); expect(tag.hasClass('is-primary')).toBeTruthy(); expect(tag.text()).toEqual(ServerStatus.ONLINE); }); it('renders table', () => { const table = shallow().find( 'table' ); expect(table.hasClass('is-fullwidth')).toBeTruthy(); expect( table.find(`NavLink[to="${clusterBrokersPath(onlineCluster.name)}"]`) .exists ).toBeTruthy(); expect( table.find(`NavLink[to="${clusterTopicsPath(onlineCluster.name)}"]`) .exists ).toBeTruthy(); }); it('matches snapshot', () => { expect( shallow() ).toMatchSnapshot(); }); }); describe('when cluster is offline', () => { it('renders with correct tag', () => { const tag = shallow().find( '.tag' ); expect(tag.hasClass('is-danger')).toBeTruthy(); expect(tag.text()).toEqual(ServerStatus.OFFLINE); }); it('renders table', () => { const table = shallow().find( 'table' ); expect(table.hasClass('is-fullwidth')).toBeTruthy(); expect( table.find(`NavLink[to="${clusterBrokersPath(onlineCluster.name)}"]`) .exists ).toBeTruthy(); expect( table.find(`NavLink[to="${clusterTopicsPath(onlineCluster.name)}"]`) .exists ).toBeTruthy(); }); it('matches snapshot', () => { expect( shallow() ).toMatchSnapshot(); }); }); describe('when cluster is read-only', () => { it('renders the tag', () => { expect( shallow( ) .find('.title') .childAt(1) .text() ).toEqual('readonly'); }); }); });