From fe0ef331f9a3c13bb947c709356e5de74a30c93b Mon Sep 17 00:00:00 2001 From: Palak Bhojani Date: Mon, 11 Feb 2019 10:43:34 -0800 Subject: [PATCH] Create tests for adminui tabs --- ui/mocks/dummyData.ts | 67 ++ .../organizations/components/Buckets.test.tsx | 38 + .../components/Collectors.test.tsx | 35 + .../organizations/components/Members.test.tsx | 31 + .../components/Scrapers.test.tsx | 33 + .../__snapshots__/Buckets.test.tsx.snap | 687 ++++++++++++++++++ .../__snapshots__/Collectors.test.tsx.snap | 55 ++ .../__snapshots__/Members.test.tsx.snap | 91 +++ .../__snapshots__/Scrapers.test.tsx.snap | 59 ++ 9 files changed, 1096 insertions(+) create mode 100644 ui/src/organizations/components/Buckets.test.tsx create mode 100644 ui/src/organizations/components/Collectors.test.tsx create mode 100644 ui/src/organizations/components/Members.test.tsx create mode 100644 ui/src/organizations/components/Scrapers.test.tsx create mode 100644 ui/src/organizations/components/__snapshots__/Buckets.test.tsx.snap create mode 100644 ui/src/organizations/components/__snapshots__/Collectors.test.tsx.snap create mode 100644 ui/src/organizations/components/__snapshots__/Members.test.tsx.snap create mode 100644 ui/src/organizations/components/__snapshots__/Scrapers.test.tsx.snap diff --git a/ui/mocks/dummyData.ts b/ui/mocks/dummyData.ts index 7c181d4f9d..d38b28d7d8 100644 --- a/ui/mocks/dummyData.ts +++ b/ui/mocks/dummyData.ts @@ -533,6 +533,37 @@ export const bucket = { labels: [], } +export const buckets = [ + { + links: { + labels: '/api/v2/buckets/034a10d6f7a6b000/labels', + log: '/api/v2/buckets/034a10d6f7a6b000/log', + org: '/api/v2/orgs/034a0adc49a6b000', + self: '/api/v2/buckets/034a10d6f7a6b000', + }, + id: '034a10d6f7a6b000', + organizationID: '034a0adc49a6b000', + organization: 'default', + name: 'newbuck', + retentionRules: [], + labels: [], + }, + { + links: { + labels: '/api/v2/buckets/034a10d6f7a6b000/labels', + log: '/api/v2/buckets/034a10d6f7a6b000/log', + org: '/api/v2/orgs/034a0adc49a6b000', + self: '/api/v2/buckets/034a10d6f7a6b000', + }, + id: '034a10d6f7a6b001', + organizationID: '034a0adc49a6b000', + organization: 'default', + name: 'newbuck1', + retentionRules: [], + labels: [], + }, +] + export const setSetupParamsResponse = { data: { user: { @@ -642,3 +673,39 @@ export const setSetupParamsResponse = { }, request: {}, } + +export const telegraf = [ + { + id: '03636a150fb51000', + name: 'Name this Configuration', + organizationID: '03636a0aabb51000', + }, + { + id: '03636a150fb51001', + name: 'Name this Configuration', + organizationID: '03636a0aabb51000', + }, +] + +export const scraperTargets = [ + { + bucket: 'a', + bucketID: '03636a0aabb51001', + id: '03636a0bfe351000', + name: 'new target', + orgID: '03636a0aabb51000', + organization: 'a', + type: 'prometheus', + url: 'http://localhost:9999/metrics', + }, + { + bucket: 'a', + bucketID: '03636a0aabb51001', + id: '03636a0bfe351001', + name: 'new target', + orgID: '03636a0aabb51000', + organization: 'a', + type: 'prometheus', + url: 'http://localhost:9999/metrics', + }, +] diff --git a/ui/src/organizations/components/Buckets.test.tsx b/ui/src/organizations/components/Buckets.test.tsx new file mode 100644 index 0000000000..8c884521bb --- /dev/null +++ b/ui/src/organizations/components/Buckets.test.tsx @@ -0,0 +1,38 @@ +// Libraries +import React from 'react' +import {renderWithRedux} from 'src/mockState' + +// Components +import BucketList from 'src/organizations/components/BucketList' + +// Constants +import {buckets} from 'mocks/dummyData' +import {DataLoaderType} from 'src/types/v2/dataLoaders' +import {withRouterProps} from 'mocks/dummyData' + +const setup = (override?) => { + const props = { + ...withRouterProps, + buckets, + emptyState: <>, + onUpdateBucket: jest.fn(), + onDeleteBucket: jest.fn(), + onSetBucketInfo: jest.fn(), + onSetDataLoadersType: jest.fn(), + dataLoaderType: DataLoaderType.Streaming, + ...override, + } + + const wrapper = renderWithRedux() + + return {wrapper} +} + +describe('BucketList', () => { + describe('rendering', () => { + it('renders', () => { + const {wrapper} = setup() + expect(wrapper).toMatchSnapshot() + }) + }) +}) diff --git a/ui/src/organizations/components/Collectors.test.tsx b/ui/src/organizations/components/Collectors.test.tsx new file mode 100644 index 0000000000..d09f9833fe --- /dev/null +++ b/ui/src/organizations/components/Collectors.test.tsx @@ -0,0 +1,35 @@ +// Libraries +import React from 'react' +import {shallow} from 'enzyme' + +// Components +import CollectorList from 'src/organizations/components/CollectorList' + +// Constants +import {telegraf} from 'mocks/dummyData' + +const setup = (override?) => { + const props = { + collectors: telegraf, + emptyState: <>, + onDelete: jest.fn(), + onUpdate: jest.fn(), + onOpenInstructions: jest.fn(), + onOpenTelegrafConfig: jest.fn(), + ...override, + } + + const wrapper = shallow() + + return {wrapper} +} + +describe('CollectorList', () => { + describe('rendering', () => { + it('renders', () => { + const {wrapper} = setup() + expect(wrapper.exists()).toBe(true) + expect(wrapper).toMatchSnapshot() + }) + }) +}) diff --git a/ui/src/organizations/components/Members.test.tsx b/ui/src/organizations/components/Members.test.tsx new file mode 100644 index 0000000000..80d37c2c9d --- /dev/null +++ b/ui/src/organizations/components/Members.test.tsx @@ -0,0 +1,31 @@ +// Libraries +import React from 'react' +import {shallow} from 'enzyme' + +// Components +import MemberList from 'src/organizations/components/MemberList' + +// Constants +import {resouceOwner} from 'src/organizations/dummyData' + +const setup = (override?) => { + const props = { + members: resouceOwner, + emptyState: <>, + ...override, + } + + const wrapper = shallow() + + return {wrapper} +} + +describe('MemberList', () => { + describe('rendering', () => { + it('renders', () => { + const {wrapper} = setup() + expect(wrapper.exists()).toBe(true) + expect(wrapper).toMatchSnapshot() + }) + }) +}) diff --git a/ui/src/organizations/components/Scrapers.test.tsx b/ui/src/organizations/components/Scrapers.test.tsx new file mode 100644 index 0000000000..cc2324d8b0 --- /dev/null +++ b/ui/src/organizations/components/Scrapers.test.tsx @@ -0,0 +1,33 @@ +// Libraries +import React from 'react' +import {shallow} from 'enzyme' + +// Components +import ScraperList from 'src/organizations/components/ScraperList' + +// Constants +import {scraperTargets} from 'mocks/dummyData' + +const setup = (override?) => { + const props = { + scrapers: scraperTargets, + emptyState: <>, + onDeleteScraper: jest.fn(), + onUpdateScraper: jest.fn(), + ...override, + } + + const wrapper = shallow() + + return {wrapper} +} + +describe('ScraperList', () => { + describe('rendering', () => { + it('renders', () => { + const {wrapper} = setup() + expect(wrapper.exists()).toBe(true) + expect(wrapper).toMatchSnapshot() + }) + }) +}) diff --git a/ui/src/organizations/components/__snapshots__/Buckets.test.tsx.snap b/ui/src/organizations/components/__snapshots__/Buckets.test.tsx.snap new file mode 100644 index 0000000000..751ab30ed8 --- /dev/null +++ b/ui/src/organizations/components/__snapshots__/Buckets.test.tsx.snap @@ -0,0 +1,687 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`BucketList rendering renders 1`] = ` +Object { + "asFragment": [Function], + "baseElement": +
+ + + + + + + + + + + + + + + + + + + + + + +
+ Name + + Retention + + +
+
+ +
+
+
+
+
+
+ +
+
+ Confirm +
+
+
+
+
+
+
+
+ +
+
+ + + +
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+ Confirm +
+
+
+
+
+
+
+
+ +
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ , + "container":
+ + + + + + + + + + + + + + + + + + + + + + +
+ Name + + Retention + + +
+
+ +
+
+
+
+
+
+ +
+
+ Confirm +
+
+
+
+
+
+
+
+ +
+
+ + + +
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+ Confirm +
+
+
+
+
+
+
+
+ +
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
, + "debug": [Function], + "getAllByAltText": [Function], + "getAllByDisplayValue": [Function], + "getAllByLabelText": [Function], + "getAllByPlaceholderText": [Function], + "getAllByRole": [Function], + "getAllBySelectText": [Function], + "getAllByTestId": [Function], + "getAllByText": [Function], + "getAllByTitle": [Function], + "getAllByValue": [Function], + "getByAltText": [Function], + "getByDisplayValue": [Function], + "getByLabelText": [Function], + "getByPlaceholderText": [Function], + "getByRole": [Function], + "getBySelectText": [Function], + "getByTestId": [Function], + "getByText": [Function], + "getByTitle": [Function], + "getByValue": [Function], + "queryAllByAltText": [Function], + "queryAllByDisplayValue": [Function], + "queryAllByLabelText": [Function], + "queryAllByPlaceholderText": [Function], + "queryAllByRole": [Function], + "queryAllBySelectText": [Function], + "queryAllByTestId": [Function], + "queryAllByText": [Function], + "queryAllByTitle": [Function], + "queryAllByValue": [Function], + "queryByAltText": [Function], + "queryByDisplayValue": [Function], + "queryByLabelText": [Function], + "queryByPlaceholderText": [Function], + "queryByRole": [Function], + "queryBySelectText": [Function], + "queryByTestId": [Function], + "queryByText": [Function], + "queryByTitle": [Function], + "queryByValue": [Function], + "rerender": [Function], + "store": Object { + "dispatch": [Function], + "getState": [Function], + "replaceReducer": [Function], + "subscribe": [Function], + Symbol(observable): [Function], + }, + "unmount": [Function], +} +`; diff --git a/ui/src/organizations/components/__snapshots__/Collectors.test.tsx.snap b/ui/src/organizations/components/__snapshots__/Collectors.test.tsx.snap new file mode 100644 index 0000000000..c5ee100ced --- /dev/null +++ b/ui/src/organizations/components/__snapshots__/Collectors.test.tsx.snap @@ -0,0 +1,55 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CollectorList rendering renders 1`] = ` + + + + + + + } + > + + + + + +`; diff --git a/ui/src/organizations/components/__snapshots__/Members.test.tsx.snap b/ui/src/organizations/components/__snapshots__/Members.test.tsx.snap new file mode 100644 index 0000000000..a9a1e26011 --- /dev/null +++ b/ui/src/organizations/components/__snapshots__/Members.test.tsx.snap @@ -0,0 +1,91 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`MemberList rendering renders 1`] = ` + + + + + + + } + > + + + John + + + owner + + + + + + Jane + + + owner + + + + + + Smith + + + owner + + + + + +`; diff --git a/ui/src/organizations/components/__snapshots__/Scrapers.test.tsx.snap b/ui/src/organizations/components/__snapshots__/Scrapers.test.tsx.snap new file mode 100644 index 0000000000..bcecc14d39 --- /dev/null +++ b/ui/src/organizations/components/__snapshots__/Scrapers.test.tsx.snap @@ -0,0 +1,59 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ScraperList rendering renders 1`] = ` + + + + + + + } + > + + + + + +`;