Skip to content

Commit

Permalink
feat(Icons): use icon keywords from mistica design in catalog story (#…
Browse files Browse the repository at this point in the history
…914)

* checkout icon keywords from mistica design

* fix bugs and update story/screenshot test

* fix pascal case
  • Loading branch information
marcoskolodny authored Oct 16, 2023
1 parent 25ed4eb commit 286e385
Show file tree
Hide file tree
Showing 22 changed files with 3,216 additions and 109 deletions.
42 changes: 40 additions & 2 deletions packages/import-mistica-icons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ const createIconComponentSource = async (name, componentName, svgIconsInfo) => {
* To update, execute "yarn start" inside "import-mistica-icons"
*/
import * as React from 'react';
${hasVariants ? "import {useTheme} from '../../hooks';" : ''}
import * as React from 'react';${
hasVariants
? `
import {useTheme} from '../../hooks';`
: ''
}
import {useIsInverseVariant} from '../../theme-variant-context';
import {vars} from '../../skins/skin-contract.css';
Expand All @@ -194,6 +198,35 @@ const createIconComponentSource = async (name, componentName, svgIconsInfo) => {
return format(source);
};

/**
* @typedef {{[key: string]: Array<string>}} IconKeywordsInfo
*/
const createAllIconKeywordsSource = () => {
const keywordsPath = join(PATH_MISTICA_ICONS_REPO, 'icons', 'icons-keywords.json');
const keywordsSource = fs.readFileSync(keywordsPath, 'utf8');
/** @type {IconKeywordsInfo} */
const keywordsMap = JSON.parse(keywordsSource);

// map icon names to kebab case
const result = {};
for (const [icon, keywords] of Object.entries(keywordsMap)) {
result[kebabCase(icon)] = keywords;
}

const source = `/*
* This file was autogenerated. Don't edit this file!
*
* To update, execute "yarn start" inside "import-mistica-icons"
*/
const iconKeywords: {[key: string]: Array<string>} = ${JSON.stringify(result)};
export default iconKeywords;
`;

return format(source);
};

const main = async () => {
checkoutMisticaIconsRepo();

Expand Down Expand Up @@ -225,6 +258,11 @@ const main = async () => {

fs.writeFileSync(PATH_OUTPUT_INDEX_FILENAME, index, 'utf8');

console.log();
console.log('Generating keywords for each icon.');
const keywordsSource = await createAllIconKeywordsSource();
fs.writeFileSync(join(PATH_OUTPUT, 'icons-keywords.tsx'), keywordsSource);

console.log();
console.log(`Done! (${allIconNames.length} components).`);
console.log(`Copy exports in `, yellow(PATH_OUTPUT_INDEX_FILENAME), ' to src/index.tsx');
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 17 additions & 25 deletions src/__screenshot_tests__/icons-screenshot-test.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
import {openStoryPage, screen} from '../test-utils';
import {openStoryPage} from '../test-utils';

const SKINS = ['Movistar', 'O2', 'Blau'] as const;

test.each(SKINS)('Icons catalog for %s', async ([skin]) => {
const ICON_TYPES = ['light', 'regular', 'filled'];

const getCases = () => {
const cases = [];
for (const skin of SKINS) {
for (const type of ICON_TYPES) {
cases.push([skin, type]);
}
}
return cases;
};

test.each(getCases())('Icons catalog for %s (%s)', async (skin, type) => {
const page = await openStoryPage({
id: 'icons-catalog--catalog',
device: 'DESKTOP',
skin: skin as (typeof SKINS)[number],
args: {light: type === 'light', regular: type === 'regular', filled: type === 'filled'},
});

const lightCheckbox = await screen.findByLabelText('Light');
const filledCheckbox = await screen.findByLabelText('Filled');
const regularCheckbox = await screen.findByLabelText('Regular');
// initially all checkboxes are checked

await filledCheckbox.click();
await regularCheckbox.click();

const light = await page.screenshot({fullPage: true});
expect(light).toMatchImageSnapshot();

await lightCheckbox.click();
await regularCheckbox.click();

const regular = await page.screenshot({fullPage: true});
expect(regular).toMatchImageSnapshot();

await regularCheckbox.click();
await filledCheckbox.click();

const filled = await page.screenshot({fullPage: true});
expect(filled).toMatchImageSnapshot();
const icons = await page.screenshot({fullPage: true});
expect(icons).toMatchImageSnapshot();
});
Loading

1 comment on commit 286e385

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for mistica-web ready!

✅ Preview
https://mistica-oemj16feg-tuentisre.vercel.app

Built with commit 286e385.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.