import { mount } from 'cypress/react';
import React, { useState } from 'react';
// Simple Button component
function Button() {
const [clicked, setClicked] = useState(false);
return (
<button onClick={() => setClicked(true)} aria-label="click-button">
{clicked ? 'Clicked!' : 'Click me'}
</button>
);
}
// Component Test
describe('Button Component Test', () => {
it('renders and changes text on click', () => {
mount(<Button />);
cy.get('button[aria-label="click-button"]').should('contain.text', 'Click me');
cy.get('button[aria-label="click-button"]').click();
cy.get('button[aria-label="click-button"]').should('contain.text', 'Clicked!');
});
});
// E2E Test
// Assume the app page renders the Button component
describe('Button E2E Test', () => {
it('loads page and button changes text on click', () => {
cy.visit('/button-page');
cy.get('button[aria-label="click-button"]').should('contain.text', 'Click me');
cy.get('button[aria-label="click-button"]').click();
cy.get('button[aria-label="click-button"]').should('contain.text', 'Clicked!');
});
});