Skip to content

Commit 929b33b

Browse files
committed
Enhance DocsHelp component with additional form validation tests and improve feedback submission handling. Added coverage tests for empty comment validation and successful feedback submission. Updated success message content and ensured form visibility is managed correctly.
1 parent 24a4513 commit 929b33b

File tree

3 files changed

+155
-1
lines changed

3 files changed

+155
-1
lines changed

cypress/components/DocsHelp.cy.tsx

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,14 @@ describe('DocsHelp Component', () => {
129129
// check if clicking on submit button should show success message
130130
cy.get(FEEDBACK_FORM_SUCCESS_MESSAGE)
131131
.should('have.prop', 'tagName', 'P')
132-
.and('contains', /Thank you for your feedback!/i);
132+
.should('contain.text', 'Thanks for the feedback! Feel free to join the')
133+
.and('contain.text', '#website')
134+
.and('contain.text', 'channel on')
135+
.and('contain.text', 'Slack')
136+
.and('contain.text', 'for further discussion.');
137+
138+
// Verify the form is no longer visible
139+
cy.get(FEEDBACK_FORM).should('not.exist');
133140
});
134141

135142
/* test feedback form functionality when status code is 500
@@ -262,6 +269,8 @@ describe('DocsHelp Component', () => {
262269
expectedGitRedirect,
263270
);
264271
});
272+
273+
// Test direct URL case
265274
const customLink = 'https://example.com/custom-docs';
266275
cy.mount(<DocsHelp fileRenderType={customLink} />);
267276
cy.get('[data-test="edit-on-github-link"]').should(
@@ -280,4 +289,36 @@ describe('DocsHelp Component', () => {
280289
cy.mount(<DocsHelp fileRenderType='indexmd' showEditOption={false} />);
281290
cy.get('[data-test="edit-on-github-link"]').should('not.exist');
282291
});
292+
293+
// Test form validation for empty comment submission
294+
it('should show error when submitting feedback with empty comment', () => {
295+
// Click on yes button to show feedback form
296+
cy.get(FEEDBACK_FORM_YES_BUTTON).click();
297+
cy.get(FEEDBACK_FORM).should('be.visible');
298+
299+
// Try to submit with empty comment
300+
cy.get(FEEDBACK_FORM_SUBMIT_BUTTON).click();
301+
302+
// Check that the error styling is applied
303+
cy.get(FEEDBACK_FORM_INPUT).should('have.class', 'border-red-500');
304+
305+
// Verify error message is displayed
306+
cy.contains('Please provide feedback before submitting').should('be.visible');
307+
});
308+
309+
// Test form validation for empty comment when creating GitHub issue
310+
it('should show error when creating GitHub issue with empty comment', () => {
311+
// Click on yes button to show feedback form
312+
cy.get(FEEDBACK_FORM_YES_BUTTON).click();
313+
cy.get(FEEDBACK_FORM).should('be.visible');
314+
315+
// Try to create GitHub issue with empty comment
316+
cy.get(CREATE_GITHUB_ISSUE_BUTTON).click();
317+
318+
// Check that the error styling is applied
319+
cy.get(FEEDBACK_FORM_INPUT).should('have.class', 'border-red-500');
320+
321+
// Verify error message is displayed
322+
cy.contains('Please provide feedback before submitting').should('be.visible');
323+
});
283324
});
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import React from 'react';
2+
import { DocsHelp } from '~/components/DocsHelp';
3+
import mockNextRouter from '../plugins/mockNextRouterUtils';
4+
5+
describe('DocsHelp Coverage Tests', () => {
6+
beforeEach(() => {
7+
mockNextRouter();
8+
cy.viewport(1200, 800);
9+
});
10+
11+
// Test for line 93-94: Empty comment validation
12+
it('should validate empty comments on form submission', () => {
13+
cy.mount(<DocsHelp />);
14+
cy.get('[data-test="feedback-survey-yes-button"]').click();
15+
cy.get('[data-test="feedback-form"]').should('be.visible');
16+
17+
// Try to submit with empty comment
18+
cy.get('[data-test="feedback-form-input"]').clear();
19+
cy.get('[data-test="feedback-submit-button"]').click();
20+
21+
// Verify error state
22+
cy.get('[data-test="feedback-form-input"]').should('have.class', 'border-red-500');
23+
cy.contains('Please provide feedback before submitting').should('be.visible');
24+
});
25+
26+
// Test for line 133-134: Successful feedback submission
27+
it('should handle successful feedback submission and reset form', () => {
28+
cy.mount(<DocsHelp />);
29+
30+
// Intercept API call
31+
cy.intercept(
32+
'POST',
33+
'https://script.google.com/macros/s/AKfycbx9KA_BwTdsYgOfTLrHAxuhHs_wgYibB5_Msj9XP1rL5Ip4A20g1O609xAuTZmnbhRv/exec',
34+
{
35+
statusCode: 200,
36+
body: { success: true },
37+
}
38+
).as('feedback');
39+
40+
// Fill and submit form
41+
cy.get('[data-test="feedback-survey-yes-button"]').click();
42+
cy.get('[data-test="feedback-form-input"]').type('Test feedback');
43+
cy.get('[data-test="feedback-submit-button"]').click();
44+
45+
// Wait for API response
46+
cy.wait('@feedback');
47+
48+
// Verify success message and form reset
49+
cy.get('[data-test="feedback-form-success-message"]').should('be.visible');
50+
cy.get('[data-test="feedback-form"]').should('not.exist');
51+
});
52+
53+
// Test for line 277: Direct URL in getGitRedirect
54+
it('should use direct URL when fileRenderType is a URL', () => {
55+
const directUrl = 'https://example.com/direct-url';
56+
cy.mount(<DocsHelp fileRenderType={directUrl} />);
57+
58+
// Verify the URL is used directly
59+
cy.get('[data-test="edit-on-github-link"]')
60+
.should('have.attr', 'href', directUrl);
61+
});
62+
63+
// Test for GitHub issue creation with empty comment
64+
it('should validate empty comments when creating GitHub issue', () => {
65+
cy.mount(<DocsHelp />);
66+
cy.get('[data-test="feedback-survey-yes-button"]').click();
67+
68+
// Try to create issue with empty comment
69+
cy.get('[data-test="create-github-issue-button"]').click();
70+
71+
// Verify error state
72+
cy.get('[data-test="feedback-form-input"]').should('have.class', 'border-red-500');
73+
cy.contains('Please provide feedback before submitting').should('be.visible');
74+
});
75+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import { DocsHelp } from '~/components/DocsHelp';
3+
import mockNextRouter from '../plugins/mockNextRouterUtils';
4+
5+
describe('DocsHelp GitRedirect Tests', () => {
6+
beforeEach(() => {
7+
mockNextRouter();
8+
});
9+
10+
it('should use direct URL when fileRenderType is a URL', () => {
11+
// This test specifically targets line 67-69 in DocsHelp.tsx
12+
const directUrl = 'https://github.com/direct-url';
13+
cy.mount(<DocsHelp fileRenderType={directUrl} />);
14+
15+
// Verify the URL is used directly without modification
16+
cy.get('[data-test="edit-on-github-link"]')
17+
.should('have.attr', 'href')
18+
.and('eq', directUrl);
19+
});
20+
21+
it('should handle different file types correctly', () => {
22+
// Test all file type cases
23+
const types = [
24+
{ type: 'tsx', expected: '/index.page.tsx' },
25+
{ type: '_indexmd', expected: '/_index.md' },
26+
{ type: 'indexmd', expected: '/index.md' },
27+
{ type: '_md', expected: '.md' },
28+
];
29+
30+
types.forEach(({ type, expected }) => {
31+
cy.mount(<DocsHelp fileRenderType={type} />);
32+
33+
cy.get('[data-test="edit-on-github-link"]')
34+
.should('have.attr', 'href')
35+
.and('include', expected);
36+
});
37+
});
38+
});

0 commit comments

Comments
 (0)