From 036acdd61aae18d63c05610bdf5db70c7f0d751f Mon Sep 17 00:00:00 2001 From: IdoLeshkowitz Date: Tue, 10 Jan 2023 15:45:07 +0200 Subject: [PATCH 1/3] deleteUser --- src/components/users-table/users-table.cy.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/components/users-table/users-table.cy.tsx b/src/components/users-table/users-table.cy.tsx index e69de29..0f0e19f 100644 --- a/src/components/users-table/users-table.cy.tsx +++ b/src/components/users-table/users-table.cy.tsx @@ -0,0 +1,14 @@ +import UsersTable from "./users-table"; + + +describe('users-table', () => { + it('should delete user when clicking on delete button', () => { + const removeUser = cy.spy().as('removeUser'); + const users = [ + {id: 1, email: 'a@a', fname: 'a', lname: 'a'}, + ]; + cy.mount(); + cy.get('button').click(); + cy.get('@removeUser').should('have.been.calledWith', {id: 1, email: 'a@a', fname: 'a', lname: 'a'}); + }); +}) \ No newline at end of file From 32815a67cf2b72205ffb685fb80d57a84a1e82cd Mon Sep 17 00:00:00 2001 From: IdoLeshkowitz Date: Tue, 10 Jan 2023 15:52:58 +0200 Subject: [PATCH 2/3] added more users to delete test --- src/components/users-table/users-table.cy.tsx | 16 +++++++++++++++- src/components/users-table/users-table.tsx | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/users-table/users-table.cy.tsx b/src/components/users-table/users-table.cy.tsx index 0f0e19f..805ab4e 100644 --- a/src/components/users-table/users-table.cy.tsx +++ b/src/components/users-table/users-table.cy.tsx @@ -6,9 +6,23 @@ describe('users-table', () => { const removeUser = cy.spy().as('removeUser'); const users = [ {id: 1, email: 'a@a', fname: 'a', lname: 'a'}, + {id: 2, email: 'b@b', fname: 'b', lname: 'b'}, + {id: 3, email: 'c@c', fname: 'c', lname: 'c'}, ]; cy.mount(); - cy.get('button').click(); + cy.get(`button[name=${users[0].id}]`).click(); cy.get('@removeUser').should('have.been.calledWith', {id: 1, email: 'a@a', fname: 'a', lname: 'a'}); }); + it ('should display 5 rows', () => { + const users = [ + {id: 1, email: 'a@a', fname: 'a', lname: 'a'}, + {id: 2, email: 'b@b', fname: 'b', lname: 'b'}, + {id: 3, email: 'c@c', fname: 'c', lname: 'c'}, + {id: 4, email: 'd@d', fname: 'd', lname: 'd'}, + {id: 5, email: 'e@e', fname: 'e', lname: 'e'}, + ]; + cy.mount( {}}/>); + cy.get('tr').should('have.length', 6); + }) + }) \ No newline at end of file diff --git a/src/components/users-table/users-table.tsx b/src/components/users-table/users-table.tsx index 093824f..3811ade 100644 --- a/src/components/users-table/users-table.tsx +++ b/src/components/users-table/users-table.tsx @@ -25,7 +25,7 @@ export default function UsersTable({users, removeUser}: UsersTableProps) { {u.fname} {u.lname} - + ))} From a9c8423bc9ad392188f7dea6625ca8f72b5616b3 Mon Sep 17 00:00:00 2001 From: IdoLeshkowitz Date: Tue, 10 Jan 2023 16:06:36 +0200 Subject: [PATCH 3/3] added td counter --- src/components/users-table/users-table.cy.tsx | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/components/users-table/users-table.cy.tsx b/src/components/users-table/users-table.cy.tsx index 805ab4e..2f0ea87 100644 --- a/src/components/users-table/users-table.cy.tsx +++ b/src/components/users-table/users-table.cy.tsx @@ -13,7 +13,7 @@ describe('users-table', () => { cy.get(`button[name=${users[0].id}]`).click(); cy.get('@removeUser').should('have.been.calledWith', {id: 1, email: 'a@a', fname: 'a', lname: 'a'}); }); - it ('should display 5 rows', () => { + it('should display 5 rows', () => { const users = [ {id: 1, email: 'a@a', fname: 'a', lname: 'a'}, {id: 2, email: 'b@b', fname: 'b', lname: 'b'}, @@ -21,8 +21,21 @@ describe('users-table', () => { {id: 4, email: 'd@d', fname: 'd', lname: 'd'}, {id: 5, email: 'e@e', fname: 'e', lname: 'e'}, ]; - cy.mount( {}}/>); + cy.mount( { + }}/>); cy.get('tr').should('have.length', 6); }) - -}) \ No newline at end of file + it('should display 6 td in each row', () => { + const users = [ + {id: 1, email: 'a@a', fname: 'a', lname: 'a'}, + {id: 2, email: 'b@b', fname: 'b', lname: 'b'}, + {id: 3, email: 'c@c', fname: 'c', lname: 'c'}, + {id: 4, email: 'd@d', fname: 'd', lname: 'd'}, + {id: 5, email: 'e@e', fname: 'e', lname: 'e'}, + ]; + cy.mount( { + }}/>); + //check that each tr has 6 td + cy.get('table').find('tr').its('length').should('eq', 6); + }) +}); \ No newline at end of file