Skip to content

Commit

Permalink
Added tests to merge function on core. (#357)
Browse files Browse the repository at this point in the history
* Added tests to  on

* Fixed a typo and added documentation
  • Loading branch information
chenlevy24 authored Oct 12, 2020
1 parent 3140fad commit 8e74e6e
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions packages/core/src/spec/lib/TwaManifestSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,119 @@ describe('TwaManifest', () => {
expect(asDisplayMode('')).toBeNull();
});
});
describe('#merge', () => {
it('Validates that the merge is done correctly in case which' +
' there are no fields to ignore', async () => {
const webManifest: WebManifestJson = {
'display': 'fullscreen',
'name': 'name',
'short_name': 'different_name',
'start_url': 'https://name.github.io/',
'icons': [{
'src': 'https://image.png',
'sizes': '512x512',
'purpose': 'any',
},
],
};
const twaManifest = new TwaManifest({
'packageId': 'id',
'host': 'host',
'name': 'name',
'launcherName': 'name',
'display': 'standalone',
'themeColor': '#FFFFFF',
'navigationColor': '#000000',
'navigationColorDark': '#000000',
'navigationDividerColor': '#000000',
'navigationDividerColorDark': '#000000',
'backgroundColor': '#FFFFFF',
'enableNotifications': false,
// The start_urls are different, but since they both resolve the same relative
// to the host url, nothing changes.
'startUrl': '/',
'iconUrl': 'https://image.png/',
'splashScreenFadeOutDuration': 300,
'signingKey': {
'alias': 'android',
'path': './android.keystore',
},
'appVersionCode': 1,
'shortcuts': [],
'generatorApp': 'bubblewrap-cli',
'webManifestUrl': 'https://name.github.io/',
'fallbackType': 'customtabs',
'features': {},
'enableSiteSettingsShortcut': true,
'isChromeOSOnly': false,
'appVersion': '1',
});
// The versions shouldn't change because the update happens in `cli`.
const expectedTwaManifest = new TwaManifest({
...twaManifest.toJson(),
'launcherName': 'different_name',
'display': 'fullscreen',
});
// A URL to insert as the webManifestUrl.
const url = new URL('https://name.github.io/');
expect(await TwaManifest.merge([], url, webManifest, twaManifest))
.toEqual(expectedTwaManifest);
});
it('Validates that the merge is done correctly in case which' +
' there are fields to ignore', async () => {
const webManifest: WebManifestJson = {
'display': 'fullscreen',
'name': 'name',
'short_name': 'different_name',
'start_url': 'https://other_url.github.io/',
'icons': [{
'src': 'https://image.png',
'sizes': '512x512',
'purpose': 'any',
},
],
};
const twaManifest = new TwaManifest({
'packageId': 'id',
'host': 'host',
'name': 'name',
'launcherName': 'name',
'display': 'standalone',
'themeColor': '#FFFFFF',
'navigationColor': '#000000',
'navigationColorDark': '#000000',
'navigationDividerColor': '#000000',
'navigationDividerColorDark': '#000000',
'backgroundColor': '#FFFFFF',
'enableNotifications': false,
// The start_urls are different, but since they both resolve the same relative
// to the host url, nothing changes.
'startUrl': '/',
'iconUrl': 'https://image.png/',
'splashScreenFadeOutDuration': 300,
'signingKey': {
'alias': 'android',
'path': './android.keystore',
},
'appVersionCode': 1,
'shortcuts': [],
'generatorApp': 'bubblewrap-cli',
'webManifestUrl': 'https://name.github.io/',
'fallbackType': 'customtabs',
'features': {},
'enableSiteSettingsShortcut': true,
'isChromeOSOnly': false,
'appVersion': '1',
});
// The versions shouldn't change because the update happens in `cli`.
const expectedTwaManifest = new TwaManifest({
...twaManifest.toJson(),
'webManifestUrl': 'https://other_url.github.io/',
});
// A URL to insert as the webManifestUrl.
const url = new URL('https://name.github.io/');
expect(await TwaManifest.merge(['short_name', 'display'], url, webManifest, twaManifest))
.toEqual(expectedTwaManifest);
});
});
});

0 comments on commit 8e74e6e

Please sign in to comment.