diff --git a/src/components/ComponentToPrint/ComponentToPrint.test.js b/src/components/ComponentToPrint/ComponentToPrint.test.js
index 0854a249..2537a71c 100644
--- a/src/components/ComponentToPrint/ComponentToPrint.test.js
+++ b/src/components/ComponentToPrint/ComponentToPrint.test.js
@@ -1,32 +1,48 @@
import React from 'react';
-import { render } from '@testing-library/react';
+import { render, screen } from '@testing-library/react';
+import { Parser } from 'html-to-react';
import ComponentToPrint from './ComponentToPrint';
-// Mock the react-barcode library
jest.mock('react-barcode', () => {
return jest.fn().mockImplementation(() =>
);
});
describe('ComponentToPrint', () => {
const templateFnMock = jest.fn();
- const dataSourceMock = {};
-
+ const templateFn = jest.fn(() => '123456');
+ const dataSource = { 'request':1 };
+ const parser = new Parser();
beforeEach(() => {
templateFnMock.mockClear();
});
-
- it('renders without crashing', () => {
- render();
+ it('should handle null result from parseWithInstructions', () => {
+ const originalParseWithInstructions = parser.parseWithInstructions;
+ parser.parseWithInstructions = jest.fn(() => null);
+ render();
+ expect(screen.queryByTestId('barcode')).not.toBeInTheDocument();
+ parser.parseWithInstructions = originalParseWithInstructions;
});
-
- it('renders a Barcode component when encountering a "barcode" tag in the template', () => {
- const templateFn = jest.fn(() => '123456');
- const dataSource = {};
-
- const { getByTestId } = render();
-
- const barcodeComponent = getByTestId('barcode-component');
-
- expect(barcodeComponent).toBeInTheDocument();
+ it('should handle empty template string', () => {
+ const emptyTemplateFn = jest.fn(() => null);
+ const { container } = render();
+ expect(container.firstChild).toBeNull();
+ });
+ it('should process the barcode rule with empty string', () => {
+ const mockBarcodeValue = '123456789';
+ const emptyString = '';
+ const mockComponentStr = `${mockBarcodeValue}${emptyString}
`;
+ templateFn.mockReturnValue(mockComponentStr);
+ render();
+ const barcodeElement = screen.getAllByTestId('barcode-component')[0];
+ expect(barcodeElement).toBeInTheDocument();
+ });
+ it('should process the barcode rule with data', () => {
+ const originalParseWithInstructions = parser.parseWithInstructions;
+ const mockParsedComponent = Mock Component
;
+ parser.parseWithInstructions = jest.fn(() => mockParsedComponent);
+ render();
+ const emptyBarcodeElement = screen.getAllByTestId('barcode-component')[1];
+ expect(emptyBarcodeElement).toBeInTheDocument();
+ parser.parseWithInstructions = originalParseWithInstructions;
});
});