-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathcomparing-attribution-with-origin.test.ts
179 lines (163 loc) · 7.32 KB
/
comparing-attribution-with-origin.test.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
168
169
170
171
172
173
174
175
176
177
178
179
// SPDX-FileCopyrightText: Meta Platforms, Inc. and its affiliates
// SPDX-FileCopyrightText: TNG Technology Consulting GmbH <https://www.tngtech.com>
//
// SPDX-License-Identifier: Apache-2.0
import { AttributionType } from '../../Frontend/enums/enums';
import { faker, test } from '../utils';
const [resourceName1, resourceName2] = faker.opossum.resourceNames({
count: 2,
});
const packageName = faker.lorem.word();
const copyright = faker.lorem.sentence();
const [attributionId1, manualPackageInfo1] = faker.opossum.rawAttribution();
const [attributionId2, manualPackageInfo2] = faker.opossum.rawAttribution({
originIds: [faker.string.uuid()],
packageName,
copyright,
licenseText: faker.opossum.license().defaultText,
firstParty: false,
});
const [externalAttributionId, externalPackageInfo] =
faker.opossum.rawAttribution(manualPackageInfo2);
test.use({
data: {
inputData: faker.opossum.inputData({
resources: faker.opossum.resources({
[resourceName1]: 1,
[resourceName2]: 1,
}),
externalAttributions: faker.opossum.rawAttributions({
[externalAttributionId]: externalPackageInfo,
}),
resourcesToAttributions: faker.opossum.resourcesToAttributions({
[faker.opossum.filePath(resourceName2)]: [externalAttributionId],
}),
}),
outputData: faker.opossum.outputData({
manualAttributions: faker.opossum.rawAttributions({
[attributionId1]: manualPackageInfo1,
[attributionId2]: manualPackageInfo2,
}),
resourcesToAttributions: faker.opossum.resourcesToAttributions({
[faker.opossum.filePath(resourceName1)]: [attributionId1],
[faker.opossum.filePath(resourceName2)]: [attributionId2],
}),
}),
},
});
test('opens the diff popup if attribution has original and compare button is clicked', async ({
attributionDetails,
diffPopup,
resourcesTree,
}) => {
await resourcesTree.goto(resourceName1);
await attributionDetails.assert.compareButtonIsHidden();
await resourcesTree.goto(resourceName2);
await attributionDetails.assert.compareButtonIsVisible();
await attributionDetails.compareButton.click();
await diffPopup.assert.isVisible();
});
test('reverts all changes and applies reverted state to temporary package info', async ({
attributionDetails,
diffPopup,
resourcesTree,
}) => {
await resourcesTree.goto(resourceName2);
const newPackageName = faker.lorem.word();
await attributionDetails.attributionForm.name.fill(newPackageName);
await attributionDetails.attributionForm.selectAttributionType(
AttributionType.FirstParty,
);
await attributionDetails.compareButton.click();
await diffPopup.currentAttributionForm.assert.nameIs(newPackageName);
await diffPopup.currentAttributionForm.assert.attributionTypeIs(
AttributionType.FirstParty,
);
await diffPopup.currentAttributionForm.assert.copyrightIs('');
await diffPopup.currentAttributionForm.assert.licenseTextIs('');
await diffPopup.currentAttributionForm.assert.licenseNameIs('');
await diffPopup.currentAttributionForm.assert.nameUndoButtonIsVisible();
await diffPopup.currentAttributionForm.assert.nameRedoButtonIsHidden();
await diffPopup.currentAttributionForm.assert.attributionTypeUndoButtonIsVisible();
await diffPopup.currentAttributionForm.assert.attributionTypeRedoButtonIsHidden();
await diffPopup.currentAttributionForm.assert.copyrightUndoButtonIsHidden();
await diffPopup.currentAttributionForm.assert.copyrightRedoButtonIsHidden();
await diffPopup.assert.applyButtonIsDisabled();
await diffPopup.revertAllButton.click();
await diffPopup.applyButton.click();
await diffPopup.assert.isHidden();
await attributionDetails.attributionForm.licenseTextToggleButton.click();
await attributionDetails.attributionForm.assert.matchesPackageInfo(
manualPackageInfo2,
);
});
test('reverts single fields correctly', async ({
attributionDetails,
diffPopup,
resourcesTree,
}) => {
await resourcesTree.goto(resourceName2);
const newPackageName = faker.lorem.word();
await attributionDetails.attributionForm.name.fill(newPackageName);
const newCopyright = faker.lorem.sentence();
await attributionDetails.attributionForm.copyright.fill(newCopyright);
await attributionDetails.compareButton.click();
await diffPopup.currentAttributionForm.assert.nameIs(newPackageName);
await diffPopup.currentAttributionForm.assert.nameUndoButtonIsVisible();
await diffPopup.currentAttributionForm.assert.nameRedoButtonIsHidden();
await diffPopup.currentAttributionForm.assert.copyrightIs(newCopyright);
await diffPopup.currentAttributionForm.assert.copyrightUndoButtonIsVisible();
await diffPopup.currentAttributionForm.assert.copyrightRedoButtonIsHidden();
await diffPopup.currentAttributionForm.nameUndoButton.click();
await diffPopup.currentAttributionForm.assert.nameRedoButtonIsVisible();
await diffPopup.currentAttributionForm.assert.nameUndoButtonIsHidden();
await diffPopup.currentAttributionForm.assert.nameIs(packageName);
await diffPopup.currentAttributionForm.nameRedoButton.click();
await diffPopup.currentAttributionForm.assert.nameIs(newPackageName);
await diffPopup.currentAttributionForm.copyrightUndoButton.click();
await diffPopup.currentAttributionForm.assert.copyrightIs(copyright);
await diffPopup.currentAttributionForm.assert.copyrightRedoButtonIsVisible();
await diffPopup.currentAttributionForm.assert.copyrightUndoButtonIsHidden();
await diffPopup.revertAllButton.click();
await diffPopup.applyButton.click();
await diffPopup.assert.isHidden();
await attributionDetails.attributionForm.licenseTextToggleButton.click();
await attributionDetails.attributionForm.assert.matchesPackageInfo(
manualPackageInfo2,
);
});
test('handles pending license and copyright changes in temporary package info correctly', async ({
attributionDetails,
diffPopup,
resourcesTree,
}) => {
await resourcesTree.goto(resourceName2);
const newPackageName = faker.lorem.word();
await attributionDetails.attributionForm.name.fill(newPackageName);
await attributionDetails.attributionForm.selectAttributionType(
AttributionType.FirstParty,
);
await attributionDetails.compareButton.click();
await diffPopup.currentAttributionForm.assert.nameIs(newPackageName);
await diffPopup.currentAttributionForm.assert.attributionTypeIs(
AttributionType.FirstParty,
);
await diffPopup.currentAttributionForm.assert.nameUndoButtonIsVisible();
await diffPopup.currentAttributionForm.assert.attributionTypeUndoButtonIsVisible();
await diffPopup.assert.applyButtonIsDisabled();
await diffPopup.currentAttributionForm.nameUndoButton.click();
await diffPopup.currentAttributionForm.assert.nameRedoButtonIsVisible();
await diffPopup.currentAttributionForm.attributionTypeUndoButton.click();
await diffPopup.currentAttributionForm.assert.attributionTypeRedoButtonIsVisible();
await diffPopup.currentAttributionForm.assert.attributionTypeUndoButtonIsHidden();
await diffPopup.assert.revertAllButtonIsDisabled();
await diffPopup.currentAttributionForm.attributionTypeRedoButton.click();
await diffPopup.applyButton.click();
await attributionDetails.attributionForm.selectAttributionType(
AttributionType.ThirdParty,
);
await attributionDetails.attributionForm.licenseTextToggleButton.click();
await attributionDetails.attributionForm.assert.matchesPackageInfo(
manualPackageInfo2,
);
});