diff --git a/Client/client/cypress/integration/1-getting-started/HomeDash.spec.jsx b/Client/client/cypress/integration/1-getting-started/HomeDash.spec.jsx index 8ac51d0..b8e43d0 100644 --- a/Client/client/cypress/integration/1-getting-started/HomeDash.spec.jsx +++ b/Client/client/cypress/integration/1-getting-started/HomeDash.spec.jsx @@ -1,5 +1,3 @@ - - describe('HomeDash Component', () => { it('Should change whats rendered when top nav links are clicked', () => { cy.visit('http://localhost:3000/'); diff --git a/Client/client/cypress/integration/1-getting-started/MyCloset.spec.js b/Client/client/cypress/integration/1-getting-started/MyCloset.spec.js new file mode 100644 index 0000000..4298ebc --- /dev/null +++ b/Client/client/cypress/integration/1-getting-started/MyCloset.spec.js @@ -0,0 +1,69 @@ +describe('HomeDash Component', () => { +it('Should change to MyCloset page when MyCloset button is pressed', () => { + cy.visit('http://localhost:3000/'); + + cy.get('input[name="email"]').type('test@test.com') + cy.get('input[name="password"]').type('test') + + cy.get('button[type="submit"]').click() + + cy.get('nav').within(()=> { + cy.get('h1').contains('Hi test!') + }) + + cy.get('.body').within(() => { + cy.get('.is-info').click() + }) + cy.url().should('include', 'http://localhost:3000/MyCloset') + + }) + + it('Should change whats rendered when top nav links are clicked', () => { + cy.visit('http://localhost:3000/'); + + cy.get('input[name="email"]').type('test@test.com') + cy.get('input[name="password"]').type('test') + + cy.get('button[type="submit"]').click() + + cy.get('nav').within(()=> { + cy.get('h1').contains('Hi test!') + }) + + cy.get('.body').within(() => { + cy.get('.is-info').click() + }) + + cy.get('.categories').within(()=> { + cy.get('li').click({multiple: true, force: true}) + + }) +}) + +it('Should change to ItemDetails Page when a item is clicked', () => { + cy.visit('http://localhost:3000/'); + + cy.get('input[name="email"]').type('test@test.com') + cy.get('input[name="password"]').type('test') + + cy.get('button[type="submit"]').click() + + cy.get('.body').within(() => { + cy.get('.is-info').click() + }) + + cy.get('.categories').within(()=> { + cy.get('li').click({multiple: true, force: true}) + + }) + + cy.get('.pt-2').within(()=> { + cy.get('div').within(() => { + cy.get('img').last().click() + + }) + }) + cy.url().should('include', 'http://localhost:3000/itemDetail') + +}) +}) \ No newline at end of file diff --git a/Client/client/cypress/integration/1-getting-started/SearchResults.spec.js b/Client/client/cypress/integration/1-getting-started/SearchResults.spec.js new file mode 100644 index 0000000..ae77438 --- /dev/null +++ b/Client/client/cypress/integration/1-getting-started/SearchResults.spec.js @@ -0,0 +1,34 @@ +describe('SearchResults Component', () => { + it('Should change whats rendered when new search terms are typed', () => { + cy.visit('http://localhost:3000/'); + + cy.get('input[name="email"]').type('test@test.com') + cy.get('input[name="password"]').type('test') + + cy.get('button[type="submit"]').click() + + cy.get('.search-bar').type('test') + + cy.get('.search-follow').within(() => { + cy.get('.is-4').contains('test') + }) + }) + it('Should change screen when an item is clicked from the search results', () => { + cy.visit('http://localhost:3000/'); + + cy.get('input[name="email"]').type('test@test.com') + cy.get('input[name="password"]').type('test') + + cy.get('button[type="submit"]').click() + + cy.get('.search-bar').type('shirt') + + cy.get('.search-follow').within(() => { + cy.get('.search-item-box').within(() => { + cy.get('img').last().click({force: true}) + }) + }) + cy.url().should('include', 'http://localhost:3000/itemDetail') + +}) +}) \ No newline at end of file diff --git a/Client/client/cypress/integration/1-getting-started/UserCloset.spec.js b/Client/client/cypress/integration/1-getting-started/UserCloset.spec.js new file mode 100644 index 0000000..5162d85 --- /dev/null +++ b/Client/client/cypress/integration/1-getting-started/UserCloset.spec.js @@ -0,0 +1,21 @@ +describe('UserCloset Component', () => { + it('Should change whats rendered when new search terms are typed', () => { + cy.visit('http://localhost:3000/'); + + cy.get('input[name="email"]').type('test@test.com') + cy.get('input[name="password"]').type('test') + + cy.get('button[type="submit"]').click() + + cy.get('.search-bar').type('test') + + cy.get('.search-follow').within(() => { + cy.get('.is-4').first().click({force: true}) + }) + + cy.url().should('include', 'http://localhost:3000/UserCloset/') + cy.get('.body').within(() => { + cy.get('.mt-5').contains("test's Closet") + }) + }) +}) \ No newline at end of file diff --git a/Client/client/src/App.tsx b/Client/client/src/App.tsx index f83be2b..eb5eff9 100644 --- a/Client/client/src/App.tsx +++ b/Client/client/src/App.tsx @@ -13,7 +13,7 @@ import UserCloset from './components/UserCloset/UserCloset'; import LoginPage from './components/LoginPage/LoginPage'; import actions from './redux/actions'; import { connect } from 'react-redux'; - +import apiService from './apiServices'; import logo from './utils/ClothierLiteCrop.png' import fetchService from './fetchService' @@ -59,6 +59,7 @@ function App({getItems, getUser, user, setSearchVal, searchVal}: props): JSX.Ele const logOut = () => { localStorage.removeItem('accessToken'); + apiService.logout(); setAuthenticated(false); } diff --git a/Client/client/src/apiServices.tsx b/Client/client/src/apiServices.tsx index cb0d0c1..b4b5860 100644 --- a/Client/client/src/apiServices.tsx +++ b/Client/client/src/apiServices.tsx @@ -27,6 +27,15 @@ async login(user:BasicUser) { .then((res) => (res.json())) .catch((err) => console.log(err)) }, +async logout() { + return fetch(`${baseURL}/logout`, { + method: 'POST', + credentials: 'include', + mode: 'cors', + }) + .then((res) => (res.json())) + .catch((err) => console.log(err)); +}, async profile (accessToken:string | number | null, tokenType:any) { return fetch(`${baseURL}/me`, { method: 'GET', @@ -112,7 +121,25 @@ async fetchOneItem (id:string) { .then(response => response.json()) .catch(err => console.log(err)); return result; -} +}, +async deleteItemFromCloset(UserId:number, ItemId:number){ + const res = fetch(baseURL + '/adq', { + method: 'DELETE', + credentials: 'include', + mode: 'cors', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + UserId, + ItemId + }) + }) + .then(response => response.json()) + .catch(err => console.log(err)); + return res; +}, + } diff --git a/Client/client/src/components/DeleteButton.tsx b/Client/client/src/components/DeleteButton.tsx new file mode 100644 index 0000000..939cdb9 --- /dev/null +++ b/Client/client/src/components/DeleteButton.tsx @@ -0,0 +1,9 @@ +import React from 'react' +import apiService from '../apiServices' +const DeleteButton = ({ user, item}:any) => { + return ( + + ) +} + +export default DeleteButton diff --git a/Client/client/src/components/MyCloset/MyCloset.tsx b/Client/client/src/components/MyCloset/MyCloset.tsx index 07778dd..6f21a2d 100644 --- a/Client/client/src/components/MyCloset/MyCloset.tsx +++ b/Client/client/src/components/MyCloset/MyCloset.tsx @@ -8,6 +8,7 @@ import '../../styles/app.css'; import fetchService from '../../fetchService'; import { User, Category } from '../../Interfaces/interfaces' import Categories from '../Categories'; +import DeleteButton from '../DeleteButton'; interface props { @@ -15,10 +16,11 @@ interface props { getUser: Function, getItems: Function searchVal: string + DeleteItemFromCloset: Function } -function MyCloset({user, getUser, getItems, searchVal}: props) : JSX.Element { +function MyCloset({user, getUser, getItems, DeleteItemFromCloset, searchVal}: props) : JSX.Element { const ADQitems = user.ADQs; const userCategories = [...new Set(user.ADQs.map((item) => item.item.category))]; const initialState = userCategories.map(category => {return {category: category, isActive: ''}}) @@ -86,6 +88,7 @@ function MyCloset({user, getUser, getItems, searchVal}: props) : JSX.Element {