Skip to content

Commit

Permalink
✅ Improve assertions
Browse files Browse the repository at this point in the history
And fail to test drag & drop
  • Loading branch information
homostellaris committed Aug 22, 2024
1 parent ab427a0 commit 849139c
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 4 deletions.
1 change: 1 addition & 0 deletions components/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ export const Important = ({ onLoad }: { onLoad: () => void }) => {
<IonReorderGroup
disabled={false}
onIonItemReorder={async event => {
console.log({ event })
// We don't use this to reorder for us because it results in a flash of 'unordered' content.
// Instead we re-order right away, calculate the new order ourselves, and update the DB.
event.detail.complete()
Expand Down
77 changes: 76 additions & 1 deletion cypress/e2e/spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ it('works', () => {
cy.contains('Confirm').click()
})

assertLists([], [], ['take the bins out'])

cy.get('#view-menu-button').click()
cy.contains('ion-button', 'Edit roles')
// For some reason clicking edit roles doesn't work so we hard-navigate
Expand Down Expand Up @@ -73,6 +75,12 @@ it('works', () => {
})
cy.get('ion-modal').contains('Confirm').click()

assertLists(
[],
[],
['plan birthday day out', 'be silly together', 'take the bins out'],
)

cy.get('#icebox').contains('take the bins out').click()
cy.get('#todo-action-sheet').contains('Move to important').click()
cy.get('#important').contains('take the bins out')
Expand All @@ -88,9 +96,76 @@ it('works', () => {
cy.get('#important').contains('plan birthday day out')
cy.get('#todo-action-sheet').should('not.exist')

assertLists(
[],
['take the bins out', 'be silly together', 'plan birthday day out'],
[],
)

// reorderImportantTodo(0, 2)
// cy.get('#important .todo')
// .first()
// .find('ion-reorder')
// .shadow()
// .find('.reorder-icon')
// .shadow()
// .find('svg')
// .drag('#important .todo:nth-child(3)')
// assertLists(
// [],
// ['be silly together', 'plan birthday day out', 'take the bins out'],
// [],
// )
// reorderImportantTodo(1, -1)
// assertLists(
// [],
// ['plan birthday day out', 'be silly together', 'take the bins out'],
// [],
// )
// cy.reload()
// assertLists(
// [],
// ['plan birthday day out', 'be silly together', 'take the bins out'],
// [],
// )

cy.get('#important')
.contains('.todo', 'take the bins out')
.find('ion-checkbox')
.click()
cy.get('#log').contains('take the bins out')

assertLists(
['take the bins out'],
['be silly together', 'plan birthday day out'],
[],
)
})

function assertLists(log: string[], important: string[], icebox: string[]) {
cy.get('#log .todo')
.should('have.length', log.length)
.invoke('toArray')
.invoke('map', item => item.textContent)
.should('deep.equal', log)
cy.get('#important .todo')
.should('have.length', important.length)
.invoke('toArray')
.invoke('map', item => item.textContent)
.should('deep.equal', important)
cy.get('#icebox .todo')
.should('have.length', icebox.length)
.invoke('toArray')
.invoke('map', item => item.textContent)
.should('deep.equal', icebox)
}

function reorderImportantTodo(todoIndex: number, places: number) {
cy.get(`#important .todo`)
.eq(todoIndex)
.find('ion-reorder')
.shadow()
.find('.reorder-icon')
.trigger('mousedown', { which: 1 })
.trigger('mousemove', { screenX: 936, screenY: 287 + 49 })
.trigger('mouseup')
}
4 changes: 3 additions & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
// }

import '@4tw/cypress-drag-drop'
11 changes: 11 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 @@ -56,6 +56,7 @@
"react-router-dom": "5.3.4"
},
"devDependencies": {
"@4tw/cypress-drag-drop": "^2.2.5",
"@capacitor/cli": "^6.0.0",
"@types/node": "20.11.25",
"@types/react": "18.2.64",
Expand Down
8 changes: 6 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
"name": "next"
}
],
"strictNullChecks": true
"strictNullChecks": true,
"types": [
"cypress",
"@4tw/cypress-drag-drop"
]
},
"include": [
"next-env.d.ts",
Expand All @@ -33,5 +37,5 @@
],
"exclude": [
"node_modules"
]
],
}

0 comments on commit 849139c

Please sign in to comment.