Hello<\/div>/);
expect(waitingElementHandlers.get('RMLREF+0')).toEqual([{
eventName: 'mouseover',
listener: handlerStream,
type: 'source',
}]);
});
});
});
describe('Sinks', () => {
describe('Attributes', () => {
describe('Classes', () => {
describe('When a string is passed', () => {
it('sets the value inline', () => {
const className = 'my-class';
const template = rml`
Hello
`;
expect(template).toEqual('
Hello
');
});
it('sets deferred values later, initial value is empty', () => {
const className = defer('my-class');
const template = rml`
Hello
`;
expect(template).toMatch(/
Hello<\/div>/);
expect(waitingElementHandlers.get('RMLREF+0')).toMatchObject([
// TODO: match the sink, too
{ source: className, type: 'sink', t: 'class' },
]);
});
});
describe('When a plain object is passed', () => {
it('sets the value inline', () => {
const classes = {
'class-a': true,
'class-b': false,
'class-c': true
};
const template = rml`Hello
`;
expect(template).toEqual('Hello
');
});
});
describe('When an object of deferred values is passed', () => {
it('sets values later, initial value is empty', () => {
const classes = { 'class-a': defer(true), 'class-b': defer(false) };
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
expect(waitingElementHandlers.get('RMLREF+0')).toMatchObject([
// TODO: match the sink, too
{ source: classes['class-a'], type: 'sink', t: 'class' },
]);
});
});
});
describe('Styles', () => {
});
});
describe('Dataset', () => {
describe('When a key is specified', () => {
it('sets the value inline', () => {
const foo = 'bar';
const template = rml`Hello
`;
expect(template).toEqual('Hello
');
});
it('sets deferred values later, initial value is empty', () => {
const foo = defer('bar');
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
expect(waitingElementHandlers.get('RMLREF+0')).toMatchObject([
// TODO: match the sink, too
{ source: foo, type: 'sink', t: 'data-foo' },
]);
});
});
});
describe('Mixins', () => {
describe('Syntax', () => {
it('works with spread operator (...) prefix', () => {
const a = { 'data-foo': 'bar' };
const template = rml`
Hello
`;
expect(template).toMatch(/
Hello<\/div>/);
});
it('works without ...', () => {
const a = { 'data-foo': 'bar' };
const template = rml`
Hello
`;
expect(template).toMatch(/
Hello<\/div>/);
});
});
describe('Classes', () => {
describe('When supplied classes resolve to a string', () => {
describe('When a Simple Present Object (an object with only present values) is supplied', () => {
it('bakes class values into the HTML', () => {
const a = {
class: 'cls1'
};
const template = rml`
Hello
`;
expect(template).toMatch(/
Hello<\/div>/);
});
});
describe('When a Future Object (a Future) is supplied', () => {
it('does not bake any values into the HTML', () => {
const a = Promise.resolve({
class: 'cls1'
});
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
});
});
describe('When an Object of Futures is supplied', () => {
it('does not bake any values into the HTML', () => {
const a = {
class: Promise.resolve('cls1'),
};
const template = rml`
Hello
`;
expect(template).toMatch(/
Hello<\/div>/);
});
});
});
describe('When supplied classes resolve to space-separated strings', () => {
describe('When a Simple Present Object (an object with only present values) is supplied', () => {
it('bakes class values into the HTML', () => {
const a = {
class: 'cls1 cls2'
};
const template = rml`
Hello
`;
expect(template).toMatch(/
Hello<\/div>/);
});
});
});
describe('When supplied classes resolve to objects', () => {
describe('When a Simple Present Object (an object with only present values) is supplied', () => {
it('only bakes present truthy class values into the HTML', () => {
const a = {
class: {
cls1: true,
cls2: true,
cls3: false,
},
};
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
});
});
describe('When a Class Chronosympton (an object with both present and future classes) is supplied', () => {
it('only bakes present class values into the HTML', () => {
const a = {
class: {
cls1: true,
cls2: true,
cls3: Promise.resolve(true),
},
};
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
});
});
});
});
describe('Styles', () => {
describe('When supplied styles resolve to a string', () => {
describe('When a Simple Present Object (an object with only present values) is supplied', () => {
it('bakes style values into the HTML', () => {
const a = {
style: 'color: red;'
};
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
});
});
describe('When a Future Object (a Future) is supplied', () => {
it('does not bake any values into the HTML', () => {
const a = Promise.resolve({
style: 'color: red;'
});
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
});
});
describe('When an Object of Futures is supplied', () => {
it('does not bake any values into the HTML', () => {
const a = {
style: Promise.resolve('color: red;'),
};
const template = rml`
Hello
`;
expect(template).toMatch(/
Hello<\/div>/);
});
});
});
describe('When supplied styles resolve to semicolon-separated strings', () => {
describe('When a Simple Present Object (an object with only present values) is supplied', () => {
it('bakes class values into the HTML', () => {
const a = {
style: 'color: red; background: blue;'
};
const template = rml`
Hello
`;
expect(template).toMatch(/
Hello<\/div>/);
});
});
});
describe('When supplied styles resolve to objects', () => {
describe('When a Simple Present Object (an object with only present values) is supplied', () => {
it('only bakes present truthy style values into the HTML', () => {
const a = {
style: {
color: 'red',
background: 'blue',
pointer: null,
},
};
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
});
});
describe('When a Style Chronosympton (an object with both present and future classes) is supplied', () => {
it('only bakes present style values into the HTML', () => {
const a = {
style: {
color: 'red',
background: 'blue',
pointer: Promise.resolve('none'),
},
};
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
});
});
});
});
describe('Futures', () => {
it('works with promises', () => {
const a = defer({
'data-foo': 'bar'
});
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
expect(waitingElementHandlers.get('RMLREF+0')).toEqual([
{ source: a, sink: AttributeObjectSink, type: 'sink', t: 'mixin' },
]);
});
it('works with observables', () => {
const a = of({ 'data-foo': 'bar' });
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
expect(waitingElementHandlers.get('RMLREF+0')).toEqual([
{ source: a, sink: AttributeObjectSink, type: 'sink', t: 'mixin' },
]);
});
describe('When multiple mixins are merged into the same element', () => {
describe('When a present mixin is followed by a future mixin', () => {
it('presents are baked in, futures deferred', () => {
const a = {
'data-foo': 'bar'
};
const b = defer({
'data-bar': 'baz'
});
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
expect(waitingElementHandlers.get('RMLREF+0')![0]).toEqual(
{ type: 'sink', t: 'mixin', source: b, sink: AttributeObjectSink },
);
});
});
describe('When a future mixin is followed by a present mixin', () => {
it('presents are baked in, futures deferred', async () => {
const a = defer({ 'data-bar': 'baz' });
const b = { 'data-foo': 'bar' };
const template = rml`
Hello
`;
const sbc = waitingElementHandlers.get('RMLREF+0')![0] as SinkBindingConfiguration;
expect(template).toMatch(/
Hello<\/div>/);
expect(sbc).toEqual(
{ type: 'sink', t: 'mixin', source: a, sink: AttributeObjectSink },
);
expect(sbc.source).resolves.toEqual(
{ 'data-bar': 'baz' },
);
});
});
describe('When a future mixin is followed by another', () => {
it('both futures are queued for mounting', async () => {
const a = defer({ 'data-foo': 'bar' });
const b = defer({ 'data-bar': 'baz' });
const template = rml`Hello
`;
const sbc0 = waitingElementHandlers.get('RMLREF+0')![0] as SinkBindingConfiguration;
const sbc1 = waitingElementHandlers.get('RMLREF+0')![1] as SinkBindingConfiguration;
expect(template).toMatch(/Hello<\/div>/);
expect(sbc0).toEqual(
{ type: 'sink', t: 'mixin', source: a, sink: AttributeObjectSink },
);
expect(sbc0).toEqual(
{ type: 'sink', t: 'mixin', source: b, sink: AttributeObjectSink },
);
expect(sbc0.source).resolves.toEqual(
{ 'data-foo': 'bar' },
);
expect(sbc1.source).resolves.toEqual(
{ 'data-bar': 'baz' },
);
});
});
});
describe('Event Handlers', () => {
it('bakes string listeners inline', () => {
const a = { 'onmouseover': 'alert(123)' };
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
});
it('leaves referenced listeners to set on mount', () => {
const fn = () => alert(123);
const a = { 'onmouseover': fn };
const template = rml`
Hello
`;
expect(template).toMatch(/
Hello<\/div>/);
expect(waitingElementHandlers.get('RMLREF+0')![0]).toStrictEqual(
{ type: 'sink', t: 'mixin', source: { 'onmouseover': fn }, sink: AttributeObjectSink },
);
});
it('always defers onmount', () => {
const fn = () => alert(123);
const a = { 'onmount': fn };
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
expect(waitingElementHandlers.get('RMLREF+0')![0]).toStrictEqual(
{ type: 'sink', t: 'mixin', source: { 'onmount': fn }, sink: AttributeObjectSink },
);
});
it('always defers rml:onmount', () => {
const fn = () => alert(123);
const a = { 'rml:onmount': fn };
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
expect(waitingElementHandlers.get('RMLREF+0')![0]).toStrictEqual(
{ type: 'sink', t: 'mixin', source: { 'rml:onmount': fn }, sink: AttributeObjectSink },
);
});
});
});
describe('When multiple mixins are passed together', () => {
it('sets them correctly when adjacent', () => {
const a = { 'data-a': 'a' };
const b = { 'data-b': 'b' };
const c = { 'data-c': 'c' };
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
});
it('sets them correctly with other attributes in between', () => {
const a = { 'data-a': 'a' };
const b = { 'data-b': 'b' };
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
});
it('sets them correctly with various types of attributes in between', () => {
const a = { 'data-a': 'a' };
const b = { 'data-b': 'b' };
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
});
it('sets them correctly with other attributes around', () => {
const a = { 'data-a': 'a' };
const b = { 'data-b': 'b' };
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
});
it('sets them correctly with other attributes around and between', () => {
const a = { 'data-a': 'a' };
const b = { 'data-b': 'b' };
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
});
it('sets them correctly with other passed-in attributes in between', () => {
const a = { 'data-a': 'a' };
const b = { 'data-b': 'b' };
const number = 42;
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
});
});
describe('When dataset attributes are passed', () => {
it('sets their values inline', () => {
const args = { 'data-foo': 'bar', 'data-baz': 'qux' };
const template = rml`Hello
`;
expect(template).toMatch(/Hello<\/div>/);
});
it('sets deferred values later, (initially empty), static ones inline', () => {
const quz = defer('quz');
const deferred = { 'data-baz': quz };
const obj = { 'data-foo': 'bar', ...deferred};
const template = rml`Hello
`;
expect(template).toMatch(/^Hello<\/div>/);
expect(waitingElementHandlers.get('RMLREF+0')).toEqual([
{ source: deferred, sink: AttributeObjectSink, type: 'sink', t: 'mixin' },
]);
});
});
});
describe('Any sink', () => {
describe('When a BehaviorSubject (.value) is passed', () => {
describe('When an implicit sink is used', () => {
it('sets the value inline', () => {
const bs = new BehaviorSubject(123)
const template = rml`${bs}
`;
expect(template).toMatch(/123<\/div>/);
});
});
describe('When an explicit sink is used', () => {
it('sets the value inline', () => {
const bs = new BehaviorSubject(123)
const template = rml`${InnerText(bs)}
`;
expect(template).toMatch(/123<\/div>/);
});
});
describe('Content', () => {
it('renders 0 when an object has a .value of 0', () => {
const zeroValueObject = new BehaviorSubject(0);
const template = rml`${zeroValueObject}
`;
expect(template).toMatch(/0<\/div>/);
});
});
describe('Attributes', () => {
it('renders 0 in an attribute when an object has a .value of 0', () => {
const zeroValueObject = new BehaviorSubject(0);
const template = rml` `;
expect(template).toMatch(//);
});
});
});
});
});
describe('Plain Objects', () => {
});
});