|
1 |
| -import { PackedEtherpadItemFactory } from '@graasp/sdk'; |
| 1 | +import { |
| 2 | + EtherpadPermission, |
| 3 | + PackedEtherpadItemFactory, |
| 4 | + PackedFolderItemFactory, |
| 5 | +} from '@graasp/sdk'; |
2 | 6 |
|
3 |
| -import { buildItemsGridMoreButtonSelector } from '../../../../../src/config/selectors'; |
4 |
| -import { EDIT_ITEM_PAUSE } from '../../../../support/constants'; |
5 |
| -import { editItem } from '../../../../support/editUtils'; |
6 |
| -import { HOME_PATH } from '../../utils'; |
| 7 | +import { |
| 8 | + EDIT_ITEM_BUTTON_CLASS, |
| 9 | + ETHERPAD_ALLOW_READER_TO_WRITE_SETTING_ID, |
| 10 | + ITEM_FORM_CONFIRM_BUTTON_ID, |
| 11 | + ITEM_FORM_NAME_INPUT_ID, |
| 12 | + buildItemsGridMoreButtonSelector, |
| 13 | +} from '../../../../../src/config/selectors'; |
| 14 | +import { HOME_PATH, buildItemPath } from '../../utils'; |
7 | 15 |
|
8 |
| -const EDITED_FIELDS = { |
9 |
| - name: 'new name', |
10 |
| -}; |
| 16 | +const editEtherpad = ( |
| 17 | + { |
| 18 | + name, |
| 19 | + toggleAllowReadersToWrite, |
| 20 | + }: { |
| 21 | + name?: string; |
| 22 | + toggleAllowReadersToWrite?: boolean; |
| 23 | + }, |
| 24 | + { confirm = true }: { confirm?: boolean } = {}, |
| 25 | +) => { |
| 26 | + cy.get(`.${EDIT_ITEM_BUTTON_CLASS}`).click(); |
11 | 27 |
|
12 |
| -const GRAASP_ETHERPAD_ITEM = PackedEtherpadItemFactory(); |
| 28 | + if (name) { |
| 29 | + cy.get(`#${ITEM_FORM_NAME_INPUT_ID}`).type(`{selectall}{backspace}${name}`); |
| 30 | + } |
13 | 31 |
|
14 |
| -describe('Edit Etherpad', () => { |
15 |
| - beforeEach(() => { |
16 |
| - cy.setUpApi({ items: [GRAASP_ETHERPAD_ITEM] }); |
17 |
| - }); |
| 32 | + if (toggleAllowReadersToWrite) { |
| 33 | + cy.get(`#${ETHERPAD_ALLOW_READER_TO_WRITE_SETTING_ID}`).click(); |
| 34 | + } |
| 35 | + |
| 36 | + if (confirm) { |
| 37 | + cy.get(`#${ITEM_FORM_CONFIRM_BUTTON_ID}`).click(); |
| 38 | + } |
| 39 | +}; |
18 | 40 |
|
| 41 | +describe('Edit Etherpad', () => { |
19 | 42 | it('edit etherpad on Home', () => {
|
| 43 | + const itemToEdit = PackedEtherpadItemFactory({ |
| 44 | + extra: { |
| 45 | + etherpad: { |
| 46 | + padID: 'padId', |
| 47 | + groupID: 'groupId', |
| 48 | + readerPermission: EtherpadPermission.Read, |
| 49 | + }, |
| 50 | + }, |
| 51 | + }); |
| 52 | + cy.setUpApi({ items: [itemToEdit] }); |
20 | 53 | cy.visit(HOME_PATH);
|
21 | 54 |
|
22 |
| - const itemToEdit = GRAASP_ETHERPAD_ITEM; |
| 55 | + cy.intercept(`/items/etherpad/${itemToEdit.id}`, (request) => { |
| 56 | + request.reply(itemToEdit); |
| 57 | + }).as('editEtherpad'); |
23 | 58 |
|
24 | 59 | // edit
|
25 | 60 | cy.get(buildItemsGridMoreButtonSelector(itemToEdit.id)).click();
|
26 |
| - editItem({ |
27 |
| - ...itemToEdit, |
28 |
| - ...EDITED_FIELDS, |
| 61 | + editEtherpad({ |
| 62 | + name: 'newName', |
| 63 | + toggleAllowReadersToWrite: true, |
29 | 64 | });
|
30 | 65 |
|
31 |
| - cy.wait('@editItem').then( |
| 66 | + cy.wait('@editEtherpad').then( |
32 | 67 | ({
|
33 |
| - response: { |
34 |
| - body: { id, name }, |
| 68 | + request: { |
| 69 | + body: { name, readerPermission }, |
35 | 70 | },
|
36 | 71 | }) => {
|
37 |
| - // check item is edited and updated |
38 |
| - cy.wait(EDIT_ITEM_PAUSE); |
| 72 | + // check item is edited |
39 | 73 | cy.get('@getAccessibleItems');
|
40 |
| - expect(id).to.equal(itemToEdit.id); |
41 |
| - expect(name).to.equal(EDITED_FIELDS.name); |
| 74 | + expect(name).to.equal('newName'); |
| 75 | + expect(readerPermission).to.eq('write'); |
42 | 76 | },
|
43 | 77 | );
|
44 | 78 | });
|
| 79 | + |
| 80 | + it('edit reader permission of etherpad', () => { |
| 81 | + const parentItem = PackedFolderItemFactory(); |
| 82 | + const itemToEdit = PackedEtherpadItemFactory({ |
| 83 | + parentItem, |
| 84 | + extra: { |
| 85 | + etherpad: { |
| 86 | + padID: 'padId', |
| 87 | + groupID: 'groupId', |
| 88 | + readerPermission: EtherpadPermission.Read, |
| 89 | + }, |
| 90 | + }, |
| 91 | + }); |
| 92 | + cy.setUpApi({ items: [parentItem, itemToEdit] }); |
| 93 | + cy.intercept(`/items/etherpad/${itemToEdit.id}`, (request) => { |
| 94 | + request.reply(itemToEdit); |
| 95 | + }).as('editEtherpad'); |
| 96 | + |
| 97 | + // go in child item |
| 98 | + cy.visit(buildItemPath(itemToEdit.id)); |
| 99 | + |
| 100 | + // edit reader permission |
| 101 | + // cy.get(buildItemsGridMoreButtonSelector(itemToEdit.id)).click(); |
| 102 | + editEtherpad({ toggleAllowReadersToWrite: true }); |
| 103 | + |
| 104 | + cy.wait('@editEtherpad').then(({ request: { body } }) => { |
| 105 | + // check item is edited |
| 106 | + cy.get('@getAccessibleItems'); |
| 107 | + expect(body.readerPermission).to.equal('write'); |
| 108 | + }); |
| 109 | + }); |
45 | 110 | });
|
0 commit comments