From 52ed8ad67bdcd4bd6d0d5c622ad8f60355f1dda5 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Sat, 26 Oct 2019 12:02:03 +0200 Subject: [PATCH] refactor: adds download tarball spec to action bar (#220) * refactor: adds download tarball spec to action bar * refactor: fixes typo --- src/components/ActionBar/ActionBar.test.tsx | 28 +++++++++++++++++++ .../__snapshots__/ActionBar.test.tsx.snap | 2 ++ 2 files changed, 30 insertions(+) diff --git a/src/components/ActionBar/ActionBar.test.tsx b/src/components/ActionBar/ActionBar.test.tsx index 2d0d677..6f09cae 100644 --- a/src/components/ActionBar/ActionBar.test.tsx +++ b/src/components/ActionBar/ActionBar.test.tsx @@ -1,6 +1,8 @@ import React from 'react'; import { mount } from 'enzyme'; +import api from '../../utils/api'; + import { ActionBar } from './ActionBar'; const mockPackageMeta: jest.Mock = jest.fn(() => ({ @@ -43,6 +45,12 @@ describe(' component', () => { expect(wrapper.html()).toEqual(''); }); + test('when there is no latest property in package meta', () => { + mockPackageMeta.mockImplementation(() => ({})); + const wrapper = mount(); + expect(wrapper.html()).toEqual(''); + }); + test('when there is a button to download a tarball', () => { mockPackageMeta.mockImplementation(() => ({ latest: { @@ -57,5 +65,25 @@ describe(' component', () => { const button = wrapper.find('button'); expect(button).toHaveLength(1); + + const spy = jest.spyOn(api, 'request'); + button.simulate('click'); + expect(spy).toHaveBeenCalled(); + }); + + test('when there is a button to open an issue', () => { + mockPackageMeta.mockImplementation(() => ({ + latest: { + bugs: { + url: 'https://verdaccio.tld/bugs', + }, + }, + })); + + const wrapper = mount(); + expect(wrapper.html()).toMatchSnapshot(); + + const button = wrapper.find('button'); + expect(button).toHaveLength(1); }); }); diff --git a/src/components/ActionBar/__snapshots__/ActionBar.test.tsx.snap b/src/components/ActionBar/__snapshots__/ActionBar.test.tsx.snap index b6c99f4..95729a8 100644 --- a/src/components/ActionBar/__snapshots__/ActionBar.test.tsx.snap +++ b/src/components/ActionBar/__snapshots__/ActionBar.test.tsx.snap @@ -3,3 +3,5 @@ exports[` component should render the component in default state 1`] = `""`; exports[` component when there is a button to download a tarball 1`] = `"
"`; + +exports[` component when there is a button to open an issue 1`] = `"
"`;