/* eslint-disable @typescript-eslint/unbound-method */
import { testData } from '@neo4j-cypher/language-support';
import { expect, test } from '@playwright/experimental-ct-react';
import { Locator } from 'playwright/test';
import { CypherEditor } from '../CypherEditor';
test.use({ viewport: { width: 1000, height: 500 } });
type TooltipExpectations = {
includes?: string[];
excludes?: string[];
};
const importCsvProc =
testData.mockSchema.procedures['CYPHER 5']['apoc.import.csv'];
function testTooltip(tooltip: Locator, expectations: TooltipExpectations) {
const includes = expectations.includes ?? [];
const excludes = expectations.excludes ?? [];
const included = Promise.all(
includes.map((text) => {
return expect(tooltip).toContainText(text, {
timeout: 10000,
});
}),
);
const excluded = Promise.all(
excludes.map((text) => {
return expect(tooltip).not.toContainText(text, {
timeout: 10000,
});
}),
);
return Promise.all([included, excluded]);
}
test('Signature help works for functions', async ({ page, mount }) => {
const query = 'RETURN abs(';
await mount(
,
);
await expect(page.locator('.cm-signature-help-panel')).toBeVisible({
timeout: 10000,
});
});
test('Signature help works for procedures', async ({ page, mount }) => {
const query = 'CALL apoc.import.csv(';
await mount(
,
);
await expect(page.locator('.cm-signature-help-panel')).toBeVisible({
timeout: 10000,
});
});
test('Signature help shows the description for the first argument', async ({
page,
mount,
}) => {
const query = 'CALL apoc.import.csv(';
await mount(
,
);
const tooltip = page.locator('.cm-signature-help-panel');
await testTooltip(tooltip, {
includes: [
testData.mockSchema.procedures['CYPHER 5']['apoc.import.csv']
.argumentDescription[0].description,
testData.mockSchema.procedures['CYPHER 5']['apoc.import.csv'].description,
],
});
});
test('Signature help shows the description for the first argument when the cursor is at that position', async ({
page,
mount,
}) => {
const query = 'CALL apoc.import.csv()';
await mount(
,
);
const tooltip = page.locator('.cm-signature-help-panel');
await testTooltip(tooltip, {
includes: [
importCsvProc.argumentDescription[0].description,
importCsvProc.description,
],
});
});
test('Signature help shows the description for the second argument', async ({
page,
mount,
}) => {
const query = 'CALL apoc.import.csv(nodes,';
await mount(
,
);
const tooltip = page.locator('.cm-signature-help-panel');
await testTooltip(tooltip, {
includes: [
importCsvProc.argumentDescription[1].description,
importCsvProc.description,
],
});
});
test('Signature help shows the description for the second argument when the cursor is at that position', async ({
page,
mount,
}) => {
const query = 'CALL apoc.import.csv(nodes,)';
await mount(
,
);
const tooltip = page.locator('.cm-signature-help-panel');
await testTooltip(tooltip, {
includes: [
importCsvProc.argumentDescription[1].description,
importCsvProc.description,
],
});
});
test('Signature help shows the description for the second argument when the cursor is at that position, even after whitespaces', async ({
page,
mount,
}) => {
const query = 'CALL apoc.import.csv(nodes, )';
await mount(
,
);
const tooltip = page.locator('.cm-signature-help-panel');
await testTooltip(tooltip, {
includes: [
'rels :: LIST