Browse Source

update: schematics package tests

pull/24530/head
sumeyye 9 months ago
parent
commit
e4f45f900f
  1. 1
      npm/ng-packs/packages/schematics/src/test-setup.ts
  2. 60
      npm/ng-packs/packages/schematics/src/tests/parse-generic-type.spec.ts

1
npm/ng-packs/packages/schematics/src/test-setup.ts

@ -1 +0,0 @@
import 'jest-preset-angular/setup-jest';

60
npm/ng-packs/packages/schematics/src/tests/parse-generic-type.spec.ts

@ -1,7 +1,6 @@
import { expect, describe, it, test } from 'vitest';
import { parseBaseTypeWithGenericTypes } from '../utils/model'; import { parseBaseTypeWithGenericTypes } from '../utils/model';
import { parseGenerics } from '../utils/tree'; import { parseGenerics } from '../utils/tree';
import {test} from '@jest/globals';
const cases: Array<[string, string[]]> = [ const cases: Array<[string, string[]]> = [
[ [
@ -17,7 +16,7 @@ const cases: Array<[string, string[]]> = [
[ [
'Volo.Abp.Application.Dtos.AuditedEntityWithUserDto', 'Volo.Abp.Application.Dtos.AuditedEntityWithUserDto',
'string', 'string',
'Volo.Abp.Identity.IdentityUserDto' 'Volo.Abp.Identity.IdentityUserDto',
], ],
], ],
[ [
@ -39,41 +38,38 @@ const cases: Array<[string, string[]]> = [
'System.String', 'System.String',
], ],
], ],
[ ['AuditedEntityWithUserDto', ['AuditedEntityWithUserDto']],
'AuditedEntityWithUserDto',
['AuditedEntityWithUserDto'],
],
]; ];
test.each(cases)('should parse %s', (inputStr, expected) => { test.each(cases)('should parse %s', (inputStr, expected) => {
const parsed = parseBaseTypeWithGenericTypes(inputStr); const parsed = parseBaseTypeWithGenericTypes(inputStr);
expect(parsed).toEqual(expected); expect(parsed).toEqual(expected);
}) });
describe('parseGenerics', () => { describe('parseGenerics', () => {
it('should work with simple type', function () {
it('should work with simple type', function() {
const node = parseGenerics('System.String'); const node = parseGenerics('System.String');
expect(node.data).toEqual('System.String'); expect(node.data).toEqual('System.String');
expect(node.index).toBe(0); expect(node.index).toBe(0);
expect(node.parent).toBe(null); expect(node.parent).toBe(null);
}); });
it('should work with simple Array type', function() { it('should work with simple Array type', function () {
const node = parseGenerics('System.String[]'); const node = parseGenerics('System.String[]');
expect(node.data).toEqual('System.String[]'); expect(node.data).toEqual('System.String[]');
expect(node.index).toBe(0); expect(node.index).toBe(0);
expect(node.parent).toBe(null); expect(node.parent).toBe(null);
}); });
it('should work with simple', function() { it('should work with simple', function () {
const node = parseGenerics('Volo.Abp.Application.Dtos.AuditedEntityWithUserDto'); const node = parseGenerics('Volo.Abp.Application.Dtos.AuditedEntityWithUserDto');
expect(node.data).toEqual('Volo.Abp.Application.Dtos.AuditedEntityWithUserDto'); expect(node.data).toEqual('Volo.Abp.Application.Dtos.AuditedEntityWithUserDto');
expect(node.index).toBe(0); expect(node.index).toBe(0);
expect(node.parent).toBe(null); expect(node.parent).toBe(null);
}); });
it('should work with `Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<Volo.Abp.Identity.IdentityUserDto>`', function() { it('should work with `Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<Volo.Abp.Identity.IdentityUserDto>`', function () {
const type = 'Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<Volo.Abp.Identity.IdentityUserDto>'; const type =
'Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<Volo.Abp.Identity.IdentityUserDto>';
const node = parseGenerics(type); const node = parseGenerics(type);
expect(node.data).toEqual('Volo.Abp.Application.Dtos.AuditedEntityWithUserDto'); expect(node.data).toEqual('Volo.Abp.Application.Dtos.AuditedEntityWithUserDto');
@ -83,37 +79,37 @@ describe('parseGenerics', () => {
expect(child.parent).toBe(node); expect(child.parent).toBe(node);
}); });
it('should work with `Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<System.string,Volo.Abp.Identity.IdentityUserDto>`', function () {
it('should work with `Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<System.string,Volo.Abp.Identity.IdentityUserDto>`', function() { const type =
const type = 'Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<System.string,Volo.Abp.Identity.IdentityUserDto>'; 'Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<System.string,Volo.Abp.Identity.IdentityUserDto>';
const node = parseGenerics(type); const node = parseGenerics(type);
expect(node.data).toEqual('Volo.Abp.Application.Dtos.AuditedEntityWithUserDto'); expect(node.data).toEqual('Volo.Abp.Application.Dtos.AuditedEntityWithUserDto');
expect(node.children.length).toBe(2); expect(node.children.length).toBe(2);
expect(node.children[0].data).toEqual('System.string'); expect(node.children[0].data).toEqual('System.string');
expect(node.children[0].index).toBe(0) expect(node.children[0].index).toBe(0);
expect(node.children[1].data).toEqual('Volo.Abp.Identity.IdentityUserDto'); expect(node.children[1].data).toEqual('Volo.Abp.Identity.IdentityUserDto');
expect(node.children[1].index).toBe(1); expect(node.children[1].index).toBe(1);
}); });
it('should Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<System.string,Volo.Abp.Identity.IdentityUserDto<System.Int>>', function() { it('should Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<System.string,Volo.Abp.Identity.IdentityUserDto<System.Int>>', function () {
const type = 'Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<System.string,Volo.Abp.Identity.IdentityUserDto<System.Int>>'; const type =
'Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<System.string,Volo.Abp.Identity.IdentityUserDto<System.Int>>';
const node = parseGenerics(type); const node = parseGenerics(type);
expect(node.data).toEqual('Volo.Abp.Application.Dtos.AuditedEntityWithUserDto'); expect(node.data).toEqual('Volo.Abp.Application.Dtos.AuditedEntityWithUserDto');
expect(node.children.length).toBe(2); expect(node.children.length).toBe(2);
expect(node.children[0].data).toEqual('System.string'); expect(node.children[0].data).toEqual('System.string');
expect((node.children[0]).parent).toBe(node); expect(node.children[0].parent).toBe(node);
expect(node.children[1].data).toEqual('Volo.Abp.Identity.IdentityUserDto'); expect(node.children[1].data).toEqual('Volo.Abp.Identity.IdentityUserDto');
expect(node.children[1].children.length).toBe(1); expect(node.children[1].children.length).toBe(1);
expect(node.children[1].children[0].data).toEqual('System.Int'); expect(node.children[1].children[0].data).toEqual('System.Int');
expect(node.children[1].children[0].parent).toBe(node.children[1]) expect(node.children[1].children[0].parent).toBe(node.children[1]);
expect(node.children[1].children[0].index).toBe(0) expect(node.children[1].children[0].index).toBe(0);
}); });
it('should Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<Volo.Abp.Identity.IdentityUserDto<System.Int>,System.string>', function() { it('should Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<Volo.Abp.Identity.IdentityUserDto<System.Int>,System.string>', function () {
const type = 'Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<Volo.Abp.Identity.IdentityUserDto<System.Int>,System.string>'; const type =
'Volo.Abp.Application.Dtos.AuditedEntityWithUserDto<Volo.Abp.Identity.IdentityUserDto<System.Int>,System.string>';
const node = parseGenerics(type); const node = parseGenerics(type);
expect(node.data).toEqual('Volo.Abp.Application.Dtos.AuditedEntityWithUserDto'); expect(node.data).toEqual('Volo.Abp.Application.Dtos.AuditedEntityWithUserDto');
expect(node.children.length).toBe(2); expect(node.children.length).toBe(2);
@ -121,9 +117,5 @@ describe('parseGenerics', () => {
expect(node.children[0].children.length).toBe(1); expect(node.children[0].children.length).toBe(1);
expect(node.children[0].children[0].data).toEqual('System.Int'); expect(node.children[0].children[0].data).toEqual('System.Int');
expect(node.children[1].data).toEqual('System.string'); expect(node.children[1].data).toEqual('System.string');
}); });
}); });

Loading…
Cancel
Save