test: test fix for legacy form
This commit is contained in:
@@ -22,7 +22,6 @@ setupYupExtensions();
|
||||
function LegacyConfigForm({ onSubmit, formRef, intl }) {
|
||||
const { discussionTopicIds, divideDiscussionIds, selectedAppId } = useSelector((state) => state.discussions);
|
||||
const appConfigObj = useModel('appConfigs', selectedAppId);
|
||||
const app = useModel('apps', selectedAppId);
|
||||
const discussionTopicsModel = useModels('discussionTopics', discussionTopicIds);
|
||||
const appConfig = { ...appConfigObj, discussionTopics: discussionTopicsModel, divideDiscussionIds };
|
||||
const LegacyAppConfig = {
|
||||
@@ -101,7 +100,7 @@ function LegacyConfigForm({ onSubmit, formRef, intl }) {
|
||||
<LegacyConfigFormProvider value={contextValue}>
|
||||
<Card className="mb-5 px-4 px-sm-5 pb-5" data-testid="legacyConfigForm">
|
||||
<Form ref={formRef} onSubmit={handleSubmit}>
|
||||
<h3 className="text-primary-500 my-3">{intl.formatMessage(messages[`appName-${app?.id}`])}</h3>
|
||||
<h3 className="text-primary-500 my-3">{intl.formatMessage(messages[`appName-${selectedAppId}`])}</h3>
|
||||
<AppConfigFormDivider thick />
|
||||
<AnonymousPostingFields
|
||||
onBlur={handleBlur}
|
||||
|
||||
@@ -2,7 +2,7 @@ import React, { createRef } from 'react';
|
||||
|
||||
import {
|
||||
act,
|
||||
fireEvent,
|
||||
fireEvent, queryAllByText,
|
||||
queryByLabelText,
|
||||
queryByRole,
|
||||
queryByTestId,
|
||||
@@ -198,7 +198,7 @@ describe('LegacyConfigForm', () => {
|
||||
const updateTopicName = async (topicId, topicName) => {
|
||||
const topicCard = queryByTestId(container, topicId);
|
||||
|
||||
userEvent.click(queryByLabelText(topicCard, 'Expand'));
|
||||
await act(async () => { userEvent.click(queryByLabelText(topicCard, 'Expand')); });
|
||||
const topicInput = topicCard.querySelector('input');
|
||||
topicInput.focus();
|
||||
await act(async () => { fireEvent.change(topicInput, { target: { value: topicName } }); });
|
||||
@@ -234,7 +234,7 @@ describe('LegacyConfigForm', () => {
|
||||
|
||||
test('check field is not collapsible in case of error', async () => {
|
||||
await mockStore(legacyApiResponse);
|
||||
createComponent(defaultAppConfig);
|
||||
createComponent();
|
||||
|
||||
const topicCard = await updateTopicName('13f106c6-6735-4e84-b097-0456cff55960', '');
|
||||
const collapseButton = queryByLabelText(topicCard, 'Collapse');
|
||||
@@ -263,31 +263,36 @@ describe('LegacyConfigForm', () => {
|
||||
|
||||
test('check duplicate error is removed on fields when name is fixed', async () => {
|
||||
const duplicateTopicInput = duplicateTopicCard.querySelector('input');
|
||||
|
||||
duplicateTopicInput.focus();
|
||||
userEvent.type(duplicateTopicInput, 'valid');
|
||||
await act(async () => { userEvent.type(duplicateTopicInput, 'valid'); });
|
||||
duplicateTopicInput.blur();
|
||||
|
||||
await waitForElementToBeRemoved(
|
||||
queryByText(duplicateTopicCard, messages.discussionTopicNameAlreadyExist.defaultMessage),
|
||||
queryAllByText(topicCard, messages.discussionTopicNameAlreadyExist.defaultMessage),
|
||||
);
|
||||
await assertDuplicateTopicNameValidation(duplicateTopicCard, false, false);
|
||||
await assertDuplicateTopicNameValidation(topicCard, false, false);
|
||||
|
||||
await assertDuplicateTopicNameValidation(duplicateTopicCard, false);
|
||||
await assertDuplicateTopicNameValidation(topicCard, false);
|
||||
assertHasErrorValidation(false);
|
||||
});
|
||||
|
||||
test('check duplicate error is removed on deleting duplicate topic', async () => {
|
||||
userEvent.click(
|
||||
queryByLabelText(duplicateTopicCard, messages.deleteAltText.defaultMessage, { selector: 'button' }),
|
||||
);
|
||||
userEvent.click(
|
||||
queryByRole(container, 'button', { name: messages.deleteButton.defaultMessage }),
|
||||
);
|
||||
await act(async () => {
|
||||
userEvent.click(
|
||||
queryByLabelText(duplicateTopicCard, messages.deleteAltText.defaultMessage, { selector: 'button' }),
|
||||
);
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
userEvent.click(
|
||||
queryByRole(container, 'button', { name: messages.deleteButton.defaultMessage }),
|
||||
);
|
||||
});
|
||||
|
||||
await waitForElementToBeRemoved(queryByText(topicCard, messages.discussionTopicNameAlreadyExist.defaultMessage));
|
||||
|
||||
expect(duplicateTopicCard).not.toBeInTheDocument();
|
||||
await assertDuplicateTopicNameValidation(topicCard, false, false);
|
||||
await assertDuplicateTopicNameValidation(topicCard, false);
|
||||
assertHasErrorValidation(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user