Skip to content

Commit

Permalink
remove unneccessary code and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
nkylstad committed Feb 6, 2024
1 parent d5beeaa commit 51f026b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ jest.mock('./Calculations', () => ({
jest.mock('react-i18next', () => ({ useTranslation: () => mockUseTranslation(texts) }));

describe('Properties', () => {
describe('Text', () => {
it('Toggles text when clicked', async () => {
render();
const button = screen.queryByRole('button', { name: textText });
await act(() => user.click(button));
expect(button).toHaveAttribute('aria-expanded', 'true');
await act(() => user.click(button));
expect(button).toHaveAttribute('aria-expanded', 'false');
});

it('Opens text when a component is selected', async () => {
const { rerender } = render();
rerender(getComponent({ formId: 'test' }));
const button = screen.queryByRole('button', { name: textText });
await waitFor(() => expect(button).toHaveAttribute('aria-expanded', 'true'));
});
});
describe('Content', () => {
it('Closes content on load', () => {
render();
Expand All @@ -60,13 +77,6 @@ describe('Properties', () => {
await act(() => user.click(button));
expect(button).toHaveAttribute('aria-expanded', 'false');
});

it('Opens text when a component is selected', async () => {
const { rerender } = render();
rerender(getComponent({ formId: 'test' }));
const button = screen.queryByRole('button', { name: textText });
await waitFor(() => expect(button).toHaveAttribute('aria-expanded', 'true'));
});
});

describe('Dynamics', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,13 @@ export const EditTextResourceBindings = ({
handleComponentChange,
textResourceBindingKeys,
}: EditTextResourceBindingsProps) => {
const handleRemoveKey = (key: string) => {
const updatedComponent = { ...component };
delete updatedComponent.textResourceBindings[key];
handleComponentChange(updatedComponent);
};

return (
<div className={classes.container}>
{textResourceBindingKeys.map((key: string) => (
<EditTextResourceBinding
key={key}
component={component}
handleComponentChange={handleComponentChange}
removeTextResourceBinding={() => handleRemoveKey(key)}
textKey={key}
labelKey={`ux_editor.modal_properties_textResourceBindings_${key}` as any}
placeholderKey={`ux_editor.modal_properties_textResourceBindings_${key}_add` as any}
Expand Down

0 comments on commit 51f026b

Please sign in to comment.