/
topic.spec.ts
167 lines (146 loc) · 5.32 KB
/
topic.spec.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
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
import { entityItemSelector } from '../../support/commands';
import {
entityTableSelector,
entityDetailsButtonSelector,
entityDetailsBackButtonSelector,
entityCreateButtonSelector,
entityCreateSaveButtonSelector,
entityCreateCancelButtonSelector,
entityEditButtonSelector,
entityDeleteButtonSelector,
entityConfirmDeleteButtonSelector,
} from '../../support/entity';
describe('Topic e2e test', () => {
const topicPageUrl = '/topic';
const topicPageUrlPattern = new RegExp('/topic(\\?.*)?$');
const username = Cypress.env('E2E_USERNAME') ?? 'user';
const password = Cypress.env('E2E_PASSWORD') ?? 'user';
const topicSample = { title: 'Personal portals AI', description: 'Profit-focused' };
let topic: any;
beforeEach(() => {
cy.login(username, password);
});
beforeEach(() => {
cy.intercept('GET', '/api/topics+(?*|)').as('entitiesRequest');
cy.intercept('POST', '/api/topics').as('postEntityRequest');
cy.intercept('DELETE', '/api/topics/*').as('deleteEntityRequest');
});
afterEach(() => {
if (topic) {
cy.authenticatedRequest({
method: 'DELETE',
url: `/api/topics/${topic.id}`,
}).then(() => {
topic = undefined;
});
}
});
it('Topics menu should load Topics page', () => {
cy.visit('/');
cy.clickOnEntityMenuItem('topic');
cy.wait('@entitiesRequest').then(({ response }) => {
if (response!.body.length === 0) {
cy.get(entityTableSelector).should('not.exist');
} else {
cy.get(entityTableSelector).should('exist');
}
});
cy.getEntityHeading('Topic').should('exist');
cy.url().should('match', topicPageUrlPattern);
});
describe('Topic page', () => {
describe('create button click', () => {
beforeEach(() => {
cy.visit(topicPageUrl);
cy.wait('@entitiesRequest');
});
it('should load create Topic page', () => {
cy.get(entityCreateButtonSelector).click();
cy.url().should('match', new RegExp('/topic/new$'));
cy.getEntityCreateUpdateHeading('Topic');
cy.get(entityCreateSaveButtonSelector).should('exist');
cy.get(entityCreateCancelButtonSelector).click();
cy.wait('@entitiesRequest').then(({ response }) => {
expect(response!.statusCode).to.equal(200);
});
cy.url().should('match', topicPageUrlPattern);
});
});
describe('with existing value', () => {
beforeEach(() => {
cy.authenticatedRequest({
method: 'POST',
url: '/api/topics',
body: topicSample,
}).then(({ body }) => {
topic = body;
cy.intercept(
{
method: 'GET',
url: '/api/topics+(?*|)',
times: 1,
},
{
statusCode: 200,
body: [topic],
}
).as('entitiesRequestInternal');
});
cy.visit(topicPageUrl);
cy.wait('@entitiesRequestInternal');
});
it('detail button click should load details Topic page', () => {
cy.get(entityDetailsButtonSelector).first().click();
cy.getEntityDetailsHeading('topic');
cy.get(entityDetailsBackButtonSelector).click();
cy.wait('@entitiesRequest').then(({ response }) => {
expect(response!.statusCode).to.equal(200);
});
cy.url().should('match', topicPageUrlPattern);
});
it('edit button click should load edit Topic page', () => {
cy.get(entityEditButtonSelector).first().click();
cy.getEntityCreateUpdateHeading('Topic');
cy.get(entityCreateSaveButtonSelector).should('exist');
cy.get(entityCreateCancelButtonSelector).click();
cy.wait('@entitiesRequest').then(({ response }) => {
expect(response!.statusCode).to.equal(200);
});
cy.url().should('match', topicPageUrlPattern);
});
it('last delete button click should delete instance of Topic', () => {
cy.get(entityDeleteButtonSelector).last().click();
cy.getEntityDeleteDialogHeading('topic').should('exist');
cy.get(entityConfirmDeleteButtonSelector).click();
cy.wait('@deleteEntityRequest').then(({ response }) => {
expect(response!.statusCode).to.equal(204);
});
cy.wait('@entitiesRequest').then(({ response }) => {
expect(response!.statusCode).to.equal(200);
});
cy.url().should('match', topicPageUrlPattern);
topic = undefined;
});
});
});
describe('new Topic page', () => {
beforeEach(() => {
cy.visit(`${topicPageUrl}`);
cy.get(entityCreateButtonSelector).click();
cy.getEntityCreateUpdateHeading('Topic');
});
it('should create an instance of Topic', () => {
cy.get(`[data-cy="title"]`).type('digital SAS Accountability').should('have.value', 'digital SAS Accountability');
cy.get(`[data-cy="description"]`).type('Books').should('have.value', 'Books');
cy.get(entityCreateSaveButtonSelector).click();
cy.wait('@postEntityRequest').then(({ response }) => {
expect(response!.statusCode).to.equal(201);
topic = response!.body;
});
cy.wait('@entitiesRequest').then(({ response }) => {
expect(response!.statusCode).to.equal(200);
});
cy.url().should('match', topicPageUrlPattern);
});
});
});