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

Article-flow #298

Open
wants to merge 1 commit into
base: main
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
15 changes: 8 additions & 7 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
const { defineConfig } = require("cypress");
const faker = require('faker');
const { faker } = require('@faker-js/faker');

const { defineConfig } = require('cypress');

module.exports = defineConfig({
e2e: {
baseUrl: 'https://conduit.mate.academy/',
setupNodeEvents(on, config) {
on('task', {
generateUser() {
const email = faker.internet.email();
const randomNumber = Math.floor(Math.random(1000) * 1000);
return {
username: faker.name.firstName() + randomNumber,
email: email.toLowerCase(),
const randomSuffix = Math.floor(Math.random() * 10000);
const user = {
email: faker.internet.email().toLowerCase(),
username: `${faker.person.firstName()}${randomSuffix}`.replace(/[^a-zA-Z0-9]/g, '').slice(0, 30),
password: '12345Qwert!'
};
return user;
}
});
}
Expand Down
50 changes: 46 additions & 4 deletions cypress/e2e/article.cy.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,55 @@
describe('', () => {
before(() => {
const { faker } = require('@faker-js/faker');

/// <reference types='cypress' />

const { articleData } = require('../support/articleData.cy');

describe('Article-flow', () => {
let user;
const article = articleData();

beforeEach(() => {
const generatedUser = {
email: faker.internet.email(),
username: faker.internet.userName(),
password: '12345Qwert!'
};
user = generatedUser;

cy.login(user.email, user.username, user.password);

Choose a reason for hiding this comment

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

The cy.login command assumes that a custom Cypress command for logging in has been defined. Ensure that this command is correctly implemented in your Cypress support files.

cy.visit('');

Choose a reason for hiding this comment

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

The cy.visit(''); line is visiting an empty URL path. Ensure that this is intentional. If you intend to visit the homepage or a specific URL, provide the correct path.

});

it('', () => {
it('Should create an article with all filled fields', () => {
cy.contains('.nav-link', 'New Article').click();

cy.get('[placeholder="Article Title"]').type(article.title);
cy.get('[placeholder="What\'s this article about?"]')
.type(article.description);
cy.get('[placeholder="Write your article (in markdown)"]')
.type(article.body);
cy.get('[placeholder="Enter tags"]').type(`${article.tags}{enter}`);

cy.contains('.btn', 'Publish Article').click();

cy.url().should('contain', 'article/');
});

it('', () => {
it('Should be able to delete article', () => {
cy.contains('.nav-link', 'New Article').click();

cy.get('[placeholder="Article Title"]').type(article.title);
cy.get('[placeholder="What\'s this article about?"]')
.type(article.description);
cy.get('[placeholder="Write your article (in markdown)"]')
.type(article.body);
cy.get('[placeholder="Enter tags"]').type(`${article.tags}{enter}`);

cy.contains('.btn', 'Publish Article').click();

cy.url().should('contain', 'article/');

cy.contains('.btn', ' Delete Article').click();

Choose a reason for hiding this comment

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

There is an extra space in the selector '.btn', ' Delete Article'. Ensure that the space is intentional and matches the actual button text. Otherwise, remove the extra space.

cy.url().should('not.contain', 'article');
});
});
10 changes: 10 additions & 0 deletions cypress/support/articleData.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { faker } = require('@faker-js/faker');

export const articleData = () => {
return {
title: faker.word.words(2),
description: faker.word.words(4),
body: faker.word.words(8),
tags: faker.word.words(1)
};
};