Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
sudhirverma committed Jan 3, 2022
1 parent 61c9e06 commit 61e3dca
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 36 deletions.
23 changes: 17 additions & 6 deletions test/functions/function-command/create-function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as sinonChai from 'sinon-chai';
import { knExecutor } from '../../../src/cli/execute';
import { def, folderStatus, validateInputField } from '../../../src/functions/function-command/create-function';
import { pathValidation } from '../../../src/functions/validate-item';
import { Platform } from '../../../src/util/platform';

const { expect } = chai;
chai.use(sinonChai);
Expand Down Expand Up @@ -46,12 +47,22 @@ suite('Function/Create', () => {
selectLocation: 'apple',
selectTemplate: 'http',
});
expect(result).deep.equal({
items: [
{ severity: 4, template: { content: 'Provide name for function', id: 'functionName' } },
{ severity: 4, template: { content: 'The selection is not a valid absolute path.', id: 'selectLocation' } },
],
});
if (Platform.OS === 'win32') {
expect(result).deep.equal({
items: [
{ severity: 4, template: { content: 'Provide name for function', id: 'functionName' } },
{ severity: 4, template: { content: 'Selected path has invalid format.', id: 'selectLocation' } },
{ severity: 4, template: { content: 'The selection is not a valid absolute path.', id: 'selectLocation' } },
],
});
} else {
expect(result).deep.equal({
items: [
{ severity: 4, template: { content: 'Provide name for function', id: 'functionName' } },
{ severity: 4, template: { content: 'The selection is not a valid absolute path.', id: 'selectLocation' } },
],
});
}
});

test('validator for function name if there is any duplicate', () => {
Expand Down
101 changes: 71 additions & 30 deletions test/functions/validate-item.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,52 @@ suite('Function/Validate', () => {
test('show error if Selected disk does not exit', () => {
const selectLocation = { id: 'selectLocation', message: 'Provide path to create function', value: 's' };
const result = selectLocationValidation(selectLocation, []);
expect(result).deep.equal({
items: [
{
severity: 4,
template: {
content: 'The selection is not a valid absolute path.',
id: 'selectLocation',
if (Platform.OS === 'win32') {
expect(result).deep.equal({
items: [
{
severity: 4,
template: {
content: 'The selection is not a valid absolute path.',
id: 'selectLocation',
},
},
},
{
severity: 4,
template: {
content: 'Selected disk does not exist.',
id: 'selectLocation',
{
severity: 4,
template: {
content: 'The selection is not a valid absolute path.',
id: 'selectLocation',
},
},
},
],
});
{
severity: 4,
template: {
content: 'Selected disk does not exist.',
id: 'selectLocation',
},
},
],
});
} else {
expect(result).deep.equal({
items: [
{
severity: 4,
template: {
content: 'The selection is not a valid absolute path.',
id: 'selectLocation',
},
},
{
severity: 4,
template: {
content: 'Selected disk does not exist.',
id: 'selectLocation',
},
},
],
});
}
});

test('show error message if path is not provided', () => {
Expand Down Expand Up @@ -88,20 +116,12 @@ suite('Function/Validate', () => {
const result = selectLocationValidation(selectLocation, []);
if (process.platform === 'win32') {
expect(result).deep.equal({
items: [
{
severity: 4,
template: {
content: 'Selected path has invalid format.',
id: 'selectLocation',
},
},
],
items: [],
});
}
});

test("don't show error message when path is valid ", () => {
test("don't show error message when path is valid", () => {
sandbox.stub(Platform, 'getOS').returns('win32');
const selectLocation = {
id: 'selectLocation',
Expand All @@ -112,6 +132,13 @@ suite('Function/Validate', () => {
if (process.platform === 'win32') {
expect(result).deep.equal({
items: [
{
severity: 4,
template: {
content: 'Selected path has invalid format.',
id: 'selectLocation',
},
},
{
severity: 4,
template: {
Expand All @@ -124,15 +151,29 @@ suite('Function/Validate', () => {
}
});

test("don't show error message when path is valid ", () => {
test("don't show error message when path is valid", () => {
const selectLocation = {
id: 'selectLocation',
message: 'Provide path to create function',
value: '/',
};
const result = selectLocationValidation(selectLocation, []);
expect(result).deep.equal({
items: [],
});
if (process.platform === 'win32') {
expect(result).deep.equal({
items: [
{
severity: 4,
template: {
content: 'Selected path has invalid format.',
id: 'selectLocation',
},
},
],
});
} else {
expect(result).deep.equal({
items: [],
});
}
});
});

0 comments on commit 61e3dca

Please # to comment.