This repository was archived by the owner on Jan 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcreateItemMembership.cy.ts
206 lines (174 loc) · 5.16 KB
/
createItemMembership.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
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
import {
PackedFolderItemFactory,
PackedLocalFileItemFactory,
PermissionLevel,
} from '@graasp/sdk';
import { buildItemPath, buildItemSharePath } from '../../../src/config/paths';
import {
CREATE_MEMBERSHIP_FORM_ID,
ITEM_MEMBERSHIP_PERMISSION_SELECT_CLASS,
SHARE_BUTTON_SELECTOR,
SHARE_ITEM_CANCEL_BUTTON_CY,
SHARE_ITEM_EMAIL_INPUT_ID,
SHARE_ITEM_SHARE_BUTTON_ID,
buildDataCyWrapper,
buildShareButtonId,
} from '../../../src/config/selectors';
import { MEMBERS } from '../../fixtures/members';
const shareItem = ({
id,
email,
permission,
submit,
}: {
email: string;
permission: PermissionLevel;
submit?: boolean;
id: string;
}) => {
cy.get(`#${buildShareButtonId(id)}`).click();
cy.fillShareForm({
email,
permission,
submit,
selector: `#${CREATE_MEMBERSHIP_FORM_ID}`,
});
};
const IMAGE_ITEM = PackedLocalFileItemFactory();
const FOLDER = PackedFolderItemFactory();
const ITEMS = [IMAGE_ITEM, FOLDER];
describe('Create Membership', () => {
it('share item', () => {
cy.setUpApi({ items: ITEMS, members: Object.values(MEMBERS) });
// go to children item
const { id } = FOLDER;
cy.visit(buildItemPath(id));
// share
const member = MEMBERS.FANNY;
const permission = PermissionLevel.Read;
shareItem({ id, email: member.email, permission });
cy.wait('@postInvitations').then(
({
request: {
url,
body: { invitations },
},
}) => {
expect(url).to.contain(id);
expect(invitations[0].permission).to.equal(permission);
expect(invitations[0].email).to.equal(member.email);
},
);
// check that the email field is emptied after sharing completes
cy.get(`#${SHARE_ITEM_EMAIL_INPUT_ID}`).should('be.empty');
});
it('open share modal, cancel and sharing reset content', () => {
cy.setUpApi({ items: ITEMS, members: Object.values(MEMBERS) });
// go to children item
const { id } = FOLDER;
cy.visit(buildItemSharePath(id));
// open modal and cancel
cy.get(buildDataCyWrapper(SHARE_BUTTON_SELECTOR)).click();
cy.get(buildDataCyWrapper(SHARE_ITEM_CANCEL_BUTTON_CY)).click();
cy.get(`#${SHARE_ITEM_SHARE_BUTTON_ID}`).should('not.exist');
// share
const member = MEMBERS.FANNY;
const permission = PermissionLevel.Admin;
cy.fillShareForm({
email: member.email,
permission,
selector: `#${CREATE_MEMBERSHIP_FORM_ID}`,
});
// check that fields are reset if reopen modal
cy.get(buildDataCyWrapper(SHARE_BUTTON_SELECTOR)).click();
cy.get(`#${SHARE_ITEM_EMAIL_INPUT_ID}`).should('be.empty');
cy.get(`.${ITEM_MEMBERSHIP_PERMISSION_SELECT_CLASS} input`).should(
'have.value',
PermissionLevel.Read,
);
});
it('share item with new admin by pressing enter', () => {
cy.setUpApi({ items: ITEMS, members: Object.values(MEMBERS) });
// go to children item
const { id } = FOLDER;
cy.visit(buildItemPath(id));
// share
const member = MEMBERS.FANNY;
const permission = PermissionLevel.Admin;
shareItem({
id,
email: `${member.email}{Enter}`,
permission,
submit: false,
});
cy.wait('@postInvitations').then(
({
request: {
url,
body: { invitations },
},
}) => {
expect(url).to.contain(id);
expect(invitations[0].permission).to.equal(permission);
expect(invitations[0].email).to.equal(member.email);
},
);
// check that the email field is emptied after sharing completes
cy.get(`#${SHARE_ITEM_EMAIL_INPUT_ID}`).should('be.empty');
});
it('cannot add membership item twice', () => {
const ITEM = PackedFolderItemFactory();
const account = MEMBERS.ANNA;
cy.setUpApi({
items: [
{
...ITEM,
memberships: [
{
item: ITEM,
permission: PermissionLevel.Read,
account,
},
],
},
],
members: Object.values(MEMBERS),
});
// go to children item
const { id } = ITEM;
cy.visit(buildItemPath(id));
// fill
const permission = PermissionLevel.Read;
shareItem({ id, email: account.email, permission });
cy.get(`#${SHARE_ITEM_SHARE_BUTTON_ID}`).should('be.disabled');
});
it('cannot invite user twice', () => {
const ITEM = PackedFolderItemFactory();
const { email } = MEMBERS.CEDRIC;
cy.setUpApi({
items: [
{
...ITEM,
invitations: [{ email }],
},
],
members: Object.values(MEMBERS),
});
const { id } = ITEM;
cy.visit(buildItemPath(id));
// fill
const permission = PermissionLevel.Read;
shareItem({ id, email, permission });
cy.get(`#${SHARE_ITEM_SHARE_BUTTON_ID}`).should('be.disabled');
});
it('cannot share item with invalid data', () => {
cy.setUpApi({ items: ITEMS, members: Object.values(MEMBERS) });
// go to children item
const { id } = FOLDER;
cy.visit(buildItemPath(id));
// fill
const permission = PermissionLevel.Read;
shareItem({ id, email: 'wrong', permission });
cy.get(`#${SHARE_ITEM_SHARE_BUTTON_ID}`).should('be.disabled');
});
});