/
init.cy.ts
57 lines (54 loc) · 1.28 KB
/
init.cy.ts
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
const testQuery = `{
longDescriptionType {
id
image
hasArgs
test {
id
isTest
__typename
}
}
}`;
const mockSuccess = {
data: {
longDescriptionType: {
id: 'abc123',
image: '/images/logo.svg',
hasArgs: '{"defaultValue":"test default value"}',
test: {
id: 'abc123',
isTest: true,
__typename: 'Test',
},
},
},
};
describe('GraphiQL On Initialization', () => {
it('Renders default value without error', () => {
const containers = [
'#graphiql',
'.graphiql-container',
'.graphiql-sessions',
'.graphiql-editors',
'.graphiql-response',
'.graphiql-editor-tool',
];
cy.visit('/');
cy.get('.graphiql-query-editor').contains('# Welcome to GraphiQL');
for (const cSelector of containers) {
cy.get(cSelector).should('be.visible');
}
});
it('Executes a GraphQL query over HTTP that has the expected result', () => {
cy.visitWithOp({ query: testQuery });
cy.clickExecuteQuery();
cy.assertQueryResult(mockSuccess);
});
it('Shows the expected error when the schema is invalid', () => {
cy.visit('/?bad=true');
cy.get('section.result-window').should(element => {
expect(element.get(0).innerText).to.contain('Names must');
});
});
});