1
0
Fork 0

fix: remove changeset trait from state label, test colorize logic

This commit is contained in:
ssube 2020-08-15 14:58:29 -05:00 committed by Sean Sube
parent 50cf48fdcf
commit 4aeb3243f7
9 changed files with 106 additions and 18 deletions

View File

@ -13,3 +13,9 @@ export interface FlagLabel extends BaseLabel, ChangeSet
```
<b>Extends:</b> BaseLabel, ChangeSet
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [requires](./cautious-journey.flaglabel.requires.md) | Array&lt;unknown&gt; | |

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [FlagLabel](./cautious-journey.flaglabel.md) &gt; [requires](./cautious-journey.flaglabel.requires.md)
## FlagLabel.requires property
<b>Signature:</b>
```typescript
requires: Array<unknown>;
```

View File

@ -9,9 +9,9 @@ Grouped labels: the equivalent of a radio group.
<b>Signature:</b>
```typescript
export interface StateLabel extends BaseLabel, ChangeSet
export interface StateLabel extends BaseLabel
```
<b>Extends:</b> BaseLabel, ChangeSet
<b>Extends:</b> BaseLabel
## Properties

View File

@ -9,9 +9,9 @@ One of many values for a particular state.
<b>Signature:</b>
```typescript
export interface StateValue extends BaseLabel
export interface StateValue extends BaseLabel, ChangeSet
```
<b>Extends:</b> BaseLabel
<b>Extends:</b> BaseLabel, ChangeSet
## Properties

View File

@ -18,6 +18,7 @@ export interface SyncOptions
| [flags](./cautious-journey.syncoptions.flags.md) | Array&lt;[FlagLabel](./cautious-journey.flaglabel.md)<!-- -->&gt; | |
| [logger](./cautious-journey.syncoptions.logger.md) | Logger | |
| [project](./cautious-journey.syncoptions.project.md) | string | |
| [random](./cautious-journey.syncoptions.random.md) | prng | |
| [remote](./cautious-journey.syncoptions.remote.md) | [Remote](./cautious-journey.remote.md) | |
| [states](./cautious-journey.syncoptions.states.md) | Array&lt;[StateLabel](./cautious-journey.statelabel.md)<!-- -->&gt; | States from project config. |

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [SyncOptions](./cautious-journey.syncoptions.md) &gt; [random](./cautious-journey.syncoptions.random.md)
## SyncOptions.random property
<b>Signature:</b>
```typescript
random: prng;
```

View File

@ -31,16 +31,23 @@ export interface BaseLabel {
* Display color.
*/
color?: string;
/**
* Long-form description.
*/
desc?: string;
/**
* Label priority.
*/
priority: number;
requires: Array<LabelRef>;
}
/**
* Individual labels: the equivalent of a checkbox.
*/
export interface FlagLabel extends BaseLabel, ChangeSet {
/* empty */
requires: Array<LabelRef>;
}
/**
@ -56,7 +63,7 @@ export interface StateChange extends ChangeSet {
/**
* One of many values for a particular state.
*/
export interface StateValue extends BaseLabel {
export interface StateValue extends BaseLabel, ChangeSet {
/**
* State changes that could occur to this value.
*/
@ -66,7 +73,7 @@ export interface StateValue extends BaseLabel {
/**
* Grouped labels: the equivalent of a radio group.
*/
export interface StateLabel extends BaseLabel, ChangeSet {
export interface StateLabel extends BaseLabel {
/**
* Values for this state.
*/
@ -121,17 +128,15 @@ export function prioritySort<TLabel extends BaseLabel>(labels: Array<TLabel>): A
/**
* Pick a label color, preferring the label data if set, falling back to a randomly selected color.
*
* TODO: this is a terrible overload
*/
export function getLabelColor(colors: Array<string>, random: prng, flag: FlagLabel): string;
export function getLabelColor(colors: Array<string>, random: prng, state: StateLabel, value: StateValue): string;
export function getLabelColor(colors: Array<string>, random: prng, label: BaseLabel, value?: StateValue): string {
if (doesExist(value) && doesExist(value.color)) {
if (doesExist(value) && doesExist(value.color) && value.color !== '') {
return value.color;
}
if (doesExist(label.color)) {
if (doesExist(label.color) && label.color !== '') {
return label.color;
}

View File

@ -15,6 +15,6 @@ export function defaultUntil<T>(...items: Array<Optional<T>>): T {
}
export function randomItem<T>(items: Array<T>, source: prng): T {
const idx = Math.floor(source() * items.length);
const idx = source.int32() % items.length;
return items[idx];
}

View File

@ -1,6 +1,7 @@
import { expect } from 'chai';
import { alea } from 'seedrandom';
import { getLabelNames, prioritySort } from '../src/labels';
import { getLabelColor, getLabelNames, prioritySort } from '../src/labels';
describe('label helpers', () => {
describe('label name helper', () => {
@ -30,23 +31,21 @@ describe('label helpers', () => {
it('should return all states', () => {
const values = [{
adds: [],
becomes: [],
name: 'bin',
priority: 1,
removes: [],
requires: [],
}];
const states = [{
adds: [],
name: 'foo',
priority: 1,
removes: [],
requires: [],
values,
}, {
adds: [],
name: 'bar',
priority: 1,
removes: [],
requires: [],
values,
}];
@ -92,4 +91,59 @@ describe('label helpers', () => {
expect(sorted[0]).to.deep.equal(FIRST_LABEL);
});
});
describe('label color helper', () => {
it('should return the value color', () => {
expect(getLabelColor(['test'], alea(), {
color: 'beans',
name: '',
priority: 1,
values: [],
}, {
adds: [],
becomes: [],
color: 'not',
name: '',
priority: 1,
removes: [],
})).to.equal('not');
});
it('should return the state color when value color is unset', () => {
expect(getLabelColor(['test'], alea(), {
color: 'beans',
name: '',
priority: 1,
values: [],
}, {
adds: [],
becomes: [],
color: '',
name: '',
priority: 1,
removes: [],
})).to.equal('beans');
});
it('should return the flag color', () => {
expect(getLabelColor(['test'], alea(), {
adds: [],
color: 'not',
name: '',
priority: 1,
removes: [],
requires: [],
})).to.equal('not');
});
it('should return a random color when the flag color is unset', () => {
expect(getLabelColor(['test'], alea(), {
adds: [],
name: '',
priority: 1,
removes: [],
requires: [],
})).to.equal('test');
});
});
});