Skip to content

Commit

Permalink
fix: reset title validation (#966)
Browse files Browse the repository at this point in the history
* fix: reset title validation

* chore: PR fix and test
  • Loading branch information
brobro10000 committed Feb 2, 2023
1 parent bf69560 commit f681246
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,44 @@ describe('<ContentHighlightStepper>', () => {
userEvent.click(footerLink);
expect(sendEnterpriseTrackEvent).toHaveBeenCalledTimes(2);
});
it('removes title validation after exiting the stepper and revisiting', () => {
renderWithRouter(<ContentHighlightStepperWrapper />);
const stepper1 = screen.getByTestId(`zero-state-card-${BUTTON_TEXT.zeroStateCreateNewHighlight}`);
userEvent.click(stepper1);
expect(screen.getByText(STEPPER_STEP_TEXT.HEADER_TEXT.createTitle)).toBeInTheDocument();
const input = screen.getByTestId('stepper-title-input');
const reallyLongTitle = 'test-title-test-title-test-title-test-title-test-title-test-title';
const reallyLongTitleLength = reallyLongTitle.length;
fireEvent.change(input, { target: { value: reallyLongTitle } });

expect(screen.getByText(`${reallyLongTitleLength}/${MAX_HIGHLIGHT_TITLE_LENGTH}`, { exact: false })).toBeInTheDocument();
expect(screen.getByText(DEFAULT_ERROR_MESSAGE.EXCEEDS_HIGHLIGHT_TITLE_LENGTH)).toBeInTheDocument();

const closeButton = screen.getByRole('button', { name: 'Close' });
userEvent.click(closeButton);

// Confirm stepper close confirmation modal
expect(screen.getByText(STEPPER_STEP_TEXT.ALERT_MODAL_TEXT.title)).toBeInTheDocument();
expect(screen.getByText(STEPPER_STEP_TEXT.ALERT_MODAL_TEXT.content)).toBeInTheDocument();
expect(screen.getByText(STEPPER_STEP_TEXT.ALERT_MODAL_TEXT.buttons.exit)).toBeInTheDocument();
expect(screen.getByText(STEPPER_STEP_TEXT.ALERT_MODAL_TEXT.buttons.cancel)).toBeInTheDocument();

const confirmCloseButton = screen.getByText(STEPPER_STEP_TEXT.ALERT_MODAL_TEXT.buttons.exit);
userEvent.click(confirmCloseButton);

// Confirm stepper confirmation modal closed
expect(screen.queryByText(STEPPER_STEP_TEXT.ALERT_MODAL_TEXT.title)).not.toBeInTheDocument();
expect(screen.queryByText(STEPPER_STEP_TEXT.ALERT_MODAL_TEXT.content)).not.toBeInTheDocument();
expect(screen.queryByText(STEPPER_STEP_TEXT.ALERT_MODAL_TEXT.buttons.exit)).not.toBeInTheDocument();
expect(screen.queryByText(STEPPER_STEP_TEXT.ALERT_MODAL_TEXT.buttons.cancel)).not.toBeInTheDocument();

// Confirm stepper closed
expect(screen.queryByText(STEPPER_STEP_TEXT.HEADER_TEXT.createTitle)).not.toBeInTheDocument();

const stepper2 = screen.getByTestId(`zero-state-card-${BUTTON_TEXT.zeroStateCreateNewHighlight}`);
userEvent.click(stepper2);

expect(screen.getByText(`0/${MAX_HIGHLIGHT_TITLE_LENGTH}`, { exact: false })).toBeInTheDocument();
expect(screen.queryByText(DEFAULT_ERROR_MESSAGE.EXCEEDS_HIGHLIGHT_TITLE_LENGTH)).not.toBeInTheDocument();
});
});
1 change: 1 addition & 0 deletions src/components/ContentHighlights/data/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function useContentHighlightsContext() {
...s.stepperModal,
isOpen: false,
highlightTitle: null,
titleStepValidationError: null,
currentSelectedRowIds: {},
},
}));
Expand Down

0 comments on commit f681246

Please sign in to comment.