Skip to content

Commit

Permalink
added component level test
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed May 6, 2021
1 parent 611a506 commit 3efeff8
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';
import { mountWithIntl } from '@kbn/test/jest';
import { notificationServiceMock } from 'src/core/public/mocks';

import { ReportingPanelContent, Props } from './reporting_panel_content';

describe('ReportingPanelContent', () => {
const mountComponent = (props: Partial<Props>) =>
mountWithIntl(
<ReportingPanelContent
requiresSavedState
// We have unsaved changes
isDirty={true}
reportType="test"
layoutId="test"
getJobParams={jest.fn().mockReturnValue({})}
objectId={'my-object-id'}
apiClient={{ getReportingJobPath: () => 'test' } as any}
toasts={notificationServiceMock.createSetupContract().toasts}
{...props}
/>
);
describe('saved state', () => {
it('prevents generating reports when saving is required and we have unsaved changes', () => {
const wrapper = mountComponent({
requiresSavedState: true,
isDirty: true,
objectId: undefined,
});
wrapper.update();
expect(wrapper.find('[data-test-subj="generateReportButton"]').last().props().disabled).toBe(
true
);
});

it('allows generating reports when saving is not required', () => {
const wrapper = mountComponent({
requiresSavedState: false,
isDirty: true,
objectId: undefined,
});
wrapper.update();
expect(wrapper.find('[data-test-subj="generateReportButton"]').last().props().disabled).toBe(
false
);
});
});
});

0 comments on commit 3efeff8

Please sign in to comment.