7 ; import * as assert from 'assert' ; import { suite , test } from 'mocha' ; import { NAVObject } from '../NAVObject' ; import * as NAVTestObjectLibrary from './NAVTestObjectLibrary' ; import { Settings } from '../Settings' ; import { DynamicsNAV } from '../DynamicsNAV' ; suite ( "NAVObject General Tests" , ( ) => { test ( "Al File without real code" , ( ) => { let testSettings = Settings . GetConfigSettings ( null ) ; let navTestObject = NAVTestObjectLibrary . getAlFileWithoutCode ( ) ; let navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; assert . equal ( navObject . NAVObjectText , navObject . NAVObjectTextFixed ) ; assert . equal ( navObject . objectFileName , navObject . objectFileNameFixed ) ; assert . equal ( navObject . objectName , navObject . objectNameFixed ) ; assert . equal ( navObject . objectNameFixedShort , '' ) ; } ) ; test ( "Reorganize Test Codeunits to 'test'-folder" , ( ) => { let testSettings = Settings . GetConfigSettings ( null ) ; let navTestObject = NAVTestObjectLibrary . getTestCodeunit ( ) ; let navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; let navTestObject2 = NAVTestObjectLibrary . getNormalCodeunitWithLongName ( ) ; let navObject2 = new NAVObject ( navTestObject2 . ObjectText , testSettings , navTestObject2 . ObjectFileName ) ; assert . equal ( navObject . objectCodeunitSubType . toLowerCase ( ) , 'test' ) ; assert . equal ( navObject2 . objectCodeunitSubType , null ) ; } ) ; test ( "Filename - <ObjectName[Short]> Normal object With Spaces" , ( ) => { let testSettings = Settings . GetConfigSettings ( null ) ; testSettings [ Settings . FileNamePattern ] = '<ObjectName>.al' ; let navTestObject = NAVTestObjectLibrary . getNormalCodeunitWithLongName ( ) ; let navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; assert . notEqual ( navObject . objectFileNameFixed . indexOf ( ' ' ) , - 1 ) ; testSettings [ Settings . FileNamePattern ] = '<ObjectNameShort>.al' ; navTestObject = NAVTestObjectLibrary . getNormalCodeunitWithLongName ( ) ; navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; assert . equal ( navObject . objectFileNameFixed . indexOf ( ' ' ) , - 1 ) ; } ) ; test ( "Filename - Wrong Extension Casing" , ( ) => { let testSettings = Settings . GetConfigSettings ( null ) ; let navTestObject = NAVTestObjectLibrary . GetFileNameWithWrongCasing ( ) ; let navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; assert . equal ( navObject . objectFileNameFixed . toLocaleLowerCase ( ) . endsWith ( '.al' ) , true ) ; } ) ; test ( "PageExtension - Automatic Naming without settings" , ( ) => { let testSettings = Settings . GetConfigSettings ( null ) ; let navTestObject = NAVTestObjectLibrary . getPageExtensionWithAmpersandInFileName ( ) ; let navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; assert . equal ( navObject . objectNameFixed , navObject . objectName ) ; } ) ; test ( "TableExtension - Automatic Naming without settings" , ( ) => { let testSettings = Settings . GetConfigSettings ( null ) ; let navTestObject = NAVTestObjectLibrary . getTableExtensionWrongFileNameAndKeyWord ( ) ; let navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; assert . equal ( navObject . objectNameFixed , navObject . objectName ) ; } ) ; test ( "Case Sensitive Object Types" , ( ) => { let testSettings = Settings . GetConfigSettings ( null ) ; let navTestObject = NAVTestObjectLibrary . getPascalCasedObjectType_Report ( ) ; let navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; assert . equal ( navObject . objectType . toLocaleLowerCase ( ) , 'report' ) ; } ) ; test ( "Filename - Rename enum" , ( ) => { let testSettings = Settings . GetConfigSettings ( null ) ; let navTestObject = NAVTestObjectLibrary . getEnumObject ( ) ; let navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; assert . notEqual ( navObject . extendedObjectName , navObject . objectName ) ; } ) ; test ( "Filename - Rename enumExtension" , ( ) => { let testSettings = Settings . GetConfigSettings ( null ) ; let navTestObject = NAVTestObjectLibrary . getEnumExtensionObject ( ) ; let navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; assert . notEqual ( navObject . extendedObjectName , navObject . objectName ) ; } ) ; test ( "Comments in table" , ( ) => { let testSettings = Settings . GetConfigSettings ( null ) ; testSettings [ Settings . ObjectNamePrefix ] = 'waldo' ; testSettings [ Settings . ObjectNameSuffix ] = 'waldo' ; testSettings [ Settings . FileNamePattern ] = '<Prefix><Suffix><ObjectType><ObjectTypeShort><ObjectTypeShortPascalCase><ObjectTypeShortUpper><ObjectId>' ; let navTestObject = NAVTestObjectLibrary . getTableWithComments ( ) ; let navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; assert . equal ( navObject . objectType . toLowerCase ( ) . startsWith ( 'table' ) , true ) ; assert . equal ( navObject . objectFileNameFixed , testSettings [ Settings . ObjectNamePrefix ] + testSettings [ Settings . ObjectNameSuffix ] + navObject . objectType + navObject . objectTypeShort + navObject . ObjectTypeShortPascalCase + navObject . objectTypeShort . toUpperCase ( ) + navObject . objectId ) ; } ) ; test ( "TableExtension - Fields with keyword-names" , ( ) => { let testSettings = Settings . GetConfigSettings ( null ) ; let navTestObject = NAVTestObjectLibrary . getTableExtensionWrongFileNameAndKeyWord ( ) ; let navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; let navObject2 = new NAVObject ( navObject . NAVObjectTextFixed , testSettings , navObject . objectFileNameFixed ) ; navObject2 . tableFields . forEach ( tableField => { if ( DynamicsNAV . getAllKeywordsLowerCased ( ) . indexOf ( tableField . name . toLowerCase ( ) ) != - 1 ) { var expectedValueToFind = `"${ tableField . name }"` ; assert . equal ( ( tableField . fullFieldText . indexOf ( expectedValueToFind ) > - 1 ) , true , `"${ tableField . name }" is a keyword and should be surrounded with quotes, while this is the fixed text: "${ tableField . fullFieldText }"` ) ; } } ) ; } ) ; test ( "TableExtension - Fields with keyword-names (with Prefix)" , ( ) => { let testSettings = Settings . GetConfigSettings ( null ) ; testSettings [ Settings . ObjectNamePrefix ] = 'waldo' ; let navTestObject = NAVTestObjectLibrary . getTableExtensionWrongFileNameAndKeyWord ( ) ; let navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; let navObject2 = new NAVObject ( navObject . NAVObjectTextFixed , testSettings , navObject . objectFileNameFixed ) ; navObject2 . tableFields . forEach ( tableField => { if ( DynamicsNAV . getAllKeywordsLowerCased ( ) . indexOf ( tableField . name . toLowerCase ( ) ) != - 1 ) { var expectedValueToFind = `"${ tableField . name }"` ; assert . equal ( ( tableField . fullFieldText . indexOf ( expectedValueToFind ) > - 1 ) , true , `"${ tableField . name }" is a keyword and should be surrounded with quotes, while this is the fixed text: "${ tableField . fullFieldText }"` ) ; } } ) ; } ) ; test ( "Table - Fields with keyword-names" , ( ) => { let testSettings = Settings . GetConfigSettings ( null ) ; let navTestObject = NAVTestObjectLibrary . getTableWrongFileNameAndKeyWord ( ) ; let navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; let navObject2 = new NAVObject ( navObject . NAVObjectTextFixed , testSettings , navObject . objectFileNameFixed ) ; navObject2 . tableFields . forEach ( tableField => { if ( DynamicsNAV . getAllKeywordsLowerCased ( ) . indexOf ( tableField . name . toLowerCase ( ) ) != - 1 ) { var expectedValueToFind = `"${ tableField . name }"` ; assert . equal ( ( tableField . fullFieldText . indexOf ( expectedValueToFind ) > - 1 ) , true , `"${ tableField . name }" is a keyword and should be surrounded with quotes, while this is the fixed text: "${ tableField . fullFieldText }"` ) ; } } ) ; } ) ; test ( "Table - Fields with keyword-names (With Prefix)" , ( ) => { let testSettings = Settings . GetConfigSettings ( null ) ; testSettings [ Settings . ObjectNamePrefix ] = 'waldo' ; let navTestObject = NAVTestObjectLibrary . getTableWrongFileNameAndKeyWord ( ) ; let navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; let navObject2 = new NAVObject ( navObject . NAVObjectTextFixed , testSettings , navObject . objectFileNameFixed ) ; navObject2 . tableFields . forEach ( tableField => { if ( DynamicsNAV . getAllKeywordsLowerCased ( ) . indexOf ( tableField . name . toLowerCase ( ) ) != - 1 ) { var expectedValueToFind = `"${ tableField . name }"` ; assert . equal ( ( tableField . fullFieldText . indexOf ( expectedValueToFind ) > - 1 ) , true , `"${ tableField . name }" is a keyword and should be surrounded with quotes, while this is the fixed text: "${ tableField . fullFieldText }"` ) ; } } ) ; } ) ; test ( "Page - Actions with keyword-names (With Prefix)" , ( ) => { let testSettings = Settings . GetConfigSettings ( null ) ; testSettings [ Settings . ObjectNamePrefix ] = 'waldo' ; let navTestObject = NAVTestObjectLibrary . getPageWithWaldoPrefixWrongName ( ) ; let navObject = new NAVObject ( navTestObject . ObjectText , testSettings , navTestObject . ObjectFileName ) ; let navObject2 = new NAVObject ( navObject . NAVObjectTextFixed , testSettings , navObject . objectFileNameFixed ) ; navObject2 . objectActions . forEach ( pageAction => { if ( DynamicsNAV . getAllKeywordsLowerCased ( ) . indexOf ( pageAction . name . toLowerCase ( ) ) != - 1 ) { var expectedValueToFind = `"${ pageAction . name }"` ; assert . equal ( ( pageAction . fullActionText . indexOf ( expectedValueToFind ) > - 1 ) , true , `"${ pageAction . name }" is a keyword and should be surrounded with quotes, while this is the fixed text: "${ pageAction . fullActionText }"` ) ; } } ) ; } ) ; } ) ;