Skip to content

Commit

Permalink
tests(prepare): factor out common vars (apache#1259)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphinesse authored and wedgberto committed May 17, 2022
1 parent d7400ef commit 73f4488
Showing 1 changed file with 21 additions and 77 deletions.
98 changes: 21 additions & 77 deletions spec/unit/prepare.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,37 @@ function mockGetSplashScreenItem (data) {
}

describe('prepare', () => {
describe('updateIcons method', function () {
// Rewire
let prepare;
// Rewire
let prepare;

// Spies
let emitSpy;
let updatePathsSpy;

beforeEach(() => {
prepare = rewire('../../bin/templates/cordova/lib/prepare');

emitSpy = jasmine.createSpy('emit');
prepare.__set__('events', {
emit: emitSpy
});

updatePathsSpy = jasmine.createSpy('updatePaths');
prepare.__set__('FileUpdater', {
updatePaths: updatePathsSpy
});
});

describe('updateIcons method', function () {
// Spies
let updateIconResourceForAdaptiveSpy;
let updateIconResourceForLegacySpy;
let emitSpy;
let updatePathsSpy;

// Mock Data
let cordovaProject;
let platformResourcesDir;

beforeEach(function () {
prepare = rewire('../../bin/templates/cordova/lib/prepare');

cordovaProject = {
root: '/mock',
projectConfig: {
Expand All @@ -126,16 +140,6 @@ describe('prepare', () => {
};
platformResourcesDir = PATH_RESOURCE;

emitSpy = jasmine.createSpy('emit');
prepare.__set__('events', {
emit: emitSpy
});

updatePathsSpy = jasmine.createSpy('updatePaths');
prepare.__set__('FileUpdater', {
updatePaths: updatePathsSpy
});

// mocking initial responses for mapImageResources
prepare.__set__('mapImageResources', function (rootDir, subDir, type, resourceName) {
if (resourceName.includes('ic_launcher.png')) {
Expand Down Expand Up @@ -508,20 +512,10 @@ describe('prepare', () => {
});

describe('prepareIcons method', function () {
let prepare;
let emitSpy;
let prepareIcons;

beforeEach(function () {
prepare = rewire('../../bin/templates/cordova/lib/prepare');

prepareIcons = prepare.__get__('prepareIcons');

// Creating Spies
emitSpy = jasmine.createSpy('emit');
prepare.__set__('events', {
emit: emitSpy
});
});

it('Test#001 : should emit extra default icon found for adaptive use case.', function () {
Expand Down Expand Up @@ -572,8 +566,6 @@ describe('prepare', () => {
});

describe('updateIconResourceForLegacy method', function () {
let prepare;

// Spies
let fsWriteFileSyncSpy;

Expand All @@ -583,8 +575,6 @@ describe('prepare', () => {
let resourceMap;

beforeEach(function () {
prepare = rewire('../../bin/templates/cordova/lib/prepare');

// Mocked Data
platformResourcesDir = PATH_RESOURCE;
preparedIcons = {
Expand Down Expand Up @@ -620,8 +610,6 @@ describe('prepare', () => {
});

describe('updateIconResourceForAdaptive method', function () {
let prepare;

// Spies
let fsWriteFileSyncSpy;

Expand All @@ -631,8 +619,6 @@ describe('prepare', () => {
let resourceMap;

beforeEach(function () {
prepare = rewire('../../bin/templates/cordova/lib/prepare');

// Mocked Data
platformResourcesDir = PATH_RESOURCE;
preparedIcons = {
Expand Down Expand Up @@ -671,24 +657,6 @@ describe('prepare', () => {
});

describe('cleanIcons method', function () {
let prepare;
let emitSpy;
let updatePathsSpy;

beforeEach(function () {
prepare = rewire('../../bin/templates/cordova/lib/prepare');

emitSpy = jasmine.createSpy('emit');
prepare.__set__('events', {
emit: emitSpy
});

updatePathsSpy = jasmine.createSpy('updatePaths');
prepare.__set__('FileUpdater', {
updatePaths: updatePathsSpy
});
});

it('Test#001 : should detect that the app does not have defined icons.', function () {
// Mock
const icons = [];
Expand Down Expand Up @@ -772,7 +740,6 @@ describe('prepare', () => {
// Rewire
let Api;
let api;
let prepare;

// Spies
let gradlePropertiesParserSpy;
Expand All @@ -783,7 +750,6 @@ describe('prepare', () => {

beforeEach(function () {
Api = rewire('../../bin/templates/cordova/Api');
prepare = rewire('../../bin/templates/cordova/lib/prepare');

cordovaProject = {
root: '/mock',
Expand All @@ -808,9 +774,6 @@ describe('prepare', () => {

Api.__set__('prepare', prepare.prepare);

prepare.__set__('events', {
emit: jasmine.createSpy('emit')
});
prepare.__set__('updateUserProjectGradleConfig', jasmine.createSpy());
prepare.__set__('updateWww', jasmine.createSpy());
prepare.__set__('updateProjectAccordingTo', jasmine.createSpy('updateProjectAccordingTo')
Expand Down Expand Up @@ -998,20 +961,11 @@ describe('prepare', () => {
});

describe('updateSplashes method', function () {
// Rewire
let prepare;

// Spies
let emitSpy;
let updatePathsSpy;

// Mock Data
let cordovaProject;
let platformResourcesDir;

beforeEach(function () {
prepare = rewire('../../bin/templates/cordova/lib/prepare');

cordovaProject = {
root: '/mock',
projectConfig: {
Expand All @@ -1025,16 +979,6 @@ describe('prepare', () => {
};
platformResourcesDir = PATH_RESOURCE;

emitSpy = jasmine.createSpy('emit');
prepare.__set__('events', {
emit: emitSpy
});

updatePathsSpy = jasmine.createSpy('updatePaths');
prepare.__set__('FileUpdater', {
updatePaths: updatePathsSpy
});

// mocking initial responses for mapImageResources
prepare.__set__('makeSplashCleanupMap', (rootDir, resourcesDir) => ({
[path.join(resourcesDir, 'drawable-mdpi/screen.png')]: null,
Expand Down

0 comments on commit 73f4488

Please sign in to comment.