generated from graasp/graasp-repo
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add shortcut previous button and map button (#716)
* feat: add shortcut previous button and map button * refactor: update graasp ui * refactor: add tests * refactor: apply PR requested changes * refactor: update yarn lock * refactor: fix name of back button * refactor: set settings * refactor: change path check * refactor: add console * refactor: use content page build * refactor: remove only * refactor: remove debug code
- Loading branch information
Showing
21 changed files
with
725 additions
and
264 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
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,141 @@ | ||
import { | ||
PackedFolderItemFactory, | ||
PackedShortcutItemFactory, | ||
} from '@graasp/sdk'; | ||
|
||
import 'cypress-iframe'; | ||
import { v4 } from 'uuid'; | ||
|
||
import { buildContentPagePath } from '@/config/paths'; | ||
import { BACK_TO_SHORTCUT_ID, buildFolderButtonId } from '@/config/selectors'; | ||
|
||
describe('Shortcuts', () => { | ||
it('Come back from shortcut navigation', () => { | ||
const parentItem = PackedFolderItemFactory({ | ||
name: 'parent item', | ||
settings: {}, | ||
}); | ||
const toShortcut = PackedFolderItemFactory({ | ||
name: 'target folder', | ||
settings: {}, | ||
}); | ||
const shortcut = PackedShortcutItemFactory({ | ||
name: 'shortcut', | ||
parentItem, | ||
settings: {}, | ||
extra: { shortcut: { target: toShortcut.id } }, | ||
}); | ||
cy.setUpApi({ items: [parentItem, shortcut, toShortcut] }); | ||
|
||
cy.visit( | ||
buildContentPagePath({ rootId: parentItem.id, itemId: parentItem.id }), | ||
); | ||
|
||
// click on folder shortcut | ||
cy.get(`#${buildFolderButtonId(toShortcut.id)}`).click(); | ||
cy.url() | ||
.should('contain', 'from') | ||
.and('contain', parentItem.id) | ||
.and('contain', 'fromName') | ||
.and('contain', 'parent+item'); | ||
|
||
cy.wait(3000); | ||
|
||
// go back to origin | ||
cy.get(`#${BACK_TO_SHORTCUT_ID}`).click(); | ||
cy.url().should('contain', parentItem.id); | ||
}); | ||
|
||
it('Keep other params from shortcut navigation like shuffle', () => { | ||
const parentItem = PackedFolderItemFactory({ | ||
name: 'parent item', | ||
settings: {}, | ||
}); | ||
const toShortcut = PackedFolderItemFactory({ | ||
name: 'target folder', | ||
settings: {}, | ||
}); | ||
const shortcut = PackedShortcutItemFactory({ | ||
name: 'shortcut', | ||
parentItem, | ||
settings: {}, | ||
extra: { shortcut: { target: toShortcut.id } }, | ||
}); | ||
cy.setUpApi({ items: [parentItem, shortcut, toShortcut] }); | ||
|
||
cy.visit( | ||
buildContentPagePath({ | ||
rootId: parentItem.id, | ||
itemId: parentItem.id, | ||
searchParams: 'fullscreen=true', | ||
}), | ||
); | ||
|
||
// click on folder shortcut | ||
cy.get(`#${buildFolderButtonId(toShortcut.id)}`).click(); | ||
cy.url() | ||
.should('contain', 'from') | ||
.and('contain', parentItem.id) | ||
.and('contain', 'fromName') | ||
.and('contain', 'parent+item') | ||
.and('contain', 'fullscreen=true'); | ||
|
||
// go back to origin | ||
cy.get(`#${BACK_TO_SHORTCUT_ID}`).click(); | ||
cy.url().should('contain', parentItem.id).and('contain', 'fullscreen=true'); | ||
}); | ||
|
||
it('No from name does not show button', () => { | ||
const parentItem = PackedFolderItemFactory({ name: 'parent item' }); | ||
cy.setUpApi({ items: [parentItem] }); | ||
|
||
cy.visit( | ||
`${buildContentPagePath({ | ||
rootId: parentItem.id, | ||
itemId: parentItem.id, | ||
})}?from=/${v4()}`, | ||
); | ||
|
||
// need wait for wrongly shown button to appear | ||
cy.wait(1000); | ||
|
||
// should not show from button | ||
cy.get(`#${BACK_TO_SHORTCUT_ID}`).should('not.exist'); | ||
}); | ||
|
||
it('Hacking query params is safe', () => { | ||
const parentItem = PackedFolderItemFactory({ name: 'parent item' }); | ||
cy.setUpApi({ items: [parentItem] }); | ||
|
||
cy.visit( | ||
`${buildContentPagePath({ | ||
rootId: parentItem.id, | ||
itemId: parentItem.id, | ||
})}?from=/idid&fromName=shouldnotdisplay`, | ||
); | ||
|
||
// need wait for wrongly shown button to appear | ||
cy.wait(1000); | ||
|
||
// should not show from button | ||
cy.get(`#${BACK_TO_SHORTCUT_ID}`).should('not.exist'); | ||
}); | ||
|
||
it('Hacking from url with external url is safe', () => { | ||
const parentItem = PackedFolderItemFactory({ name: 'parent item' }); | ||
cy.setUpApi({ items: [parentItem] }); | ||
|
||
cy.visit( | ||
`${buildContentPagePath({ | ||
rootId: parentItem.id, | ||
itemId: parentItem.id, | ||
})}?from=http://example.org&fromName=shouldnotdisplay`, | ||
); | ||
|
||
// need wait for wrongly shown button to appear | ||
cy.wait(1000); | ||
|
||
// should not show from button | ||
cy.get(`#${BACK_TO_SHORTCUT_ID}`).should('not.exist'); | ||
}); | ||
}); |
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.