发布于 2025-01-21 23:48:48 字数 8 浏览 0 评论 0原文

continue

the challenge am having is explained below

Am trying to set a draft_id value after the submit-recipients data-testid is clicked.
The beforementioned value is passed to a React ContextProvider that wraps my component named SendSurvey which in fact uses the draft_id value

My 2 questions are

  1. How do I import the SendSurvey component to the test spec written below?

    I have tried out doing this import SendSurvey from '.../../src/website/Surveys/SendSurvey' in my cypress test files but I get this import error
    Just as a side note, I had imported this import { mount } from '@cypress/react' but it caused my cy.visitto fail

  2. How do I wrap my ContextProvider around the SendSurvey component (assuming we imported this component successfully) and pass in the draft_id value to its ContextProvider?

    Worth mentioning that I have imported React and createContext hooks from React successfully as such

        import * as React from 'react'
        import { createContext } from 'react'
    
        /*lines skipped here*/
        //what i want to do is to create a context provider and
        //      pass in the value of the draft id to be used to get draft data
        const SendSurveyContext = createContext({})
        const SendSurveyProvider = SendSurveyContext.Provider
    

The actual test spec

   describe('Send Message To all contacts', () => {
    beforeEach(() => {
        cy.intercept('GET', `**/surveys/1`, {
            fixture: 'surveys/survey_draft.json',
        })
        cy.intercept('GET', `**/surveys/1/survey_questions?**`, {
            fixture: 'surveys/survey_questions_draft.json',
        })
    })
    it.only('should successfully select all contacts from the api', () => {
        cy.intercept('POST', '**/drafts', {
            fixture: 'sendsurveys/contacts_draft_success.json',
        }).as('createContactsDraft')

        cy.intercept('GET', '**/contacts?**', {
            fixture: 'sendsurveys/all_contacts.json',
        }).as('fetchAllContacts')
               cy.visit('/send-survey/1')
        cy.get('[data-testid=all-contacts]').click()

        cy.wait('@fetchAllContacts')
        cy.get('[data-testid=submit-recipients]').click()
        cy.contains('Successfully added the contacts.')
                
               // this is where I would like to wrap my context provider around the `SendSurvey` component and 
               //   pass in the draft_id value

    })
  })

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

五里雾 2025-01-28 23:48:48
import { mount } from '@cypress/react'
import SendSurvey from '.../../src/website/Surveys/SendSurvey'
import sendSurveyprops from '../fixtures/surveys/sendSurvey/sendSurveyProps'
import draftId from '../fixtures/surveys/sendSurvey/draftId'


 describe('Send Message To all contacts', () => {
    beforeEach(() => {
        cy.intercept('GET', `**/surveys/1`, {
            fixture: 'surveys/survey_draft.json',
        })
        cy.intercept('GET', `**/surveys/1/survey_questions?**`, {
            fixture: 'surveys/survey_questions_draft.json',
        })
    })

        mount(
              <UserContext.Provider value={draftId}>
                   <SendSurvey props={sendSurveyprops} />
              </UserContext.Provider> 
        )
 
    it.only('should successfully select all contacts from the api', () => {
        cy.intercept('POST', '**/drafts', {
            fixture: 'sendsurveys/contacts_draft_success.json',
        }).as('createContactsDraft')

        cy.intercept('GET', '**/contacts?**', {
            fixture: 'sendsurveys/all_contacts.json',
        }).as('fetchAllContacts')
        cy.get('[data-testid=all-contacts]').click()

        cy.wait('@fetchAllContacts')
        cy.get('[data-testid=submit-recipients]').click()
        cy.contains('Successfully added the contacts.')
    })
  })

这是一个工作实现。

import { mount } from '@cypress/react'
import SendSurvey from '.../../src/website/Surveys/SendSurvey'
import sendSurveyprops from '../fixtures/surveys/sendSurvey/sendSurveyProps'
import draftId from '../fixtures/surveys/sendSurvey/draftId'


 describe('Send Message To all contacts', () => {
    beforeEach(() => {
        cy.intercept('GET', `**/surveys/1`, {
            fixture: 'surveys/survey_draft.json',
        })
        cy.intercept('GET', `**/surveys/1/survey_questions?**`, {
            fixture: 'surveys/survey_questions_draft.json',
        })
    })

        mount(
              <UserContext.Provider value={draftId}>
                   <SendSurvey props={sendSurveyprops} />
              </UserContext.Provider> 
        )
 
    it.only('should successfully select all contacts from the api', () => {
        cy.intercept('POST', '**/drafts', {
            fixture: 'sendsurveys/contacts_draft_success.json',
        }).as('createContactsDraft')

        cy.intercept('GET', '**/contacts?**', {
            fixture: 'sendsurveys/all_contacts.json',
        }).as('fetchAllContacts')
        cy.get('[data-testid=all-contacts]').click()

        cy.wait('@fetchAllContacts')
        cy.get('[data-testid=submit-recipients]').click()
        cy.contains('Successfully added the contacts.')
    })
  })

This is a working implementation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文