Skip to content

Commit

Permalink
✅ Add tests and fix bug
Browse files Browse the repository at this point in the history
Add test skeletons and fix not being able to amend dates properly.

Unforuntately due to a limitation / bug in the
datepicker being used it was not possible to
start with the existing dates the user had
selected previously. Instead the user has to
pick their date afresh each time.
  • Loading branch information
homostellaris committed Feb 19, 2024
1 parent 6cefbd3 commit 1650f02
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 83 deletions.
4 changes: 2 additions & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'cypress'
import plugins from './cypress/plugins/index.cjs'
import {defineConfig} from 'cypress'
import plugins from './cypress/plugins/index.js'

export default defineConfig({
e2e: {
Expand Down
99 changes: 81 additions & 18 deletions cypress/e2e/index.cy.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,87 @@
it('should work', () => {
cy.visit('/')
cy.get('#name').should('be.focused').type('Dan')
cy.contains('button', 'NEXT').click()
before(() => {
cy.clock()
})

describe('when an organiser wants to schedule a social', () => {
it('they can do so', () => {
cy.visit('/')
cy.get('#name').should('be.focused').type('Dan')
cy.contains('button', 'NEXT').click()

cy.url().should('include', '/you')
cy.get('.calendar-date').last().click()
cy.contains('button', 'NEXT').click()

cy.url().should('include', '/everyone')
cy.get('.invitee').should('contain.text', 'Dan')
cy.get('.streaming-status').should('contain.text', 'Live-streaming updates')

cy.task('updateSocial', '1970-01-02')
cy.reload() // This shouldn't be necessary but HTTP2 isn't supported by Cypress so streaming doesn't work
cy.get('.invitee').should('contain.text', 'Max')

cy.wait(1000) // Fix weird re-render that changes date format and resets checked state
cy.get('#best-dates [type="radio"]').first().check()
cy.contains('button', 'NEXT').click()

cy.url().should('include', '/decision')
cy.contains('Your social is on')
})
})

cy.url().should('include', '/you')
cy.get('.calendar-date').last().click()
cy.contains('button', 'NEXT').click()
describe('when an invitee has chosen their availability', () => {
beforeEach(() => {
cy.task('createSocial', {
invitees: {
organiserID: {
dates: ['1970-01-02', '1970-01-03', '1970-01-04'],
name: 'Olaf',
},
inviteeID: {
dates: ['1970-01-02', '1970-01-03'],
name: 'Ingrid',
},
},
organizer: 'organiserID',
}).as('social')
cy.setCookie('userId', 'inviteeID')
})

cy.url().should('include', '/everyone')
cy.get('.invitee').should('contain.text', 'Dan')
cy.get('.streaming-status').should('contain.text', 'Live-streaming updates')
it('they can go back and amend it', function () {
cy.visit(`/${this.social.id}/everyone`)
cy.contains('BACK').click()

cy.task('updateSocial', '2025-01-01')
cy.reload() // This shouldn't be necessary but HTTP2 isn't supported by Cypress so streaming doesn't work
cy.get('.invitee').should('contain.text', 'Max')
// Force a wait for the page to re-render, think this may be caused by the SvelteKit server does intiial render in current time.
cy.contains('January 1970').should('exist')
cy.contains('.calendar-date', /^3$/).click()
cy.contains('.calendar-date', /^4$/).click()

cy.wait(1000) // Fix weird re-render that changes date format and resets checked state
cy.get('#best-dates [type="radio"]').first().check()
cy.contains('button', 'NEXT').click()
cy.contains('NEXT').click()
cy.get('#best-dates')
.table()
.should('deep.equal', [
['', 'Rank', 'Date', 'Available Invitees', 'Invitees Total'],
['', '1', 'Saturday, 3 January', '🤴🧙‍♂️', '2/2'],
['', '2', 'Sunday, 4 January', '🤴🧙‍♂️', '2/2'],
['', '3', 'Friday, 2 January', '🤴', '1/2'],
])
})
})

describe('when a decision has been made', () => {
it.skip('anyone can go back and amend it', () => {})

it.skip("redirects invitees who haven't seen it yet", () => {})
})

describe('when an invitee joins the social', () => {
// Can't test this until Cypress supports HTTP/2.
it.skip('updates the everyone page in real time', () => {})

// Not sure how to test this yet.
it.skip('send push notifications to invitees who have enabled them', () => {})
})

cy.url().should('include', '/decision')
cy.contains('Your social is on')
describe('when an invitee from another timezone joins the social', () => {
it.skip('shows them the same dates as others disregarding timezones entirely', () => {})
})
59 changes: 0 additions & 59 deletions cypress/plugins/index.cjs

This file was deleted.

2 changes: 2 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

import 'cypress-map/commands/table'
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@sveltejs/kit": "^1.0.0-next.325",
"ava": "^4.0.0",
"cypress": "^13.6.4",
"cypress-map": "^1.30.0",
"dotenv": "^16.4.2",
"fauna-shell": "^0.13.0",
"gitmoji-cli": "^9.1.0",
Expand Down
4 changes: 1 addition & 3 deletions src/routes/[socialId=socialId]/you.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ export async function put({locals, params, request}) {
data: {
invitees: {
[locals.userId]: {
dates: dates.map(date =>
q.Date(date),
),
dates: dates.map(date => q.Date(date)),
},
},
},
Expand Down
5 changes: 4 additions & 1 deletion src/routes/[socialId=socialId]/you.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
let organizer = social.invitees[social.organizer]
let name = $page.url.searchParams.get('name') || user.name
let loading
let dates = user.dates || []
// Datepicker doesn't update bound array properly so unfortunately need to start with a fresh array everytime they return here.
// let dates = user.dates || []
let dates = []
</script>

<svelte:head>
Expand Down

0 comments on commit 1650f02

Please sign in to comment.