-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(format): adding android/resources format
- Loading branch information
1 parent
75f0ba3
commit e43aafd
Showing
6 changed files
with
509 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
__tests__/formats/__snapshots__/androidResources.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
|
||
}); | ||
|
||
}); |
Oops, something went wrong.