Skip to content

Commit

Permalink
add additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahd93 committed Apr 29, 2019
1 parent 7329e61 commit 1fc54fe
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ exports[`Titlebar tests should not render content if user is logged out 1`] = `
src="/img/gsa.svg"
/>
</div>
<div />
<div>
Vendor Version
</div>
</div>
</div>
</body>
Expand Down
65 changes: 64 additions & 1 deletion gsa/src/web/components/bar/__tests__/progressbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,75 @@ describe('ProgressBar tests', () => {
expect(progress).toHaveStyleRule('width', '90%');
});

test('should render background', () => {
test('should not render progress > 100', () => {
const {getByTestId} = render(
<ProgressBar background="low" progress="101" title="Progress" />,
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('width', '100%');
});

test('should not render progress < 0', () => {
const {getByTestId} = render(
<ProgressBar background="low" progress="-1" title="Progress" />,
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('width', '0%');
});

test('should render background = warn', () => {
const {getByTestId} = render(
<ProgressBar background="warn" progress="10" title="Progress" />,
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', '#F0A519');
});

test('should render background = error', () => {
const {getByTestId} = render(
<ProgressBar background="error" progress="10" title="Progress" />,
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', '#C83814');
});

test('should render background = low', () => {
const {getByTestId} = render(
<ProgressBar background="low" progress="10" title="Progress" />,
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', '#4F91C7');
});

test('should render background = new', () => {
const {getByTestId} = render(
<ProgressBar background="new" progress="10" title="Progress" />,
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', '#99BE48');
});

test('should render background = run', () => {
const {getByTestId} = render(
<ProgressBar background="run" progress="10" title="Progress" />,
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', '#70C000');
});

test('should render background = log', () => {
const {getByTestId} = render(
<ProgressBar background="log" progress="10" title="Progress" />,
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', 'gray');
});
});
22 changes: 22 additions & 0 deletions gsa/src/web/components/bar/__tests__/severitybar.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,32 @@ describe('SeverityBar tests', () => {
expect(progress).toHaveStyleRule('width', '95%');
});

test('should not render progress > 100', () => {
const {getByTestId} = render(<SeverityBar severity="10.1" />);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('width', '100%');
});

test('should not render progress < 0', () => {
const {getByTestId} = render(<SeverityBar severity="-0.1" />);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('width', '0%');
});

test('should render background', () => {
const {getByTestId} = render(<SeverityBar severity="9.5" />);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', '#C83814');
});

test('should render without severity prop', () => {
const {getByTestId} = render(<SeverityBar />);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', '#4F91C7');
expect(progress).toHaveStyleRule('width', '0%');
});
});
18 changes: 18 additions & 0 deletions gsa/src/web/components/bar/__tests__/statusbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ describe('StatusBar tests', () => {
expect(progress).toHaveStyleRule('width', '90%');
});

test('should not render progress > 100', () => {
const {getByTestId} = render(
<StatusBar progress="101" status={TASK_STATUS.stopped} />,
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('width', '100%');
});

test('should not render progress < 0', () => {
const {getByTestId} = render(
<StatusBar progress="-1" status={TASK_STATUS.stopped} />,
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('width', '0%');
});

test('should render background', () => {
const {getByTestId} = render(
<StatusBar progress="90" status={TASK_STATUS.stopped} />,
Expand Down
7 changes: 6 additions & 1 deletion gsa/src/web/components/bar/__tests__/titlebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,22 @@ describe('Titlebar tests', () => {

expect(baseElement).toMatchSnapshot();
expect(isLoggedIn).toHaveBeenCalled();
const links = baseElement.querySelectorAll('a');
expect(links[1]).toHaveTextContent('username');
expect(baseElement).not.toHaveTextContent('Vendor Version');
});

test('should not render content if user is logged out', () => {
const isLoggedIn = jest.fn().mockReturnValue(false);
const gmp = {isLoggedIn, settings: {vendorVersion: ''}};
const gmp = {isLoggedIn, settings: {vendorVersion: 'Vendor Version'}};
const {render, store} = rendererWith({gmp, router: true, store: true});
store.dispatch(setUsername('username'));

const {baseElement} = render(<Titlebar />);

expect(baseElement).toMatchSnapshot();
expect(isLoggedIn).toHaveBeenCalled();
expect(baseElement).not.toHaveTextContent('username');
expect(baseElement).toHaveTextContent('Vendor Version');
});
});
3 changes: 3 additions & 0 deletions gsa/src/web/components/bar/progressbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ const Progress = styled.div`
if (progress > 100) {
progress = 100;
}
if (progress < 0) {
progress = 0;
}
return {
width: progress + '%',
background,
Expand Down

0 comments on commit 1fc54fe

Please sign in to comment.