Skip to content

Commit 6264226

Browse files
bugfix/dep243: SonarQube cloud improvements.
1 parent bd25d08 commit 6264226

2 files changed

Lines changed: 58 additions & 59 deletions

File tree

web/src/components/engagement/subscribe/Subscription.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import { Grid2 as Grid } from '@mui/material';
44
import { BodyText, Heading1 } from 'components/common/Typography';
55
import { Banner } from 'components/banner/Banner';
66
import LandingPageBanner from 'assets/images/LandingPageBanner.png';
7-
import { useAppDispatch, useAppSelector } from 'hooks';
7+
import { useAppDispatch, useAppSelector, useAppTranslation } from 'hooks';
88
import { openNotification } from 'services/notificationService/notificationSlice';
99
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
1010
import { faCircleCheck } from '@fortawesome/pro-solid-svg-icons/faCircleCheck';
1111
import { SubscriptionParams, SubscriptionType } from './types';
1212
import { verifyEmailVerification } from 'services/emailVerificationService';
1313
import { confirmSubscription, unSubscribe } from 'services/subscriptionService';
14-
import { useAppTranslation } from 'hooks';
1514

1615
export const Subscription = () => {
1716
const { t: translate } = useAppTranslation();
@@ -37,7 +36,7 @@ export const Subscription = () => {
3736
const subscribed_email = await verifyEmailVerification(token);
3837
const subscribed = JSON.stringify(subscribed_email);
3938
await confirmSubscription({
40-
engagement_id: parseInt(engagementId ?? ''),
39+
engagement_id: Number.parseInt(engagementId ?? ''),
4140
participant_id: JSON.parse(subscribed).participant_id,
4241
is_subscribed: true,
4342
});
@@ -46,7 +45,7 @@ export const Subscription = () => {
4645
if (scriptionAction == SubscriptionType.UNSUBSCRIBE) {
4746
const participant_id = scriptionKey;
4847
await unSubscribe({
49-
participant_id: parseInt(participant_id ?? ''),
48+
participant_id: Number.parseInt(participant_id ?? ''),
5049
is_subscribed: false,
5150
});
5251
setSubscriptionText([
@@ -60,7 +59,7 @@ export const Subscription = () => {
6059
}
6160
} catch (error) {
6261
dispatch(openNotification({ severity: 'error', text: translate('subscription.notification') }));
63-
return Promise.reject(error);
62+
throw error;
6463
}
6564
};
6665

web/tests/unit/components/subscribe/Subscribe.test.tsx

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,60 @@ jest.mock('react-router', () => ({
9797
}),
9898
}));
9999

100+
async function addSubscribeWidget() {
101+
await waitFor(() => expect(screen.getByText('Add Widget')).toBeInTheDocument());
102+
await waitFor(() => expect(screen.getByText('Add Widget')).toBeEnabled());
103+
fireEvent.click(screen.getByText('Add Widget'));
104+
await waitFor(() => expect(screen.getByText('Select Widget')).toBeVisible());
105+
fireEvent.click(screen.getByTestId(`widget-drawer-option/${WidgetType.Subscribe}`));
106+
107+
await waitFor(() => {
108+
expect(screen.getByText('Email List')).toBeVisible();
109+
expect(screen.getByText('Form Sign-up')).toBeVisible();
110+
});
111+
}
112+
113+
async function inputMockSubscribeData() {
114+
const callToActionText = document.querySelector('input[name="callToActionText"]') as HTMLInputElement;
115+
const richTextEditorDesc = screen.getByTestId('rich-text-editor') as HTMLDivElement;
116+
117+
const linkRadioButton = screen.getByLabelText('Link');
118+
const buttonRadioButton = screen.getByLabelText('Button');
119+
120+
// Simulate typing into the rich text editor
121+
richTextEditorDesc.textContent = 'Your desired text';
122+
fireEvent.input(richTextEditorDesc);
123+
fireEvent.change(callToActionText, { target: { value: 'Click here' } });
124+
fireEvent.click(linkRadioButton);
125+
126+
await waitFor(() => {
127+
expect(richTextEditorDesc.textContent).toBe('Your desired text');
128+
expect(callToActionText.value).toBe('Click here');
129+
// Check if the "Link" radio button is selected
130+
expect(linkRadioButton).toBeChecked();
131+
// Check if the "Button" radio button is not selected
132+
expect(buttonRadioButton).not.toBeChecked();
133+
});
134+
}
135+
136+
async function selectEmailList() {
137+
const emailListButton = screen.getByRole('button', { name: 'Email List' });
138+
fireEvent.click(emailListButton);
139+
await waitFor(() => {
140+
expect(screen.getByText('Description')).toBeVisible();
141+
expect(screen.getByText('Call-to-action Type')).toBeVisible();
142+
});
143+
}
144+
145+
async function selectFormSignUp() {
146+
const formSignUpButton = screen.getByRole('button', { name: 'Form Sign-up' });
147+
fireEvent.click(formSignUpButton);
148+
await waitFor(() => {
149+
expect(screen.getByText('Description')).toBeVisible();
150+
expect(screen.getByText('Call-to-action Type')).toBeVisible();
151+
});
152+
}
153+
100154
describe('Subscribe Widget tests', () => {
101155
const getWidgetsMock = jest.spyOn(widgetService, 'getWidgets').mockReturnValue(Promise.resolve([]));
102156

@@ -116,60 +170,6 @@ describe('Subscribe Widget tests', () => {
116170
}));
117171
});
118172

119-
async function addSubscribeWidget() {
120-
await waitFor(() => expect(screen.getByText('Add Widget')).toBeInTheDocument());
121-
await waitFor(() => expect(screen.getByText('Add Widget')).toBeEnabled());
122-
fireEvent.click(screen.getByText('Add Widget'));
123-
await waitFor(() => expect(screen.getByText('Select Widget')).toBeVisible());
124-
fireEvent.click(screen.getByTestId(`widget-drawer-option/${WidgetType.Subscribe}`));
125-
126-
await waitFor(() => {
127-
expect(screen.getByText('Email List')).toBeVisible();
128-
expect(screen.getByText('Form Sign-up')).toBeVisible();
129-
});
130-
}
131-
132-
async function inputMockSubscribeData() {
133-
const callToActionText = document.querySelector('input[name="callToActionText"]') as HTMLInputElement;
134-
const richTextEditorDesc = screen.getByTestId('rich-text-editor') as HTMLDivElement;
135-
136-
const linkRadioButton = screen.getByLabelText('Link');
137-
const buttonRadioButton = screen.getByLabelText('Button');
138-
139-
// Simulate typing into the rich text editor
140-
richTextEditorDesc.textContent = 'Your desired text';
141-
fireEvent.input(richTextEditorDesc);
142-
fireEvent.change(callToActionText, { target: { value: 'Click here' } });
143-
fireEvent.click(linkRadioButton);
144-
145-
await waitFor(() => {
146-
expect(richTextEditorDesc.textContent).toBe('Your desired text');
147-
expect(callToActionText.value).toBe('Click here');
148-
// Check if the "Link" radio button is selected
149-
expect(linkRadioButton).toBeChecked();
150-
// Check if the "Button" radio button is not selected
151-
expect(buttonRadioButton).not.toBeChecked();
152-
});
153-
}
154-
155-
async function selectEmailList() {
156-
const emailListButton = screen.getByRole('button', { name: 'Email List' });
157-
fireEvent.click(emailListButton);
158-
await waitFor(() => {
159-
expect(screen.getByText('Description')).toBeVisible();
160-
expect(screen.getByText('Call-to-action Type')).toBeVisible();
161-
});
162-
}
163-
164-
async function selectFormSignUp() {
165-
const formSignUpButton = screen.getByRole('button', { name: 'Form Sign-up' });
166-
fireEvent.click(formSignUpButton);
167-
await waitFor(() => {
168-
expect(screen.getByText('Description')).toBeVisible();
169-
expect(screen.getByText('Call-to-action Type')).toBeVisible();
170-
});
171-
}
172-
173173
test('Subscribe widget is created when option is clicked', async () => {
174174
render(<RouterProvider router={router} />);
175175

0 commit comments

Comments
 (0)