Skip to content

Commit

Permalink
Fix the tests and align basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed Aug 1, 2020
1 parent 24e0f19 commit 74374b1
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
import { activateLS, showFile, sleep, FILE_LOAD_SLEEP_TIME } from '../../lsp/helper';
import { position, getDocUri } from '../util';
import { position, getDocUri } from '../../util';
import { testCompletion, testNoSuchCompletion } from './helper';
import { CompletionItem, CompletionItemKind, MarkdownString } from 'vscode';

describe('Should autocomplete interpolation for <template> in class component', () => {
const templateDocUri = getDocUri('completion/BasicClass.vue');
const parentTemplateDocUri = getDocUri('completion/ParentClass.vue');

before('activate', async () => {
await activateLS();
await showFile(templateDocUri);
await sleep(FILE_LOAD_SLEEP_TIME);
await sleep(FILE_LOAD_SLEEP_TIME);
});

const defaultList: CompletionItem[] = [
{
label: 'foo',
documentation: new MarkdownString('My foo').appendCodeblock(
`foo: {
type: Boolean,
default: false
}`,
'js'
),
kind: CompletionItemKind.Property
},
// Typescript can't typing when `@Component({ props: { foo: String } })`.
// Because decorator cant affect return type.
// {
// label: 'foo',
// documentation: new MarkdownString('My foo').appendCodeblock(
// `foo: {
// type: Boolean,
// default: false
// }`,
// 'js'
// ),
// kind: CompletionItemKind.Field
// },
{
label: 'msg',
documentation: new MarkdownString('My msg').appendCodeblock(`msg = 'Vetur means "Winter" in icelandic.'`, 'js'),
kind: CompletionItemKind.Property
kind: CompletionItemKind.Field
},
{
label: 'count',
Expand All @@ -39,7 +33,7 @@ describe('Should autocomplete interpolation for <template> in class component',
}`,
'js'
),
kind: CompletionItemKind.Property
kind: CompletionItemKind.Field
},
{
label: 'hello',
Expand All @@ -50,7 +44,7 @@ describe('Should autocomplete interpolation for <template> in class component',
'js'
),

kind: CompletionItemKind.Method
kind: CompletionItemKind.Function
}
];

Expand All @@ -59,10 +53,20 @@ describe('Should autocomplete interpolation for <template> in class component',
await testCompletion(templateDocUri, position(2, 7), defaultList);
});

it('completes an object property', async () => {
await testCompletion(templateDocUri, position(3, 11), [
{
label: 'msg',
kind: CompletionItemKind.Field
}
]);
});

it(`completes child component tag`, async () => {
await testCompletion(parentTemplateDocUri, position(4, 5), [
await testCompletion(parentTemplateDocUri, position(5, 5), [
{
label: 'basic-class',
kind: CompletionItemKind.Property,
documentationStart: 'My basic tag\n```js\n@Component('
}
]);
Expand All @@ -72,6 +76,23 @@ describe('Should autocomplete interpolation for <template> in class component',
await testCompletion(parentTemplateDocUri, position(2, 18), [
{
label: 'foo',
kind: CompletionItemKind.Value,
documentation: new MarkdownString('My foo').appendCodeblock(
`foo: {
type: Boolean,
default: false
}`,
'js'
)
}
]);
});

it(`completes child component's props when camel case component name`, async () => {
await testCompletion(parentTemplateDocUri, position(4, 16), [
{
label: 'foo',
kind: CompletionItemKind.Value,
documentation: new MarkdownString('My foo').appendCodeblock(
`foo: {
type: Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
import { activateLS, showFile, sleep, FILE_LOAD_SLEEP_TIME } from '../../lsp/helper';
import { position, getDocUri } from '../util';
import { position, getDocUri } from '../../util';
import { testCompletion, testNoSuchCompletion } from './helper';
import { CompletionItem, CompletionItemKind, MarkdownString } from 'vscode';

describe('Should autocomplete interpolation for <template> in property class component', () => {
const templateDocUri = getDocUri('completion/BasicPropertyClass.vue');
const parentTemplateDocUri = getDocUri('completion/ParentPropertyClass.vue');

before('activate', async () => {
await activateLS();
await showFile(templateDocUri);
await sleep(FILE_LOAD_SLEEP_TIME);
await sleep(FILE_LOAD_SLEEP_TIME);
});

const defaultList: CompletionItem[] = [
{
label: 'foo',
documentation: new MarkdownString('My foo').appendCodeblock(
`@Prop({ type: Boolean, default: false }) foo`,
'js'
),
kind: CompletionItemKind.Property
documentation: new MarkdownString('My foo').appendCodeblock(`@Prop({ type: Boolean, default: false }) foo`, 'js'),
kind: CompletionItemKind.Field
},
{
label: 'msg',
documentation: new MarkdownString('My msg').appendCodeblock(`msg = 'Vetur means "Winter" in icelandic.'`, 'js'),
kind: CompletionItemKind.Property
kind: CompletionItemKind.Field
},
{
label: 'count',
Expand All @@ -36,7 +25,7 @@ describe('Should autocomplete interpolation for <template> in property class com
}`,
'js'
),
kind: CompletionItemKind.Property
kind: CompletionItemKind.Field
},
{
label: 'hello',
Expand All @@ -47,7 +36,7 @@ describe('Should autocomplete interpolation for <template> in property class com
'js'
),

kind: CompletionItemKind.Method
kind: CompletionItemKind.Function
}
];

Expand All @@ -56,10 +45,20 @@ describe('Should autocomplete interpolation for <template> in property class com
await testCompletion(templateDocUri, position(2, 7), defaultList);
});

it('completes an object property', async () => {
await testCompletion(templateDocUri, position(3, 11), [
{
label: 'msg',
kind: CompletionItemKind.Field
}
]);
});

it(`completes child component tag`, async () => {
await testCompletion(parentTemplateDocUri, position(4, 5), [
await testCompletion(parentTemplateDocUri, position(5, 5), [
{
label: 'basic-property-class',
kind: CompletionItemKind.Property,
documentationStart: 'My basic tag\n```js\n@Component('
}
]);
Expand All @@ -69,6 +68,20 @@ describe('Should autocomplete interpolation for <template> in property class com
await testCompletion(parentTemplateDocUri, position(2, 27), [
{
label: 'foo',
kind: CompletionItemKind.Value,
documentation: new MarkdownString('My foo').appendCodeblock(
`@Prop({ type: Boolean, default: false }) foo`,
'js'
)
}
]);
});

it(`completes child component's props when camel case component name`, async () => {
await testCompletion(parentTemplateDocUri, position(4, 24), [
{
label: 'foo',
kind: CompletionItemKind.Value,
documentation: new MarkdownString('My foo').appendCodeblock(
`@Prop({ type: Boolean, default: false }) foo`,
'js'
Expand Down
8 changes: 8 additions & 0 deletions test/interpolation/fixture/completion/BasicClass.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div>
{{ }}
{{ obj. }}
</div>
</template>

Expand Down Expand Up @@ -28,6 +29,13 @@ export default class BasicClass extends Vue {
*/
msg = 'Vetur means "Winter" in icelandic.'
/**
* My obj
*/
obj = {
msg: 'Object message.'
}
/**
* My count
*/
Expand Down
8 changes: 8 additions & 0 deletions test/interpolation/fixture/completion/BasicPropertyClass.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div>
{{ }}
{{ obj. }}
</div>
</template>

Expand All @@ -23,6 +24,13 @@ export default class BasicPropertyClass extends Vue {
*/
msg = 'Vetur means "Winter" in icelandic.'
/**
* My obj
*/
obj = {
msg: 'Object message.'
}
/**
* My count
*/
Expand Down
1 change: 1 addition & 0 deletions test/interpolation/fixture/completion/ParentClass.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div>
<basic-class :></basic-class>
<basic-class v-if="" @click="" :foo=""></basic-class>
<BasicClass />
<
</div>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div>
<basic-property-class :></basic-property-class>
<basic-property-class v-if="" @click="" :foo=""></basic-property-class>
<BasicPropertyClass />
<
</div>
</template>
Expand Down

0 comments on commit 74374b1

Please sign in to comment.