|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +import React from 'react'; |
| 9 | +import { render, screen } from '@testing-library/react'; |
| 10 | +import { ComplianceScoreBar } from './compliance_score_bar'; |
| 11 | +import { |
| 12 | + COMPLIANCE_SCORE_BAR_UNKNOWN, |
| 13 | + COMPLIANCE_SCORE_BAR_PASSED, |
| 14 | + COMPLIANCE_SCORE_BAR_FAILED, |
| 15 | +} from './test_subjects'; |
| 16 | + |
| 17 | +describe('<ComplianceScoreBar />', () => { |
| 18 | + it('should display 0% compliance score with status unknown when both passed and failed are 0', () => { |
| 19 | + render(<ComplianceScoreBar totalPassed={0} totalFailed={0} />); |
| 20 | + expect(screen.getByText('0%')).toBeInTheDocument(); |
| 21 | + expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_UNKNOWN)).not.toBeNull(); |
| 22 | + expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_FAILED)).toBeNull(); |
| 23 | + expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_PASSED)).toBeNull(); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should display 100% compliance score when passed is greater than 0 and failed is 0', () => { |
| 27 | + render(<ComplianceScoreBar totalPassed={10} totalFailed={0} />); |
| 28 | + expect(screen.getByText('100%')).toBeInTheDocument(); |
| 29 | + expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_PASSED)).not.toBeNull(); |
| 30 | + expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_FAILED)).toBeNull(); |
| 31 | + expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_UNKNOWN)).toBeNull(); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should display 0% compliance score when passed is 0 and failed is greater than 0', () => { |
| 35 | + render(<ComplianceScoreBar totalPassed={0} totalFailed={10} />); |
| 36 | + expect(screen.getByText('0%')).toBeInTheDocument(); |
| 37 | + expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_FAILED)).not.toBeNull(); |
| 38 | + expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_PASSED)).toBeNull(); |
| 39 | + expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_UNKNOWN)).toBeNull(); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should display 50% compliance score when passed is equal to failed', () => { |
| 43 | + render(<ComplianceScoreBar totalPassed={5} totalFailed={5} />); |
| 44 | + expect(screen.getByText('50%')).toBeInTheDocument(); |
| 45 | + expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_FAILED)).not.toBeNull(); |
| 46 | + expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_PASSED)).not.toBeNull(); |
| 47 | + expect(screen.queryByTestId(COMPLIANCE_SCORE_BAR_UNKNOWN)).toBeNull(); |
| 48 | + }); |
| 49 | +}); |
0 commit comments