diff options
| author | 2020-12-14 13:49:14 +0200 | |
|---|---|---|
| committer | 2020-12-14 13:49:14 +0200 | |
| commit | a43fa25ffb3c32a58f6619423bb33eb64c7d2d45 (patch) | |
| tree | a8a85715f0008f1b1ce300363148f94ce62bbebd | |
| parent | Update LandingPage to use forms from API (diff) | |
Update tests to match with changes in discovery
| -rw-r--r-- | src/tests/api/forms.test.ts | 6 | ||||
| -rw-r--r-- | src/tests/components/FormListing.test.tsx | 31 | ||||
| -rw-r--r-- | src/tests/pages/LandingPage.test.tsx | 21 | 
3 files changed, 46 insertions, 12 deletions
| diff --git a/src/tests/api/forms.test.ts b/src/tests/api/forms.test.ts index 7c851a7..6e63965 100644 --- a/src/tests/api/forms.test.ts +++ b/src/tests/api/forms.test.ts @@ -1,11 +1,7 @@  import { getForm, getForms } from "../../api/forms"; -test('fetch a list of all forms', () => { -    expect(getForms()).toBeInstanceOf(Array); -}); -  test('fetch a specific form', () => { -    expect(getForm("ban-appeals")).resolves.toHaveProperty("title", "Ban Appeals") +    expect(getForm("ban-appeals")).resolves.toHaveProperty("name", "Ban Appeals")  });  export default null; diff --git a/src/tests/components/FormListing.test.tsx b/src/tests/components/FormListing.test.tsx index 5062a95..0afe10c 100644 --- a/src/tests/components/FormListing.test.tsx +++ b/src/tests/components/FormListing.test.tsx @@ -4,20 +4,37 @@ import '@testing-library/jest-dom/extend-expect';  import FormListing from "../../components/FormListing";  import { BrowserRouter as Router } from 'react-router-dom'; -import { AllFormsForm } from '../../api/forms'; +import { Form, FormFeatures } from '../../api/forms'; +import { QuestionType } from '../../api/question'; -const openFormListing: AllFormsForm = { -    title: "Example form listing", +const openFormListing: Form = { +    name: "Example form listing",      id: "example-form-listing",      description: "My form listing", -    open: true +    features: [FormFeatures.Discoverable, FormFeatures.Open], +    questions: [ +        { +            "id": "my-question", +            "name": "My question", +            "type": QuestionType.ShortText, +            "data": {} +        } +    ]  } -const closedFormListing: AllFormsForm = { -    title: "Example form listing", +const closedFormListing: Form = { +    name: "Example form listing",      id: "example-form-listing",      description: "My form listing", -    open: false +    features: [FormFeatures.Discoverable], +    questions: [ +        { +            "id": "what-should-i-ask", +            "name": "What should I ask?", +            "type": QuestionType.ShortText, +            "data": {} +        } +    ]  }  test('renders form listing with specified title', () => { diff --git a/src/tests/pages/LandingPage.test.tsx b/src/tests/pages/LandingPage.test.tsx index ba32bab..23195bd 100644 --- a/src/tests/pages/LandingPage.test.tsx +++ b/src/tests/pages/LandingPage.test.tsx @@ -2,10 +2,31 @@ import React from 'react';  import { render } from '@testing-library/react';  import LandingPage from "../../pages/LandingPage"; +import * as forms from "../../api/forms";  import { BrowserRouter as Router } from "react-router-dom"; +import { QuestionType } from '../../api/question'; + +const testingForm: forms.Form = { +    "id": "testing-form", +    "name": "Testing Form", +    "description": "Meant for testing", +    "features": [forms.FormFeatures.Discoverable], +    "questions": [ +        { +            "id": "my-question", +            "name": "My Question", +            "type": QuestionType.ShortText, +            "data": {} +        } +    ] +}  test('renders landing page', () => { +    const setForms = jest.fn(() => [testingForm]); +    Object.defineProperty(forms, "getForms", setForms); +    const handleForms = jest.spyOn(React, "useState"); +    handleForms.mockImplementation(_value => [[testingForm], setForms]);      const { getByText } = render(<Router><LandingPage /></Router>);      // If we rendered the headerbar we rendered the landing page.      let headerBar = getByText(/Python Discord Forms/); | 
