This commit is contained in:
parent
7959fe85cc
commit
b9485e4097
32 changed files with 4692 additions and 65 deletions
|
|
@ -393,7 +393,9 @@ describe('URL state', () => {
|
|||
};
|
||||
expect(decodeState(rawLink(legacy))).toEqual({ state, error: null });
|
||||
expect(
|
||||
decodeState('?skirting.length=4800&skirting.stock=3600&skirting.stock=2400&done=skirting:S6'),
|
||||
decodeState(
|
||||
'?flooring.optimisation=cuts&skirting.length=4800&skirting.stock=3600&skirting.stock=2400&done=skirting:S6',
|
||||
),
|
||||
).toEqual({ state, error: null });
|
||||
});
|
||||
|
||||
|
|
@ -523,7 +525,9 @@ describe('URL state', () => {
|
|||
const state = defaultState();
|
||||
state.project.completedBoards = ['floor:B4', 'floor:B4'];
|
||||
expect(() => encodeState(state)).toThrow(/duplicate entries/);
|
||||
const distinct = decodeState('?skirting.length=2400&done=floor:B1&done=skirting:S1');
|
||||
const distinct = decodeState(
|
||||
'?flooring.optimisation=cuts&skirting.length=2400&done=floor:B1&done=skirting:S1',
|
||||
);
|
||||
expect(distinct.error).toBeNull();
|
||||
expect(distinct.state.project.completedBoards).toEqual(['floor:B1', 'skirting:S1']);
|
||||
});
|
||||
|
|
@ -573,6 +577,51 @@ describe('URL state', () => {
|
|||
expectInvalid(`?name=${'x'.repeat(URL_LIMITS.queryLength)}`, /link is too large/);
|
||||
});
|
||||
|
||||
it.each(['cuts', 'random'] as const)(
|
||||
'saves the %s optimisation and current completion marks',
|
||||
(optimisation) => {
|
||||
const state = defaultState();
|
||||
state.project.flooring.optimisation = optimisation;
|
||||
state.project.completedBoards = ['floor:B4'];
|
||||
const query = encodeState(state);
|
||||
expect(query).toContain(`flooring.optimisation=${optimisation}`);
|
||||
expect(decodeState(query)).toEqual({ state, error: null });
|
||||
},
|
||||
);
|
||||
|
||||
it('migrates the previous optimiser without carrying completion onto a different allocation', () => {
|
||||
const state = defaultState();
|
||||
state.project.completedBoards = ['floor:B4', 'skirting:S6'];
|
||||
const query = new URLSearchParams(encodeState(state));
|
||||
query.delete('flooring.optimisation');
|
||||
const old = {
|
||||
...state,
|
||||
project: {
|
||||
...state.project,
|
||||
flooring: { ...state.project.flooring, optimisation: undefined },
|
||||
},
|
||||
};
|
||||
for (const link of [`?${query}`, rawLink(old)]) {
|
||||
const migrated = decodeState(link);
|
||||
expect(migrated.error).toBeNull();
|
||||
expect(migrated.state.project.flooring.optimisation).toBe('cuts');
|
||||
expect(migrated.state.project.completedBoards).toEqual([]);
|
||||
migrated.state.project.completedBoards = ['floor:B1'];
|
||||
expect(decodeState(encodeState(migrated.state))).toEqual(migrated);
|
||||
}
|
||||
});
|
||||
|
||||
it.each([null, 42, true, {}, 'waste'])('rejects unsupported optimisation %j', (optimisation) => {
|
||||
const state = defaultState();
|
||||
expectInvalid(
|
||||
rawLink({
|
||||
...state,
|
||||
project: { ...state.project, flooring: { ...state.project.flooring, optimisation } },
|
||||
}),
|
||||
/Flooring optimisation/,
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects oversized compressed and expanded payloads', () => {
|
||||
expectInvalid(`#plan=${'a'.repeat(URL_LIMITS.hashLength)}`, /link is too large/);
|
||||
expectInvalid(
|
||||
|
|
|
|||
Loading…
Reference in a new issue