-
Notifications
You must be signed in to change notification settings - Fork 0
/
Integration.spec.js
217 lines (198 loc) · 8.32 KB
/
Integration.spec.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/* eslint-disable jest/valid-expect-in-promise */
/* eslint-disable jest/valid-expect */
/* eslint-disable no-undef */
describe('Integration tests', () => {
beforeEach(() => {
cy.visit('http://localhost:3000')
});
it('has a book title input', () => {
cy.get('#FindBookForm-Form')
.find('input#FindBookForm-Input-BookTitle')
.should('have.attr', 'placeholder', 'Enter a book title...');
});
it('has subject input', () => {
cy.get('#FindBookForm-Form')
.find('input#FindBookForm-Input-Subject')
.should('have.attr', 'placeholder', 'Enter subject...');
});
it('has author name input', () => {
cy.get('#FindBookForm-Form')
.find('input#FindBookForm-Input-AuthorName')
.should('have.attr', 'placeholder', 'Enter author name...');
});
it('has select language select', () => {
cy.get('#FindBookForm-Select-Language')
.should('have.length', 1);
});
it('should get data from API via book title', () => {
cy.request('https://www.googleapis.com/books/v1/volumes?q=Potop&maxResults=10&startIndex=0&key=AIzaSyCpVyXQfzzvrymmeAp2vcxD3GRVyZLXeok')
.then((response) => {
expect(response.status).to.eq(200);
expect(response.body.items).to.have.length(10);
expect(response.body.items[0].volumeInfo.title).to.contain('Potop');
expect(response.body.items[3].volumeInfo.title).to.contain('Potop');
expect(response.body.items[5].volumeInfo.title).to.contain('Potop');
expect(response.body.items[8].volumeInfo.title).to.contain('Potop');
})
});
it('should get data from API via subject', () => {
cy.request('https://www.googleapis.com/books/v1/volumes?q="Medicine"&maxResults=10&startIndex=0&key=AIzaSyCpVyXQfzzvrymmeAp2vcxD3GRVyZLXeok')
.then((response) => {
expect(response.status).to.eq(200);
expect(response.body.items).to.have.length(10);
expect(response.body.items[0].volumeInfo.categories).to.contain('Medical');
expect(response.body.items[4].volumeInfo.categories).to.contain('Medical');
expect(response.body.items[8].volumeInfo.categories).to.contain('Medical');
})
});
it('should get data from API via language', () => {
cy.request('https://www.googleapis.com/books/v1/volumes?q=%22pl%22&maxResults=10&startIndex=0&key=AIzaSyCpVyXQfzzvrymmeAp2vcxD3GRVyZLXeok')
.then((response) => {
expect(response.status).to.eq(200);
expect(response.body.items).to.have.length(10);
expect(response.body.items[1].volumeInfo.language).to.contain('pl');
expect(response.body.items[4].volumeInfo.language).to.contain('pl');
expect(response.body.items[5].volumeInfo.language).to.contain('pl');
expect(response.body.items[9].volumeInfo.language).to.contain('pl');
})
});
it('should get data from API with all parameters', () => {
cy.request('https://www.googleapis.com/books/v1/volumes?q=intitle:%22DNA%22+subject:%22Medical%22+%24inauthor:%22McCabe%22+en&key=AIzaSyCpVyXQfzzvrymmeAp2vcxD3GRVyZLXeok')
.then((response) => {
expect(response.status).to.eq(200);
expect(response.body.items).to.have.length(1);
expect(response.body.items[0].volumeInfo.title).to.contain('DNA');
expect(response.body.items[0].volumeInfo.categories).to.contain('Medical');
expect(response.body.items[0].volumeInfo.authors[0]).to.contain('McCabe');
expect(response.body.items[0].volumeInfo.language).to.contain('en');
})
});
it('should get data by book title via title input', () => {
cy.get('#FindBookForm-Form')
.find('#FindBookForm-Input-BookTitle')
.type('Stary człowiek i morze');
cy.get('#FindBookForm-Submit-Button').click();
cy.get('#BookCard-Container').should('have.length', 1);
cy.get('#BookCard-Container')
.eq(0)
.find('.BookCard-Row > .BookCard-Header > div > h2 > i > b').contains("Stary człowiek i morze");
});
it('should get data by subject via subject input', () => {
cy.get('#FindBookForm-Form')
.find('#FindBookForm-Input-Subject')
.type('Medicine');
cy.get('#FindBookForm-Submit-Button').click();
cy.get('.BookContainer-Column')
.eq(2)
.find('div > #BookCard-Container')
.should('have.length', 10);
cy.get('#BookCard-Container')
.eq(0)
.find('.BookCard-Row > .BookCard-Header > div > h2 > i > b').contains("Gross Anatomy");
});
it('should get data by author via author name input', () => {
cy.get('#FindBookForm-Form')
.find('#FindBookForm-Input-AuthorName')
.type('Joseph Conrad');
cy.get('#FindBookForm-Submit-Button').click();
cy.get('.BookContainer-Column')
.eq(2)
.find('div > #BookCard-Container')
.should('have.length', 10);
cy.get('#BookCard-Container')
.eq(0)
.find('.BookCard-Row > .BookCard-Header > div > h2 > i > b').contains("Placówka postępu");
});
it('should get data by language via language select', () => {
cy.get('#FindBookForm-Form')
.find('#FindBookForm-Select-Language')
.click();
cy.get('#react-select-FindBookForm-Select-Language-option-13')
.click();
cy.get('#FindBookForm-Submit-Button').click();
cy.get('.BookContainer-Column')
.eq(2)
.find('div > #BookCard-Container')
.should('have.length', 10);
cy.get('#col-d1-9 > .BookCard-Container > .BookCard-Row > .BookCard-Header > div > h2 > i > b').contains("Web.de");
});
it('should get data with all parameters', () => {
cy.get('#FindBookForm-Input-BookTitle')
.type('DNA');
cy.get('#FindBookForm-Input-AuthorName')
.type('McCabe');
cy.get('#FindBookForm-Input-Subject')
.type('Medical');
cy.get('#FindBookForm-Select-Language')
.click();
cy.get('#react-select-FindBookForm-Select-Language-option-10')
.click();
cy.get('#FindBookForm-Submit-Button').click();
cy.get('.BookContainer-Column')
.eq(2)
.find('div > #BookCard-Container')
.should('have.length', 1);
cy.get('#BookCard-Container')
.eq(0)
.find('.BookCard-Row > .BookCard-Header > div > h2 > i > b').contains("DNA");
cy.get('#BookCard-Container')
.eq(0)
.find('.BookCard-Row > .BookCard-Header > h3').contains("Medical");
});
it('should show noData component with wrong data', () => {
cy.get('#FindBookForm-Form')
.find('#FindBookForm-Input-Subject')
.type('bladasadnad');
cy.get('#FindBookForm-Submit-Button').click();
cy.get('img').should('have.class', 'NoData-Image');
});
it('should check new search after searching with wrong data', () => {
cy.get('#FindBookForm-Form')
.find('#FindBookForm-Input-Subject')
.type('bladasadnad');
cy.get('#FindBookForm-Submit-Button').click();
cy.get('#NoData-Button-NewSearch').click();
cy.get('#FindBookForm-Input-BookTitle')
.type('DNA');
cy.get('#FindBookForm-Input-AuthorName')
.type('McCabe');
cy.get('#FindBookForm-Input-Subject')
.type('Medical');
cy.get('#FindBookForm-Select-Language')
.click();
cy.get('#react-select-FindBookForm-Select-Language-option-10')
.click();
cy.get('#FindBookForm-Submit-Button').click();
cy.get('.BookContainer-Column')
.eq(2)
.find('div > #BookCard-Container')
.should('have.length', 1);
cy.get('#BookCard-Container')
.eq(0)
.find('.BookCard-Row > .BookCard-Header > div > h2 > i > b').contains("DNA");
cy.get('#BookCard-Container')
.eq(0)
.find('.BookCard-Row > .BookCard-Header > h3').contains("Medical");
});
it('should find new data', () => {
cy.get('#FindBookForm-Form')
.find('#FindBookForm-Input-Subject')
.type('Medicine');
cy.get('#FindBookForm-Submit-Button').click();
cy.get('.BookContainer-Column')
.eq(2)
.find('div > #BookCard-Container')
.should('have.length', 10);
cy.get('#BookCard-Container')
.eq(0)
.find('.BookCard-Row > .BookCard-Header > div > h2 > i > b').contains("Gross Anatomy");
cy.get('#BookContainer-Button-NewSearch').click();
cy.get('#FindBookForm-Input-BookTitle')
.type('Stary człowiek i morze');
cy.get('#FindBookForm-Submit-Button').click();
cy.get('#BookCard-Container').should('have.length', 1);
cy.get('#BookCard-Container')
.eq(0)
.find('.BookCard-Row > .BookCard-Header > div > h2 > i > b').contains("Stary człowiek i morze");
});
})