|
| 1 | +import ModelViewerElementBase from '../model-viewer-base.js'; |
| 2 | +import {timePasses} from './helpers.js'; |
| 3 | + |
| 4 | +export type Constructor<T = object> = { |
| 5 | + new (...args: any[]): T |
| 6 | +}; |
| 7 | + |
| 8 | +const expect = chai.expect; |
| 9 | + |
| 10 | +export const BasicSpecTemplate = |
| 11 | + (ModelViewerElementAccessor: () => Constructor<ModelViewerElementBase>, |
| 12 | + tagNameAccessor: () => string) => { |
| 13 | + test('can be directly instantiated', () => { |
| 14 | + const ModelViewerElement = ModelViewerElementAccessor(); |
| 15 | + const element = new ModelViewerElement(); |
| 16 | + expect(element).to.be.ok; |
| 17 | + }); |
| 18 | + |
| 19 | + test('can be instantiated with document.createElement', () => { |
| 20 | + const tagName = tagNameAccessor(); |
| 21 | + const element = document.createElement(tagName); |
| 22 | + expect(element).to.be.ok; |
| 23 | + }); |
| 24 | + |
| 25 | + suite('compatibility', () => { |
| 26 | + suite('when WebGL is not supported', () => { |
| 27 | + let nativeGetContext: any; |
| 28 | + |
| 29 | + setup(() => { |
| 30 | + nativeGetContext = HTMLCanvasElement.prototype.getContext; |
| 31 | + HTMLCanvasElement.prototype.getContext = function( |
| 32 | + type: string, ...args: Array<any>) { |
| 33 | + if (/webgl/.test(type)) { |
| 34 | + return null; |
| 35 | + } |
| 36 | + return nativeGetContext.call(this, type, ...args); |
| 37 | + }; |
| 38 | + }); |
| 39 | + |
| 40 | + teardown(() => { |
| 41 | + HTMLCanvasElement.prototype.getContext = nativeGetContext; |
| 42 | + }); |
| 43 | + |
| 44 | + test( |
| 45 | + 'does not explode when created and appended to the document', |
| 46 | + async () => { |
| 47 | + const ModelViewerElement = ModelViewerElementAccessor(); |
| 48 | + const element = new ModelViewerElement(); |
| 49 | + document.body.appendChild(element); |
| 50 | + await timePasses(); |
| 51 | + document.body.removeChild(element); |
| 52 | + }); |
| 53 | + }); |
| 54 | + }); |
| 55 | + }; |
0 commit comments