初始提交
This commit is contained in:
111
ai/static/tests/transcript_parser.test.js
Normal file
111
ai/static/tests/transcript_parser.test.js
Normal file
@@ -0,0 +1,111 @@
|
||||
import { describe, expect, test } from "@odoo/hoot";
|
||||
import { parseTimedText } from "@ai/views/fields/call_debrief/transcript_parser";
|
||||
|
||||
describe.current.tags("desktop", "call_debrief");
|
||||
|
||||
test("Parse SRT: Standard format", () => {
|
||||
const srt = `1
|
||||
00:00:01,000 --> 00:00:04,000
|
||||
Hello world
|
||||
|
||||
2
|
||||
00:00:05,000 --> 00:00:09,000
|
||||
Second line
|
||||
Multi line text`;
|
||||
|
||||
const result = parseTimedText(srt);
|
||||
expect(result).toEqual([
|
||||
{ startSec: 1, endSec: 4, text: "Hello world" },
|
||||
{ startSec: 5, endSec: 9, text: "Second line\nMulti line text" },
|
||||
]);
|
||||
});
|
||||
|
||||
test("Parse VTT: Standard format with header", () => {
|
||||
const vtt = `WEBVTT
|
||||
|
||||
00:00:01.000 --> 00:00:04.000
|
||||
Hello world
|
||||
|
||||
00:00:05.000 --> 00:00:09.000
|
||||
Second line`;
|
||||
|
||||
const result = parseTimedText(vtt);
|
||||
expect(result).toEqual([
|
||||
{ startSec: 1, endSec: 4, text: "Hello world" },
|
||||
{ startSec: 5, endSec: 9, text: "Second line" },
|
||||
]);
|
||||
});
|
||||
|
||||
test("Parse VTT: MM:SS format (no hours)", () => {
|
||||
const vtt = `WEBVTT
|
||||
|
||||
00:01.000 --> 00:04.000
|
||||
Short timestamp`;
|
||||
|
||||
const result = parseTimedText(vtt);
|
||||
expect(result).toEqual([{ startSec: 1, endSec: 4, text: "Short timestamp" }]);
|
||||
});
|
||||
|
||||
test("Parse VTT: With Cue Settings", () => {
|
||||
const vtt = `WEBVTT
|
||||
|
||||
00:00:01.000 --> 00:00:04.000 align:start size:50%
|
||||
Hello world`;
|
||||
|
||||
// The parser currently ignores settings but should still extract time correctly
|
||||
const result = parseTimedText(vtt);
|
||||
expect(result[0].startSec).toBe(1);
|
||||
expect(result[0].endSec).toBe(4);
|
||||
expect(result[0].text).toBe("Hello world");
|
||||
});
|
||||
|
||||
test("Parse VTT: With Comments/Notes", () => {
|
||||
const vtt = `WEBVTT
|
||||
|
||||
NOTE This is a comment
|
||||
|
||||
00:00:01.000 --> 00:00:04.000
|
||||
Hello world
|
||||
|
||||
NOTE
|
||||
Multi-line
|
||||
comment
|
||||
|
||||
00:00:05.000 --> 00:00:06.000
|
||||
Next line`;
|
||||
|
||||
const result = parseTimedText(vtt);
|
||||
// Ideally comments should be ignored.
|
||||
// Current impl might fail on multi-line comments or treat them as garbage blocks
|
||||
// checking expected behavior for valid cues
|
||||
const validCues = result.filter((r) => r.text === "Hello world" || r.text === "Next line");
|
||||
expect(validCues.length).toBe(2);
|
||||
});
|
||||
|
||||
test("Parse: Timestamps without milliseconds", () => {
|
||||
const srt = `1
|
||||
00:00:01 --> 00:00:04
|
||||
Hello world`;
|
||||
|
||||
const result = parseTimedText(srt);
|
||||
expect(result).toEqual([{ startSec: 1, endSec: 4, text: "Hello world" }]);
|
||||
});
|
||||
|
||||
test("Parse: Malformed timestamps (garbage)", () => {
|
||||
const srt = `1
|
||||
00:xx:01,000 --> 00:00:04,000
|
||||
Bad Start
|
||||
|
||||
2
|
||||
00:00:05,000 --> garbage
|
||||
Bad End`;
|
||||
|
||||
const result = parseTimedText(srt);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
|
||||
test("Parse: Empty file", () => {
|
||||
expect(parseTimedText("")).toEqual([]);
|
||||
expect(parseTimedText(null)).toEqual([]);
|
||||
expect(parseTimedText(undefined)).toEqual([]);
|
||||
});
|
||||
Reference in New Issue
Block a user