import { Typography } from '@mui/material';
import { faker } from '@faker-js/faker';
import { useFormikContext } from 'formik';
import { object } from 'yup';
import { Button } from '../components';
import { Form } from './Form';
import { InputType } from './Inputs/models';
faker.seed(42);
const AddItem = ({ addItem }: { addItem: (item) => void }): JSX.Element => {
const { values } = useFormikContext();
const add = (): void => {
addItem({
alias: faker.company.name(),
id: values.list.length,
name: faker.person.firstName()
});
};
return (
);
};
const SortContent = ({
name,
alias
}: {
alias: string;
name: string;
}): JSX.Element => (
{name} ({alias})
);
const initializeFormList = (): void => {
cy.mount({
Component: (
)
});
};
describe('Form list', () => {
beforeEach(initializeFormList);
it('adds an element to the list', () => {
cy.contains('Add an item to the list').should('be.visible');
cy.contains('Sort items').should('be.visible');
cy.contains('Add item').click();
cy.findByLabelText('sort-0').should('be.visible');
cy.findByLabelText('delete-0').should('be.visible');
cy.contains('Lavinia (Wiegand LLC)').should('be.visible');
cy.makeSnapshot();
});
it('sorts elements in the list', () => {
cy.contains('Add an item to the list').should('be.visible');
cy.contains('Sort items').should('be.visible');
cy.contains('Add item').click();
cy.contains('Add item').click();
cy.findByLabelText('sort-0').should('be.visible');
cy.findByLabelText('delete-0').should('be.visible');
cy.contains('Sammie (Crist - Beer)').should('be.visible');
cy.findByLabelText('sort-1').should('be.visible');
cy.findByLabelText('delete-1').should('be.visible');
cy.contains('Waino (Quigley Group)').should('be.visible');
cy.moveSortableElementUsingAriaLabel({
ariaLabel: 'sort-0',
direction: 'down'
});
cy.contains('Waino (Quigley Group)').should('be.visible');
cy.contains('Sammie (Crist - Beer)').should('be.visible');
cy.makeSnapshot();
});
it('removes an element from the list', () => {
cy.contains('Add an item to the list').should('be.visible');
cy.contains('Sort items').should('be.visible');
cy.contains('Add item').click();
cy.contains('Add item').click();
cy.findByLabelText('sort-0').should('be.visible');
cy.findByLabelText('delete-0').should('be.visible');
cy.contains('Elliott (Effertz, Deckow and Deckow)').should('be.visible');
cy.findByLabelText('sort-1').should('be.visible');
cy.findByLabelText('delete-1').should('be.visible');
cy.contains('Leopoldo (Kemmer Inc)').should('be.visible');
cy.findByLabelText('delete-0').click();
cy.contains('Elliott (Effertz, Deckow and Deckow)').should('not.exist');
cy.makeSnapshot();
});
});
const initializeFormWithSections = (): void => {
cy.mount({
Component: (
)
});
};
const initializeFile = () => {
cy.mount({
Component: (
)
});
};
describe('File', () => {
it('uploads a file when a file is selected', () => {
initializeFile();
cy.contains('Drop or select a file').should('be.visible');
cy.findByLabelText('select a file').selectFile('package.json', {
force: true
});
cy.contains('package.json').should('be.visible');
cy.makeSnapshot();
});
});
describe('Form with sections', () => {
beforeEach(initializeFormWithSections);
it('displays sections when correct amount of sections', () => {
cy.contains('First group').should('be.visible');
cy.contains('Second group').should('be.visible');
cy.contains('Third group').should('be.visible');
cy.contains('Fourth group').should('be.visible');
cy.makeSnapshot();
});
it('scrolls correctly to section', () => {
cy.window().then((win) => {
const initialScrollY = win.scrollY;
cy.contains('Third group').click();
cy.window().its('scrollY').should('be.greaterThan', initialScrollY);
});
cy.wait(500); // Wait for the scroll animation to complete
cy.makeSnapshot();
});
});