-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanager.cy.js
146 lines (133 loc) · 5.25 KB
/
manager.cy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { faker } from '@faker-js/faker'
import { customer } from '../fixtures/validCustomers'
describe('Performing tests at manager page', () => {
beforeEach(() => {
cy.visit(Cypress.config('baseUrl') + '/#/manager')
})
it('Check main elements visibility', () => {
cy.findByRole('button', { name: /add customer/i }).should('be.visible')
cy.findByRole('button', { name: /open account/i }).should('be.visible')
cy.findByRole('button', { name: /customers/i }).should('be.visible')
})
it('Check add customer functionality with good data and verify its persistence', () => {
const randomCustomer = {
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
postCode: faker.address.zipCode(),
}
cy.findByRole('button', { name: /add customer/i }).click()
cy.fillFormCustomer(
randomCustomer.firstName,
randomCustomer.lastName,
randomCustomer.postCode
)
cy.findAllByRole('button', { name: /add customer/i })
.last()
.click()
cy.on('window:alert', (text) => {
expect(text).to.contains('Customer added successfully with customer id')
})
// It should be another 'it' block, but when I change page, local storage is cleared
cy.getLocalStorage('User').then((data) => {
const user = JSON.parse(data)
const length = Object.keys(user).length
expect(user[length].fName).to.equal(randomCustomer.firstName)
expect(user[length].lName).to.equal(randomCustomer.lastName)
})
})
it('Check add customer functionality with empty fields', () => {
cy.findByRole('button', { name: /add customer/i }).click()
cy.findByPlaceholderText(/First Name/i)
.invoke('prop', 'validity')
.should('deep.include', {
valid: false,
})
cy.findByPlaceholderText(/Last Name/i)
.invoke('prop', 'validity')
.should('deep.include', {
valid: false,
})
cy.findByPlaceholderText(/post code/i)
.invoke('prop', 'validity')
.should('deep.include', {
valid: false,
})
})
it('Check add customer with blank spaces as data', () => {
cy.findByRole('button', { name: /add customer/i }).click()
cy.findByPlaceholderText(/First Name/i).type(' ')
cy.findByPlaceholderText(/Last Name/i).type(' ')
cy.findByPlaceholderText(/post code/i).type(' ')
cy.findAllByRole('button', { name: /add customer/i })
.last()
.click()
cy.on('window:alert', (text) => {
// This error message should be changed in the future
expect(text).to.contains(
'Please check the details. Customer may be duplicate.'
)
})
})
it.skip('[Issue #1 opened] Check add customer with uncommon input data', () => {
cy.findByRole('button', { name: /add customer/i }).click()
cy.fillFormCustomer('%%¨$#@$%*(', '*', 'letters as zip code')
cy.findAllByRole('button', { name: /add customer/i })
.last()
.click()
cy.on('window:alert', (text) => {
// Cypress ins't doing this assertion correctly
expect(text).not.contains('Customer added successfully with customer id')
})
})
it.skip('[Issue #1 opened] Check add customer with short input data (1 character only)', () => {
cy.findByRole('button', { name: /add customer/i }).click()
cy.fillFormCustomer('&', '$', '#')
cy.findAllByRole('button', { name: /add customer/i })
.last()
.click()
cy.on('window:alert', (text) => {
// Cypress ins't doing this assertion correctly
expect(text).not.contains('Customer added successfully with customer id')
})
})
it('Check Customer search field', () => {
cy.findByRole('button', { name: /Customers/i }).click()
cy.findByPlaceholderText(/search customer/i).type(customer[0].fName)
cy.findByText(customer[0].fName).should('be.visible')
})
it('Check delete customer functionality', () => {
cy.findByRole('button', { name: /Customers/i }).click()
cy.findByPlaceholderText(/search customer/i).type(customer[0].fName)
cy.findByRole('button', { name: /delete/i }).click()
cy.findByPlaceholderText(/search customer/i)
.clear()
.type(customer[0].fName)
cy.findByText(customer[0].fName).should('not.exist')
})
it('Check open account without select a customer and/or a currency', () => {
cy.findByRole('button', { name: /Open account/i }).click()
cy.findByRole('button', { name: /Process/i }).click()
cy.get('#userSelect')
.invoke('prop', 'validity')
.should('deep.include', { valid: false })
cy.get('#currency')
.invoke('prop', 'validity')
.should('deep.include', { valid: false })
})
it('Check open account correctly selecting customer and currency', () => {
const curr = 'Dollar'
cy.findByRole('button', { name: /Open Account/i }).click()
cy.get('#userSelect').select(customer[0].name)
cy.get('#currency').select(curr)
cy.findByRole('button', { name: /Process/i }).click()
cy.on('window:alert', (text) => {
expect(text).to.contains('Account created successfully')
})
cy.getLocalStorage('Account').then((data) => {
const account = JSON.parse(data)
const last = Object.keys(account).pop()
expect(parseInt(account[last].userId)).to.eq(customer[0].id)
expect(account[last].currency).to.equal(curr)
})
})
})