forked from JeremyHeleine/Photo-Sphere-Viewer
-
-
Notifications
You must be signed in to change notification settings - Fork 686
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
250 additions
and
41 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
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,156 @@ | ||
import type { OptionsSetting, SettingsPlugin, ToggleSetting } from '@photo-sphere-viewer/settings-plugin'; | ||
import { getPlugin, getViewer, waitViewerReady } from '../../utils'; | ||
|
||
describe('plugin: settings', () => { | ||
beforeEach(() => { | ||
localStorage.photoSphereViewer_touchSupport = 'false'; | ||
cy.visit('e2e/plugins/settings.html'); | ||
waitViewerReady(); | ||
// createBaseSnapshot(); | ||
}); | ||
|
||
const TOGGLE_SETTING = { | ||
id: 'toggle-setting', | ||
label: 'Toggle setting', | ||
type: 'toggle', | ||
active: () => false, | ||
toggle: () => void 0, | ||
} satisfies ToggleSetting; | ||
|
||
const OPTIONS_SETTING = { | ||
id: 'options-setting', | ||
label: 'Options setting', | ||
type: 'options', | ||
current: () => 'A', | ||
options: () => [ | ||
{ id: 'A', label: 'Option A' }, | ||
{ id: 'B', label: 'Option B' }, | ||
], | ||
apply: () => void 0, | ||
} satisfies OptionsSetting; | ||
|
||
it('should add a navbar button', () => { | ||
cy.get('.psv-settings-button').should('not.be.visible'); | ||
|
||
getSettings('add setting').then(settings => settings.addSetting(TOGGLE_SETTING)); | ||
|
||
cy.get('.psv-settings-button') | ||
.should('be.visible') | ||
.click() | ||
.should('have.class', 'psv-button--active'); | ||
}); | ||
|
||
it('should place the menu close to the button', () => { | ||
getSettings('add setting').then(settings => settings.addSetting(TOGGLE_SETTING)); | ||
|
||
[ | ||
['caption settings', 'right', '0px'], | ||
['settings caption', 'left', '0px'], | ||
['zoom move settings caption', 'left', '290px'], | ||
['download settings caption', 'left', '0px'], | ||
['caption settings fullscreen', 'right', '0px'], | ||
].forEach(([navbar, prop, value]) => { | ||
getViewer(`navbar "${navbar}"`).then(viewer => viewer.setOption('navbar', navbar)); | ||
|
||
cy.get('.psv-settings-button').click(); | ||
|
||
cy.get('.psv-settings').should('have.css', prop, value); | ||
|
||
cy.get('.psv-settings-button').click(); | ||
}); | ||
}); | ||
|
||
it('should show toggle and options settings', () => { | ||
getSettings('add setting').then(settings => { | ||
settings.addSetting(TOGGLE_SETTING); | ||
settings.addSetting(OPTIONS_SETTING); | ||
}); | ||
|
||
cy.get('.psv-settings-button').click(); | ||
|
||
cy.get('.psv-settings').compareScreenshots('base'); | ||
}); | ||
|
||
it('should toggle the toggle', () => { | ||
const value = { v: false }; | ||
|
||
getSettings('add setting').then(settings => { | ||
settings.addSetting({ | ||
...TOGGLE_SETTING, | ||
active: () => value.v, | ||
toggle: () => value.v = !value.v, | ||
}); | ||
settings.addSetting(OPTIONS_SETTING); | ||
}); | ||
|
||
cy.get('.psv-settings-button').click(); | ||
cy.get('[data-setting-id=toggle-setting]').click(); | ||
|
||
cy.wrap(value).its('v').should('eq', true); | ||
cy.get('.psv-settings').compareScreenshots('toggle-true'); | ||
|
||
cy.get('[data-setting-id=toggle-setting]').click(); | ||
|
||
cy.wrap(value).its('v').should('eq', false); | ||
cy.get('.psv-settings').compareScreenshots('base'); | ||
}); | ||
|
||
it('should select an option', () => { | ||
const value = { v: 'A' }; | ||
|
||
getSettings('add setting').then(settings => { | ||
settings.addSetting(TOGGLE_SETTING); | ||
settings.addSetting({ | ||
...OPTIONS_SETTING, | ||
current: () => value.v, | ||
apply: (option) => value.v = option, | ||
}); | ||
}); | ||
|
||
cy.get('.psv-settings-button').click(); | ||
cy.get('[data-setting-id=options-setting]').click(); | ||
|
||
cy.get('.psv-settings').compareScreenshots('option-list'); | ||
|
||
cy.get('[data-option-id=__back]').click(); | ||
|
||
cy.wrap(value).its('v').should('eq', 'A'); | ||
cy.get('.psv-settings').compareScreenshots('base'); | ||
|
||
cy.get('[data-setting-id=options-setting]').click(); | ||
cy.get('[data-option-id=B]').click(); | ||
|
||
cy.wrap(value).its('v').should('eq', 'B'); | ||
cy.get('.psv-settings').should('not.be.visible'); | ||
|
||
cy.get('.psv-settings-button').click(); | ||
|
||
cy.get('.psv-settings').compareScreenshots('option-b'); | ||
}); | ||
|
||
it('should display a badge', () => { | ||
const value = { v: 'A' }; | ||
|
||
getSettings('add setting').then(settings => { | ||
settings.addSetting({ | ||
...OPTIONS_SETTING, | ||
current: () => value.v, | ||
apply: (option) => value.v = option, | ||
badge: () => value.v, | ||
}); | ||
}); | ||
|
||
cy.get('.psv-settings-button').compareScreenshots('badge-a'); | ||
|
||
cy.get('.psv-settings-button').click(); | ||
cy.get('[data-setting-id=options-setting]').click(); | ||
cy.get('[data-option-id=B]').click(); | ||
|
||
cy.get('.psv-settings-button').compareScreenshots('badge-b'); | ||
}); | ||
|
||
|
||
function getSettings(log: string) { | ||
return getPlugin<SettingsPlugin>('settings', log); | ||
} | ||
}); |
Binary file added
BIN
+1.21 KB
cypress/snapshots/base/cypress/e2e/plugins/settings.cy.ts/badge-a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.26 KB
cypress/snapshots/base/cypress/e2e/plugins/settings.cy.ts/option-b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+8.14 KB
cypress/snapshots/base/cypress/e2e/plugins/settings.cy.ts/option-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.03 KB
cypress/snapshots/base/cypress/e2e/plugins/settings.cy.ts/toggle-true.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
"types": [ | ||
"cypress", | ||
"node", | ||
"cypress-real-events", | ||
"cypress-mochawesome-reporter" | ||
] | ||
} | ||
|
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
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,51 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>PhotoSphereViewer - settings demo</title> | ||
|
||
<link rel="stylesheet" href="/dist/core/index.css" /> | ||
<link rel="stylesheet" href="/dist/settings-plugin/index.css" /> | ||
<link rel="stylesheet" href="../../style.css" /> | ||
|
||
<style> | ||
/* inconsistent behavior in Cypress */ | ||
.psv-settings *:focus-visible { | ||
outline: none !important; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="photosphere"></div> | ||
|
||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"three": "/node_modules/three/build/three.module.js", | ||
"@photo-sphere-viewer/core": "/dist/core/index.module.js", | ||
"@photo-sphere-viewer/settings-plugin": "/dist/settings-plugin/index.module.js" | ||
} | ||
} | ||
</script> | ||
|
||
<script type="module"> | ||
import { Viewer } from '@photo-sphere-viewer/core'; | ||
import { SettingsPlugin } from '@photo-sphere-viewer/settings-plugin'; | ||
|
||
const baseUrl = 'https://photo-sphere-viewer-data.netlify.app/assets/'; | ||
|
||
const viewer = new Viewer({ | ||
container: 'photosphere', | ||
panorama: baseUrl + 'sphere.jpg', | ||
caption: 'Parc national du Mercantour <b>© Damien Sorel</b>', | ||
loadingImg: baseUrl + 'loader.gif', | ||
plugins: [ | ||
SettingsPlugin, | ||
], | ||
}); | ||
|
||
window.viewer = viewer; | ||
</script> | ||
</body> | ||
</html> |
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.