@cainiaofe/cn-ui-m
Version:
44 lines (43 loc) • 1.8 kB
JavaScript
import { __assign } from "tslib";
import React from 'react';
import { render } from '@testing-library/react';
import { useItemStyle } from '../use-item-style';
import { useUploadState } from '@cainiaofe/cn-ui-common';
jest.mock('@cainiaofe/cn-ui-common', function () {
var originalModule = jest.requireActual('@cainiaofe/cn-ui-common');
return __assign(__assign({}, originalModule), { useUploadState: jest.fn() });
});
describe('useItemStyle', function () {
beforeEach(function () {
useUploadState.mockReturnValue({
readOnly: true,
});
});
afterEach(function () {
jest.resetAllMocks();
});
test('当 mode=single 时,无样式', function () {
useUploadState.mockReturnValue({
props: {},
});
var TestComponents = function (props) {
var result = useItemStyle(props);
return (React.createElement("div", { "data-testid": "test-img", ref: result.containerRef, style: result.itemStyle }));
};
var getByTestId = render(React.createElement(TestComponents, { mode: "single" })).getByTestId;
var img = getByTestId('test-img');
expect(img).not.toHaveStyle('');
});
test('当 readOnly=false 时,返回默认样式', function () {
useUploadState.mockReturnValue({
props: {},
});
var TestComponents = function (props) {
var result = useItemStyle(props);
return (React.createElement("div", { "data-testid": "test-img", ref: result.containerRef, style: result.itemStyle }));
};
var getByTestId = render(React.createElement(TestComponents, null)).getByTestId;
var img = getByTestId('test-img');
expect(img).toHaveStyle('width: 80px; height: 80px;');
});
});