diff --git a/README.md b/README.md index e3e663b6..8e854ad9 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ In this project you will build an application that allows for todos to be added, - Once a todo is submitted, the Todo List should re-render and show the added todo. ## Submission Format -- [ ] Only work on main. -- [ ] Make sure to push your code at regular intervals. -- [ ] Copy your github repo url and paste it into Canvas to submit your project \ No newline at end of file +- [ ] If this is your first time connecting a submission, authorize your github account within the codegrade assignment. +- [ ] Connect your fork to Codegrade using the "Connect Git" button. +- [ ] Find your newly created fork from the list and push your work to main. +- [ ] Check this video for details: www.youtube.com/watch?v=fC2BO7dI6IQ diff --git a/codegrade_mvp1.test.js b/codegrade_mvp1.test.js index 495fda09..3899be86 100644 --- a/codegrade_mvp1.test.js +++ b/codegrade_mvp1.test.js @@ -1,162 +1,9 @@ -import { server } from './src/mocks/server' -import { resetArticles } from './src/mocks/data' -import { BrowserRouter as Router, Route} from "react-router-dom"; - import MutationObserver from 'mutationobserver-shim'; -import React from 'react' - -import App from './src/components/App' -import Login from './src/components/Login'; -import View from './src/components/View'; - -import { render, screen, waitFor, within} from '@testing-library/react' -import userEvent from '@testing-library/user-event'; - import '@testing-library/jest-dom/extend-expect' -beforeAll(() => { server.listen() }) -afterAll(() => { server.close() }) -beforeEach(() => { - resetArticles() -}) -afterEach(() => { - server.resetHandlers() - document.body.innerHTML = '' -}) - test('Is the latest version of the project', () => { const pjson = require('./package.json') expect(pjson.version).toBe('0.0.1') }); - -const cred = { - username: "Lambda", - password: "School" -} - -describe("Login Authentication", ()=> { - test("App does nothing when login incorrect username", async ()=>{ - render( - - ); - - const nameInput = document.querySelector("#username"); - const passwordInput = document.querySelector("#password"); - - userEvent.clear(nameInput); - userEvent.type(nameInput, "wrong"); - let wait = await screen.findAllByRole("button"); - - userEvent.clear(passwordInput); - userEvent.type(passwordInput, cred.password); - wait = await screen.findAllByRole("button"); - - const button = document.querySelector("#submit"); - userEvent.click(button); - wait = await screen.findAllByRole("button"); - - await waitFor(()=> { - const error = document.querySelector("#error"); - expect(error.textContent).toBeTruthy(); - }); - }); - - test("App does nothing when login incorrect password", async ()=>{ - render( - - ); - - const nameInput = document.querySelector("#username"); - const passwordInput = document.querySelector("#password"); - - userEvent.clear(nameInput); - userEvent.type(nameInput, cred.username); - let wait = await screen.findAllByRole("button"); - - userEvent.clear(passwordInput); - userEvent.type(passwordInput, "wrong"); - wait = await screen.findAllByRole("button"); - - const button = document.querySelector("#submit"); - userEvent.click(button); - wait = await screen.findAllByRole("button"); - - await waitFor(()=> { - const error = document.querySelector("#error"); - expect(error.textContent).toBeTruthy(); - }); - }); - - test("App Successfully redirects", async ()=>{ - render(); - const nameInput = document.querySelector("#username"); - const passwordInput = document.querySelector("#password"); - - userEvent.clear(nameInput); - userEvent.type(nameInput, cred.username); - let wait = await screen.findAllByRole("button"); - - userEvent.clear(passwordInput); - userEvent.type(passwordInput, cred.password); - wait = await screen.findAllByRole("button"); - - const button = document.querySelector("#submit"); - userEvent.click(button); - wait = await screen.findAllByRole("button"); - wait = await screen.findAllByRole("button"); - - await waitFor(()=> { - const title = screen.getByText('View Articles'); - expect(title).toBeInTheDocument(); - }); - }); -}) - -describe("View Page", ()=> { - test("Loads all articles on initial rendering", async ()=>{ - localStorage.setItem("token", "ahuBHejkJJiMDhmODZhZi0zaeLTQ4ZfeaseOGZgesai1jZWYgrTA07i73Gebhu98") - render(); - const articles = await screen.findAllByTestId("article"); - expect(articles).toHaveLength(4); - }); - - test("Successfully deletes an article", async ()=>{ - localStorage.setItem("token", "ahuBHejkJJiMDhmODZhZi0zaeLTQ4ZfeaseOGZgesai1jZWYgrTA07i73Gebhu98") - - render(); - const deleteButtons = await screen.findAllByTestId('deleteButton'); - userEvent.click(deleteButtons[0]); - - await waitFor(async ()=> { - const articles = await screen.findAllByTestId("article"); - expect(articles).toHaveLength(3); - }); - }); - - test("Successfully edits an article", async ()=>{ - localStorage.setItem("token", "ahuBHejkJJiMDhmODZhZi0zaeLTQ4ZfeaseOGZgesai1jZWYgrTA07i73Gebhu98") - render(); - const editButtons = await screen.findAllByTestId('editButton'); - userEvent.click(editButtons[0]); - let wait = await screen.findAllByRole("button"); - wait = await screen.findAllByRole("button"); - - const headline = document.querySelector('#headline'); - userEvent.type(headline, '{selectall}{del}'); - wait = await screen.findAllByRole("button"); - userEvent.type(headline, 'Test'); - wait = await screen.findAllByRole("button"); - - const editButton = document.querySelector('#editButton'); - userEvent.click(editButton); - wait = await screen.findAllByRole("button"); - - await waitFor(async ()=> { - const articles = await screen.findAllByTestId("article"); - const newHeadline = within(articles[0]).queryByTestId("headline"); - expect(newHeadline) - }); - }); -}); \ No newline at end of file