text: import { 
      handleChangePage,
      handleSetPageSize,
      exportConfig,
      buildActiveFilters,
      removeFilters
  } from './TableToolbarHelper';
  
  const mockGeneralFilters = {
      rule_presence: "true",
      sort: "-public_date",
  };
  
  const mockGeneralChip = {
      key: 'rule_presence',
      multiValue: [ 'true' ],
      category: 'Security rules',
      chips: [ {
                name: "Has security rule",
                value: "true",
            },
        ]
  };
  
  const mockApply = jest.fn();
  
  describe('TableToolbarHelper', () => {
      it('Should handleChangePage apply with provided page', () => {
          const testPage = 1;
          const testApply = jest.fn();
          handleChangePage(null, testPage, testApply);
          expect(testApply).toHaveBeenCalledWith({ page: testPage })
      });
  
      it('Should handleSetPageSize apply with provided page size and page 1', () => {
          const testPageSize = 1;
          const testApply = jest.fn();
          handleSetPageSize(null, testPageSize, testApply);
          expect(testApply).toHaveBeenCalledWith({ page_size: testPageSize, page: 1 })
      });
  
      it('Should exportConfig call downloadReport with fileType', () => {
          const testMethods = { downloadReport: jest.fn() };
          const result = exportConfig(testMethods);
          result.onSelect(null, 'testFileType');
  
          expect(testMethods.downloadReport).toHaveBeenCalledWith('testFileType');
      });
  
      it('Should set filterRulevalues to empty array safely', () => {
          const result = buildActiveFilters(mockGeneralFilters);
      });
  
      it('Should build active filters', () => {
          const result = buildActiveFilters(mockGeneralFilters, []);
          expect(result).toEqual([mockGeneralChip]
        );
      });
  
      it('Should push search filter chip into filterChips array', () => {
          const result = buildActiveFilters({ ...mockGeneralFilters, filter: 'testFilter' }, []);
          expect(result).toEqual([
              mockGeneralChip,
              { 
                  key: 'filter', 
                  category: 'Search term', 
                  chips: [{
                      name: 'testFilter'
                  }] 
              }
          ]);        
      });
  
      it('Should handle multi value filters (e.g business_risk = "0,3"', () => {
          const result = buildActiveFilters({ ...mockGeneralFilters, business_risk_id: '0,3' }, []);
          expect(result).toEqual([
              {
                  key: 'business_risk_id',
                  multiValue: [ '0', '3' ],
                  category: 'Business risk',
                  chips: [               
                        {
                        name: "Not defined",
                        value: "0",
                        },
                        {
                          name: "High",
                          value: "3",
                      },          
                    ]
              },
              mockGeneralChip
          ]);      
      });
  
      it('Should handle filters with a range', () => {
          const result = buildActiveFilters({ ...mockGeneralFilters, cvss_filter: "less4", cvss_from: 0, cvss_to: 4 }, []);
          expect(result).toEqual([
              {
                  key: 'cvss_filter',
                  category: 'CVSS base score',
                  chips: [{
                            name: "0.0 - 4.0"
                  }]
              },
              mockGeneralChip
          ]);
      });
  
      it('Should handle security rule filters', () => {
          const mockRuleFilters = [{ value: "testRulevalue", label: "testRuleLabel" }];
          const result = buildActiveFilters({ rule_presence: "testRulevalue"}, mockRuleFilters);
          expect(result).toEqual([
              {
                  key: 'rule_presence',
                  multiValue: [ 'testRulevalue' ],
                  category: 'Security rules',
                  chips: [{
                      name: "testRuleLabel",
                      value: "testRulevalue",
                  }]
              }
          ]);
      });
  
      it('Should handle security rule filters without label safely', () => {
          const mockRuleFilters = [{ value: "testRulevalue" }];
          const result = buildActiveFilters({ rule_presence: "testRulevalue"}, mockRuleFilters);
          expect(result).toEqual([
              {
                  key: 'rule_presence',
                  multiValue: [ 'testRulevalue' ],
                  category: 'Security rules',
                  chips: [{
                      name: "testRulevalue",
                      value: "testRulevalue",
                  }]
              }
          ]);
      });
  
      it('Should exclude filters with undefined and empty string values filter', () => {
          const result = buildActiveFilters({ ...mockGeneralFilters, status_id: undefined, business_risk_id: undefined }, []);
          expect(result).toEqual([mockGeneralChip]);
      });
  
      it('Should remove filters', () => {
          removeFilters([mockGeneralChip], mockApply);
          expect(mockApply).toHaveBeenCalledWith({ rule_presence: undefined, rule: '', page: 1 });
      });
  
      it('Should remove search filters and multi value filters with only one value safely', () => {
          const mockSingleValueChips = [
              {
                  key: 'business_risk_id',
                  multiValue: [ '0' ],
                  category: 'Business risk',
                  chips: [               
                          {
                          name: "Not defined",
                          value: "0",
                          }        
                  ]
          }];
          removeFilters(mockSingleValueChips, mockApply);
          expect(mockApply).toHaveBeenCalledWith({ business_risk_id: undefined, page: 1});
      });
  
      it('Should handle multi value filters safely', () => {
          const mockMultiValueChips = [{
              key: 'business_risk_id',
              multiValue: [ '0', '3' ],
              category: 'Business risk',
              chips: [               
                      {
                      name: "Not defined",
                      value: "0",
                      },
                      {
                      name: "High",
                      value: "3",
                  },          
                  ]
          }];
          removeFilters(mockMultiValueChips, mockApply);
          expect(mockApply).toHaveBeenCalledWith({ business_risk_id: undefined, page: 1 });
      });
  });
  