|
|
@ -21,8 +21,29 @@ describe('Profile page', () => {
|
|
|
|
|
|
|
|
|
|
|
|
it('can see favorited articles', function () {
|
|
|
|
it('can see favorited articles', function () {
|
|
|
|
const apiUrl = Cypress.env('apiUrl')
|
|
|
|
const apiUrl = Cypress.env('apiUrl')
|
|
|
|
// we already test adding favourites in home spec
|
|
|
|
// we already test adding favorite in home spec, we know it works
|
|
|
|
// here we can mock my favourited articles list
|
|
|
|
// here we can use API to favourite an article (then we have tested it E2E)
|
|
|
|
|
|
|
|
// create a new article
|
|
|
|
|
|
|
|
cy.createArticle().then((link) => {
|
|
|
|
|
|
|
|
// and then add newly created article to favorites
|
|
|
|
|
|
|
|
cy.request({
|
|
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
|
|
url: `${apiUrl}/articles/${link}/favorite`,
|
|
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
|
|
authorization: `Token ${window.localStorage.getItem('jwtToken')}`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
cy.visit(`/@${this.username}`)
|
|
|
|
|
|
|
|
cy.get(profile.favouritedArticlesTab).click()
|
|
|
|
|
|
|
|
cy.get(profile.articles).should('be.visible')
|
|
|
|
|
|
|
|
.and('have.length', 1)
|
|
|
|
|
|
|
|
.and('contain', 'My Cypress article')
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('can see favorited articles - mock response', function () {
|
|
|
|
|
|
|
|
const apiUrl = Cypress.env('apiUrl')
|
|
|
|
|
|
|
|
// example how to mock favourited articles list
|
|
|
|
cy.intercept(`${apiUrl}/articles?favorited=${this.username}&limit=5&offset=0*`, {
|
|
|
|
cy.intercept(`${apiUrl}/articles?favorited=${this.username}&limit=5&offset=0*`, {
|
|
|
|
fixture: 'favorited_list'
|
|
|
|
fixture: 'favorited_list'
|
|
|
|
})
|
|
|
|
})
|
|
|
|