-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add articles, article details page e2e cypress tests
- Loading branch information
Showing
13 changed files
with
176 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,32 @@ | ||
describe('empty spec', () => { | ||
it('passes', () => { | ||
cy.visit('https://example.cypress.io'); | ||
let currentArticleId = ''; | ||
describe('to article details page', () => { | ||
beforeEach(() => { | ||
cy.login(); | ||
cy.createArticle().then((article) => { | ||
currentArticleId = article.id; | ||
cy.visit(`articles/${article.id}`); | ||
}); | ||
}); | ||
// Add new article - test everything - delete article | ||
afterEach(() => { | ||
cy.removeArticle(currentArticleId); | ||
}); | ||
it('article details page loaded', () => { | ||
cy.getByTestId('ArticlesDetails.Info').should('exist'); | ||
}); | ||
it('article details recommendations list loaded', () => { | ||
cy.getByTestId('ArticleRecommendationsList').should('exist'); | ||
}); | ||
it('article details comments list', () => { | ||
cy.getByTestId('ArticlesDetails.Info'); | ||
cy.getByTestId('AddCommentForm').scrollIntoView(); | ||
cy.addComment('text'); | ||
cy.getByTestId('CommentCard.Content').should('have.length', 1); | ||
}); | ||
it('article details rating', () => { | ||
cy.getByTestId('ArticlesDetails.Info'); | ||
cy.getByTestId('RatingCard').scrollIntoView(); | ||
cy.setRate(3, 'feedback test'); | ||
cy.get('[data-selected=true]').should('have.length', 3); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import * as commonCommands from './commands/common'; | ||
import * as profileCommands from './commands/profile'; | ||
import * as articleCommands from './commands/article'; | ||
import * as commentsCommands from './commands/comments'; | ||
import * as ratingCommands from './commands/rating'; | ||
|
||
Cypress.Commands.addAll(commonCommands); | ||
Cypress.Commands.addAll(profileCommands); | ||
Cypress.Commands.addAll(articleCommands); | ||
Cypress.Commands.addAll(commentsCommands); | ||
Cypress.Commands.addAll(ratingCommands); | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Article } from '../../../src/entities/Article'; | ||
|
||
const defaultArticle = { | ||
title: 'TESTING ARTICLE', | ||
subtitle: 'Subtitle text', | ||
img: 'https://avatars.mds.yandex.net/get-zen_doc/2746556/pub_5f50dd' | ||
+ '7e1a1ddf4776aa5569_5f50decd2506f211d1de6284/scale_1200', | ||
views: 1022, | ||
createdAt: '26.02.2022', | ||
userId: '1', | ||
type: [ | ||
'SCIENCE', | ||
], | ||
blocks: [], | ||
}; | ||
|
||
export const createArticle = (article?: Article) => cy.request({ | ||
method: 'POST', | ||
url: 'http://localhost:8000/articles', | ||
headers: { Authorization: 'asasf' }, | ||
body: article ?? defaultArticle, | ||
}).then((resp) => resp.body); | ||
|
||
export const removeArticle = (articleId: string) => cy.request({ | ||
method: 'DELETE', | ||
url: `http://localhost:8000/articles/${articleId}`, | ||
headers: { Authorization: 'asasf' }, | ||
}); | ||
|
||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
createArticle(article?: Article): Chainable<Article>; | ||
removeArticle(articleId: string): Chainable<void>; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const addComment = (text: string) => { | ||
cy.getByTestId('AddCommentForm.Input').type(text); | ||
cy.getByTestId('AddCommentForm.Button').click(); | ||
}; | ||
|
||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
addComment(text: string): Chainable<void>; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const setRate = (starsCount = 5, feedback = 'feedback') => { | ||
cy.getByTestId(`StarRating.${starsCount}`).click(); | ||
cy.getByTestId('RatingCard.Input').type(feedback); | ||
cy.getByTestId('RatingCard.Send').click(); | ||
}; | ||
|
||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
setRate(starsCount: number, feedback: string): Chainable<void>; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters