This repository has been 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from graasp/14/editItem
feat: edit item
- Loading branch information
Showing
31 changed files
with
787 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,65 @@ | ||
import { ITEM_TYPES } from '../../src/config/constants'; | ||
|
||
export const CURRENT_USER_ID = 'some_creator_id'; | ||
|
||
const DEFAULT_ITEM = { | ||
description: '', | ||
extra: {}, | ||
creator: CURRENT_USER_ID, | ||
type: 'Space', | ||
type: ITEM_TYPES.SPACE, | ||
}; | ||
|
||
export const CREATED_ITEM = { | ||
name: 'created item', | ||
type: 'Space', | ||
type: ITEM_TYPES.SPACE, | ||
description: 'I am a newly created element', | ||
extra: { | ||
image: 'someimageurl', | ||
}, | ||
}; | ||
|
||
export const EDITED_FIELDS = { | ||
name: 'new name', | ||
description: 'new description', | ||
}; | ||
|
||
export const SIMPLE_ITEMS = [ | ||
{ | ||
...DEFAULT_ITEM, | ||
id: 'ecafbd2a-5688-11eb-ae93-0242ac130002', | ||
name: 'own_item_name1', | ||
path: 'ecafbd2a_5688_11eb_ae93_0242ac130002', | ||
extra: { | ||
image: 'someimageurl', | ||
}, | ||
}, | ||
{ | ||
...DEFAULT_ITEM, | ||
id: 'fdf09f5a-5688-11eb-ae93-0242ac130002', | ||
name: 'own_item_name2', | ||
path: 'fdf09f5a_5688_11eb_ae93_0242ac130002', | ||
extra: { | ||
image: 'someimageurl', | ||
}, | ||
}, | ||
{ | ||
...DEFAULT_ITEM, | ||
id: 'fdf09f5a-5688-11eb-ae93-0242ac130003', | ||
name: 'own_item_name3', | ||
path: | ||
'ecafbd2a_5688_11eb_ae93_0242ac130002.fdf09f5a_5688_11eb_ae93_0242ac130003', | ||
extra: { | ||
image: 'someimageurl', | ||
}, | ||
}, | ||
{ | ||
...DEFAULT_ITEM, | ||
id: 'fdf09f5a-5688-11eb-ae93-0242ac130004', | ||
name: 'own_item_name4', | ||
path: | ||
'ecafbd2a_5688_11eb_ae93_0242ac130002.fdf09f5a_5688_11eb_ae93_0242ac130004', | ||
extra: { | ||
image: 'someimageurl', | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { ITEM_TYPES } from '../../src/config/constants'; | ||
import { buildItemPath } from '../../src/config/paths'; | ||
import { | ||
buildItemCard, | ||
buildItemLink, | ||
buildItemMenu, | ||
ITEM_MENU_BUTTON_CLASS, | ||
ITEM_MENU_EDIT_BUTTON_CLASS, | ||
ITEM_FORM_CONFIRM_BUTTON_ID, | ||
ITEM_FORM_DESCRIPTION_INPUT_ID, | ||
ITEM_FORM_IMAGE_INPUT_ID, | ||
ITEM_FORM_NAME_INPUT_ID, | ||
ITEM_FORM_TYPE_SELECT_ID, | ||
} from '../../src/config/selectors'; | ||
import { EDITED_FIELDS, SIMPLE_ITEMS } from '../fixtures/items'; | ||
import { EDIT_ITEM_PAUSE } from '../support/constants'; | ||
|
||
const editItem = ({ | ||
id, | ||
name = '', | ||
type = ITEM_TYPES.SPACE, | ||
extra = {}, | ||
description = '', | ||
}) => { | ||
const menuSelector = `#${buildItemCard(id)} .${ITEM_MENU_BUTTON_CLASS}`; | ||
cy.get(menuSelector).click(); | ||
cy.get(`#${buildItemMenu(id)} .${ITEM_MENU_EDIT_BUTTON_CLASS}`).click(); | ||
|
||
cy.get(`#${ITEM_FORM_NAME_INPUT_ID}`).clear().type(name); | ||
|
||
cy.get(`#${ITEM_FORM_DESCRIPTION_INPUT_ID}`).clear().type(description); | ||
|
||
cy.get(`#${ITEM_FORM_TYPE_SELECT_ID}`).click(); | ||
cy.get(`li[data-value="${type}"]`).click(); | ||
cy.get(`#${ITEM_FORM_IMAGE_INPUT_ID}`).clear().type(extra.image); | ||
|
||
cy.get(`#${ITEM_FORM_CONFIRM_BUTTON_ID}`).click(); | ||
}; | ||
|
||
describe('Edit Item', () => { | ||
it('edit item on Home', () => { | ||
cy.setUpApi({ items: SIMPLE_ITEMS }); | ||
cy.visit('/'); | ||
|
||
const itemToEdit = SIMPLE_ITEMS[0]; | ||
|
||
// edit | ||
editItem({ | ||
...itemToEdit, | ||
...EDITED_FIELDS, | ||
}); | ||
|
||
cy.wait('@editItem').then( | ||
({ | ||
response: { | ||
body: { id, name }, | ||
}, | ||
}) => { | ||
// check item is edited and updated | ||
cy.wait(EDIT_ITEM_PAUSE); | ||
cy.get(`#${buildItemCard(id)}`).should('exist'); | ||
cy.get(`#${buildItemLink(id)}`).contains(name); | ||
}, | ||
); | ||
}); | ||
|
||
it('create item in item', () => { | ||
cy.setUpApi({ items: SIMPLE_ITEMS }); | ||
// go to children item | ||
cy.visit(buildItemPath(SIMPLE_ITEMS[0].id)); | ||
|
||
const itemToEdit = SIMPLE_ITEMS[2]; | ||
|
||
// edit | ||
editItem({ | ||
...itemToEdit, | ||
...EDITED_FIELDS, | ||
}); | ||
|
||
cy.wait('@editItem').then( | ||
({ | ||
response: { | ||
body: { id, name }, | ||
}, | ||
}) => { | ||
// check item is edited and updated | ||
cy.wait(EDIT_ITEM_PAUSE); | ||
cy.get(`#${buildItemCard(id)}`).should('exist'); | ||
cy.get(`#${buildItemLink(id)}`).contains(name); | ||
}, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const CREATE_ITEM_PAUSE = 1000; | ||
export const EDIT_ITEM_PAUSE = 1000; | ||
export const NAVIGATE_PAUSE = 500; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.