Skip to content

Commit

Permalink
fix: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-mng committed Nov 28, 2024
1 parent f0a4add commit cb97ec2
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 256 deletions.

This file was deleted.

72 changes: 0 additions & 72 deletions src/web/components/bar/__tests__/__snapshots__/statusbar.jsx.snap

This file was deleted.

12 changes: 9 additions & 3 deletions src/web/components/bar/__tests__/compliancestatusbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('ComplianceStatusBar tests', () => {
test('should render', () => {
const {element} = render(<ComplianceStatusBar complianceStatus={75} />);

expect(element).toMatchSnapshot();
expect(element).toBeVisible();
});

test('should render text content', () => {
Expand Down Expand Up @@ -63,7 +63,10 @@ describe('ComplianceStatusBar tests', () => {
const progress = getByTestId('progress');
const progressbarBox = getByTestId('progressbar-box');

expect(progress).toHaveStyleRule('background', Theme.statusRunGreen);
expect(progress).toHaveStyleRule(
'background',
`linear-gradient(90deg, ${Theme.statusRunGreen} 0%, ${Theme.statusRunGreen} 100%)`,
);
expect(progressbarBox).toHaveStyleRule('background', Theme.errorRed);
});

Expand All @@ -72,7 +75,10 @@ describe('ComplianceStatusBar tests', () => {
const progress = getByTestId('progress');
const progressbarBox = getByTestId('progressbar-box');

expect(progress).toHaveStyleRule('background', Theme.statusRunGreen);
expect(progress).toHaveStyleRule(
'background',
`linear-gradient(90deg, ${Theme.statusRunGreen} 0%, ${Theme.statusRunGreen} 100%)`,
);
expect(progress).toHaveStyleRule('width', '0%');

expect(progressbarBox).toHaveStyleRule('background', Theme.darkGray);
Expand Down
30 changes: 24 additions & 6 deletions src/web/components/bar/__tests__/progressbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ describe('ProgressBar tests', () => {
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', Theme.severityWarnYellow);
expect(progress).toHaveStyleRule(
'background',
`linear-gradient(90deg, ${Theme.severityWarnYellow} 0%, ${Theme.severityWarnYellow} 100%)`,
);
});

test('should render background = error', () => {
Expand All @@ -70,7 +73,10 @@ describe('ProgressBar tests', () => {
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', Theme.errorRed);
expect(progress).toHaveStyleRule(
'background',
`linear-gradient(90deg, ${Theme.errorRed} 0%, ${Theme.errorRed} 100%)`,
);
});

test('should render background = low', () => {
Expand All @@ -79,7 +85,10 @@ describe('ProgressBar tests', () => {
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', Theme.severityLowBlue);
expect(progress).toHaveStyleRule(
'background',
`linear-gradient(90deg, ${Theme.severityLowBlue} 0%, ${Theme.severityLowBlue} 100%)`,
);
});

test('should render background = new', () => {
Expand All @@ -88,7 +97,10 @@ describe('ProgressBar tests', () => {
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', Theme.statusNewGreen);
expect(progress).toHaveStyleRule(
'background',
`linear-gradient(90deg, ${Theme.statusNewGreen} 0%, ${Theme.statusNewGreen} 100%)`,
);
});

test('should render background = run', () => {
Expand All @@ -97,7 +109,10 @@ describe('ProgressBar tests', () => {
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', Theme.statusRunGreen);
expect(progress).toHaveStyleRule(
'background',
`linear-gradient(90deg, ${Theme.statusRunGreen} 0%, ${Theme.statusRunGreen} 100%)`,
);
});

test('should render background = log', () => {
Expand All @@ -106,7 +121,10 @@ describe('ProgressBar tests', () => {
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', 'gray');
expect(progress).toHaveStyleRule(
'background',
`linear-gradient(90deg, gray 0%, gray 100%)`,
);
});

test('should render box background', () => {
Expand Down
10 changes: 8 additions & 2 deletions src/web/components/bar/__tests__/severitybar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,20 @@ describe('SeverityBar tests', () => {
const {getByTestId} = render(<SeverityBar severity="9.5" />);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', Theme.errorRed);
expect(progress).toHaveStyleRule(
'background',
`linear-gradient(90deg, ${Theme.errorRed} 0%, ${Theme.errorRed} 100%)`,
);
});

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

expect(progress).toHaveStyleRule('background', Theme.severityLowBlue);
expect(progress).toHaveStyleRule(
'background',
`linear-gradient(90deg, ${Theme.severityLowBlue} 0%, ${Theme.severityLowBlue} 100%)`,
);
expect(progress).toHaveStyleRule('width', '0%');
});
});
7 changes: 5 additions & 2 deletions src/web/components/bar/__tests__/statusbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('StatusBar tests', () => {
test('should render', () => {
const {element} = render(<StatusBar progress="90" status="Unknown" />);

expect(element).toMatchSnapshot();
expect(element).toBeVisible();
});

test('should render text content', () => {
Expand Down Expand Up @@ -71,7 +71,10 @@ describe('StatusBar tests', () => {
);
const progress = getByTestId('progress');

expect(progress).toHaveStyleRule('background', Theme.severityWarnYellow);
expect(progress).toHaveStyleRule(
'background',
`linear-gradient(90deg, ${Theme.severityWarnYellow} 0%, ${Theme.severityWarnYellow} 100%)`,
);
});
});

Expand Down
20 changes: 16 additions & 4 deletions src/web/components/date/__tests__/datetime.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ describe('DateTime render tests', () => {
afterAll(() => {
localStorage.setItem = originalSetItem;
});

const removeStyleTags = html => {
let previous;
do {
previous = html;
html = html.replace(/<style[^>]*>.*?<\/style>/g, '');
} while (html !== previous);
return html;
};

test('should render nothing if date is undefined', () => {
const {render, store} = rendererWith({gmp, store: true});
store.dispatch(
Expand All @@ -50,9 +60,10 @@ describe('DateTime render tests', () => {
}),
);

const {element} = render(<DateTime />);
const {container} = render(<DateTime />);

expect(element).toBeNull();
const content = removeStyleTags(container.innerHTML).trim();
expect(content).toBe('');
});

test('should render nothing for invalid date', () => {
Expand All @@ -72,9 +83,10 @@ describe('DateTime render tests', () => {

expect(date.isValid()).toEqual(false);

const {element} = render(<DateTime date={date} />);
const {container} = render(<DateTime date={date} />);

expect(element).toBeNull();
const content = removeStyleTags(container.innerHTML).trim();
expect(content).toBe('');

console.warn = consoleWarn;
});
Expand Down
Loading

0 comments on commit cb97ec2

Please sign in to comment.