Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(preview): remove dependency on isSignRemoveInterstitialEnabled feature flag #3733

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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>
);
}

Expand Down
71 changes: 33 additions & 38 deletions src/elements/content-sidebar/__tests__/SidebarNavSign.test.tsx
Original file line number Diff line number Diff line change
@@ -1,80 +1,75 @@
import * as React from 'react';
import { render, fireEvent } from '@testing-library/react';
import { IntlProvider } from 'react-intl';
import SidebarNavSign from '../SidebarNavSign';
// @ts-ignore Module is written in Flow
import FeatureProvider from '../../common/feature-checking/FeatureProvider';
// @ts-ignore Module is written in Flow
import messages from '../messages';
// @ts-ignore Module is written in Flow
import localize from '../../../../test/support/i18n.js';

jest.unmock('react-intl');

describe('elements/content-sidebar/SidebarNavSign', () => {
const onClickRequestSignature = jest.fn();
const onClickSignMyself = jest.fn();
const signLabel = localize(messages.boxSignRequestSignature.id);
const requestSignatureButtonText = localize(messages.boxSignRequestSignature.id);
const signMyselfButtonText = localize(messages.boxSignSignMyself.id);

const renderComponent = (props = {}, features = {}) =>
render(
<FeatureProvider features={features}>
<SidebarNavSign {...props} />
</FeatureProvider>,
{
wrapper: ({ children }: { children?: React.ReactNode }) => (
<IntlProvider locale="en-US">{children}</IntlProvider>
),
},
);

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

const wrapper = renderComponent({}, features);
expect(wrapper.getByTestId('sign-button')).toBeVisible();
expect(wrapper.getByLabelText(signLabel)).toBeVisible();
});

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', () => {
const wrapper = renderComponent();

expect(onClickRequestSignature).toBeCalled();
});
fireEvent.click(wrapper.getByLabelText(signLabel));

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(wrapper.getByText(requestSignatureButtonText)).toBeVisible();
expect(wrapper.getByText(signMyselfButtonText)).toBeVisible();
});

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

fireEvent.click(wrapper.getByLabelText(signLabel));
fireEvent.click(wrapper.getByText(requestSignatureButtonText));

expect(onClickRequestSignature).toBeCalled();
});

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

fireEvent.click(wrapper.getByLabelText(signLabel));
fireEvent.click(wrapper.getByText(signMyselfButtonText));

expect(onClickSignMyself).toBeCalled();
});
});
Loading