To effectively test the updateXmlTreeAndReturnNewConditionStateSelector, you want to cover scenarios that ensure the selector handles the input correctly and produces the expected output. Here’s how you can structure those tests using a testing framework like Jest.
Setup the necessary mocks for any dependencies your selector relies on, such as staticProductXmlTreeStringSelector, createFullXml, getUpdatedOtherTypicalConditionData, and getUpdatedPropagations.
Define test cases that check the functionality of the selector, including various input conditions (like isFirstRender, passAll, etc.), and validate the output state.
Here's what the test code might look like:
javascript
import { updateXmlTreeAndReturnNewConditionStateSelector } from '../path/to/your/selector';
import { staticProductXmlTreeStringSelector } from '../slices';
import { createFullXml, getUpdatedOtherTypicalConditionData, getUpdatedPropagations } from '../helpers';
import { AppState } from '$ufs-common';
jest.mock('../slices', () => ({
staticProductXmlTreeStringSelector: jest.fn(),
}));
jest.mock('../helpers', () => ({
createFullXml: jest.fn(),
getUpdatedOtherTypicalConditionData: jest.fn(),
getUpdatedPropagations: jest.fn(),
}));
describe('updateXmlTreeAndReturnNewConditionStateSelector', () => {
let mockState: AppState;
beforeEach(() => {
mockState = {
/* Set up a basic initial state as necessary */
// e.g., conditions: {}, user: {}
};
jest.clearAllMocks();
});
it('should return updated condition state on valid XML', () => {
const formState = {
id: '1',
otherTypicalConditionData: {},
propagations: [],
// other state fields
};
const props = {
alwaysAvailableAttributes: true,
conditionGroupId: 'groupId',
formState,
isFirstRender: false,
passAll: false,
selectedPropagationIndex: 0,
xmlTreeTagName: 'someTag',
};
const mockXmlString = '<xml></xml>';
const mockUpdatedOtherTypicalData = { /* mock data */ };
const mockUpdatedPropagations = { /* mock data */ };
// Mocks
staticProductXmlTreeStringSelector.mockReturnValue(mockXmlString);
createFullXml.mockReturnValue(mockXmlString);
getUpdatedOtherTypicalConditionData.mockReturnValue(mockUpdatedOtherTypicalData);
getUpdatedPropagations.mockReturnValue(mockUpdatedPropagations);
const result = updateXmlTreeAndReturnNewConditionStateSelector(mockState, props);
expect(result).toEqual({
...formState,
otherTypicalConditionData: mockUpdatedOtherTypicalData,
propagations: mockUpdatedPropagations,
});
});
it('should log error and return unchanged condition state on invalid XML', () => {
const formState = {
id: '1',
otherTypicalConditionData: {},
propagations: [],
};
const props = {
alwaysAvailableAttributes: true,
conditionGroupId: 'groupId',
formState,
isFirstRender: false,
passAll: false,
selectedPropagationIndex: 0,
xmlTreeTagName: 'someTag',
};
// Mocks
staticProductXmlTreeStringSelector.mockReturnValue('<xml></xml>');
createFullXml.mockReturnValue(null); // Simulate invalid XML
console.error = jest.fn(); // Mock console error
const result = updateXmlTreeAndReturnNewConditionStateSelector(mockState, props);
expect(console.error).toHaveBeenCalledWith('Ошибка построения XML дерева');
expect(result).toEqual(formState); // should return original formState
});
// Add more test cases as necessary based on the functionality
});
Explanation:
Mocks: The tests use Jest mocks for the imported helper functions and store selectors to control their output and track interactions.
Tests: The test scenarios include conditions for valid and invalid XML responses, ensuring different aspects of the selector's logic are covered.
Assertions: Each test checks that the output state is what you expect based on the inputs and mocks set up.
You can expand this with more tests for additional complexity, edge cases, and different configurations.
To test the getUpdatedChildAttributes function, we need to create unit tests that will mock dependencies and provide a range of inputs. This will help ensure the function behaves as expected under various conditions.
Steps to Create Tests:
Mock Dependencies: Since our function utilizes defaultAtrValuesMapper and createAtrAvailabilityMapper, we should mock these functions to control their outputs during tests.
Define Various Scenarios: You should cover cases such as:
When childAttributesValue is an empty array.
When childAttributesValue has items, and those items are transformed correctly.
The behavior of the function when either of the mapping functions (defaultAtrValuesMapper or createAtrAvailabilityMapper) returns null.
Here's how the test code could look using Jest:
javascript
import { getUpdatedChildAttributes } from '../path/to/getUpdatedChildAttributes';
import { defaultAtrValuesMapper } from '../../defaultAtrValuesMapper';
import { createAtrAvailabilityMapper } from '../../createAtrAvailabilityMapper';
import type { Attribute, Propagation } from '$conditions-core';
jest.mock('../../defaultAtrValuesMapper');
jest.mock('../../createAtrAvailabilityMapper');
describe('getUpdatedChildAttributes', () => {
const mockXmlTree = new DOMParser().parseFromString('<root></root>', 'text/xml'); // Example XML Document
const mockPropagation: Propagation = { /* Define a mock Propagation object */ };
beforeEach(() => {
jest.clearAllMocks();
});
it('should return empty array when childAttributesValue is empty', () => {
const result = getUpdatedChildAttributes({
childAttributesValue: [],
xmlTree: mockXmlTree,
propagationIndex: 0,
selectedPropagationIndex: 0,
propagation: mockPropagation,
});
expect(result).toEqual([]);
});
it('should return updated child attributes based on mapping functions', () => {
const childAttributesValue: Attribute[] = [
{ id: '1', value: 'foo' },
{ id: '2', value: 'bar' },
];
(defaultAtrValuesMapper as jest.Mock).mockImplementation(({ attribute }) => {
return { ...attribute, value: `mapped_${attribute.value}` };
});
(createAtrAvailabilityMapper as jest.Mock).mockImplementation(() => (attribute) => {
// Assuming that it checks attribute availability and can modify/return it
return { ...attribute, available: true };
});
const result = getUpdatedChildAttributes({
childAttributesValue,
xmlTree: mockXmlTree,
propagationIndex: 0,
selectedPropagationIndex: 0,
propagation: mockPropagation,
});
expect(result).toEqual([
{ id: '1', value: 'mapped_foo', available: true },
{ id: '2', value: 'mapped_bar', available: true },
]);
});
it('should filter out null results from mapping functions', () => {
const childAttributesValue: Attribute[] = [
{ id: '1', value: 'foo' },
{ id: '2', value: 'bar' },
];
(defaultAtrValuesMapper as jest.Mock).mockImplementation(({ attribute }) => {
if (attribute.id === '1') {
return null; // Simulating that the first attribute is not valid
}
return { ...attribute, value: `mapped_${attribute.value}` };
});
(createAtrAvailabilityMapper as jest.Mock).mockImplementation(() => (attribute) => {
return { ...attribute, available: true };
});
const result = getUpdatedChildAttributes({
childAttributesValue,
xmlTree: mockXmlTree,
propagationIndex: 0,
selectedPropagationIndex: 0,
propagation: mockPropagation,
});
expect(result).toEqual([
{ id: '2', value: 'mapped_bar', available: true },
]);
});
});
Explanation:
Mock Implementation: We use jest.mock to mock the external functions so that we can define how they behave in our tests.
Clear Mocks: The jest.clearAllMocks() in beforeEach resets the mocks before each test, preventing side effects between tests.
Functionality Testing: We define three tests:
Empty Input: Tests that passing an empty array for childAttributesValue returns an empty array.
Valid Attributes: Tests that valid attributes are processed correctly through the mapping functions.
Filtering Nulls: Tests the case where one of the mapping functions returns null to ensure the final output filters these out.
This structure provides a solid foundation for testing getUpdatedChildAttributes, ensuring all critical pathways are validated.
/* Для Boolean всегда нужно устанавливать значение при инициализации,
иначе после рендера при простановке значения в компоненте, меняется дерево. KOTEAM1-13654
Для TextList по умолчанию нужно добавлять одно пустое поле
*/
if (updatedAtrByType) {
return updatedAtrByType;
}
}
return { ...updatedAttribute };
};
To test the defaultAtrValuesMapper function effectively, you'll want to confirm that it processes attributes and their child attributes properly, while also verifying that it calls the updateAtrByType function correctly under certain conditions. The function has multiple branches based on the attribute’s type and default value, so various scenarios should be evaluated to ensure complete coverage.
Test Setup
Mock Dependencies: Since updateAtrByType is a dependency, you should mock its functionality to control its behavior during tests.
Input Scenarios: Develop multiple test cases that cover:
Attributes without child attributes.
Attributes with child attributes.
Attributes that satisfy the conditions for updateAtrByType.
Attributes that do not require updating.
Here’s how you can write the Jest tests for defaultAtrValuesMapper:
javascript
import { defaultAtrValuesMapper } from '../path/to/defaultAtrValuesMapper';
import { updateAtrByType } from './updateAtrByType';
import type { Attribute, Propagation } from '$conditions-core';
jest.mock('./updateAtrByType');
describe('defaultAtrValuesMapper', () => {
const mockXmlTree = new DOMParser().parseFromString('<root></root>', 'text/xml'); // Example XML Document
const mockPropagation: Propagation = { /* Define a mock Propagation object */ };
beforeEach(() => {
jest.clearAllMocks();
});
it('should map an attribute without child attributes correctly', () => {
const attribute: Attribute = {
id: '1',
attributeType: { id: 'BOOLEAN' },
defaultValue: true,
childAttributes: [],
};
(updateAtrByType as jest.Mock).mockReturnValue(null);
const result = defaultAtrValuesMapper({
attribute,
xmlTree: mockXmlTree,
propagation: mockPropagation,
propagationIndex: 0,
});
expect(result).toEqual({
...attribute,
childAttributes: [],
});
expect(updateAtrByType).not.toHaveBeenCalled(); // Ensure it's not called with this attribute
});
it('should map an attribute with child attributes', () => {
const childAttribute: Attribute = {
id: '2',
attributeType: { id: 'TEXT_LIST' },
defaultValue: null,
childAttributes: [],
};
const attribute: Attribute = {
id: '1',
attributeType: { id: 'NUMERIC' },
defaultValue: false,
childAttributes: [childAttribute],
};
(updateAtrByType as jest.Mock).mockReturnValue(null);
const result = defaultAtrValuesMapper({
attribute,
xmlTree: mockXmlTree,
propagation: mockPropagation,
propagationIndex: 0,
});
expect(result).toEqual({
...attribute,
childAttributes: [childAttribute],
});
expect(updateAtrByType).not.toHaveBeenCalled(); // Ensure it's not called with this attribute
});
it('should call updateAtrByType and return updated attributes when conditions are met', () => {
const attribute: Attribute = {
id: '1',
attributeType: { id: 'AMOUNT' },
defaultValue: null,
childAttributes: [],
};
const updatedAttribute: Attribute = {
...attribute,
defaultValue: 100,
};
(updateAtrByType as jest.Mock).mockReturnValue(updatedAttribute);
const result = defaultAtrValuesMapper({
attribute,
xmlTree: mockXmlTree,
propagation: mockPropagation,
propagationIndex: 0,
});
expect(updateAtrByType).toHaveBeenCalledWith(expect.objectContaining({
attribute,
propagation: mockPropagation,
propagationIndex: 0,
xmlTree: mockXmlTree,
defaultAtrValuesMapper,
updatedAttribute: expect.any(Object),
}));
expect(result).toEqual(updatedAttribute);
});
it('should return updated attribute if defaultValue is present', () => {
const attribute: Attribute = {
id: '3',
attributeType: { id: 'SELECT' },
defaultValue: 'selectedValue',
childAttributes: [],
};
(updateAtrByType as jest.Mock).mockReturnValue(null);
const result = defaultAtrValuesMapper({
attribute,
xmlTree: mockXmlTree,
propagation: mockPropagation,
propagationIndex: 0,
});
expect(result).toEqual({
...attribute,
childAttributes: [],
});
expect(updateAtrByType).not.toHaveBeenCalled(); // Ensure it's not called since defaultValue present
});
});
Explanation of the Test Cases:
No Child Attributes: Checks that an attribute without child attributes is returned correctly.
With Child Attributes: Ensures that attributes with child attributes are processed without calling updateAtrByType.
Condition for Update: Validates that if the attribute type requires an update (e.g., AMOUNT), the updateAtrByType function is called, and the correct updated attribute is returned.
Presence of Default Value: Tests that an attribute with a default value does not invoke updateAtrByType, and simply returns the original attribute.
Mocking and Validation:
Module Mocking: Using jest.mock for the updateAtrByType ensures that we can control its output without invoking the actual implementation.
Assertions: We use expect functions to assert the output and whether certain functions were called, ensuring that the logic within defaultAtrValuesMapper is executed correctly based on the conditions provided.
This set of tests should provide good coverage for your defaultAtrValuesMapper function and will help to ensure its reliability as changes are made in the future.
import type { Attribute, Propagation } from '$conditions-core';
import {
checkIsAmount,
checkIsBoolean,
checkIsNumeric,
checkIsPercentage,
checkIsScalar,
checkIsSelect,
checkIsTextList,
} from '../../../../attributeTypeGuards';
import { getDefaultBooleanValue } from './getDefaultBooleanValue';
import { getDefaultCurrency } from './getDefaultCurrency';
import { getDefaultSelectedOption } from './getDefaultSelectedOption';
import { getNumberDefaultValue } from './getNumberDefaultValue';
describe('updateAtrByType', () => {
test('should update selected option for select attributes', () => {
const updatedAttribute = {
selectedOption: null,
} as unknown as Attribute;
code
});
попоаврь тесты
It looks like you have a good structure in your test cases for the updateAtrByType function, but there are a few key areas that might need adjustments or improvements. Here’s how to clean up and refine your tests to ensure they align correctly with the updateAtrByType function.
Key Improvements
Correct Parameter Passing: The test cases are currently passing a wrong structure in function calls. The attributes of the updateAtrByType function need to correctly correspond to the expected types from your function.
Mocking Dependencies: Ensure the mocked functions are correctly referenced to avoid undefined behaviors.
Removing Redundant Parameters: The defaultBooleanValue, defaultCurrency, defaultNumberValue, and defaultSelectedOption should be extracted from the mocked dependency calls instead of having them passed as parameters in the test cases.
Here’s a revised version of your test cases:
javascript
import {
checkIsAmount,
checkIsBoolean,
checkIsNumeric,
checkIsPercentage,
checkIsScalar,
checkIsSelect,
checkIsTextList,
} from '../../../../../attributeTypeGuards';
import { Attribute } from '$conditions-core';
import { updateAtrByType } from '../updateAtrByType';
jest.mock('../../../../../attributeTypeGuards', () => ({
checkIsSelect: jest.fn(),
checkIsBoolean: jest.fn(),
checkIsAmount: jest.fn(),
checkIsNumeric: jest.fn(),
checkIsPercentage: jest.fn(),
checkIsScalar: jest.fn(),
checkIsTextList: jest.fn(),
}));
describe('updateAtrByType', () => {
test('should update selected option for select attributes', () => {
const updatedAttribute = {
selectedOption: null,
} as unknown as Attribute;
(checkIsSelect as jest.Mock).mockReturnValueOnce(true);
const defaultSelectedOption = { code: 'value1' }; // Mocking as expected structure
const result = updateAtrByType({
updatedAttribute,
xmlTree: new DOMParser().parseFromString('<root></root>', 'text/xml'), // Mocked XML tree
propagationIndex: 0,
propagation: {}, // Provide a mock of the propagation object if needed
defaultAtrValuesMapper: jest.fn(), // if you want to mock this too
// assuming we mock any required functions or values within the context of the test as needed.
});
expect(result).toEqual({
...updatedAttribute,
selectedOption: defaultSelectedOption,
});
});
test('should update boolean value for boolean attributes', () => {
const updatedAttribute = {
booleanValue: null,
} as unknown as Attribute;
(checkIsBoolean as jest.Mock).mockReturnValueOnce(true);
const defaultBooleanValue = true; // Mock the expected default value
const result = updateAtrByType({
updatedAttribute,
xmlTree: new DOMParser().parseFromString('<root></root>', 'text/xml'),
propagationIndex: 0,
propagation: {},
defaultAtrValuesMapper: jest.fn(),
});
expect(result).toEqual({
...updatedAttribute,
booleanValue: defaultBooleanValue,
});
});
test('should update currency for amount attributes', () => {
const updatedAttribute = {
currency: null,
} as Attribute;
(checkIsAmount as jest.Mock).mockReturnValueOnce(true);
const defaultCurrency = 'USD'; // Provide the default currency value
const result = updateAtrByType({
updatedAttribute,
xmlTree: new DOMParser().parseFromString('<root></root>', 'text/xml'),
propagationIndex: 0,
propagation: {},
defaultAtrValuesMapper: jest.fn(),
});
expect(result).toEqual({
...updatedAttribute,
currency: defaultCurrency,
});
});
test('should update numeric value for numeric attributes', () => {
const updatedAttribute = {
numeric: null,
} as Attribute;
(checkIsNumeric as jest.Mock).mockReturnValueOnce(true);
const defaultNumberValue = 10; // Mock the expected default numeric value
const result = updateAtrByType({
updatedAttribute,
xmlTree: new DOMParser().parseFromString('<root></root>', 'text/xml'),
propagationIndex: 0,
propagation: {},
defaultAtrValuesMapper: jest.fn(),
});
expect(result).toEqual({
...updatedAttribute,
numeric: defaultNumberValue,
});
});
test('should update percentage value for percentage attributes', () => {
const updatedAttribute = {
percent: null,
} as unknown as Attribute;
(checkIsPercentage as jest.Mock).mockReturnValueOnce(true);
const defaultNumberValue = 25; // Provide the default percentage value
const result = updateAtrByType({
updatedAttribute,
xmlTree: new DOMParser().parseFromString('<root></root>', 'text/xml'),
propagationIndex: 0,
propagation: {},
defaultAtrValuesMapper: jest.fn(),
});
expect(result).toEqual({
...updatedAttribute,
percent: defaultNumberValue,
});
});
test('should ensure textFields are an array for text list attributes', () => {
const updatedAttribute = {
textFields: [],
} as unknown as Attribute;
(checkIsTextList as jest.Mock).mockReturnValueOnce(true);
const result = updateAtrByType({
updatedAttribute,
xmlTree: new DOMParser().parseFromString('<root></root>', 'text/xml'),
propagationIndex: 0,
propagation: {},
defaultAtrValuesMapper: jest.fn(),
});
expect(result).toEqual({
...updatedAttribute,
textFields: [''],
});
});
test('should update scalar value for scalar attributes', () => {
const updatedAttribute = {
scalar: 123,
defaultValue: 'defaultScalarValue',
} as unknown as Attribute;
(checkIsScalar as jest.Mock).mockReturnValueOnce(true);
const result = updateAtrByType({
updatedAttribute,
xmlTree: new DOMParser().parseFromString('<root></root>', 'text/xml'),
propagationIndex: 0,
propagation: {},
defaultAtrValuesMapper: jest.fn(),
});
expect(result).toEqual({
...updatedAttribute,
scalar: updatedAttribute.scalar, // The scalar remains the same since it was a number
});
});
});
Key Changes:
Correct Structure: Ensure that the objects and parameters you pass to updateAtrByType match what your function expects.
Mock Values: Make sure mock values for defaults (like defaultCurrency, defaultNumberValue, etc.) are declared properly within each test scope and those variables are consumed within the mock implementation.
Provide Complete Parameters: Make sure to provide all necessary parameters to correctly execute updateAtrByType.
By following these revised test cases, you’ll ensure that your tests will successfully cover all the key behaviors of the updateAtrByType function while maintaining clarity and correctness.
To properly update and ensure that the tests for the updateAtrByType function run correctly, we need to address the following:
Correct Parameter Structure: Ensure that the parameters passed to the updateAtrByType function correlate with what the function expects based on its implementation.
Mocking Functions: Use Jest's mocking functionalities to ensure that the appropriate attribute type check functions return the expected boolean values during tests.
Default Values Mocking: Use the correct strategies for mocking any required external functions or constants that provide default values.
Below is a revised version of your test suite that addresses these items.
Updated Test Suite for updateAtrByType
javascript
import {
checkIsAmount,
checkIsBoolean,
checkIsNumeric,
checkIsPercentage,
checkIsScalar,
checkIsSelect,
checkIsTextList,
} from '../../../../../attributeTypeGuards';
import { updateAtrByType } from '../updateAtrByType';
import { Attribute } from '$conditions-core';
jest.mock('../../../../../attributeTypeGuards', () => ({
checkIsSelect: jest.fn(),
checkIsBoolean: jest.fn(),
checkIsAmount: jest.fn(),
checkIsNumeric: jest.fn(),
checkIsPercentage: jest.fn(),
checkIsScalar: jest.fn(),
checkIsTextList: jest.fn(),
}));
describe('updateAtrByType', () => {
const mockXmlTree = new DOMParser().parseFromString('<root></root>', 'application/xml');
it('should update selected option for select attributes', () => {
const updatedAttribute = { selectedOption: null } as unknown as Attribute;
(checkIsSelect as jest.Mock).mockReturnValue(true);
const result = updateAtrByType({
updatedAttribute,
xmlTree: mockXmlTree,
propagationIndex: 0,
propagation: {}, // Mock as necessary
defaultAtrValuesMapper: jest.fn(),
});
// Mock the default option for this test
const defaultSelectedOption = { code: 'value1' };
expect(result).toEqual({
...updatedAttribute,
selectedOption: defaultSelectedOption,
});
});
it('should update boolean value for boolean attributes', () => {
const updatedAttribute = { booleanValue: null } as unknown as Attribute;
(checkIsBoolean as jest.Mock).mockReturnValue(true);
const defaultBooleanValue = true; // Mock the default value
const result = updateAtrByType({
updatedAttribute,
xmlTree: mockXmlTree,
propagationIndex: 0,
propagation: {}, // Mock as necessary
defaultAtrValuesMapper: jest.fn(), // Mock if used
});
expect(result).toEqual({
...updatedAttribute,
booleanValue: defaultBooleanValue,
});
});
it('should update currency for amount attributes', () => {
const updatedAttribute = { currency: null } as Attribute;
(checkIsAmount as jest.Mock).mockReturnValue(true);
const defaultCurrency = 'USD'; // Mock the default currency
const result = updateAtrByType({
updatedAttribute,
xmlTree: mockXmlTree,
propagationIndex: 0,
propagation: {}, // Mock as necessary
defaultAtrValuesMapper: jest.fn(), // Mock if used
});
expect(result).toEqual({
...updatedAttribute,
currency: defaultCurrency,
});
});
it('should update numeric value for numeric attributes', () => {
const updatedAttribute = { numeric: null } as Attribute;
(checkIsNumeric as jest.Mock).mockReturnValue(true);
const defaultNumberValue = 10; // Mock the default numeric value
const result = updateAtrByType({
updatedAttribute,
xmlTree: mockXmlTree,
propagationIndex: 0,
propagation: {}, // Mock as necessary
defaultAtrValuesMapper: jest.fn(), // Mock if used
});
expect(result).toEqual({
...updatedAttribute,
numeric: defaultNumberValue,
});
});
it('should update percentage value for percentage attributes', () => {
const updatedAttribute = { percent: null } as unknown as Attribute;
(checkIsPercentage as jest.Mock).mockReturnValue(true);
const defaultNumberValue = 25; // Mock the default numeric value
const result = updateAtrByType({
updatedAttribute,
xmlTree: mockXmlTree,
propagationIndex: 0,
propagation: {}, // Mock as necessary
defaultAtrValuesMapper: jest.fn(), // Mock if used
});
expect(result).toEqual({
...updatedAttribute,
percent: defaultNumberValue,
});
});
it('should ensure textFields are an array for text list attributes', () => {
const updatedAttribute = { textFields: [] } as unknown as Attribute;
(checkIsTextList as jest.Mock).mockReturnValue(true);
const result = updateAtrByType({
updatedAttribute,
xmlTree: mockXmlTree,
propagationIndex: 0,
propagation: {}, // Mock as necessary
defaultAtrValuesMapper: jest.fn(), // Mock if used
});
expect(result).toEqual({
...updatedAttribute,
textFields: [''], // Should set to an empty string
});
});
it('should update scalar value for scalar attributes', () => {
const updatedAttribute = {
scalar: 123,
defaultValue: 'defaultScalarValue',
} as unknown as Attribute;
(checkIsScalar as jest.Mock).mockReturnValue(true);
const result = updateAtrByType({
updatedAttribute,
xmlTree: mockXmlTree,
propagationIndex: 0,
propagation: {}, // Mock as necessary
defaultAtrValuesMapper: jest.fn(), // Mock if used
});
expect(result).toEqual({
...updatedAttribute,
scalar: updatedAttribute.defaultValue, // Should take the default value
});
});
});
Key Changes and Fixes
Mocking and Defaults: We mock the default values within each test so that the expected outputs can be easily validated.
Function Parameterization: Each test provides necessary parameters expected by updateAtrByType, ensuring correctness.
Assertions: Updates assertion logic to correctly reflect expected values based on mock implementations.
Final Notes
Ensure that the attribute checks (like checkIsSelect, checkIsBoolean, etc.) accurately reflect the conditions you want to test. Adjust the mocks accordingly to ensure they fit your application's architecture. By following this refined test suite, you should have a solid foundation for testing the updateAtrByType function effectively.