Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(prepare): factor out common vars #1259

Merged
merged 1 commit into from
Jul 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
98 changes: 21 additions & 77 deletions spec/unit/prepare.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,37 @@ function mockGetSplashScreenItem (data) {
}

describe('prepare', () => {
describe('updateIcons method', function () {
// Rewire
let prepare;
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 @@ -124,16 +138,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 @@ -506,20 +510,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 @@ -570,8 +564,6 @@ describe('prepare', () => {
});

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

// Spies
let fsWriteFileSyncSpy;

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

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

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

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

// Spies
let fsWriteFileSyncSpy;

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

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

// Mocked Data
platformResourcesDir = PATH_RESOURCE;
preparedIcons = {
Expand Down Expand Up @@ -669,24 +655,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 @@ -767,10 +735,9 @@ describe('prepare', () => {
});

describe('prepare arguments', () => {
// Rewire
// Rewire
let Api;
let api;
let prepare;

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

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

cordovaProject = {
root: '/mock',
Expand All @@ -806,9 +772,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 @@ -848,20 +811,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 @@ -875,16 +829,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