|
| 1 | +//#region ZoneSetup |
| 2 | + |
| 3 | +import 'zone.js/dist/zone'; |
| 4 | +import 'zone.js/dist/long-stack-trace-zone'; |
| 5 | +import 'zone.js/dist/async-test'; |
| 6 | +import 'zone.js/dist/fake-async-test'; |
| 7 | +import 'zone.js/dist/sync-test'; |
| 8 | +import 'zone.js/dist/proxy'; |
| 9 | + |
| 10 | +//#endregion |
| 11 | + |
| 12 | +//#region Simulate window in node.js |
| 13 | + |
| 14 | +import { JSDOM } from 'jsdom'; |
| 15 | + |
| 16 | +const window = (new JSDOM('<!doctype html><html><body></body></html>')).window; |
| 17 | +const document = window.document; |
| 18 | +const testGlobal: any = global; |
| 19 | +testGlobal.window = window; |
| 20 | +testGlobal.document = document; |
| 21 | +testGlobal.Document = document; |
| 22 | +testGlobal.HTMLElement = window.HTMLElement; |
| 23 | +testGlobal.XMLHttpRequest = window.XMLHttpRequest; |
| 24 | +testGlobal.Node = window.Node; |
| 25 | +testGlobal.Event = window.Event; |
| 26 | +testGlobal.Element = window.Element; |
| 27 | +testGlobal.navigator = window.navigator; |
| 28 | +testGlobal.KeyboardEvent = window.KeyboardEvent; |
| 29 | + |
| 30 | +testGlobal.localStorage = { |
| 31 | + store: {}, |
| 32 | + |
| 33 | + getItem(key: any) { |
| 34 | + return this.store[key] || null; |
| 35 | + }, |
| 36 | + setItem(key: any, value: any) { |
| 37 | + this.store[key] = value; |
| 38 | + }, |
| 39 | + clear() { |
| 40 | + this.store = {}; |
| 41 | + } |
| 42 | +}; |
| 43 | + |
| 44 | +testGlobal.sessionStorage = { |
| 45 | + store: {}, |
| 46 | + |
| 47 | + getItem(key: any) { |
| 48 | + return this.store[key] || null; |
| 49 | + }, |
| 50 | + setItem(key: any, value: any) { |
| 51 | + this.store[key] = value; |
| 52 | + }, |
| 53 | + clear() { |
| 54 | + this.store = {}; |
| 55 | + } |
| 56 | +}; |
| 57 | + |
| 58 | +// https://github.com/angular/material2/issues/7101 |
| 59 | +Object.defineProperty( |
| 60 | + document.body.style, |
| 61 | + 'transform', |
| 62 | + { |
| 63 | + value: () => ({ enumerable: true, configurable: true }) |
| 64 | + }); |
| 65 | + |
| 66 | +//#endregion |
| 67 | + |
| 68 | +// //#region Mocha setup |
| 69 | + |
| 70 | +// import * as Mocha from 'mocha'; |
| 71 | + |
| 72 | +// testGlobal.Mocha = testGlobal.Mocha ?? Mocha; |
| 73 | +// testGlobal.window.Mocha = testGlobal.window.Mocha ?? testGlobal.Mocha ?? Mocha; |
| 74 | +// testGlobal.window.Zone = testGlobal.window.Zone ?? testGlobal.Zone; |
| 75 | + |
| 76 | +// import 'zone.js/dist/mocha-patch'; |
| 77 | + |
| 78 | +// //#endregion |
| 79 | + |
| 80 | +import { expect } from 'chai'; |
| 81 | +import 'mocha'; |
| 82 | + |
| 83 | +import { AceComponent } from '..'; |
| 84 | +import { AppServiceInfoRegistry } from '@kephas/core'; |
| 85 | +import { AngularAppServiceInfoRegistry } from '@kephas/ngx-core'; |
| 86 | +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
| 87 | + |
| 88 | +describe('AceComponent.constructor', () => { |
| 89 | + let component: AceComponent; |
| 90 | + let fixture: ComponentFixture<AceComponent>; |
| 91 | + |
| 92 | + beforeEach(async(() => { |
| 93 | + const angularRegistry = new AngularAppServiceInfoRegistry(AppServiceInfoRegistry.Instance); |
| 94 | + return TestBed.configureTestingModule( |
| 95 | + { |
| 96 | + declarations: [AceComponent], |
| 97 | + providers: angularRegistry.getRootProviders(), |
| 98 | + }) |
| 99 | + .compileComponents(); |
| 100 | + })); |
| 101 | + |
| 102 | + beforeEach(() => { |
| 103 | + fixture = TestBed.createComponent(AceComponent); |
| 104 | + component = fixture.componentInstance; |
| 105 | + fixture.detectChanges(); |
| 106 | + }); |
| 107 | + |
| 108 | + it('should initialize editor type', () => { |
| 109 | + const widget = fixture.componentRef.instance; |
| 110 | + expect(widget.editorType).is.equal('json'); |
| 111 | + }); |
| 112 | +}); |
0 commit comments