Skip to content

Commit

Permalink
LRAC-14385 Create unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
interaminense authored and brianchandotcom committed Aug 16, 2023
1 parent a1caed3 commit 21c1e22
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const ExperimentOverviewPage: React.FC<IExperimentOverviewPage> = ({
const {selectedChannel} = useChannelContext();

useAddRefetch(refetch);

return (
<SafeResults {...result}>
{({experiment}) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import client from 'shared/apollo/client';
import ExperimentOverviewPage from '../ExperimentOverviewPage';
import mockStore from 'test/mock-store';
import React from 'react';
import {ApolloProvider} from '@apollo/react-hooks';
import {MemoryRouter, Route} from 'react-router-dom';
import {MockedProvider} from '@apollo/react-testing';
import {mockExperimentRootReq, mockTimeRangeReq} from 'test/graphql-data';
import {Provider} from 'react-redux';
import {render} from '@testing-library/react';
import {Routes} from 'shared/util/router';
import {waitForLoadingToBeRemoved} from 'test/helpers';

jest.unmock('react-dom');

const WrappedComponent = ({status}) => (
<ApolloProvider client={client}>
<Provider store={mockStore() as any}>
<MemoryRouter
initialEntries={['/workspace/1000/2000/tests/overview/123']}
>
<Route path={Routes.TESTS_OVERVIEW}>
<MockedProvider
mocks={[
mockTimeRangeReq(),
mockExperimentRootReq({status})
]}
>
<ExperimentOverviewPage
router={{
params: {
channelId: '2000',
groupId: '1000',
id: '123'
},
query: {}
}}
/>
</MockedProvider>
</Route>
</MemoryRouter>
</Provider>
</ApolloProvider>
);

describe('ExperimentOverviewPage', () => {
it('renders review and delete button to experiment to status DRAFT', async () => {
const {container, getByRole} = render(
<WrappedComponent status='DRAFT' />
);

await waitForLoadingToBeRemoved(container);

const reviewButton = getByRole('link', {
name: /review/i
}) as HTMLAnchorElement;
const deleteButton = getByRole('link', {
name: /delete/i
}) as HTMLAnchorElement;

expect(reviewButton).toBeInTheDocument();
expect(reviewButton.href).toEqual(
'https://www.beryl.com/experiment-test?segmentsExperimentKey=123&segmentsExperimentAction=reviewAndRun'
);

expect(deleteButton).toBeInTheDocument();
expect(deleteButton.href).toEqual(
'https://www.beryl.com/experiment-test?segmentsExperimentKey=123&segmentsExperimentAction=delete'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
import {EventTypes} from 'event-analysis/utils/types';
import {
EXPERIMENT_QUERY,
EXPERIMENT_ROOT_QUERY,
EXPERIMENT_SESSION_HISTOGRAM_QUERY,
EXPERIMENT_SESSION_VARIANTS_HISTOGRAM_QUERY,
EXPERIMENT_VARIANTS_HISTOGRAM_QUERY
Expand Down Expand Up @@ -263,6 +264,29 @@ export function mockExperimentReq() {
};
}

export function mockExperimentRootReq({status}) {
return {
request: {
query: EXPERIMENT_ROOT_QUERY,
variables: {
experimentId: '123'
}
},
result: {
data: {
experiment: {
__typename: 'Experiment',
channelId: '2000',
id: '123',
name: 'Experiment Test',
pageURL: 'https://www.beryl.com/experiment-test',
status
}
}
}
};
}

export function mockBag({items, itemTypeName, name, typeName}) {
return {
[name]: {
Expand Down

0 comments on commit 21c1e22

Please sign in to comment.