Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alteração em JSX #2646

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
16 changes: 16 additions & 0 deletions src/components/Person/Person.jsx
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
// export const Person = ({ person }) => ();
import React from 'react';

export function Person({ person }) {
return (
<div>
<p className="Person__name">My name is {person.name}</p>
{person.age && <p className="Person__age">I am {person.age}</p>}
<p className="Person__partner">
{person.isMarried
? `${person.partnerName} is my ${person.sex === 'm' ? 'wife' : 'husband'}`
: 'I am not married'}
Comment on lines +10 to +12

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a check to ensure person.partnerName is defined before using it. This will prevent potential errors if partnerName is undefined. You can use a conditional check similar to how person.age is handled.

</p>
<p className="Person__greeting">Hello, my name is {person.name} and I am {person.age || 'unknown'} years old.</p> {/* Informação adicional */}
</div>
);
}
20 changes: 6 additions & 14 deletions src/components/Person/Person.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import { mount } from '@cypress/react18';
import { Person } from './Person';

describe('Person', () => {
describe('', () => {
describe('when person is male', () => {
beforeEach(() => {
const misha = {
name: 'Misha',
Expand All @@ -11,24 +12,23 @@ describe('Person', () => {
isMarried: true,
partnerName: 'Natasha',
};

mount(<Person person={misha} />);
});

it('should print a name', () => {
cy.get('.Person__name').should('have.text', 'My name is Misha');
});

it('should print an age', () => {
cy.get('.Person__age').should('have.text', 'I am 37');
});

it('should print a partner', () => {
cy.get('.Person__partner').should('have.text', 'Natasha is my wife');
});
it('should print a greeting message', () => { // Informação adicional
cy.get('.Person__greeting').should('have.text', 'Hello, my name is Misha and I am 37 years old.');
});
});

describe('', () => {
describe('when person is female', () => {
it('should show partner as a husband when the person is female', () => {
const olya = {
name: 'Olya',
Expand All @@ -37,12 +37,9 @@ describe('Person', () => {
isMarried: true,
partnerName: 'Maksym',
};

mount(<Person person={olya} />);

cy.get('.Person__partner').should('have.text', 'Maksym is my husband');
});

it('should show correct message if a person is not married', () => {
const tanya = {
name: 'Tanya',
Expand All @@ -51,21 +48,16 @@ describe('Person', () => {
isMarried: false,
partnerName: 'Some Partner',
};

mount(<Person person={tanya} />);

cy.get('.Person__partner').should('contain.text', 'not married');
});

it('should not show age if age is omitted', () => {
const sasha = {
name: 'Sasha',
sex: 'f',
isMarried: false,
};

mount(<Person person={sasha} />);

cy.get('.Person__age').should('not.exist');
Comment on lines 54 to 61

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test case checks that the .Person__age element does not exist when age is omitted, which is correct. However, it might be beneficial to also check that the greeting message displays 'unknown' for the age in this scenario, as per the component's implementation.

});
});
Expand Down
Loading