Skip to content

Commit

Permalink
refactor: change some variable naming and remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnwesson committed Jan 17, 2024
1 parent 75423f4 commit 7b0326e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 111 deletions.
12 changes: 6 additions & 6 deletions src/plugins/directPlugins/DirectPluginSlot.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import organizePlugins from './utils';
const DirectPluginSlot = ({ defaultContents, slotId, renderWidget }) => {
const allPluginChanges = React.useContext(DirectPluginContext);

Check warning on line 8 in src/plugins/directPlugins/DirectPluginSlot.jsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/directPlugins/DirectPluginSlot.jsx#L7-L8

Added lines #L7 - L8 were not covered by tests

const contents = React.useMemo(() => {
const preparedWidgets = React.useMemo(() => {

Check warning on line 10 in src/plugins/directPlugins/DirectPluginSlot.jsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/directPlugins/DirectPluginSlot.jsx#L10

Added line #L10 was not covered by tests
const slotChanges = allPluginChanges.getDirectSlotChanges()[slotId] ?? [];
return organizePlugins(defaultContents, slotChanges);

Check warning on line 12 in src/plugins/directPlugins/DirectPluginSlot.jsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/directPlugins/DirectPluginSlot.jsx#L12

Added line #L12 was not covered by tests
}, [allPluginChanges, defaultContents, slotId]);

return (

Check warning on line 15 in src/plugins/directPlugins/DirectPluginSlot.jsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/directPlugins/DirectPluginSlot.jsx#L15

Added line #L15 was not covered by tests
<>
{contents.map((c) => {
if (c.hidden) {
{preparedWidgets.map((preppedWidget) => {

Check warning on line 17 in src/plugins/directPlugins/DirectPluginSlot.jsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/directPlugins/DirectPluginSlot.jsx#L17

Added line #L17 was not covered by tests
if (preppedWidget.hidden) {
return null;

Check warning on line 19 in src/plugins/directPlugins/DirectPluginSlot.jsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/directPlugins/DirectPluginSlot.jsx#L19

Added line #L19 was not covered by tests
}
if (c.wrappers) {
if (preppedWidget.wrappers) {
// TODO: define how the reduce logic is able to wrap widgets and make it testable
// eslint-disable-next-line max-len
return c.wrappers.reduce((widget, wrapper) => React.createElement(wrapper, { widget, key: c.id }), renderWidget(c));
return preppedWidget.wrappers.reduce((widget, wrapper) => React.createElement(wrapper, { widget, key: preppedWidget.id }), renderWidget(preppedWidget));

Check warning on line 24 in src/plugins/directPlugins/DirectPluginSlot.jsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/directPlugins/DirectPluginSlot.jsx#L24

Added line #L24 was not covered by tests
}
return renderWidget(c);
return renderWidget(preppedWidget);

Check warning on line 26 in src/plugins/directPlugins/DirectPluginSlot.jsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/directPlugins/DirectPluginSlot.jsx#L26

Added line #L26 was not covered by tests
})}
</>
);
Expand Down
33 changes: 0 additions & 33 deletions src/plugins/directPlugins/mocks/DefaultComponentMock.jsx

This file was deleted.

65 changes: 0 additions & 65 deletions src/plugins/directPlugins/mocks/PluginComponentsMock.jsx

This file was deleted.

12 changes: 5 additions & 7 deletions src/plugins/directPlugins/utils.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import '@testing-library/jest-dom';
import organizePlugins from './utils';
import { DirectPluginOperations } from './DirectPlugin';

jest.unmock('./utils');

const mockModifyComponent = (widget) => {
const mockModifyWidget = (widget) => {
const newContent = {
url: '/search',
label: 'Search',
Expand All @@ -15,7 +13,7 @@ const mockModifyComponent = (widget) => {
return modifiedWidget;
};

function mockWrapComponent({ widget }) {
function mockWrapWidget({ widget }) {
const isAdmin = true;
return isAdmin ? widget : null;
}
Expand All @@ -24,7 +22,7 @@ const mockSlotChanges = [
{
op: DirectPluginOperations.Wrap,
widgetId: 'drafts',
wrapper: mockWrapComponent,
wrapper: mockWrapWidget,
},
{
op: DirectPluginOperations.Hide,
Expand All @@ -33,7 +31,7 @@ const mockSlotChanges = [
{
op: DirectPluginOperations.Modify,
widgetId: 'lookUp',
fn: mockModifyComponent,
fn: mockModifyWidget,
},
{
op: DirectPluginOperations.Insert,
Expand Down Expand Up @@ -132,7 +130,7 @@ describe('organizePlugins', () => {
const widget = plugins.find((w) => w.id === 'drafts');
expect(plugins.length).toEqual(4);
expect(widget.wrappers.length).toEqual(2);
expect(widget.wrappers[0]).toEqual(mockWrapComponent);
expect(widget.wrappers[0]).toEqual(mockWrapWidget);
expect(widget.wrappers[1]).toEqual(newMockWrapComponent);
});

Expand Down

0 comments on commit 7b0326e

Please sign in to comment.