-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathinstruments-general.cy.js
More file actions
206 lines (152 loc) · 5.86 KB
/
Copy pathinstruments-general.cy.js
File metadata and controls
206 lines (152 loc) · 5.86 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
const path = require("path");
import { testData } from "../../fixtures/testData";
import { testConfig } from "../../fixtures/testData";
import { getFormattedFileNamingDate, mergeConfig } from "../../support/utils";
describe("Instruments general", () => {
beforeEach(() => {
cy.login(Cypress.env("username"), Cypress.env("password"));
});
after(() => {
cy.removeInstruments();
});
describe("Instruments table and details", () => {
it("should be able to see instrument in a table and visit the instrument details page", () => {
const instrument = {
...testData.instrument,
name: "Cypress test instrument",
uniqueName: `Instrument-${Math.floor(1000 + Math.random() * 9000).toString()}`,
};
cy.createInstrument(instrument);
cy.visit("/instruments");
cy.get("mat-table mat-header-row").should("exist");
cy.finishedLoading();
cy.get("mat-table mat-row").should("contain", instrument.uniqueName);
cy.get("mat-cell")
.contains(instrument.uniqueName)
.closest("mat-row")
.contains(instrument.name)
.click();
cy.url().should("include", `/instruments`);
cy.contains(instrument.uniqueName);
});
it("instrument should have metadata and if not it should be able to add", () => {
const metadataName = "Instrument Metadata Name";
const metadataValue = "instrument metadata value";
const instrument = {
...testData.instrument,
name: "Cypress test instrument",
uniqueName: `Instrument-${Math.floor(1000 + Math.random() * 9000).toString()}`,
};
cy.createInstrument(instrument);
cy.visit("/instruments");
cy.finishedLoading();
cy.get("mat-cell")
.contains(instrument.uniqueName)
.closest("mat-row")
.contains(instrument.name)
.click();
cy.finishedLoading();
cy.get('[data-cy="instrument-metadata-card"]').should("exist");
cy.get('[data-cy="instrument-metadata-card"] [role="tab"]')
.contains("Edit")
.click();
cy.get('[data-cy="add-new-row"]').click();
// simulate click event on the drop down
cy.get("mat-select[data-cy=field-type-input]").last().click(); // opens the drop down
// simulate click event on the drop down item (mat-option)
cy.get("mat-option")
.contains("string")
.then((option) => {
option[0].click();
});
cy.get("[data-cy=metadata-name-input]")
.last()
.focus()
.type(`${metadataName}{enter}`);
cy.get("[data-cy=metadata-value-input]")
.last()
.focus()
.type(`${metadataValue}{enter}`);
cy.get("button[data-cy=save-changes-button]").click();
cy.finishedLoading();
cy.reload();
cy.finishedLoading();
cy.contains(instrument.name);
cy.get('[data-cy="instrument-metadata-card"]').contains(metadataName, {
matchCase: true,
});
cy.get('[data-cy="instrument-metadata-card"]').contains(metadataValue, {
matchCase: true,
});
});
});
describe("Instruments dynamic material table", () => {
it("should be able to sort for instrument in the column sort", () => {
const newInstrument = {
...testData.instrument,
name: "000 Cypress test instrument",
uniqueName: `Instrument-${Math.floor(1000 + Math.random() * 9000).toString()}`,
};
const newInstrument2 = {
...testData.instrument,
name: "001 Cypress test instrument",
uniqueName: `Instrument-${Math.floor(1000 + Math.random() * 9000).toString()}`,
};
cy.createInstrument(newInstrument2);
cy.createInstrument(newInstrument);
cy.visit("/instruments");
cy.get("mat-table mat-row")
.first()
.should("not.contain", newInstrument.name);
cy.get(".mat-sort-header-container").contains("Name").click();
cy.get("mat-table mat-row").first().should("contain", newInstrument.name);
cy.reload();
cy.get("mat-table mat-row").first().should("contain", newInstrument.name);
});
it("should be able to download table data as a json", () => {
const instrument = {
...testData.instrument,
uniqueName: `Instrument-${Math.floor(1000 + Math.random() * 9000).toString()}`,
};
cy.createInstrument(instrument);
cy.visit("/instruments");
cy.get("dynamic-mat-table table-menu button").click();
cy.get('[role="menu"] button').contains("Save data").click();
cy.get('[role="menu"] button').contains("Json file").click();
const downloadsFolder = Cypress.config("downloadsFolder");
const tableName = "instrumentsTable";
cy.readFile(
path.join(
downloadsFolder,
`${tableName}${getFormattedFileNamingDate()}.json`,
),
).then((actualExport) => {
const foundInstrument = actualExport.find(
(instrument) => instrument.uniqueName === instrument.uniqueName,
);
expect(foundInstrument).to.exist;
});
});
it("should be able to download table data as a csv", () => {
const instrument = {
...testData.instrument,
uniqueName: `Instrument-${Math.floor(1000 + Math.random() * 9000).toString()}`,
};
cy.createInstrument(instrument);
cy.visit("/instruments");
cy.get("dynamic-mat-table table-menu button").click();
cy.get('[role="menu"] button').contains("Save data").click();
cy.get('[role="menu"] button').contains("CSV file").click();
const downloadsFolder = Cypress.config("downloadsFolder");
const tableName = "instrumentsTable";
cy.readFile(
path.join(
downloadsFolder,
`${tableName}${getFormattedFileNamingDate()}.csv`,
),
).then((actualExport) => {
expect(actualExport).to.contain(instrument.uniqueName);
});
});
});
});