Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NEXT_PUBLIC_MARVEL_API_BASE_URL=
NEXT_PUBLIC_MARVEL_API_PUBLIC_KEY=
NEXT_PUBLIC_MARVEL_API_PRIVATE_KEY=
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

.env
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"tailwindAttributes": [
"className"
],
"tailwindFunctions": [
"clsx"
],
"semi": false,
"plugins": [
"prettier-plugin-tailwindcss"
]
}
17 changes: 17 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
baseUrl: "http://localhost:3000",
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
defaultCommandTimeout: 6000,
component: {
devServer: {
framework: "next",
bundler: "webpack",
},
},
});
30 changes: 30 additions & 0 deletions cypress/e2e/character_page.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe('The Home Page', () => {
beforeEach(() => {
cy.visit('/')
cy.get('div#character-list').should('exist').within(() => {
cy.get('a').first().click()
})
})

it('renders the page components', () => {
cy.get('body > main > div > div').first().within(() => {
cy.get('a').should('have.attr', 'href', '/').within(() => {
cy.get('img').should('have.attr', 'alt').and('include', 'icon')
cy.get('p').should('have.text', 'Voltar')
})
cy.get('p').last().should('have.text', 'Character')
})

cy.get('#character-details-card').within(() => {
cy.get('div').first().find('img').should('have.attr', 'alt', 'hero image')
cy.get('#comics-list').should('exist').within(() => {
cy.get('img').should('be.visible').should('have.attr', 'alt', 'hero image')
})
})
})

it('redirects to home page when clicked on back arrow', () => {
cy.get('a').first().click()
cy.url().should('match', /\//)
})
})
38 changes: 38 additions & 0 deletions cypress/e2e/home_page.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
describe('The Home Page', () => {
beforeEach(() => {
cy.visit('/')
})

it('renders the page components', () => {
cy.get('input').should('exist').and('have.class', 'shadow-lg')

cy.get('div#pagination-bar').should('exist').first().within(() => {
cy.get('img').should('have.attr', 'alt').and('include', 'icon')
})
cy.get('div#pagination-bar').should('exist').last().within(() => {
cy.get('img').should('have.attr', 'alt').and('include', 'icon')
})

cy.get('div#character-list').should('exist').within(() => {
cy.get('a').first().within(() => {
cy.get('p').should('have.class', 'peer')
cy.get('img').should('have.attr', 'alt', 'hero image')
})
})

cy.get('div#page-footer').within(() => {
cy.get('p').should('have.text', '2024 © Carlos Edilson Junior')
})
})

it('shows red border on input on focus', () => {
cy.get('input').focus().should('have.class', 'focus:ring-red-600')
})

it('redirects to next page when clicked on character card', () => {
cy.get('div#character-list').should('exist').within(() => {
cy.get('a').first().click()
cy.url().should('match', /character\/.*/)
})
})
})
182 changes: 182 additions & 0 deletions cypress/fixtures/charactersApiResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
{
"code": 200,
"status": "Ok",
"copyright": "© 2024 MARVEL",
"attributionText": "Data provided by Marvel. © 2024 MARVEL",
"attributionHTML": "<a href=\"http://marvel.com\">Data provided by Marvel. © 2024 MARVEL</a>",
"etag": "bde0f4477acc21704a64368e0e66bbfd5a624def",
"data": {
"offset": 0,
"limit": 1,
"total": 1564,
"count": 1,
"results": [
{
"id": 1011334,
"name": "3-D Man",
"description": "custom description",
"modified": "2014-04-29T14:18:17-0400",
"thumbnail": {
"path": "https://images.unsplash.com/photo-1612036781997-c3c7622682fb?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTl8fG1hcnZlbHxlbnwwfHwwfHx8MA%3D%3D",
"extension": "jpg"
},
"resourceURI": "http://gateway.marvel.com/v1/public/characters/1011334",
"comics": {
"available": 12,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011334/comics",
"items": [
{
"resourceURI": "http://gateway.marvel.com/v1/public/comics/21366",
"name": "Avengers: The Initiative (2007) #14"
}
],
"returned": 2
},
"series": {
"available": 3,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011334/series",
"items": [
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/1945",
"name": "Avengers: The Initiative (2007 - 2010)"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/2005",
"name": "Deadpool (1997 - 2002)"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/2045",
"name": "Marvel Premiere (1972 - 1981)"
}
],
"returned": 3
},
"stories": {
"available": 21,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011334/stories",
"items": [
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/19947",
"name": "Cover #19947",
"type": "cover"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/19948",
"name": "The 3-D Man!",
"type": "interiorStory"
}
],
"returned": 2
},
"events": {
"available": 1,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011334/events",
"items": [
{
"resourceURI": "http://gateway.marvel.com/v1/public/events/269",
"name": "Secret Invasion"
}
],
"returned": 1
},
"urls": [
{
"type": "detail",
"url": "http://marvel.com/characters/74/3-d_man?utm_campaign=apiRef&utm_source=7c21a580ba468b057331c9bcd27adbe2"
},
{
"type": "wiki",
"url": "http://marvel.com/universe/3-D_Man_(Chandler)?utm_campaign=apiRef&utm_source=7c21a580ba468b057331c9bcd27adbe2"
},
{
"type": "comiclink",
"url": "http://marvel.com/comics/characters/1011334/3-d_man?utm_campaign=apiRef&utm_source=7c21a580ba468b057331c9bcd27adbe2"
}
]
},
{
"id": 1011334,
"name": "3-D Man",
"description": "custom description",
"modified": "2014-04-29T14:18:17-0400",
"thumbnail": {
"path": "https://images.unsplash.com/photo-1612036781997-c3c7622682fb?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTl8fG1hcnZlbHxlbnwwfHwwfHx8MA%3D%3D",
"extension": "jpg"
},
"resourceURI": "http://gateway.marvel.com/v1/public/characters/1011334",
"comics": {
"available": 12,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011334/comics",
"items": [
{
"resourceURI": "http://gateway.marvel.com/v1/public/comics/21366",
"name": "Avengers: The Initiative (2007) #14"
}
],
"returned": 2
},
"series": {
"available": 3,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011334/series",
"items": [
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/1945",
"name": "Avengers: The Initiative (2007 - 2010)"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/2005",
"name": "Deadpool (1997 - 2002)"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/series/2045",
"name": "Marvel Premiere (1972 - 1981)"
}
],
"returned": 3
},
"stories": {
"available": 21,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011334/stories",
"items": [
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/19947",
"name": "Cover #19947",
"type": "cover"
},
{
"resourceURI": "http://gateway.marvel.com/v1/public/stories/19948",
"name": "The 3-D Man!",
"type": "interiorStory"
}
],
"returned": 2
},
"events": {
"available": 1,
"collectionURI": "http://gateway.marvel.com/v1/public/characters/1011334/events",
"items": [
{
"resourceURI": "http://gateway.marvel.com/v1/public/events/269",
"name": "Secret Invasion"
}
],
"returned": 1
},
"urls": [
{
"type": "detail",
"url": "http://marvel.com/characters/74/3-d_man?utm_campaign=apiRef&utm_source=7c21a580ba468b057331c9bcd27adbe2"
},
{
"type": "wiki",
"url": "http://marvel.com/universe/3-D_Man_(Chandler)?utm_campaign=apiRef&utm_source=7c21a580ba468b057331c9bcd27adbe2"
},
{
"type": "comiclink",
"url": "http://marvel.com/comics/characters/1011334/3-d_man?utm_campaign=apiRef&utm_source=7c21a580ba468b057331c9bcd27adbe2"
}
]
}
]
}
}
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
Binary file added cypress/fixtures/marvel.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
14 changes: 14 additions & 0 deletions cypress/support/component-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Components App</title>
<!-- Used by Next.js to inject CSS. -->
<div id="__next_css__DO_NOT_USE__"></div>
</head>
<body>
<div data-cy-root></div>
</body>
</html>
Loading