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

Add sign-up test #176

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion cypress/e2e/signUp.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { generateUser } from '../support/generate';

describe('Sign Up page', () => {
it('should provide an ability to register new account', () => {

const user = generateUser();
cy.visit('https://react-redux.realworld.io/#/register?_k=rkc761');

Choose a reason for hiding this comment

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

The URL you are visiting is hard-coded. This can lead to maintenance issues if the URL changes in the future. Consider defining it as a constant or environment variable at the top of your tests or in a configuration file. This way, if the URL changes, you only need to update it in one place.

cy.get('input[placeholder="Username"]').type(user.username);
cy.get('input[placeholder="Email"]').type(user.email);
cy.get('input[placeholder="Password"]').type(user.password);
Comment on lines +7 to +9

Choose a reason for hiding this comment

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

The selectors you are using to target input fields are based on their placeholder text. While this works, it might break if the placeholder text changes in the future. A more robust solution would be to add data attributes in your application code and select elements based on these. This makes your tests more resilient against changes in the UI.

cy.get('button[type="submit"]').click();
cy.get('.nav-link').should('contain', user.username);

Choose a reason for hiding this comment

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

You are asserting that the username appears somewhere in the navigation bar. This test might pass even if the registration did not succeed and the username is displayed in an error message or some other context. To make the test more precise, you could assert that the username is displayed in a specific location, such as within a 'Profile' link.

});
});