<commit_before>///<reference path="../../../types/jasmine/jasmine.d.ts"/>
///<reference path="../../../types/angular/angular-mocks.d.ts"/>
///<reference path="../../../assets/build/pow-edit.d.ts"/>

describe("pow2.editor.AppController",()=>{
   var controller:pow2.editor.AppController;
   // When platform.enumPath is called this is the result array.
   var files:pow2.editor.IFileInfo[] = [];
   // When platform.readFile is called, this is the data that will be returned.
   var selectedFileData:any = null;

   beforeEach(module('pow-edit'));
   beforeEach(inject(($controller:ng.IControllerService,$rootScope:ng.IRootScopeService) => {
      controller = $controller('AppController',{
         $scope:$rootScope.$new(),

         // Mock out IAppPlatform
         $platform:<pow2.editor.IAppPlatform>{
            enumPath: (location:string,cb:(err:any,files?:pow2.editor.IFileInfo[])=>any) => { setTimeout(()=>{ cb(null,files); },100); },
            readFile: (location:string,done:(data:any) => any) => { setTimeout(()=>{ done(selectedFileData); },100); },
            setTitle:(text:string) => {},
            getDirName:(location:string):string => { return location; },
            normalizePath:(url:string):string => { return url; },
            pathAsAppProtocol:(url:string):string => { return url; },
            pathAsFile:(url:string):string => { return url; }
         }
      });
   }));
   it("should satisfy expected dependencies",()=>{
      expect(controller.$scope).toBeDefined();
      expect(controller.$platform).toBeDefined();
      expect(controller.$tasks).toBeDefined();
   });

   it("should fire event when the file system has been enumerated",(done)=>{
      files = [
         {
            name: 'README.md',
            path: '/fixtures/',
            full: '/fixtures/README.md'
         },
         {
            name: '.gitignore',
            path: '/fixtures/',
            full: '/fixtures/.gitignore'
         }
      ];
      controller.$scope.$on('fs-enumerated',()=>{
         done();
      });
   });

   describe('selectFile',()=>{
      it("should update scope document when file system node is selected",(done)=>{
         var file:pow2.editor.IFileInfo = {
            name: 'README.md',
            path: '/fixtures/',
            full: '/fixtures/README.md'
         };
         controller.selectFile(controller.makeNode(file));
         controller.$scope.$on('document-loaded',()=>{
            expect(controller.document.data).toBe(selectedFileData);
            expect(controller.document.url).toBe(file.full);
            done();
         });
      });

   });
});
<commit_msg>test(AppController): getDocumentType method<commit_after>///<reference path="../../../types/jasmine/jasmine.d.ts"/>
///<reference path="../../../types/angular/angular-mocks.d.ts"/>
///<reference path="../../../assets/build/pow-edit.d.ts"/>

describe("pow2.editor.AppController",()=>{
   var controller:pow2.editor.AppController;
   // When platform.enumPath is called this is the result array.
   var files:pow2.editor.IFileInfo[] = [];
   // When platform.readFile is called, this is the data that will be returned.
   var selectedFileData:any = null;

   beforeEach(module('pow-edit'));
   beforeEach(inject(($controller:ng.IControllerService,$rootScope:ng.IRootScopeService) => {
      controller = $controller('AppController',{
         $scope:$rootScope.$new(),

         // Mock out IAppPlatform
         $platform:<pow2.editor.IAppPlatform>{
            enumPath: (location:string,cb:(err:any,files?:pow2.editor.IFileInfo[])=>any) => { setTimeout(()=>{ cb(null,files); },100); },
            readFile: (location:string,done:(data:any) => any) => { setTimeout(()=>{ done(selectedFileData); },100); },
            setTitle:(text:string) => {},
            getDirName:(location:string):string => { return location; },
            normalizePath:(url:string):string => { return url; },
            pathAsAppProtocol:(url:string):string => { return url; },
            pathAsFile:(url:string):string => { return url; }
         }
      });
   }));
   it("should satisfy expected dependencies",()=>{
      expect(controller.$scope).toBeDefined();
      expect(controller.$platform).toBeDefined();
      expect(controller.$tasks).toBeDefined();
   });

   it("should fire event when the file system has been enumerated",(done)=>{
      files = [
         {
            name: 'README.md',
            path: '/fixtures/',
            full: '/fixtures/README.md'
         },
         {
            name: '.gitignore',
            path: '/fixtures/',
            full: '/fixtures/.gitignore'
         }
      ];
      controller.$scope.$on('fs-enumerated',()=>{
         done();
      });
   });

   describe('getDocumentType',()=>{
      it('should return unknown for unrecognized extensions',()=>{
         angular.forEach(['pun'],(ext:string)=>{
            expect(controller.getDocumentType(ext)).toBe('unknown');
         });
      });
      it('should identify tiled map files',()=>{
         angular.forEach(['tmx'],(ext:string)=>{
            expect(controller.getDocumentType(ext)).toBe('tiled');
         });
      });
      it('should identify markdown files',()=>{
         angular.forEach(['md','markdown'],(ext:string)=>{
            expect(controller.getDocumentType(ext)).toBe('markdown');
         });
      });
      it('should identify image files',()=>{
         angular.forEach(['png','gif','jpg','jpeg','bmp'],(ext:string)=>{
            expect(controller.getDocumentType(ext)).toBe('image');
         });
      });
   });

   describe('selectFile',()=>{
      it("should update scope document when file system node is selected",(done)=>{
         var file:pow2.editor.IFileInfo = {
            name: 'README.md',
            path: '/fixtures/',
            full: '/fixtures/README.md'
         };
         controller.selectFile(controller.makeNode(file));
         controller.$scope.$on('document-loaded',()=>{
            expect(controller.document.data).toBe(selectedFileData);
            expect(controller.document.url).toBe(file.full);
            done();
         });
      });

   });
});

{'fraction_non_alphanumeric': 0.18799804846316473, 'fraction_numerical': 0.003903073670515531, 'mean_word_length': 2.5203205495134515, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3739026', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1719, 'n_words': 278}