Skip to content

Commit

Permalink
added unit tests for progressScoreBar and noEntitiesFound component
Browse files Browse the repository at this point in the history
  • Loading branch information
PreetiW committed Apr 26, 2024
1 parent e55d1fc commit 4f9f963
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"server:ctr": "node src/server/generateServerKey.js",
"start": "HOT=true fec dev",
"test": "TZ=UTC jest --verbose --no-cache",
"test:local": "TZ=UTC jest --verbose --no-cache --coverage --coverageReporters='text-summary' --watch",
"test:local": "TZ=UTC jest --verbose --no-cache --coverage --coverageDirectory='coverage' --watch",
"verify": "npm-run-all build lint test",
"postinstall": "ts-patch install"
},
Expand Down
24 changes: 22 additions & 2 deletions src/Components/NoEntitiesFound/NoEntitiesFound.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
import { test } from '@jest/globals';
import { describe } from '@jest/globals';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import NoEntitiesFound from './NoEntitiesFound';

describe('NoEntitiesFound tests', () => {
it('should render correctly when there are no records', () => {

// render
render(<NoEntitiesFound />);

// query

const noInstanceText = screen.getByText('No suggested instance types found');
const gettingStartedButton = screen.getByRole('link');

// assert
expect(noInstanceText).toBeVisible();
expect(gettingStartedButton).toBeVisible();

});
});

test.todo('NoEntitiesFound tests');
3 changes: 2 additions & 1 deletion src/Components/RosTable/ProgressScoreBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export const ProgressScoreBar = ({ utilizedValue, measureLocation, eleId }) =>
<Progress value={ utilizedValue }
className={ `progress-score-bar blue-300` }
measureLocation={ measureLocation }
{ ...(eleId ? { id: eleId } : null) } />
{ ...(eleId ? { id: eleId } : null) }
data-testid='progress-score-bar' />
</React.Fragment>
);
};
Expand Down
40 changes: 38 additions & 2 deletions src/Components/RosTable/ProgressScoreBar.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
import { test } from '@jest/globals';
import { describe } from '@jest/globals';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { ProgressScoreBar } from './ProgressScoreBar';

describe('ProgressScoreBar component tests', () => {
it('expect to render with blue-300 class with 40%', () => {

// render
render(<ProgressScoreBar measureLocation='outside' eleId='345' utilizedValue={40} />);

// query
const progressScoreBar = screen.getByTestId('progress-score-bar');
const progressText40 = screen.getByText('40%');

// assert
expect(progressScoreBar).toBeVisible();
expect(progressScoreBar).toHaveClass('pf-v5-c-progress blue-300');
expect(progressText40).toBeVisible();

});

it('expect to render with blue-300 class with 90%', () => {

// render
render(<ProgressScoreBar measureLocation='outside' utilizedValue={90} />);

// query
const progressScoreBar = screen.getByTestId('progress-score-bar');
const progressText90 = screen.getByText('90%');

// assert
expect(progressScoreBar).toBeVisible();
expect(progressScoreBar).toHaveClass('pf-v5-c-progress blue-300');
expect(progressText90).toBeVisible();

});
});

test.todo('ProgressScoreBar component tests');

0 comments on commit 4f9f963

Please sign in to comment.