|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import { CodeEditorService } from "./code-editor.service"; |
| 21 | + |
| 22 | +describe("CodeEditorService", () => { |
| 23 | + let service: CodeEditorService; |
| 24 | + |
| 25 | + beforeEach(() => { |
| 26 | + service = new CodeEditorService(); |
| 27 | + }); |
| 28 | + |
| 29 | + it("should be created", () => { |
| 30 | + expect(service).toBeTruthy(); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should emit true after setEditorState is called with true", () => { |
| 34 | + let value: boolean | undefined; |
| 35 | + service.getEditorState("op1").subscribe(v => (value = v)); |
| 36 | + service.setEditorState("op1", true); |
| 37 | + expect(value).toBe(true); |
| 38 | + }); |
| 39 | + |
| 40 | + it("should emit false after setEditorState is called with false", () => { |
| 41 | + let value: boolean | undefined; |
| 42 | + service.getEditorState("op1").subscribe(v => (value = v)); |
| 43 | + service.setEditorState("op1", false); |
| 44 | + expect(value).toBe(false); |
| 45 | + }); |
| 46 | + |
| 47 | + it("should track state independently for different operator IDs", () => { |
| 48 | + let valueA: boolean | undefined; |
| 49 | + let valueB: boolean | undefined; |
| 50 | + service.getEditorState("opA").subscribe(v => (valueA = v)); |
| 51 | + service.getEditorState("opB").subscribe(v => (valueB = v)); |
| 52 | + service.setEditorState("opA", true); |
| 53 | + expect(valueA).toBe(true); |
| 54 | + expect(valueB).toBe(false); |
| 55 | + }); |
| 56 | +}); |
0 commit comments