-
Notifications
You must be signed in to change notification settings - Fork 342
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 #304
base: main
Are you sure you want to change the base?
solution #304
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
describe('', () => { | ||
before(() => { | ||
import ArticlePageObject from '../support/pages/article.pageObject'; | ||
|
||
}); | ||
const ArticlePage = new ArticlePageObject(); | ||
|
||
it('', () => { | ||
describe('Article', () => { | ||
let user; | ||
|
||
beforeEach(() => { | ||
cy.task('generateUser').then((generatedUser) => { | ||
user = generatedUser; | ||
cy.login(user.email, user.username, user.password); | ||
cy.visit('/editor'); | ||
}); | ||
}); | ||
|
||
it('', () => { | ||
it('should fill in article and create it', () => { | ||
const article = ArticlePage.generateArticle(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method |
||
ArticlePage.createArticle(article); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method |
||
ArticlePage.onClickSubmitArticle(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method |
||
ArticlePage.assertArticleTitle(article.title); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method |
||
}); | ||
|
||
it('should be able to delete an article', () => { | ||
const article = ArticlePage.generateArticle(); | ||
cy.createArticle(article).then((response) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
cy.visit(`/article/${response.body.article.slug}`); | ||
ArticlePage.assertArticleTitle(article.title); | ||
cy.get('.btn.btn-outline-danger.btn-sm').eq(0).click(); | ||
cy.assertPageURL('/'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class PageObject { | ||
visit(url) { | ||
cy.visit(url || this.url); | ||
} | ||
} | ||
|
||
export default PageObject; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,24 +47,35 @@ Cypress.Commands.add('login', (email, username, password) => { | |
}); | ||
}); | ||
|
||
Cypress.Commands.add('createArticle', (title, description, body) => { | ||
cy.getCookie('auth').then((token) => { | ||
const authToken = token.value; | ||
Cypress.Commands.add('findByPlaceholder', (placeholder) => { | ||
return cy.get(`[placeholder="${placeholder}"]`); | ||
}); | ||
|
||
Cypress.Commands.add( | ||
'createArticle', | ||
({ title, description, body, tag }) => { | ||
cy.getCookie('auth').then((token) => { | ||
const authToken = token.value; | ||
|
||
cy.request({ | ||
method: 'POST', | ||
url: '/api/articles', | ||
body: { | ||
article: { | ||
title, | ||
description, | ||
body, | ||
tagList: [] | ||
cy.request({ | ||
method: 'POST', | ||
url: '/api/articles', | ||
body: { | ||
article: { | ||
title, | ||
description, | ||
body, | ||
tagList: [tag] | ||
} | ||
}, | ||
headers: { | ||
Authorization: `Token ${authToken}` | ||
} | ||
}, | ||
headers: { | ||
Authorization: `Token ${authToken}` | ||
} | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that the |
||
}); | ||
}); | ||
} | ||
); | ||
|
||
Cypress.Commands.add('assertPageURL', (url) => { | ||
cy.url().should('equal', Cypress.config().baseUrl + url); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import PageObject from '../PageObject'; | ||
|
||
class ArticlePageObject extends PageObject { | ||
get articleTitleField() { | ||
return cy.findByPlaceholder('Article Title'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that the |
||
} | ||
|
||
get articleAboutField() { | ||
return cy.findByPlaceholder(`What's this article about?`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that the |
||
} | ||
|
||
get articleBodyField() { | ||
return cy.findByPlaceholder('Write your article (in markdown)'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that the |
||
} | ||
|
||
get articleTagsField() { | ||
return cy.findByPlaceholder('Enter tags'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that the |
||
} | ||
|
||
get submitButton() { | ||
return cy.get('.btn.btn-lg.btn-primary'); | ||
} | ||
|
||
onClickSubmitArticle() { | ||
this.submitButton.click(); | ||
} | ||
|
||
generateArticle() { | ||
return { | ||
title: faker.lorem.word(), | ||
description: faker.lorem.words(), | ||
body: faker.lorem.words(), | ||
tag: faker.lorem.word() | ||
}; | ||
} | ||
|
||
createArticle(article) { | ||
const { title, description, tag, body } = article; | ||
|
||
this.articleTitleField.type(title); | ||
this.articleAboutField.type(description); | ||
this.articleBodyField.type(body); | ||
this.articleTagsField.type(`${tag}{Enter}`); | ||
} | ||
|
||
assertArticleTitle(title) { | ||
cy.contains(title).should('be.visible'); | ||
} | ||
}; | ||
|
||
export default ArticlePageObject; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that the
cy.login
command is correctly defined in your Cypress commands. If it's a custom command, verify its implementation to ensure it logs in the user as expected.