|
| 1 | +"use babel" |
| 2 | +import { StyleReader } from "../commons-ui/dom-style-reader" |
| 3 | + |
| 4 | +const styles = ` |
| 5 | + atom-text-editor { |
| 6 | + position: relative; |
| 7 | + } |
| 8 | +
|
| 9 | + atom-text-editor-minimap[stand-alone] { |
| 10 | + width: 100px; |
| 11 | + height: 100px; |
| 12 | + } |
| 13 | +
|
| 14 | + atom-text-editor { |
| 15 | + line-height: 17px; |
| 16 | + } |
| 17 | +
|
| 18 | + atom-text-editor atom-text-editor-minimap { |
| 19 | + background: rgba(255,0,0,0.3); |
| 20 | + } |
| 21 | +
|
| 22 | + atom-text-editor atom-text-editor-minimap .minimap-scroll-indicator { |
| 23 | + background: rgba(0,0,255,0.3); |
| 24 | + } |
| 25 | +
|
| 26 | + atom-text-editor atom-text-editor-minimap .minimap-visible-area { |
| 27 | + background: rgba(0,255,0,0.3); |
| 28 | + opacity: 1; |
| 29 | + } |
| 30 | +
|
| 31 | + atom-text-editor atom-text-editor-minimap .open-minimap-quick-settings { |
| 32 | + opacity: 1 !important; |
| 33 | + } |
| 34 | +` |
| 35 | + |
| 36 | +describe("StyleReader", () => { |
| 37 | + const styleReader = new StyleReader() |
| 38 | + |
| 39 | + let body: HTMLElement |
| 40 | + let targetElement: HTMLElement |
| 41 | + |
| 42 | + beforeEach(async () => { |
| 43 | + body = atom.workspace.getElement() |
| 44 | + jasmine.attachToDOM(body) |
| 45 | + targetElement = (await atom.workspace.open(__filename)).getElement() |
| 46 | + |
| 47 | + const styleNode = document.createElement("style") |
| 48 | + styleNode.textContent = styles |
| 49 | + body.appendChild(styleNode) |
| 50 | + }) |
| 51 | + |
| 52 | + it("can get the color of the text", () => { |
| 53 | + expect(styleReader.retrieveStyleFromDom([".editor"], "color", targetElement, true)).toEqual(`rgb(157, 165, 180)`) |
| 54 | + }) |
| 55 | + |
| 56 | + describe("color rotation", () => { |
| 57 | + let additionnalStyleNode |
| 58 | + |
| 59 | + function setup(color = "read") { |
| 60 | + styleReader.invalidateDOMStylesCache() |
| 61 | + |
| 62 | + additionnalStyleNode = document.createElement("style") |
| 63 | + additionnalStyleNode.textContent = ` |
| 64 | + atom-text-editor .editor, .editor { |
| 65 | + color: ${color}; |
| 66 | + -webkit-filter: hue-rotate(180deg); |
| 67 | + } |
| 68 | + ` |
| 69 | + |
| 70 | + body.appendChild(additionnalStyleNode) |
| 71 | + } |
| 72 | + |
| 73 | + it("when a hue-rotate filter is applied to a rgb color computes the new color by applying the hue rotation", () => { |
| 74 | + setup("red") |
| 75 | + expect(styleReader.retrieveStyleFromDom([".editor"], "color", targetElement, true)).toEqual(`rgb(0, 109, 109)`) |
| 76 | + }) |
| 77 | + |
| 78 | + it("computes the new color by applying the hue rotation", () => { |
| 79 | + setup("rgba(255, 0, 0, 0)") |
| 80 | + expect(styleReader.retrieveStyleFromDom([".editor"], "color", targetElement, true)).toEqual( |
| 81 | + `rgba(0, 109, 109, 0)` |
| 82 | + ) |
| 83 | + }) |
| 84 | + }) |
| 85 | +}) |
0 commit comments