Skip to content

Commit 144286d

Browse files
committed
tests: add tests for getTypeAtPosition
1 parent 7f8ceb8 commit 144286d

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/utils/FlowYamlUtils.test.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@ describe("deleteBlock", () => {
543543
})
544544
})
545545

546-
547546
describe("extractFieldFromMaps", () => {
548547
test("extracts field from maps", () => {
549548
const yamlSrc = `
@@ -1684,4 +1683,41 @@ describe("get lines infos", () => {
16841683
const tasksLines = YamlUtils.getTasksLines(yamlString);
16851684
expect(tasksLines).to.containSubset({plugin1: {start: 3, end: 6}});
16861685
})
1687-
});
1686+
});
1687+
1688+
describe("getTypeAtPosition", () => {
1689+
test("gets type at given line and column", () => {
1690+
const yamlString = `
1691+
id: sqlserver_v3
1692+
namespace: io.kestra.blx
1693+
1694+
tasks:
1695+
- type: io.kestra.plugin.core.log.Log
1696+
id: asda
1697+
message: hoo
1698+
- type: io.kestra.plugin.jdbc.sqlserver.Query
1699+
version: 1.0.0
1700+
id: select
1701+
url: help
1702+
`;
1703+
const result = YamlUtils.getTypeAtPosition(yamlString, {
1704+
lineNumber:9,
1705+
column: 15
1706+
}, [
1707+
'io.kestra.plugin.jdbc.sqlserver.Query',
1708+
'io.kestra.plugin.core.log.Log'
1709+
]); // line 9, column 15 corresponds to io.kestra.plugin.jdbc.sqlserver.Query
1710+
expect(result).toBe("io.kestra.plugin.jdbc.sqlserver.Query");
1711+
});
1712+
1713+
test("returns null if no type found at position", () => {
1714+
const yamlString = `
1715+
tasks:
1716+
- id: plugin1
1717+
type: type1
1718+
name: Plugin 1
1719+
`;
1720+
const result = YamlUtils.getTypeAtPosition(yamlString, {lineNumber: 2, column:5}, ["type1"]); // line 2, column 5 is 'tasks' field
1721+
expect(result).toBeNull();
1722+
});
1723+
})

0 commit comments

Comments
 (0)