Skip to content
Merged
1 change: 1 addition & 0 deletions functions/src/emulator/seed/content-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ async function setMockNotifications(user: IMockAuthUser) {
howto_mention: true,
new_comment_research: true,
research_useful: true,
research_mention: true,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type notificationType =
| 'howto_useful'
| 'new_comment_research'
| 'research_useful'
| 'research_mention'

export interface UserNotificationItem {
type: notificationType
Expand Down
2 changes: 1 addition & 1 deletion packages/cypress/src/integration/notifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('[Notifications]', () => {
cy.visit('how-to')
cy.login('howto_reader@test.com', 'test1234')
cy.visit('/research/qwerty')
cy.get('[data-cy="ResearchComments: button open-comments"]').click()
cy.get('[data-cy="ResearchComments: button open-comments"]').first().click()
cy.get('[data-cy="comments-form"]').type('some sample comment')
cy.get('[data-cy="comment-submit"]').click()
cy.wait(DB_WAIT_TIME)
Expand Down
34 changes: 26 additions & 8 deletions packages/cypress/src/integration/research/comments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,39 @@ describe('[Research]', () => {
cy.visit('/research/qwerty')
})

it('[Open comments]', () => {
cy.get('[data-cy="ResearchComments: button open-comments"]').click()
cy.get('[data-cy="comment"]').should('have.length.gte', 1)
cy.get('[data-cy="comment-submit"]').should('be.disabled')
describe('[Open comments]', () => {
it('using UI elements', () => {
cy.get('[data-cy="ResearchComments: button open-comments"]')
.first()
.click()
cy.get('[data-cy="comment"]').should('have.length.gte', 1)
cy.get('[data-cy="comment-submit"]').should('be.disabled')
})

it('using URL', () => {
cy.visit('/research/qwerty#update-12-comment:abc123')
cy.get('[data-cy="comment"]').should('have.length.gte', 1)
cy.get('[data-cy="comment"]').should('be.inViewport')
})
})

describe('[By Authenticated]', () => {
it('has active comment button for logged in user', () => {
cy.login('howto_creator@test.com', 'test1234')
cy.visit('/research/qwerty')
cy.get('[data-cy="ResearchComments: button open-comments"]').click()
cy.get('[data-cy="ResearchComments: button open-comments"]')
.first()
.click()
cy.get('[data-cy="comments-form"]').type('An example comment')
cy.get('[data-cy="comment-submit"]').should('not.be.disabled')
})

it('allows logged in user to post a commment', () => {
cy.login('howto_creator@test.com', 'test1234')
cy.visit('/research/qwerty')
cy.get('[data-cy="ResearchComments: button open-comments"]').click()
cy.get('[data-cy="ResearchComments: button open-comments"]')
.first()
.click()
cy.get('[data-cy="comments-form"]').type('An example comment')
cy.get('[data-cy="comment-submit"]').click()

Expand All @@ -34,7 +48,9 @@ describe('[Research]', () => {
it('allows comment author to edit', () => {
cy.login('howto_creator@test.com', 'test1234')
cy.visit('/research/qwerty')
cy.get('[data-cy="ResearchComments: button open-comments"]').click()
cy.get('[data-cy="ResearchComments: button open-comments"]')
.first()
.click()
cy.get('[data-cy="comment"]').should('have.length.gte', 2)
cy.get('[data-cy="comment"]')
.last()
Expand All @@ -45,7 +61,9 @@ describe('[Research]', () => {
it('allows comment author to delete', () => {
cy.login('howto_creator@test.com', 'test1234')
cy.visit('/research/qwerty')
cy.get('[data-cy="ResearchComments: button open-comments"]').click()
cy.get('[data-cy="ResearchComments: button open-comments"]')
.first()
.click()
cy.get('[data-cy="comment"]').should('have.length.gte', 2)
cy.get('[data-cy="comment"]')
.last()
Expand Down
17 changes: 17 additions & 0 deletions packages/cypress/src/support/custom-assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ declare global {
}
}

chai.use((chaiObj, utils) => {
function assertIsInViewport() {
const subject = this._obj

const bottom = Cypress.$(cy.state('window')).height()
const width = Cypress.$(cy.state('window')).width()
const rect = subject[0].getBoundingClientRect()

expect(
rect.top < bottom && rect.right <= width && rect.left >= 0,
'expected #{this} to be in the viewport',
).to.eq(true)
}

chaiObj.Assertion.addMethod('inViewport', assertIsInViewport)
})

const eqHowto = (chaiObj, utils) => {
function compare(this: any, expected: any) {
const subject: IHowto = this._obj
Expand Down
Loading