You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2018/06/27 10:40:55 UTC

[GitHub] raphinesse commented on a change in pull request #458: Unit tests for AndroidProject and Builders

raphinesse commented on a change in pull request #458: Unit tests for AndroidProject and Builders
URL: https://github.com/apache/cordova-android/pull/458#discussion_r198445024
 
 

 ##########
 File path: spec/unit/AndroidProject.spec.js
 ##########
 @@ -0,0 +1,134 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+
+const path = require('path');
+const rewire = require('rewire');
+
+describe('AndroidProject', () => {
+    const PROJECT_DIR = 'platforms/android';
+    let AndroidProject;
+    let AndroidStudioSpy;
+
+    beforeEach(() => {
+        AndroidProject = rewire('../../bin/templates/cordova/lib/AndroidProject');
+
+        AndroidStudioSpy = jasmine.createSpyObj('AndroidStudio', ['isAndroidStudioProject']);
+        AndroidProject.__set__('AndroidStudio', AndroidStudioSpy);
+    });
+
+    describe('constructor', () => {
+        it('should set the project directory and www folder', () => {
+            const project = new AndroidProject(PROJECT_DIR);
+            expect(project.projectDir).toBe(PROJECT_DIR);
+        });
+
+        it('should set www folder correctly if not Android Studio project', () => {
+            AndroidStudioSpy.isAndroidStudioProject.and.returnValue(false);
+
+            const project = new AndroidProject(PROJECT_DIR);
+            expect(project.www).toBe(path.join(PROJECT_DIR, 'assets/www'));
+        });
+
+        it('should set www folder correctly if it is an Android Studio project', () => {
+            AndroidStudioSpy.isAndroidStudioProject.and.returnValue(true);
+
+            const project = new AndroidProject(PROJECT_DIR);
+            expect(project.www).toBe(path.join(PROJECT_DIR, 'app/src/main/assets/www'));
+        });
+    });
+
+    describe('getProjectFile', () => {
+        it('should create and return a new project if one does not exist', () => {
+            const newProject = AndroidProject.getProjectFile(PROJECT_DIR);
+
+            expect(newProject).toEqual(jasmine.any(AndroidProject));
+        });
+
+        it('should return the existing project', () => {
+            const newProject = AndroidProject.getProjectFile(PROJECT_DIR);
+            const secondProject = AndroidProject.getProjectFile(PROJECT_DIR);
+
+            expect(newProject).toEqual(jasmine.any(AndroidProject));
+            expect(secondProject).toBe(newProject);
+        });
+    });
+
+    describe('purgeCache', () => {
+        beforeEach(() => {
+            AndroidProject.__set__('projectFileCache', {
+                project1: 'test',
+                project2: 'anothertest',
+                project3: 'finaltest'
+            });
+        });
+
+        it('should only remove the specified project from the cache', () => {
+            const projectToRemove = 'project2';
+            AndroidProject.purgeCache(projectToRemove);
+
+            const cache = AndroidProject.__get__('projectFileCache');
+            expect(Object.keys(cache).length).toBe(2);
+            expect(cache[projectToRemove]).toBe(undefined);
 
 Review comment:
   I find `in` to be vastly underused in the JS community :wink: 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org