Skip to content

Commit

Permalink
fix: preset style not present on text - refs #257668
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaelaCretu11 authored Sep 25, 2023
1 parent ccf0e13 commit bbfd66f
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
51 changes: 51 additions & 0 deletions src/BlockStyleWrapper/BlockStyleWrapperEdit.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react';
import { render } from '@testing-library/react';
import { BrowserRouter as Router } from 'react-router-dom';
import { Provider } from 'react-redux';
import configureMockStore from 'redux-mock-store';
import '@testing-library/jest-dom/extend-expect';

import BlockStyleWrapperEdit from './BlockStyleWrapperEdit';

jest.mock('react-portal', () => {
return {
Portal: ({ children }) => children,
};
});

describe('BlockStyleWrapperEdit', () => {
const defaultProps = {
selected: true,
block: {},
data: {
align: 'left',
size: 'medium',
styles: {
backgroundColor: 'red',
textColor: 'blue',
},
},
};

const initialState = {
userSession: {
token: 'mockToken',
},
};

const mockStore = configureMockStore();
const store = mockStore(initialState);

it('renders correctly when selected is true', () => {
const { container } = render(
<Provider store={store}>
<Router>
<BlockStyleWrapperEdit {...defaultProps} />
</Router>
</Provider>,
);

expect(container.querySelector('.open-styles-button')).toBeInTheDocument();
expect(container.querySelector('.styled')).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion src/StyleWrapper/StyleWrapperView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ const StyleWrapperView = (props) => {
const ViewComponentWrapper = style?.viewComponent;

return styled ? (
nativeIntegration ? (
nativeIntegration && !style_name?.includes('content-box') ? (
children
) : (
<div {...attrs} ref={props.setRef}>
Expand Down
32 changes: 32 additions & 0 deletions src/StyleWrapper/StyleWrapperView.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ describe('getInlineStyles', () => {
borderRadius: '5px',
};

const dataWithLessProperties = {
margin: { top: '1', right: '1', bottom: '1', left: '1', unit: 'em' },
padding: { top: '2', right: '2', bottom: '2', left: '2', unit: 'em' },
borderRadius: '5px',
};

const expectedStyles = {
backgroundColor: 'red',
'--background-color': 'red',
Expand All @@ -46,6 +52,13 @@ describe('getInlineStyles', () => {
padding: '2em 2em 2em 2em',
borderRadius: '5px',
};

const expectedStylesWithLessProperties = {
margin: '1em 1em 1em 1em',
padding: '2em 2em 2em 2em',
borderRadius: '5px',
};

it('returns the correct styles', () => {
const props = {
mode: 'edit',
Expand Down Expand Up @@ -120,6 +133,25 @@ describe('getInlineStyles', () => {
const styles = getInlineStyles(newData, props);
expect(styles).toEqual(newExpectedStyles);
});

it('returns the correct styles with missing properties', () => {
const newData = {
...dataWithLessProperties,
shadowColor: '',
};

const newExpectedStyles = {
...expectedStylesWithLessProperties,
lineHeight: undefined,
};

const props = {
mode: 'edit',
};

const styles = getInlineStyles(newData, props);
expect(styles).toEqual(newExpectedStyles);
});
});

describe('getStyle', () => {
Expand Down

0 comments on commit bbfd66f

Please sign in to comment.