From 9e0c9db78cc186a5896e3adfdaddff8cbf9763a1 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Tue, 9 Jul 2019 23:48:26 +0200 Subject: [PATCH] chore: adds unit tests for component --- src/components/Repository/Repository.test.tsx | 59 ++++++++++++++++++- .../__snapshots__/Repository.test.tsx.snap | 2 +- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/components/Repository/Repository.test.tsx b/src/components/Repository/Repository.test.tsx index 73d14f9..e07f8be 100644 --- a/src/components/Repository/Repository.test.tsx +++ b/src/components/Repository/Repository.test.tsx @@ -1,11 +1,68 @@ import React from 'react'; import { shallow } from 'enzyme'; -import Repository from './Repository'; +jest.mock('./img/git.png', () => ''); describe(' component', () => { + beforeEach(() => { + jest.resetModules(); + }); + test('should render the component in default state', () => { + const packageMeta = { + latest: { + repository: { + type: 'git', + url: 'git+https://github.com/verdaccio/ui.git', + }, + }, + }; + + jest.doMock('../../pages/version/Version', () => ({ + DetailContextConsumer: component => { + return component.children({ packageMeta }); + }, + })); + + const Repository = require('./Repository').default; const wrapper = shallow(); expect(wrapper.html()).toMatchSnapshot(); }); + + test('should render the component in with no repository data', () => { + const packageMeta = { + latest: {}, + }; + + jest.doMock('../../pages/version/Version', () => ({ + DetailContextConsumer: component => { + return component.children({ packageMeta }); + }, + })); + + const Repository = require('./Repository').default; + const wrapper = shallow(); + expect(wrapper.html()).toEqual(''); + }); + + test('should render the component in with invalid url', () => { + const packageMeta = { + latest: { + repository: { + type: 'git', + url: 'git://github.com/verdaccio/ui.git', + }, + }, + }; + + jest.doMock('../../pages/version/Version', () => ({ + DetailContextConsumer: component => { + return component.children({ packageMeta }); + }, + })); + + const Repository = require('./Repository').default; + const wrapper = shallow(); + expect(wrapper.html()).toEqual(''); + }); }); diff --git a/src/components/Repository/__snapshots__/Repository.test.tsx.snap b/src/components/Repository/__snapshots__/Repository.test.tsx.snap index 8fbdcc8..193dd0b 100644 --- a/src/components/Repository/__snapshots__/Repository.test.tsx.snap +++ b/src/components/Repository/__snapshots__/Repository.test.tsx.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` component should render the component in default state 1`] = `""`; +exports[` component should render the component in default state 1`] = `""`;