2024-02-06 22:58:49 +01:00
|
|
|
import tap from 'tap';
|
|
|
|
import {parseHint as parse} from '../../parse/hint.js';
|
2019-09-03 15:35:12 +02:00
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
const ctx = {
|
|
|
|
data: {},
|
|
|
|
opt: {},
|
2024-02-06 22:58:49 +01:00
|
|
|
profile: {},
|
|
|
|
};
|
2019-09-03 15:35:12 +02:00
|
|
|
|
2021-05-20 16:42:43 +01:00
|
|
|
tap.test('parses hints correctly', (t) => {
|
2019-09-03 15:35:12 +02:00
|
|
|
const input = {
|
|
|
|
type: 'A',
|
|
|
|
code: 'bf',
|
|
|
|
prio: 123,
|
2024-02-06 22:58:49 +01:00
|
|
|
txtN: 'some text',
|
|
|
|
};
|
2019-09-03 15:35:12 +02:00
|
|
|
const expected = {
|
|
|
|
type: 'hint',
|
|
|
|
code: 'bf',
|
2024-02-06 22:58:49 +01:00
|
|
|
text: 'some text',
|
|
|
|
};
|
2019-09-03 15:35:12 +02:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
t.same(parse(ctx, input), expected);
|
2021-05-20 16:42:43 +01:00
|
|
|
t.same(parse(ctx, {
|
2024-02-06 22:58:49 +01:00
|
|
|
...input, type: 'I',
|
|
|
|
}), expected);
|
2019-09-03 15:35:12 +02:00
|
|
|
|
|
|
|
// alternative trip
|
2021-05-20 16:42:43 +01:00
|
|
|
t.same(parse(ctx, {
|
2024-02-06 22:58:49 +01:00
|
|
|
...input, type: 'L', jid: 'trip id',
|
2019-09-03 15:35:12 +02:00
|
|
|
}), {
|
2024-02-06 22:58:49 +01:00
|
|
|
...expected, type: 'status', code: 'alternative-trip', tripId: 'trip id',
|
|
|
|
});
|
2019-09-03 15:35:12 +02:00
|
|
|
|
|
|
|
// type: M
|
2021-05-20 16:42:43 +01:00
|
|
|
t.same(parse(ctx, {
|
2024-02-06 22:58:49 +01:00
|
|
|
...input, type: 'M', txtS: 'some summary',
|
2019-09-03 15:35:12 +02:00
|
|
|
}), {
|
2024-02-06 22:58:49 +01:00
|
|
|
...expected, type: 'status', summary: 'some summary',
|
|
|
|
});
|
2019-09-03 15:35:12 +02:00
|
|
|
|
|
|
|
// type: D
|
|
|
|
for (const type of ['D', 'U', 'R', 'N', 'Y']) {
|
2021-05-20 16:42:43 +01:00
|
|
|
t.same(parse(ctx, {...input, type}), {
|
2024-02-06 22:58:49 +01:00
|
|
|
...expected, type: 'status',
|
|
|
|
});
|
2019-09-03 15:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// .code via .icon
|
2021-05-20 16:42:43 +01:00
|
|
|
t.same(parse(ctx, {
|
2024-02-06 22:58:49 +01:00
|
|
|
...input, code: null, icon: {type: 'cancel'},
|
|
|
|
}), {...expected, code: 'cancelled'});
|
2019-09-03 15:35:12 +02:00
|
|
|
|
|
|
|
// invalid
|
2024-02-06 22:58:49 +01:00
|
|
|
t.equal(parse(ctx, {...input, type: 'X'}), null);
|
2019-09-03 15:35:12 +02:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
t.end();
|
|
|
|
});
|