Skip to content

Commit

Permalink
Test selectors getter
Browse files Browse the repository at this point in the history
  • Loading branch information
julianrubisch committed Jun 3, 2021
1 parent d916662 commit a93880e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
56 changes: 27 additions & 29 deletions javascript/reflex_data.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
import { extractElementAttributes, extractElementDataset } from "./attributes";
import { getReflexRoots } from "./reflexes";
import { uuidv4 } from "./utils";
import { elementToXPath } from "./utils";
import { extractElementAttributes, extractElementDataset } from './attributes'
import { getReflexRoots } from './reflexes'
import { uuidv4 } from './utils'
import { elementToXPath } from './utils'

export default class ReflexData {
constructor(options, reflexElement, controllerElement) {
this.options = options;
this.reflexElement = reflexElement;
this.controllerElement = controllerElement;
constructor (options, reflexElement, controllerElement) {
this.options = options
this.reflexElement = reflexElement
this.controllerElement = controllerElement
}

get attrs() {
return (
this.options["attrs"] || extractElementAttributes(this.reflexElement)
);
get attrs () {
return this.options['attrs'] || extractElementAttributes(this.reflexElement)
}

get reflexId() {
return this.options["reflexId"] || uuidv4();
get reflexId () {
return this.options['reflexId'] || uuidv4()
}

get selectors() {
get selectors () {
const selectors =
this.options["selectors"] || getReflexRoots(this.reflexElement);
if (typeof selectors === "string") {
return [selectors];
this.options['selectors'] || getReflexRoots(this.reflexElement)
if (typeof selectors === 'string') {
return [selectors]
} else {
return selectors;
return selectors
}
}

get resolveLate() {
return this.options["resolveLate"] || false;
get resolveLate () {
return this.options['resolveLate'] || false
}

get dataset() {
return extractElementDataset(this.reflexElement);
get dataset () {
return extractElementDataset(this.reflexElement)
}

get xpathController() {
return elementToXPath(this.controllerElement);
get xpathController () {
return elementToXPath(this.controllerElement)
}

get xpathElement() {
return elementToXPath(this.reflexElement);
get xpathElement () {
return elementToXPath(this.reflexElement)
}

valueOf() {
valueOf () {
return {
attrs: this.attrs,
dataset: this.dataset,
Expand All @@ -55,6 +53,6 @@ export default class ReflexData {
resolveLate: this.resolveLate,
xpathController: this.xpathController,
xpathElement: this.xpathElement
};
}
}
}
15 changes: 15 additions & 0 deletions javascript/test/reflexData.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import assert from 'assert'
import ReflexData from '../reflex_data'

describe('ReflexData', () => {
it('returns an array of selectors', () => {
assert.deepStrictEqual(new ReflexData({ selectors: '#an-id' }).selectors, [
'#an-id'
])

assert.deepStrictEqual(
new ReflexData({ selectors: ['.item', 'li'] }).selectors,
['.item', 'li']
)
})
})

0 comments on commit a93880e

Please sign in to comment.