mirror of
https://github.com/apache/cordova-android.git
synced 2026-04-04 00:02:03 +08:00
Features/webp support for splashscreen (#1113)
* - linting - platform independent paths in testing - addes some unittest - remove duplication + add comments - delete webp's if png's added, delete png's if webp' added. - Update bin/templates/cordova/lib/prepare.js Co-authored-by: エリス <erisu@users.noreply.github.com> - fix https://github.com/apache/cordova-plugin-splashscreen/issues/257 webp support for android * revert changes * refactor: use source extension for target in getImageResourcePath * fix(prepare): include more extensions in initial splash-screen resource map * tests(prepare): quick-fix for tests * backward slashes must be changed to forward slashes for fast-glob package. Co-authored-by: Raphael von der Grün <raphinesse@gmail.com>
This commit is contained in:
@@ -81,6 +81,18 @@ function mockGetIconItem (data) {
|
||||
}, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a mock item from the getSplashScreen collection with the supplied updated data.
|
||||
*
|
||||
* @param {Object} data Changes to apply to the mock getSplashScreen item
|
||||
*/
|
||||
function mockGetSplashScreenItem (data) {
|
||||
return Object.assign({}, {
|
||||
src: undefined,
|
||||
density: undefined
|
||||
}, data);
|
||||
}
|
||||
|
||||
describe('prepare', () => {
|
||||
describe('updateIcons method', function () {
|
||||
// Rewire
|
||||
@@ -833,4 +845,129 @@ describe('prepare', () => {
|
||||
).toBeResolved();
|
||||
});
|
||||
});
|
||||
|
||||
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: {
|
||||
path: '/mock/config.xml',
|
||||
cdvNamespacePrefix: 'cdv'
|
||||
},
|
||||
locations: {
|
||||
plugins: '/mock/plugins',
|
||||
www: '/mock/www'
|
||||
}
|
||||
};
|
||||
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,
|
||||
[path.join(resourcesDir, 'drawable-mdpi/screen.webp')]: null
|
||||
}));
|
||||
});
|
||||
|
||||
it('Test#001 : Should detect no defined splash screens.', function () {
|
||||
const updateSplashes = prepare.__get__('updateSplashes');
|
||||
|
||||
// mock data.
|
||||
cordovaProject.projectConfig.getSplashScreens = function (platform) {
|
||||
return [];
|
||||
};
|
||||
|
||||
updateSplashes(cordovaProject, platformResourcesDir);
|
||||
|
||||
// The emit was called
|
||||
expect(emitSpy).toHaveBeenCalled();
|
||||
|
||||
// The emit message was.
|
||||
const actual = emitSpy.calls.argsFor(0)[1];
|
||||
const expected = 'This app does not have splash screens defined';
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('Test#02 : Should update splash png icon.', function () {
|
||||
const updateSplashes = prepare.__get__('updateSplashes');
|
||||
|
||||
// mock data.
|
||||
cordovaProject.projectConfig.getSplashScreens = function (platform) {
|
||||
return [mockGetSplashScreenItem({
|
||||
density: 'mdpi',
|
||||
src: 'res/splash/android/mdpi-screen.png'
|
||||
})];
|
||||
};
|
||||
|
||||
updateSplashes(cordovaProject, platformResourcesDir);
|
||||
|
||||
// The emit was called
|
||||
expect(emitSpy).toHaveBeenCalled();
|
||||
|
||||
// The emit message was.
|
||||
const actual = emitSpy.calls.argsFor(0)[1];
|
||||
const expected = 'Updating splash screens at ' + PATH_RESOURCE;
|
||||
expect(actual).toEqual(expected);
|
||||
|
||||
const actualResourceMap = updatePathsSpy.calls.argsFor(0)[0];
|
||||
const expectedResourceMap = {};
|
||||
expectedResourceMap[path.join(PATH_RESOURCE, 'drawable-mdpi', 'screen.png')] = 'res/splash/android/mdpi-screen.png';
|
||||
expectedResourceMap[path.join(PATH_RESOURCE, 'drawable-mdpi', 'screen.webp')] = null;
|
||||
|
||||
expect(actualResourceMap).toEqual(expectedResourceMap);
|
||||
});
|
||||
|
||||
it('Test#03 : Should update splash webp icon.', function () {
|
||||
const updateSplashes = prepare.__get__('updateSplashes');
|
||||
|
||||
// mock data.
|
||||
cordovaProject.projectConfig.getSplashScreens = function (platform) {
|
||||
return [mockGetSplashScreenItem({
|
||||
density: 'mdpi',
|
||||
src: 'res/splash/android/mdpi-screen.webp'
|
||||
})];
|
||||
};
|
||||
|
||||
// Creating Spies
|
||||
updateSplashes(cordovaProject, platformResourcesDir);
|
||||
|
||||
// The emit was called
|
||||
expect(emitSpy).toHaveBeenCalled();
|
||||
|
||||
// The emit message was.
|
||||
const actual = emitSpy.calls.argsFor(0)[1];
|
||||
const expected = 'Updating splash screens at ' + PATH_RESOURCE;
|
||||
expect(actual).toEqual(expected);
|
||||
|
||||
const actualResourceMap = updatePathsSpy.calls.argsFor(0)[0];
|
||||
|
||||
const expectedResourceMap = {};
|
||||
expectedResourceMap[path.join(PATH_RESOURCE, 'drawable-mdpi', 'screen.webp')] = 'res/splash/android/mdpi-screen.webp';
|
||||
expectedResourceMap[path.join(PATH_RESOURCE, 'drawable-mdpi', 'screen.png')] = null;
|
||||
|
||||
expect(actualResourceMap).toEqual(expectedResourceMap);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user