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

Solution #172

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Solution #172

wants to merge 3 commits into from

Conversation

vStryhun
Copy link

@vStryhun vStryhun commented Oct 9, 2024

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Great work so far! 😊 However, there are a few areas that need some improvements. Please consider generating a random password instead of using a fixed one, check for more specific elements after successful registration, and avoid hardcoding URLs in your tests. Keep up the good work! 💪

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

describe('Sign Up page', () => {
it('should provide an ability to register new account', () => {
const { email, username, password } = generateUser();

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

Choose a reason for hiding this comment

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

Hardcoding URLs in the tests is not a good practice. If the URL changes in the future, you will have to change it in every place it's used. Consider storing the base URL in a configuration file or environment variable and just append the path specific to the test.

.type(password);

cy.get('button[type=submit]')
.should('exist').click();

Choose a reason for hiding this comment

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

The .should('exist') assertion before the click action might not be necessary. Cypress automatically waits for elements to exist before executing actions (like click). If the button doesn't exist, the test will fail anyway.

cy.get('button[type=submit]')
.should('exist').click();

cy.url().should('not.contain', '/register');

Choose a reason for hiding this comment

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

This assertion checks that the URL does not contain '/register', but it doesn't check if the user was redirected to the correct page after registration. Consider checking that the URL matches the expected URL after successful registration.


cy.get('a.nav-link').contains(username).should('exist');

Choose a reason for hiding this comment

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

Although checking for the existence of a username in the navigation bar is a good way to confirm successful registration, it might be more robust to check something more specific to the user's account, like a welcome message or user settings. This would make your test more resistant to changes in the UI.

import { faker } from '@faker-js/faker';

function generateUser() {
const randomNumber = Math.random().toString().slice(2, 6);

Choose a reason for hiding this comment

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

Consider adding a comment here explaining the purpose of the randomNumber and why it's used in the username. This will improve the readability of your code.

const randomNumber = Math.random().toString().slice(2, 6);
const username = faker.internet.userName() + '_' + randomNumber;
const email = `${username}@mail.com`;
const password = '12345Qwert!';

Choose a reason for hiding this comment

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

Hardcoding passwords in your code can be a security risk, even for test data. Consider generating a random password for each user instead. This could also help you catch potential issues with different password inputs.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Great work so far! 👍 However, there are a few improvements that can be made to enhance the code quality and maintainability. Please consider using more specific selectors, avoid hardcoding URLs in your tests, move the base URL to a global configuration file, and handle uncaught exceptions in a global configuration file. Keep up the good work! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

@@ -1,5 +1,28 @@
import { generateUser } from '../support/generate';

Cypress.on('uncaught:exception', () => {

Choose a reason for hiding this comment

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

It's recommended to handle uncaught exceptions in a global configuration file (like commands.js or index.js in the support folder) instead of in individual test files. This improves code maintainability and readability.

describe('Sign Up page', () => {
it('should provide an ability to register new account', () => {
const { email, username, password } = generateUser();

cy.visit('/#/register?_k=spysa9');

Choose a reason for hiding this comment

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

It's better to move the base URL ('/#/register?_k=spysa9') to a global configuration file or environment variable. This will make it easier to change the base URL when the test environment changes.


cy.get('button[type=submit]').click();

cy.url().should('contain', '/#/?_k=c1q9kl');

Choose a reason for hiding this comment

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

It's better to avoid hardcoding URLs in your tests. If the URL structure changes, your tests will break. Consider using a relative URL or a URL from the application's state.


cy.get('a.nav-link').contains(username).should('exist');

Choose a reason for hiding this comment

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

It's better to use more specific selectors than 'a.nav-link'. This will make your tests more resilient to changes in the HTML structure. Consider adding a data-test attribute to the element you want to select.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Great job on your pull request! Your code is generally well-written and it's great to see you using the faker library to generate random user credentials. There are a few areas that could be improved, such as adding assertions to check if registration was successful and adding comments to your tests. Keep up the good work and continue learning and improving! 👍

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨


cy.get('a.nav-link').contains(username).should('exist');

Choose a reason for hiding this comment

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

It's good that you are checking if the username appears on the navigation bar after registration, but you should also add some assertions to check if the registration was successful. For example, you could check if a success message appears on the screen or if the user is redirected to the correct page. This will make your tests more robust and reliable.

Comment on lines 3 to 21
describe('Sign Up page', () => {
it('should provide an ability to register new account', () => {
const { email, username, password } = generateUser();

cy.visit(Cypress.config().baseUrl);

cy.get('[placeholder=Username]')
.type(username);

cy.get('[placeholder=Email]')
.type(email);

cy.get('[placeholder=Password]')
.type(password);

cy.get('button[type=submit]').click();

cy.get('a.nav-link').contains(username).should('exist');
});

Choose a reason for hiding this comment

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

It's a good practice to add comments to your tests to explain what each part of the test is doing. This can make your tests easier to understand and maintain, especially for other people who might work on them in the future. Try to describe the purpose of each test, what actions it performs and what results it expects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants