forked from JeremyHeleine/Photo-Sphere-Viewer
-
-
Notifications
You must be signed in to change notification settings - Fork 699
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
11 changed files
with
238 additions
and
15 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 |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import type { ResolutionPlugin } from '@photo-sphere-viewer/resolution-plugin'; | ||
import { callPlugin, callViewer, checkEventHandler, checkPanorama, setPanorama, waitViewerReady } from '../../utils'; | ||
import { BASE_URL } from '../../utils/constants'; | ||
|
||
|
||
describe('plugin: resolution', () => { | ||
beforeEach(() => { | ||
localStorage.photoSphereViewer_touchSupport = 'false'; | ||
cy.visit('e2e/plugins/resolution.html'); | ||
waitViewerReady(); | ||
// createBaseSnapshot(); | ||
}); | ||
|
||
it('should destroy', () => { | ||
callViewer('destroy').then(viewer => viewer.destroy()); | ||
}); | ||
|
||
it('should display the settings', () => { | ||
cy.get('.psv-settings-button') | ||
.compareScreenshots('button-sd') | ||
.click(); | ||
|
||
cy.get('.psv-settings').compareScreenshots('settings'); | ||
|
||
cy.get('[data-setting-id="resolution"]').click(); | ||
|
||
cy.get('.psv-settings').compareScreenshots('settings-options'); | ||
}); | ||
|
||
it('should not show the settings badge', () => { | ||
cy.visit('e2e/plugins/resolution.html?showBadge=false'); | ||
|
||
cy.get('.psv-settings-button').should('not.include.text', 'SD'); | ||
}); | ||
|
||
it('should translate the setting', () => { | ||
callViewer('set lang').then(viewer => viewer.setOption('lang', { resolution: 'Qualité' })); | ||
|
||
cy.get('.psv-settings-button').click(); | ||
|
||
cy.get('.psv-settings').should('include.text', 'Qualité'); | ||
}); | ||
|
||
it('should use the first resolution', () => { | ||
checkPanorama('sphere-small.jpg'); | ||
}); | ||
|
||
it('should use the default resolution', () => { | ||
cy.visit('e2e/plugins/resolution.html?resolution=HD'); | ||
|
||
checkPanorama('sphere.jpg'); | ||
}); | ||
|
||
it('should ignore default resolution with initial panorama', () => { | ||
cy.visit('e2e/plugins/resolution.html?resolution=HD&withPanorama=true'); | ||
|
||
checkPanorama('sphere-small.jpg'); | ||
}); | ||
|
||
it('should change the resolution', () => { | ||
const resolutionChangeHandler = listenResolutionEvent('resolution-changed'); | ||
|
||
cy.get('.psv-settings-button').click(); | ||
cy.get('[data-setting-id="resolution"]').click(); | ||
cy.get('[data-option-id="HD"]').click(); | ||
|
||
checkPanorama('sphere.jpg'); | ||
checkEventHandler(resolutionChangeHandler, { resolutionId: 'HD' }); | ||
cy.get('.psv-settings-button').compareScreenshots('button-hd'); | ||
}); | ||
|
||
it('should change the resolution by API', () => { | ||
const resolutionChangeHandler = listenResolutionEvent('resolution-changed'); | ||
|
||
callResolution('set resolution').then(resolution => resolution.setResolution('HD')); | ||
|
||
checkPanorama('sphere.jpg'); | ||
checkEventHandler(resolutionChangeHandler, { resolutionId: 'HD' }); | ||
|
||
callResolution('set bad resolution').then(resolution => { | ||
expect(() => resolution.setResolution('MD')).to.throw('Resolution "MD" unknown'); | ||
}); | ||
}); | ||
|
||
it('should update resolution on panorama change', () => { | ||
const resolutionChangeHandler = listenResolutionEvent('resolution-changed'); | ||
|
||
setPanorama('sphere.jpg'); | ||
|
||
checkEventHandler(resolutionChangeHandler, { resolutionId: 'HD' }); | ||
}); | ||
|
||
it('should change resolutions', () => { | ||
const resolutionChangeHandler = listenResolutionEvent('resolution-changed'); | ||
|
||
// the current panorama is found in the new list | ||
callResolution('set resolutions w.o. default').then(resolution => resolution.setResolutions([ | ||
{ id: 'large', label: 'large', panorama: BASE_URL + 'sphere.jpg' }, | ||
{ id: 'small', label: 'small', panorama: BASE_URL + 'sphere-small.jpg' }, | ||
])); | ||
|
||
checkEventHandler(resolutionChangeHandler, { resolutionId: 'small' }); | ||
|
||
resolutionChangeHandler.reset(); | ||
|
||
// a default value is provided | ||
callResolution('set resolutions w. default').then(resolution => resolution.setResolutions([ | ||
{ id: 'large', label: 'large', panorama: BASE_URL + 'sphere.jpg' }, | ||
{ id: 'small', label: 'small', panorama: BASE_URL + 'sphere-small.jpg' }, | ||
], 'large')); | ||
cy.wait(200); | ||
|
||
checkPanorama('sphere.jpg'); | ||
checkEventHandler(resolutionChangeHandler, { resolutionId: 'large' }); | ||
|
||
resolutionChangeHandler.reset(); | ||
|
||
// the current panorama is NOT found in the new list | ||
setPanorama('sphere-test.jpg'); | ||
callResolution('set resolutions w.o. default no match').then(resolution => resolution.setResolutions([ | ||
{ id: 'small', label: 'small', panorama: BASE_URL + 'sphere-small.jpg' }, | ||
{ id: 'large', label: 'large', panorama: BASE_URL + 'sphere.jpg' }, | ||
])); | ||
cy.wait(200); | ||
|
||
checkPanorama('sphere-small.jpg'); | ||
checkEventHandler(resolutionChangeHandler, { resolutionId: 'small' }); | ||
}); | ||
|
||
it('should throw if missing properties', () => { | ||
callResolution('set resolutions').then(resolution => { | ||
expect(() => resolution.setResolutions([{ id: null, label: 'label', panorama: 'sphere.jpg' }])).to.throw('Missing resolution id'); | ||
|
||
expect(() => resolution.setResolutions([{ id: 'sd', label: null, panorama: 'sphere.jpg' }])).to.throw('Missing resolution label'); | ||
|
||
expect(() => resolution.setResolutions([{ id: 'sd', label: 'label', panorama: null }])).to.throw('Missing resolution panorama'); | ||
}); | ||
}); | ||
|
||
function callResolution(log: string) { | ||
return callPlugin<ResolutionPlugin>('resolution', log); | ||
} | ||
|
||
function listenResolutionEvent(name: Parameters<ResolutionPlugin['addEventListener']>[0]): Cypress.Agent<sinon.SinonStub> { | ||
const handler = cy.stub(); | ||
callResolution(`listen "${name}"`).then(resolution => resolution.addEventListener(name, handler)); | ||
return handler; | ||
} | ||
|
||
}); |
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,69 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>PhotoSphereViewer</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/resolution-plugin": "/dist/resolution-plugin/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 { ResolutionPlugin } from '@photo-sphere-viewer/resolution-plugin'; | ||
import { SettingsPlugin } from '@photo-sphere-viewer/settings-plugin'; | ||
|
||
const baseUrl = 'https://photo-sphere-viewer-data.netlify.app/assets/'; | ||
|
||
const urlParams = new URLSearchParams(window.location.search); | ||
|
||
const viewer = new Viewer({ | ||
container: 'photosphere', | ||
panorama: urlParams.get('withPanorama') ? baseUrl + 'sphere-small.jpg' : null, | ||
plugins: [ | ||
SettingsPlugin, | ||
[ResolutionPlugin, { | ||
showBadge: urlParams.get('showBadge') !== 'false', | ||
defaultResolution: urlParams.get('resolution'), | ||
resolutions: [ | ||
{ | ||
id: 'SD', | ||
label: 'Small', | ||
panorama: baseUrl + 'sphere-small.jpg', | ||
}, | ||
{ | ||
id: 'HD', | ||
label: 'Normal', | ||
panorama: baseUrl + 'sphere.jpg', | ||
}, | ||
], | ||
}], | ||
], | ||
}); | ||
|
||
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
Binary file added
BIN
+1.07 KB
cypress/snapshots/base/cypress/e2e/plugins/resolution.cy.ts/button-hd.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
+1.19 KB
cypress/snapshots/base/cypress/e2e/plugins/resolution.cy.ts/button-sd.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
+5.38 KB
cypress/snapshots/base/cypress/e2e/plugins/resolution.cy.ts/settings-options.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
+3.02 KB
cypress/snapshots/base/cypress/e2e/plugins/resolution.cy.ts/settings.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