mirror of
https://github.com/apache/cordova-android.git
synced 2026-04-04 00:02:03 +08:00
feat!: android 12 splash screen (#1441)
* chore!: remove old splashscreen logic * feat(splashscreen): add backwards compatibility * chore: remove unused method * chore: prefix splashscreen_background with cdv_ * feat: support android 12 splashscreen api configs * feat: improve & refactor the logic for android splashscreen api 12 * feat: splashscreen copy image resources * feat: splashscreen branding image & xml cleanup * fix: splashscreen cleanup & branding conditions * fix: splashscreen @color usage * feat: update default Apache Cordova splash screen * chore: add missing asf header * fix: splashscreen image size * chore: use Theme.SplashScreen.IconBackground as default parent to support windowSplashScreenIconBackgroundColor * fix: center default test image by correct pivot * fix: fs-extra copySync * feat: re-add AutoHideSplashScreen and SplashScreenDelay preference support * chore: move splashscreen into CordovaActivity * feat: support splashscreen.hide & centralize to SplashScreenPlugin * chore: cleanup SplashScreenPlugin * feat: support fade, default auto hide on onPageFinished, support delays, refactor * refactor: cleanup splash screen * refactor: cleanup remove unused import * chore: add show method as unsupported * test: create a spy on updateProjectSplashScreen * style: add ending new line * chore: improve logging to warn when image path is missing * chore: split windowSplashScreenAnimatedIcon and windowSplashScreenBrandingImage case and added branding warning * chore: improve when to display warning * fix: add splashscreen dependency to app as well * chore: move the core-splashscreen dep lower Co-authored-by: Niklas Merz <niklasmerz@linux.com>
This commit is contained in:
@@ -83,18 +83,6 @@ 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', () => {
|
||||
// Rewire
|
||||
let prepare;
|
||||
@@ -779,7 +767,6 @@ describe('prepare', () => {
|
||||
prepare.__set__('updateProjectAccordingTo', jasmine.createSpy('updateProjectAccordingTo')
|
||||
.and.returnValue(Promise.resolve()));
|
||||
prepare.__set__('updateIcons', jasmine.createSpy('updateIcons').and.returnValue(Promise.resolve()));
|
||||
prepare.__set__('updateSplashes', jasmine.createSpy('updateSplashes').and.returnValue(Promise.resolve()));
|
||||
prepare.__set__('updateFileResources', jasmine.createSpy('updateFileResources').and.returnValue(Promise.resolve()));
|
||||
prepare.__set__('updateConfigFilesFrom',
|
||||
jasmine.createSpy('updateConfigFilesFrom')
|
||||
@@ -871,7 +858,7 @@ describe('prepare', () => {
|
||||
|
||||
prepare.__set__('updateWww', jasmine.createSpy('updateWww'));
|
||||
prepare.__set__('updateIcons', jasmine.createSpy('updateIcons').and.returnValue(Promise.resolve()));
|
||||
prepare.__set__('updateSplashes', jasmine.createSpy('updateSplashes').and.returnValue(Promise.resolve()));
|
||||
prepare.__set__('updateProjectSplashScreen', jasmine.createSpy('updateProjectSplashScreen'));
|
||||
prepare.__set__('updateFileResources', jasmine.createSpy('updateFileResources').and.returnValue(Promise.resolve()));
|
||||
prepare.__set__('updateConfigFilesFrom',
|
||||
jasmine.createSpy('updateConfigFilesFrom')
|
||||
@@ -960,110 +947,4 @@ describe('prepare', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateSplashes method', function () {
|
||||
// Mock Data
|
||||
let cordovaProject;
|
||||
let platformResourcesDir;
|
||||
|
||||
beforeEach(function () {
|
||||
cordovaProject = {
|
||||
root: '/mock',
|
||||
projectConfig: {
|
||||
path: '/mock/config.xml',
|
||||
cdvNamespacePrefix: 'cdv'
|
||||
},
|
||||
locations: {
|
||||
plugins: '/mock/plugins',
|
||||
www: '/mock/www'
|
||||
}
|
||||
};
|
||||
platformResourcesDir = PATH_RESOURCE;
|
||||
|
||||
// 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