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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[Demo](https://dlart.github.io/react-burger/index.html)

# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
Expand Down
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: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
baseUrl: 'http://localhost:3000',
},

component: {
devServer: {
framework: "create-react-app",
bundler: "webpack",
},
},
});
8 changes: 8 additions & 0 deletions cypress/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"plugins": [
"cypress"
],
"extends": [
"plugin:cypress/recommended"
]
}
96 changes: 96 additions & 0 deletions cypress/e2e/burgerConstructor.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
const ingredientTestId = '[data-testid="643d69a5c3f7b9001cfa093c"]';

describe('burger constructor test', () => {
beforeEach(() => {
cy.intercept(
'GET',
'api/auth/user',
{fixture: 'user.json'},
);

cy.intercept(
'POST',
'api/orders',
{fixture: 'order.json'},
).as('createOrder');

window
.localStorage
.setItem(
'accessToken',
JSON.stringify('accessToken')
);

window
.localStorage
.setItem(
'refreshToken',
JSON.stringify('refreshToken')
);

cy.visit('/');

cy.intercept(
'GET',
'api/ingredients',
{fixture: 'ingredients.json',
});
});

it('should handle ingredient modal', () => {
cy.get(ingredientTestId).click();

cy.get('[data-testid="modal-title"]').should(
'have.text',
'Детали ингредиента',
);

cy.get('[data-testid="modal-close-button"]').click();

cy.get('[data-testid="constructor-title"]').should(
'have.text',
'Соберите бургер',
);
});

it('should handle drag and drop and order', () => {
cy.get(ingredientTestId).trigger('dragstart');

cy.get('[data-testid="top-bun-drop-target"]').trigger('drop');

cy.get('[data-testid="643d69a5c3f7b9001cfa093c-ingredient-card"] .counter__num').should(
'have.text',
'2',
);

const anotherIngredientTestId = '[data-testid="643d69a5c3f7b9001cfa0941"]';

cy.get(anotherIngredientTestId).trigger('dragstart');

const ingredientDropTarget = '[data-testid="ingredient-drop-target"]';

cy.get(ingredientDropTarget).trigger('drop');

cy.get(anotherIngredientTestId).trigger('dragstart');

cy.get(ingredientDropTarget).trigger('drop');

cy.get('[data-testid="643d69a5c3f7b9001cfa0941-ingredient-card"] .counter__num').should(
'have.text',
'2',
);

cy.get('[data-testid="top-bun-drop-target"]').contains('Краторная булка N-200i');

cy.get('[data-testid="bottom-bun-drop-target"]').contains('Краторная булка N-200i');

cy.get(ingredientDropTarget).contains('Биокотлета из марсианской Магнолии');

cy.get('[data-testid="order-button"]').click();

cy.get('[data-testid="modal-order-number"]').should(
'have.text',
'1234',
);
});
});
47 changes: 47 additions & 0 deletions cypress/fixtures/ingredients.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"data": [
{
"__v": 0,
"_id": "643d69a5c3f7b9001cfa093c",
"calories": 420,
"carbohydrates": 53,
"fat": 24,
"image": "https://code.s3.yandex.net/react/code/bun-02.png",
"image_large": "https://code.s3.yandex.net/react/code/bun-02-large.png",
"image_mobile": "https://code.s3.yandex.net/react/code/bun-02-mobile.png",
"name": "Краторная булка N-200i",
"price": 1255,
"proteins": 80,
"type": "bun"
},
{
"__v": 0,
"_id": "643d69a5c3f7b9001cfa0941",
"calories": 4242,
"carbohydrates": 242,
"fat": 142,
"image": "https://code.s3.yandex.net/react/code/meat-01.png",
"image_large": "https://code.s3.yandex.net/react/code/meat-01-large.png",
"image_mobile": "https://code.s3.yandex.net/react/code/meat-01-mobile.png",
"name": "Биокотлета из марсианской Магнолии",
"price": 424,
"proteins": 420,
"type": "main"
},
{
"__v": 0,
"_id": "643d69a5c3f7b9001cfa093e",
"calories": 643,
"carbohydrates": 85,
"fat": 26,
"image": "https://code.s3.yandex.net/react/code/meat-03.png",
"image_large": "https://code.s3.yandex.net/react/code/meat-03-large.png",
"image_mobile": "https://code.s3.yandex.net/react/code/meat-03-mobile.png",
"name": "Филе Люминесцентного тетраодонтимформа",
"price": 988,
"proteins": 44,
"type": "main"
}
],
"success": true
}
7 changes: 7 additions & 0 deletions cypress/fixtures/order.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Order name",
"order": {
"number": "1234"
},
"success": true
}
7 changes: 7 additions & 0 deletions cypress/fixtures/user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"success": true,
"user": {
"email": "foo@bar.ru",
"name": "foo"
}
}
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>
// }
// }
// }
12 changes: 12 additions & 0 deletions cypress/support/component-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!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>
</head>
<body>
<div data-cy-root></div>
</body>
</html>
39 changes: 39 additions & 0 deletions cypress/support/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ***********************************************************
// This example support/component.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')

import { mount } from 'cypress/react18'

// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.
declare global {
namespace Cypress {
interface Chainable {
mount: typeof mount
}
}
}

Cypress.Commands.add('mount', mount)

// Example use:
// cy.mount(<MyComponent />)
20 changes: 20 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading