Skip to content

Commit

Permalink
feat: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lan Le committed Aug 10, 2023
1 parent 7ab248f commit 82a254c
Showing 1 changed file with 65 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import React from 'react';
import expect from 'expect';
import Enzyme, { mount, shallow } from 'enzyme';
import Enzyme, { shallow } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import {
describe, it, beforeEach
describe, it, beforeEach, afterEach
} from 'mocha';
Enzyme.configure({ adapter: new Adapter() });

import {
PanelGroup,
Panel,
Button,
OverlayTrigger, SplitButton, ButtonGroup, MenuItem, Tooltip
} from 'react-bootstrap';

import ReactionDetailsContainers from 'src/apps/mydb/elements/details/reactions/analysesTab/ReactionDetailsContainers';

import Reaction from 'src/models/Reaction';
import Container from 'src/models/Container';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';

Enzyme.configure({ adapter: new Adapter() });

describe('ReactionDetailsContainers', () => {
describe('It does not have any analysis', () => {
const reaction = Reaction.buildEmpty();
it('Render without any analysis and readonly', () => {
const wrapper = shallow(<ReactionDetailsContainers reaction={reaction} readOnly={true} />);
const wrapper = shallow(<ReactionDetailsContainers reaction={reaction} readOnly />);
const expectedValue = shallow(
<div
style={{ marginBottom: '10px' }}
Expand All @@ -36,7 +38,7 @@ describe('ReactionDetailsContainers', () => {
expect(wrapper.html()).toEqual(expectedValue.html());
});

it('Render without any analysisy', () => {
it('Render without any analysis', () => {
const wrapper = shallow(<ReactionDetailsContainers reaction={reaction} readOnly={false} />);
const expectedValue = shallow(
<div
Expand All @@ -56,5 +58,61 @@ describe('ReactionDetailsContainers', () => {
expect(wrapper.html()).toEqual(expectedValue.html());
});
});


describe('It has analyses', () => {
let reaction = null;

beforeEach(() => {
reaction = Reaction.buildEmpty();
});

afterEach(() => {
reaction = null;
});

it('Render with analysis is deleted', () => {
const analysis = Container.buildAnalysis();
analysis.is_deleted = true;
reaction.container.children[0].children.push(analysis);

const wrapper = shallow(
<DndProvider backend={HTML5Backend}>
<ReactionDetailsContainers reaction={reaction} readOnly={false} />
</DndProvider>
);
const expectedValue = shallow(
<div>
<div style={{ marginBottom: '10px' }}>
&nbsp;<Button
className="button-right"
bsSize="xsmall"
bsStyle="success"
>
Add analysis
</Button>
</div>
<PanelGroup id="reaction-analyses-panel" defaultActiveKey={0} activeKey={0} accordion>
<Panel
eventKey={0}
key={`reaction_container_deleted_${analysis.id}`}
>
<Panel.Heading>
<div style={{ width: '100%' }}>
<strike>
{analysis.name}
{` - Type: ${analysis.extended_metadata.kind}`}

</strike>
<Button className="pull-right" bsSize="xsmall" bsStyle="danger">
<i className="fa fa-undo" />
</Button>
</div>
</Panel.Heading>
</Panel>
</PanelGroup>
</div>
);
expect(wrapper.html()).toEqual(expectedValue.html());
});
});
});

0 comments on commit 82a254c

Please sign in to comment.