Skip to content

Commit

Permalink
fix(preview): remove dependency on isSignRemoveInterstitialEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
diogostavares committed Nov 6, 2024
1 parent f6a9496 commit 8fd8f2e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 81 deletions.
49 changes: 18 additions & 31 deletions src/elements/content-sidebar/SidebarNavSign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,27 @@ export function SidebarNavSign() {
onClickSignMyself: onBoxClickSignMyself,
status: boxSignStatus,
targetingApi: boxSignTargetingApi,
isSignRemoveInterstitialEnabled,
} = useFeatureConfig('boxSign');

return (
<>
{isSignRemoveInterstitialEnabled ? (
<DropdownMenu isResponsive constrainToWindow isRightAligned>
<SidebarNavSignButton
blockedReason={boxSignBlockedReason}
status={boxSignStatus}
targetingApi={boxSignTargetingApi}
data-resin-target={SIDEBAR_NAV_TARGETS.SIGN}
/>
<Menu>
<MenuItem data-testid="sign-request-signature-button" onClick={onBoxClickRequestSignature}>
<SignMeOthers32 width={16} height={16} className="bcs-SidebarNavSign-icon" />
<FormattedMessage {...messages.boxSignRequestSignature} />
</MenuItem>
<MenuItem data-testid="sign-sign-myself-button" onClick={onBoxClickSignMyself}>
<SignMe32 width={16} height={16} className="bcs-SidebarNavSign-icon" />
<FormattedMessage {...messages.boxSignSignMyself} />
</MenuItem>
</Menu>
</DropdownMenu>
) : (
<SidebarNavSignButton
blockedReason={boxSignBlockedReason}
data-resin-target={SIDEBAR_NAV_TARGETS.SIGN}
onClick={onBoxClickRequestSignature}
status={boxSignStatus}
targetingApi={boxSignTargetingApi}
/>
)}
</>
<DropdownMenu isResponsive constrainToWindow isRightAligned>
<SidebarNavSignButton
blockedReason={boxSignBlockedReason}
status={boxSignStatus}
targetingApi={boxSignTargetingApi}
data-resin-target={SIDEBAR_NAV_TARGETS.SIGN}
/>
<Menu>
<MenuItem onClick={onBoxClickRequestSignature}>
<SignMeOthers32 width={16} height={16} className="bcs-SidebarNavSign-icon" />
<FormattedMessage {...messages.boxSignRequestSignature} />
</MenuItem>
<MenuItem onClick={onBoxClickSignMyself}>
<SignMe32 width={16} height={16} className="bcs-SidebarNavSign-icon" />
<FormattedMessage {...messages.boxSignSignMyself} />
</MenuItem>
</Menu>
</DropdownMenu>
);
}

Expand Down
78 changes: 28 additions & 50 deletions src/elements/content-sidebar/__tests__/SidebarNavSign.test.tsx
Original file line number Diff line number Diff line change
@@ -1,80 +1,58 @@
import * as React from 'react';
import { render, fireEvent } from '@testing-library/react';

import { userEvent } from '@testing-library/user-event';
import { render, screen } from '../../../test-utils/testing-library';
import SidebarNavSign from '../SidebarNavSign';
// @ts-ignore Module is written in Flow
import FeatureProvider from '../../common/feature-checking/FeatureProvider';

describe('elements/content-sidebar/SidebarNavSign', () => {
const onClickRequestSignature = jest.fn();
const onClickSignMyself = jest.fn();

const renderComponent = (props = {}, features = {}) =>
render(
<FeatureProvider features={features}>
<SidebarNavSign {...props} />
</FeatureProvider>,
);
render(<SidebarNavSign {...props} />, {
wrapperProps: { features },
});

test.each([true, false])('should render sign button', isRemoveInterstitialEnabled => {
const features = {
boxSign: {
isSignRemoveInterstitialEnabled: isRemoveInterstitialEnabled,
},
};
test('should render sign button', async () => {
renderComponent();

const wrapper = renderComponent({}, features);
expect(wrapper.getByTestId('sign-button')).toBeVisible();
expect(screen.getByRole('button', { name: 'Request Signature' })).toBeInTheDocument();
});

test('should call correct handler when sign button is clicked', () => {
const features = {
boxSign: {
isSignRemoveInterstitialEnabled: false,
onClick: onClickRequestSignature,
},
};
const { getByTestId } = renderComponent({}, features);

fireEvent.click(getByTestId('sign-button'));
test('should open dropdown with 2 menu items when sign button is clicked', async () => {
renderComponent();

expect(onClickRequestSignature).toBeCalled();
});
await userEvent.click(screen.getByRole('button', { name: 'Request Signature' }));

test('should open dropdown with 2 menu items when sign button is clicked', () => {
const features = {
boxSign: {
isSignRemoveInterstitialEnabled: true,
},
};
const { getByTestId } = renderComponent({}, features);
fireEvent.click(getByTestId('sign-button'));
expect(getByTestId('sign-request-signature-button')).toBeVisible();
expect(getByTestId('sign-sign-myself-button')).toBeVisible();
expect(screen.getByRole('menuitem', { name: 'Request Signature' })).toBeVisible();
expect(screen.getByRole('menuitem', { name: 'Sign Myself' })).toBeVisible();
});

test('should call correct handler when request signature option is clicked', () => {
test('should call correct handler when request signature option is clicked', async () => {
const features = {
boxSign: {
isSignRemoveInterstitialEnabled: true,
onClick: onClickRequestSignature,
},
};
const { getByTestId } = renderComponent({}, features);
fireEvent.click(getByTestId('sign-button'));
fireEvent.click(getByTestId('sign-request-signature-button'));
expect(onClickRequestSignature).toBeCalled();
renderComponent({}, features);

await userEvent.click(screen.getByRole('button', { name: 'Request Signature' }));
await userEvent.click(screen.getByRole('menuitem', { name: 'Request Signature' }));

expect(onClickRequestSignature).toHaveBeenCalled();
});

test('should call correct handler when sign myself option is clicked', () => {
test('should call correct handler when sign myself option is clicked', async () => {
const features = {
boxSign: {
isSignRemoveInterstitialEnabled: true,
onClickSignMyself,
},
};
const { getByTestId } = renderComponent({}, features);
fireEvent.click(getByTestId('sign-button'));
fireEvent.click(getByTestId('sign-sign-myself-button'));
expect(onClickSignMyself).toBeCalled();
renderComponent({}, features);

await userEvent.click(screen.getByRole('button', { name: 'Request Signature' }));
await userEvent.click(screen.getByRole('menuitem', { name: 'Sign Myself' }));

expect(onClickSignMyself).toHaveBeenCalled();
});
});

0 comments on commit 8fd8f2e

Please sign in to comment.