Skip to content

Commit 57fd0ab

Browse files
committed
modified-test-working
1 parent fbfa907 commit 57fd0ab

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

components/DocsHelp.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface DocsHelpProps {
88

99
export function DocsHelp({ fileRenderType }: DocsHelpProps) {
1010
const router = useRouter();
11+
console.log(router.asPath)
1112
const [isFormOpen, setIsFormOpen] = useState(false);
1213
const [feedbackStatus, setFeedbackStatus] = useState('');
1314
const [isSubmitting, setIsSubmitting] = useState(false);

cypress/components/DocsHelp.cy.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const FEEDBACK_FORM_GITHUB_SUCCESS_MESSAGE =
1919
// DocsHelp Component
2020
describe('DocsHelp Component', () => {
2121
const extractPathWithoutFragment = (path: any) => path.split('#')[0];
22-
let mockRouter: MockRouter;
22+
let mockRouter:MockRouter;
2323
beforeEach(() => {
2424
const markdownFile = "indexmd";
2525
mockRouter = mockNextRouter();
@@ -86,23 +86,33 @@ describe('DocsHelp Component', () => {
8686
});
8787

8888
it('should handle successful feedback submission', () => {
89+
// mocking the feedback api call
8990
cy.intercept(
9091
'POST',
9192
'https://script.google.com/macros/s/AKfycbx9KA_BwTdsYgOfTLrHAxuhHs_wgYibB5_Msj9XP1rL5Ip4A20g1O609xAuTZmnbhRv/exec',
92-
{ statusCode: 200, body: { success: true } },
93+
{
94+
statusCode: 200,
95+
body: { success: true },
96+
},
9397
).as('feedback');
9498

99+
/* click on yes button and check if feedback form is visible
100+
Note: checking both yes and no button to cover both scenarios */
95101
cy.get(FEEDBACK_FORM_YES_BUTTON).click();
96102
cy.get(FEEDBACK_FORM_NO_BUTTON).click();
97103
cy.get(FEEDBACK_FORM).should('be.visible');
98104

105+
// now type in feedback form and submit
99106
cy.get(FEEDBACK_FORM_INPUT).type('JSON Schema is awesome');
100107
cy.get(FEEDBACK_FORM_SUBMIT_BUTTON).click();
101108

109+
// check if response status code is 200
102110
cy.wait('@feedback').its('response.statusCode').should('eq', 200);
111+
112+
// check if clicking on submit button should show success message
103113
cy.get(FEEDBACK_FORM_SUCCESS_MESSAGE)
104114
.should('have.prop', 'tagName', 'P')
105-
.and('contain.text', 'Thank you for your feedback!');
115+
.and('contains', /Thank you for your feedback!/i);
106116
});
107117

108118
it('should handle API error response', () => {
@@ -180,15 +190,14 @@ describe('DocsHelp Component', () => {
180190
let expectedGitRedirect = '';
181191

182192
if (type === 'tsx') {
183-
expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment('/some/path') + '/index.page.tsx'}`;
193+
expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/index.page.tsx'}`;
184194
} else if (type === '_indexmd') {
185-
expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment('/some/path') + '/_index.md'}`;
195+
expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/_index.md'}`;
186196
} else if (type === 'indexmd') {
187-
expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment('/some/path') + '/index.md'}`;
197+
expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '/index.md'}`;
188198
} else {
189-
expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment('/some/path') + '.md'}`;
199+
expectedGitRedirect = `https://github.com/json-schema-org/website/blob/main/pages${extractPathWithoutFragment(mockRouter.asPath) + '.md'}`;
190200
}
191-
192201
cy.mount(<DocsHelp fileRenderType={type} />);
193202

194203
cy.get('[data-test="edit-on-github-link"]').should(

0 commit comments

Comments
 (0)