Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ MONGO_MIGRATION_URL=
OPENAI_API_KEY=

ZENVIA_API_URL=
ZENVIA_API_TOKEN=
ZENVIA_API_TOKEN=
18 changes: 15 additions & 3 deletions cypress/e2e/tests/review.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const assignUser = () => {
cy.get(locators.claimReview.BTN_START_CLAIM_REVIEW).should("exist").click();
cy.get(locators.claimReview.INPUT_USER)
.should("exist")
.type(`${review.username}{downarrow}{enter}`, { delay: 200 })
.type(`${review.username}{downarrow}{enter}`, { delay: 200 });
cy.get('[title="reCAPTCHA"]').should("exist");
cy.get(locators.claimReview.BTN_ASSIGN_USER).should("be.disabled");
cy.checkRecaptcha();
Expand All @@ -37,11 +37,21 @@ const assignUser = () => {
};

const blockAssignedUserReview = () => {
// Wait for the form to be fully loaded with review data (including classification)
// before interacting. The classification field has a validation rule, and if its value
// hasn't been restored via react-hook-form's reset(reviewData) before the submit button
// is clicked, validation fails silently and the state transition never happens.
cy.get(locators.claimReview.INPUT_CLASSIFICATION).should("exist");
cy.checkRecaptcha();
cy.get(locators.claimReview.BTN_SELECTED_REVIEW).should("exist").click();
cy.get(locators.claimReview.BTN_SELECTED_REVIEW)
.should("be.visible")
.and("be.enabled")
.click();
cy.get(locators.claimReview.INPUT_REVIEWER)
.should("exist")
.type(`${review.username}{downarrow}{downarrow}{enter}`, { delay: 200 })
.type(`${review.username}{downarrow}{downarrow}{enter}`, {
delay: 200,
});
cy.checkRecaptcha();
cy.get(locators.claimReview.BTN_SUBMIT).should("be.enabled").click();
cy.get(locators.claimReview.TEXT_REVIEWER_ERROR).should("exist");
Expand Down Expand Up @@ -113,8 +123,10 @@ describe("Test claim review", () => {
});

it("should not be able submit after choosing assigned user as reviewer", () => {
cy.intercept("GET", "/api/reviewtask/hash/*").as("getReviewTask");
cy.login();
goToClaimReviewPage();
cy.wait("@getReviewTask");
blockAssignedUserReview();
});
});
34 changes: 26 additions & 8 deletions lib/editor-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ export class EditorParser {
*/
private convertToParagraphElements(content: MultiParagraphContent): string {
const lines = content.split('\n');

// Check if there are any empty lines (for visual spacing)
const hasEmptyLines = lines.some(line => line.trim() === '');

if (hasEmptyLines) {
// Use <br> approach for content with intentional empty lines/spacing
return this.convertLineBreaksToHtml(content);
Expand Down Expand Up @@ -157,7 +157,7 @@ export class EditorParser {
if (this.isMultiParagraphContent(contentStr)) {
const lines = contentStr.split('\n');
const hasEmptyLines = lines.some(line => line.trim() === '');

if (hasEmptyLines) {
// Use <br> approach for content with intentional empty lines/spacing
const htmlContent = this.convertLineBreaksToHtml(contentStr);
Expand Down Expand Up @@ -215,7 +215,7 @@ export class EditorParser {
if (this.isMultiParagraphContent(joinedContent)) {
const lines = joinedContent.split('\n');
const hasEmptyLines = lines.some(line => line.trim() === '');

if (hasEmptyLines) {
// Use <br> approach for content with intentional empty lines/spacing
const finalContent = this.convertLineBreaksToHtml(joinedContent);
Expand Down Expand Up @@ -355,10 +355,10 @@ export class EditorParser {
{ type, content: cardContent }: RemirrorJSON
): MultiParagraphContent {
const paragraphContents: ParagraphContent[] = [];

for (const { content } of cardContent) {
const textFragments: TextFragment[] = [];

if (content) {
for (const { text, marks } of content) {
if (marks) {
Expand All @@ -376,12 +376,12 @@ export class EditorParser {
}
}
}

// Combine all fragments within a paragraph into a single paragraph content
const paragraphContent: ParagraphContent = textFragments.join("");
paragraphContents.push(paragraphContent);
}

// Join paragraphs with newlines to create multi-paragraph content
return paragraphContents.join("\n") as MultiParagraphContent;
}
Expand Down Expand Up @@ -684,4 +684,22 @@ export class EditorParser {
const match = fragmentText.match(MarkupCleanerRegex);
return match ? match[1] : "";
}

removeTrailingParagraph(editorJSON: RemirrorJSON): RemirrorJSON {
if (!editorJSON?.content || !Array.isArray(editorJSON.content)) {
return editorJSON;
}

const content = [...editorJSON.content];
const lastItem = content[content.length - 1];

if (lastItem?.type === "paragraph") {
content.pop();
}

return {
...editorJSON,
content,
};
}
}
Loading
Loading