Skip to content

Commit

Permalink
Manage model for each test individually to facilitate adding new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-tng committed Nov 24, 2021
1 parent 0f8d78e commit d8ed9c0
Showing 1 changed file with 58 additions and 28 deletions.
86 changes: 58 additions & 28 deletions src/client/components/threatbar/threatbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,48 +26,78 @@ describe('<Threatbar>', () => {
},
};

const model = {
detail: {
diagrams: {
diagram1: {
diagramJson: {
cells: [
{
id: 'component1',
type: 'type',
attrs: {
text: {
text: 'text'
}
},
threats: [
{
title: 'Existing Threat 1'
it('shows identified threats in reverse order', () => {
const model = {
detail: {
diagrams: {
diagram1: {
diagramJson: {
cells: [
{
id: 'component1',
type: 'type',
attrs: {
text: {
text: 'text'
}
},
{
title: 'Existing Threat 2'
}
]
}
]
threats: [
{
title: 'Existing Threat 1'
},
{
title: 'Existing Threat 2'
}
]
}
]
}
}
}
}
}
};
};

beforeEach(() => {
render(<Threatbar G={G} ctx={{}} moves={{}} active names={[]} model={model}/>);
});

it('shows identified threats in reverse order', () => {
const threats = screen.getAllByText(/^Identified Threat \d+$/);
expect(threats).toHaveLength(2);
expect(threats[0]).toHaveTextContent('Identified Threat 2');
expect(threats[1]).toHaveTextContent('Identified Threat 1');
});

it('shows existing threats in reverse order', () => {
const model = {
detail: {
diagrams: {
diagram1: {
diagramJson: {
cells: [
{
id: 'component1',
type: 'type',
attrs: {
text: {
text: 'text'
}
},
threats: [
{
title: 'Existing Threat 1'
},
{
title: 'Existing Threat 2'
}
]
}
]
}
}
}
}
};

render(<Threatbar G={G} ctx={{}} moves={{}} active names={[]} model={model}/>);

const threats = screen.getAllByText(/^Existing Threat \d+$/);
expect(threats).toHaveLength(2);
expect(threats[0]).toHaveTextContent('Existing Threat 2');
Expand Down

0 comments on commit d8ed9c0

Please sign in to comment.