1
0
Fork 0

fix(test): add cases for state changes

This commit is contained in:
ssube 2020-08-29 02:16:53 -05:00 committed by Sean Sube
parent 804c3bb133
commit 2e816f7c75
2 changed files with 144 additions and 2 deletions

View File

@ -33,7 +33,7 @@ describe('resolve labels', () => {
for (const test of TEST_CASES) { for (const test of TEST_CASES) {
it(`should resolve ${test.name}`, () => { it(`should resolve ${test.name}`, () => {
const actualResult = resolveProject(test.input); const actualResult = resolveProject(test.input);
expect(actualResult).to.deep.equal(test.result); expect(actualResult).to.deep.include(test.result);
}); });
} }
}); });

View File

@ -1,11 +1,98 @@
import { ResolveInput, ResolveResult } from '../../src/resolve'; import { ResolveInput, ResolveResult } from '../../src/resolve';
import { StateLabel } from '../../src';
export interface ResolveTestCase { export interface ResolveTestCase {
input: ResolveInput; input: ResolveInput;
name: string; name: string;
result: ResolveResult; result: Partial<ResolveResult>;
} }
export const TWO_STATE_CYCLE: StateLabel = {
adds: [],
divider: '/',
name: 'foo',
priority: 1,
removes: [],
requires: [],
values: [{
adds: [{
name: 'fin',
}],
becomes: [{
adds: [{
name: 'foo/bin',
}],
matches: [{
name: 'next',
}],
removes: [],
}],
name: 'bar',
priority: 1,
removes: [{
name: 'bob',
}],
requires: [],
}, {
adds: [],
becomes: [{
adds: [{
name: 'foo/bar',
}],
matches: [{
name: 'next',
}],
removes: [],
}],
name: 'bin',
priority: 1,
removes: [{
name: 'bob',
}],
requires: [],
}],
};
export const SECOND_STATE_FALLBACK: StateLabel = {
adds: [],
divider: '/',
name: 'foo',
priority: 1,
removes: [],
requires: [],
values: [{
adds: [],
becomes: [{
adds: [{
name: 'fin',
}],
matches: [{
name: 'next',
}],
removes: [],
}],
name: 'bar',
priority: 1,
removes: [],
requires: [{
name: 'bob',
}],
}, {
adds: [],
becomes: [{
adds: [],
matches: [{
name: 'next',
}],
removes: [],
}],
name: 'bin',
priority: 1,
removes: [],
requires: [],
}],
};
export const TEST_CASES: Array<ResolveTestCase> = [{ export const TEST_CASES: Array<ResolveTestCase> = [{
input: { input: {
flags: [], flags: [],
@ -40,4 +127,59 @@ export const TEST_CASES: Array<ResolveTestCase> = [{
'test', 'test',
], ],
}, },
}, {
input: {
flags: [],
labels: ['foo/bar', 'next'],
states: [TWO_STATE_CYCLE],
},
name: 'become adds',
result: {
errors: [],
labels: ['fin', 'foo/bin'],
},
}, {
input: {
flags: [],
labels: ['foo/bar', 'next', 'bob'],
states: [TWO_STATE_CYCLE],
},
name: 'become removes',
result: {
errors: [],
labels: ['fin', 'foo/bin'],
},
}, {
input: {
flags: [],
labels: ['foo/bar', 'foo/bin'],
states: [TWO_STATE_CYCLE],
},
name: 'state single value',
result: {
errors: [],
labels: ['foo/bar', 'fin'],
},
}, {
input: {
flags: [],
labels: ['foo/bar', 'foo/bin'],
states: [SECOND_STATE_FALLBACK],
},
name: 'second state requires missing',
result: {
errors: [],
labels: ['foo/bin'],
},
}, {
input: {
flags: [],
labels: ['foo/bar', 'foo/bin', 'bob'],
states: [SECOND_STATE_FALLBACK],
},
name: 'second state requires present',
result: {
errors: [],
labels: ['foo/bar', 'bob'],
},
}]; }];