Skip to content

Commit

Permalink
feat(format): adding android/resources format
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanksdesign authored Dec 15, 2020
1 parent 75f0ba3 commit e43aafd
Show file tree
Hide file tree
Showing 6 changed files with 509 additions and 0 deletions.
14 changes: 14 additions & 0 deletions __tests__/formats/__snapshots__/all.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ exports[`formats all should match android/integers snapshot 1`] = `
"
`;
exports[`formats all should match android/resources snapshot 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<!--
Do not edit directly
Generated on Sat, 01 Jan 2000 00:00:00 GMT
-->
<resources>
<color name=\\"color_red\\">#FF0000</color><!-- comment -->
</resources>
"
`;
exports[`formats all should match android/strings snapshot 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
Expand Down
50 changes: 50 additions & 0 deletions __tests__/formats/__snapshots__/androidResources.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`formats android/resources should match default snapshot 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<!--
Do not edit directly
Generated on Sat, 01 Jan 2000 00:00:00 GMT
-->
<resources>
<dimen name=\\"size-font-small\\">12rem</dimen>
<dimen name=\\"size-font-large\\">18rem</dimen>
<color name=\\"color-base-red\\">#ff0000</color><!-- comment -->
<color name=\\"color-white\\">#ffffff</color>
</resources>
"
`;
exports[`formats android/resources with resourceMap override should match snapshot 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<!--
Do not edit directly
Generated on Sat, 01 Jan 2000 00:00:00 GMT
-->
<resources>
<color name=\\"backgroundColorSecondary\\">#F2F3F4</color>
<color name=\\"fontColorPrimary\\">#000000</color>
</resources>
"
`;
exports[`formats android/resources with resourceType override should match snapshot 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<!--
Do not edit directly
Generated on Sat, 01 Jan 2000 00:00:00 GMT
-->
<resources>
<dimen name=\\"size-font-small\\">12rem</dimen>
<dimen name=\\"size-font-large\\">18rem</dimen>
<dimen name=\\"color-base-red\\">#ff0000</dimen><!-- comment -->
<dimen name=\\"color-white\\">#ffffff</dimen>
</resources>
"
`;
239 changes: 239 additions & 0 deletions __tests__/formats/androidResources.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

const formats = require('../../lib/common/formats');

const dictionary = {
"properties": {
"size": {
"font": {
"small": {
"value": "12rem",
"original": {
"value": "12px"
},
"name": "size-font-small",
"attributes": {
"category": "size",
"type": "font",
"item": "small"
},
"path": [
"size",
"font",
"small"
]
},
"large": {
"value": "18rem",
"original": {
"value": "18px"
},
"name": "size-font-large",
"attributes": {
"category": "size",
"type": "font",
"item": "large"
},
"path": [
"size",
"font",
"large"
]
}
}
},
"color": {
"base": {
"red": {
"value": "#ff0000",
"comment": "comment",
"original": {
"value": "#FF0000",
"comment": "comment"
},
"name": "color-base-red",
"attributes": {
"category": "color",
"type": "base",
"item": "red"
},
"path": [
"color",
"base",
"red"
]
}
},
"white": {
"value": "#ffffff",
"original": {
"value": "#ffffff"
},
"name": "color-white",
"attributes": {
"category": "color",
"type": "white"
},
"path": [
"color",
"white"
]
}
},
},
"allProperties": [
{
"value": "12rem",
"original": {
"value": "12px"
},
"name": "size-font-small",
"attributes": {
"category": "size",
"type": "font",
"item": "small"
},
"path": [
"size",
"font",
"small"
]
},
{
"value": "18rem",
"original": {
"value": "18px"
},
"name": "size-font-large",
"attributes": {
"category": "size",
"type": "font",
"item": "large"
},
"path": [
"size",
"font",
"large"
]
},
{
"value": "#ff0000",
"comment": "comment",
"original": {
"value": "#FF0000",
"comment": "comment"
},
"name": "color-base-red",
"attributes": {
"category": "color",
"type": "base",
"item": "red"
},
"path": [
"color",
"base",
"red"
]
},
{
"value": "#ffffff",
"original": {
"value": "#ffffff"
},
"name": "color-white",
"attributes": {
"category": "color",
"type": "white"
},
"path": [
"color",
"white"
]
},
]
};

const customDictionary = {
properties: {
fontColor: {
primary: {
name: "fontColorPrimary",
value: "#000000",
attributes: {
category: "fontColor"
}
}
},
backgroundColor: {
secondary: {
name: "backgroundColorSecondary",
value: "#F2F3F4",
attributes: {
category: "backgroundColor"
}
}
}
},
allProperties: [{
name: "backgroundColorSecondary",
value: "#F2F3F4",
attributes: {
category: "backgroundColor"
}
},{
name: "fontColorPrimary",
value: "#000000",
attributes: {
category: "fontColor"
}
}]
}

const format = formats['android/resources'];
const file = {
"destination": "__output/",
"format": 'android/resources'
};

describe('formats', () => {

describe(`android/resources`, () => {
// mock the Date.now() call to a fixed value
const constantDate = new Date('2000-01-01');
const globalDate = global.Date;
global.Date = function() { return constantDate };

it('should match default snapshot', () => {
expect(format(dictionary, {}, file)).toMatchSnapshot();
});

it('with resourceType override should match snapshot', () => {
expect(format(dictionary, {}, {resourceType: "dimen"})).toMatchSnapshot();
});

it('with resourceMap override should match snapshot', () => {
expect(
format(customDictionary, {}, {
resourceMap: {
color: 'color',
fontColor: 'color',
backgroundColor: 'color'
}
})
).toMatchSnapshot();
});

});

});
Loading

0 comments on commit e43aafd

Please sign in to comment.