Skip to content

Commit

Permalink
Test for completion of required attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Aurélien Pupier <[email protected]>
  • Loading branch information
apupier committed Jul 8, 2020
1 parent 292c956 commit fdbe820
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/autoCompletion.requiredproperties.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Red Hat. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { TextDocument } from 'vscode-languageserver';
import { getLanguageService } from '../src/languageservice/yamlLanguageService';
import { toFsPath, schemaRequestService, workspaceContext } from './utils/testHelper';
import assert = require('assert');
import path = require('path');

const languageService = getLanguageService(schemaRequestService, workspaceContext, [], null);

const languageSettings = {
schemas: [],
completion: true
};

const uri = toFsPath(path.join(__dirname, './fixtures/testRequiredProperties.json'));
const fileMatch = ['*.yml', '*.yaml'];
languageSettings.schemas.push({ uri, fileMatch: fileMatch });
languageService.configure(languageSettings);

suite('Auto Completion Tests for required properties', () => {

describe('yamlCompletion with required properties', function () {

describe('doComplete', function () {

function setup(content: string) {
return TextDocument.create('file://~/Desktop/vscode-k8s/test.yaml', 'yaml', 0, content);
}

function parseSetup(content: string, position) {
const testTextDocument = setup(content);
return languageService.doComplete(testTextDocument, testTextDocument.positionAt(position), false);
}

it('Insert required attributes at correct level', done => {
const content = '- ';
const completion = parseSetup(content, content.length);
completion.then(function (result) {
const insertText = result.items[0].insertText;
assert.equal(insertText, 'top\n prop1: $1');
}).then(done, done);
});

});
});
});
21 changes: 21 additions & 0 deletions test/fixtures/testRequiredProperties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$id": "https://example.com/arrays.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "array",
"items": {
"properties": {
"top": {
"type": "object",
"properties": {
"prop1": {
"type": "string"
},
"prop2": {
"type": "string"
}
},
"required": ["prop1"]
}
}
}
}

0 comments on commit fdbe820

Please sign in to comment.