From cd48d9895dd3103722db15a2979dc46a7323c27c Mon Sep 17 00:00:00 2001 From: colinmfoster4723 Date: Fri, 8 Nov 2024 17:19:54 -0600 Subject: [PATCH] Added tests for marketplace --- ui/cypress/e2e/marketplace.cy.ts | 28 ----- ui/cypress/fixtures/marketplace/listing.json | 13 ++ .../buy-team-listing-modal.cy.tsx | 66 ++++++++++ .../subscription/team-listing.cy.tsx | 115 ++++++++++++++++++ 4 files changed, 194 insertions(+), 28 deletions(-) delete mode 100644 ui/cypress/e2e/marketplace.cy.ts create mode 100644 ui/cypress/fixtures/marketplace/listing.json create mode 100644 ui/cypress/integration/subscription/buy-team-listing-modal.cy.tsx create mode 100644 ui/cypress/integration/subscription/team-listing.cy.tsx diff --git a/ui/cypress/e2e/marketplace.cy.ts b/ui/cypress/e2e/marketplace.cy.ts deleted file mode 100644 index 50b0bb2f..00000000 --- a/ui/cypress/e2e/marketplace.cy.ts +++ /dev/null @@ -1,28 +0,0 @@ -import getMarketplaceListings from '@/lib/subscription/getMarketplaceListings' - -describe('Marketplace', () => { - beforeEach(() => { - cy.visit('/marketplace') - }) - - it('Renders the marketplace', () => { - cy.get('h1').should('exist').should('have.text', 'Marketplace') - }) - - it('Should upcharge for non-citizens', () => { - cy.get('#link-frame').eq(0).should('exist') - - cy.wrap(getMarketplaceListings()).then((listings: any) => { - const originalListingPrice = listings[0].price - - cy.get('#listing-price') - .eq(0) - .should((price) => { - const parsedPrice = parseFloat(price.text()) - expect(parsedPrice.toFixed(5)).to.equal( - (originalListingPrice * 1.1).toFixed(5) - ) - }) - }) - }) -}) diff --git a/ui/cypress/fixtures/marketplace/listing.json b/ui/cypress/fixtures/marketplace/listing.json new file mode 100644 index 00000000..a269bee0 --- /dev/null +++ b/ui/cypress/fixtures/marketplace/listing.json @@ -0,0 +1,13 @@ +{ + "id": 1, + "teamId": "1", + "title": "Test Title", + "description": "Test Description", + "price": "1", + "currency": "ETH", + "image": "https://b507f59d2508ebfb5e70996008095782.ipfscdn.io/ipfs/bafybeigj5k75odq5azftrivrnjlsdd7jqs7f72qmgzfi67znkbooeriy3e/", + "metadata": "", + "startTime": 0, + "endTime": 0, + "shipping": "false" +} diff --git a/ui/cypress/integration/subscription/buy-team-listing-modal.cy.tsx b/ui/cypress/integration/subscription/buy-team-listing-modal.cy.tsx new file mode 100644 index 00000000..562b2ba6 --- /dev/null +++ b/ui/cypress/integration/subscription/buy-team-listing-modal.cy.tsx @@ -0,0 +1,66 @@ +import { PrivyProvider } from '@privy-io/react-auth' +import { Sepolia } from '@thirdweb-dev/chains' +import { ZERO_ADDRESS } from 'const/config' +import CitizenProvider from '@/lib/citizen/CitizenProvider' +import { PrivyThirdwebSDKProvider } from '@/lib/privy/PrivyThirdwebSDKProvider' +import BuyTeamListingModal from '@/components/subscription/BuyTeamListingModal' +import { TeamListing } from '@/components/subscription/TeamListing' + +describe('', () => { + let props: any + let listing: TeamListing + + before(() => { + cy.fixture('marketplace/listing').then((l) => { + listing = l + }) + }) + + beforeEach(() => { + props = { + selectedChain: Sepolia, + listing, + recipient: ZERO_ADDRESS, + setEnabled: cy.stub(), + } + + cy.mount( + + + + + + ) + }) + + it('Renders the component', () => { + cy.contains('h2', 'Buy a Listing').should('be.visible') + cy.contains(listing.title).should('be.visible') + cy.contains(listing.description).should('be.visible') + cy.contains(`${listing.price} ${listing.currency}`).should('be.visible') + }) + + it('Shows markedup price for non-citizens', () => { + cy.get('#listing-price').should( + 'have.text', + `${+listing.price * 1.1} ${listing.currency}` + ) + }) + + it('Shows regular price for citizens', () => { + cy.mount( + + + + + + + + ) + + cy.get('#listing-price').should( + 'have.text', + `${listing.price} ${listing.currency}` + ) + }) +}) diff --git a/ui/cypress/integration/subscription/team-listing.cy.tsx b/ui/cypress/integration/subscription/team-listing.cy.tsx new file mode 100644 index 00000000..358184e7 --- /dev/null +++ b/ui/cypress/integration/subscription/team-listing.cy.tsx @@ -0,0 +1,115 @@ +import { PrivyProvider } from '@privy-io/react-auth' +import { Sepolia } from '@thirdweb-dev/chains' +import { PrivyThirdwebSDKProvider } from '@/lib/privy/PrivyThirdwebSDKProvider' +import TeamListing, { + TeamListing as TeamListingType, +} from '@/components/subscription/TeamListing' + +describe('', () => { + let listing: TeamListingType + let props: any + + before(() => { + cy.fixture('marketplace/listing').then((l) => { + listing = l + }) + }) + + beforeEach(() => { + props = { + selectedChain: Sepolia, + listing, + teamContract: { + erc721: { + get: cy.stub().resolves({ + metadata: { name: 'Test Team Name' }, + owner: '0x123', + }), + }, + }, + marketplaceTableContract: { + call: cy.stub().resolves(), + }, + refreshListings: cy.stub(), + teamName: true, + queriedListingId: 1, + } + }) + + it('Renders the component', () => { + cy.mount( + + + + + + ) + + cy.get('#listing-team-name').should('exist') + cy.get('#main-header').should('have.text', props.listing.title) + cy.get('#listing-description').should( + 'have.text', + props.listing.description + ) + }) + + it('Shows markedup price for non-citizens', () => { + cy.mount( + + + + + + ) + + cy.get('#listing-price').should((price) => { + const parsedPrice = parseFloat(price.text()) + expect(parsedPrice.toFixed(5)).to.equal((+listing.price * 1.1).toFixed(5)) + }) + }) + + it('Shows regular price for citizens', () => { + cy.mount( + + + + + + ) + + cy.get('#listing-price').should((price) => { + const parsedPrice = parseFloat(price.text()) + expect(parsedPrice.toFixed(5)).to.equal((+listing.price).toFixed(5)) + }) + }) + + it('Opens the edit modal when the edit button is clicked', () => { + cy.mount( + + + + + + ) + + cy.get('#edit-listing-button').click() + cy.get('#team-marketplace-listing-modal-backdrop').should('exist') + }) + + it('Deletes the listing when the delete button is clicked', () => { + cy.mount( + + + + + + ) + + cy.get('#delete-listing-button').click() + cy.wrap(props.marketplaceTableContract.call).should( + 'be.calledWith', + 'deleteFromTable', + [listing.id, listing.teamId] + ) + }) +})