-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathgraphql-apiml.cy.js
More file actions
208 lines (139 loc) · 6.54 KB
/
graphql-apiml.cy.js
File metadata and controls
208 lines (139 loc) · 6.54 KB
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
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/
/* eslint-disable no-undef */
/// <reference types="Cypress" />
const expectedKeyWords = ['name', 'getAllBooks', 'Effective Java', "Hitchhiker's Guide to the Galaxy", 'Down Under'];
function login() {
cy.visit(`${Cypress.env('catalogHomePage')}/index.html#/login`);
const username = Cypress.env('username');
const password = Cypress.env('password');
cy.get('button[type="submit"]').as('submitButton');
cy.get('#username').type(username);
cy.get('input[name="password"]').type(password);
cy.get('@submitButton').click();
}
describe('>>> GraphiQL Playground page test', () => {
it('Detail page test', () => {
login();
cy.get('#grid-container').contains('Discoverable client with GraphQL').click();
cy.url().should('contain', '/service/graphqlclient');
cy.get('#go-back-button').should('exist');
cy.get('.api-description-container').should('exist');
});
it('Should display the service information in the detail page', () => {
login();
cy.contains('Discoverable client with GraphQL').click();
cy.visit(`${Cypress.env('catalogHomePage')}/index.html#/service/graphqlclient`);
cy.get('.tabs-container').should('not.exist');
cy.get('.serviceTab').should('exist').and('contain', 'Discoverable client with GraphQL');
cy.contains('Service Homepage').should('exist');
cy.contains('Swagger/OpenAPI JSON Document').should('not.exist');
cy.contains('Service ID and Version').should('not.exist');
cy.get('#version-div').should('not.exist');
cy.contains('Sample for data demonstration using GraphiQL Playround.');
cy.get('#swagger-label').should('contain', 'GraphQL');
cy.get(`a[href="#/service/graphqlclient"]`).should('have.class', 'Mui-selected');
});
it('Should display the GraphiQL Playground', () => {
login();
cy.contains('Discoverable client with GraphQL').click();
cy.get('#graphiql-container').should('exist');
const query = '{ "query": "{ hello }" }';
cy.contains('# Write your query here!') // clear out the placeholder/default text
.type(query, {parseSpecialCharSequences: false});
});
it('Should run query', () => {
login();
cy.contains('Discoverable client with GraphQL').click();
cy.contains('# Write your query here!').click()
.type('{ctrl}a')
.type('{del}')
const query = 'query {' + 'getAllBooks{' + 'name' + ' }';
cy.get('.graphiql-editor').first()
.type(query, {parseSpecialCharSequences: false})
cy.get('.graphiql-execute-button').click();
cy.get('span.cm-def').should('contain.text', 'data');
cy.get('.result-window').then(($container) => {
const text = $container.text().trim();
expectedKeyWords.forEach((word) => {
expect(text).to.include(word);
});
});
});
it('Should add and remove a tab in the playground', () => {
login();
cy.contains('Discoverable client with GraphQL').click();
cy.get('.graphiql-un-styled.graphiql-tab-add').click();
cy.get('#graphiql-session-tab-1').should('exist').should('contain.text', 'My Query 2');
cy.get('.graphiql-un-styled.graphiql-tab-close').last().click();
cy.get('#graphiql-session-tab-1').should('not.exist');
});
it('Should open the Documentation Explorer', () => {
login();
cy.contains('Discoverable client with GraphQL').click();
cy.get('[aria-label="Show Documentation Explorer"]').click();
cy.get('.graphiql-doc-explorer').should('be.visible');
cy.get('.graphiql-markdown-description').should(
'contain',
'A GraphQL schema provides a root type for each kind of operation.'
);
});
it('Should open the History window', () => {
login();
cy.contains('Discoverable client with GraphQL').click();
cy.get('[aria-label="Show History"]').click();
cy.get('.graphiql-history').should('be.visible').should('contain', 'History');
});
it('Refetch button is present', () => {
login();
cy.contains('Discoverable client with GraphQL').click();
cy.get('[aria-label="Re-fetch GraphQL schema"]').should('be.visible');
});
it('Should open the short keys dialog', () => {
login();
cy.contains('Discoverable client with GraphQL').click();
cy.get('[aria-label="Open short keys dialog"]').click();
cy.get('.graphiql-dialog-header h2').should('be.visible').should('contain', 'Short Keys');
});
it('Should open the settings keys dialog', () => {
login();
cy.contains('Discoverable client with GraphQL').click();
cy.get('[aria-label="Open settings dialog"]').click();
cy.get('.graphiql-dialog-header h2').should('be.visible').should('contain', 'Settings');
});
it('Variable usage', () => {
login();
cy.contains('Discoverable client with GraphQL').click();
cy.get('[data-name="variables"]').click();
cy.get('.graphiql-editor-tool').should('be.visible');
const variable = '{"id" :"book-1"}';
cy.get('.graphiql-editor-tool .cm-s-graphiql').first().as('variablesInput').click();
cy.get('@variablesInput').first()
.type(variable, {parseSpecialCharSequences: false});
cy.get('.graphiql-editor-tool').then(($container) => {
const text = $container.text().trim();
expect(text).to.include(variable);
});
});
it('Variable usage', () => {
login();
cy.contains('Discoverable client with GraphQL').click();
cy.get('[data-name="headers"]').click();
cy.get('.graphiql-editor-tool').should('be.visible');
const header = '{"X-Custom-Header": "CustomValue"}';
cy.get('.graphiql-editor-tool .cm-s-graphiql').last().as('headersInput').click();
cy.get('@headersInput').first()
.type(header, {parseSpecialCharSequences: false});
cy.get('.graphiql-editor-tool').then(($container) => {
const text = $container.text().trim();
expect(text).to.include(header);
});
});
});