ant-design/tests/shared/demoTest.js
二货机器人 2ea28af6ed
Virtual select component (#18658)
* init

* fix firefox

* add active style

* adjust arrow style

* update select

* update icon logic

* render empty

* init multiple

* fix ff display style

* sync font size

* adjust padding style

* add padding

* padding it

* hotfix of chrome

* single sm

* multiple size

* update option group style

* update snapshot

* clean up transition

* rm combobox in ts define

* auto complete init

* fix auto option def

* update demo

* update demo

* update uncertain demo

* update demo

* warning if user set `size` on AutoComplete

* add debug demo

* updat demo

* update demo of disabled

* update snapshot

* rm useless test

* fix pagination test

* fix Table test

* fix calendar test case

* fix calendar test case

* adjust style

* add big data demo

* support clean up

* fix ts define

* fix lint

* fix demo lint

* fix style lint fix

* rm useless deps

* update snapshot

* stop mock

* add space
2019-09-12 20:15:17 +08:00

65 lines
1.9 KiB
JavaScript

import glob from 'glob';
import { render } from 'enzyme';
import MockDate from 'mockdate';
import moment from 'moment';
// We should avoid use it in 4.0. Reopen if can not handle this.
const USE_REPLACEMENT = false;
const testDist = process.env.LIB_DIR === 'dist';
/**
* rc component will generate id for aria usage.
* It's created as `test-uuid` when env === 'test'.
* Or `f7fa7a3c-a675-47bc-912e-0c45fb6a74d9`(randomly) when not test env.
* So we need hack of this to modify the `aria-controls`.
*/
function ariaConvert(wrapper) {
if (!testDist || !USE_REPLACEMENT) return wrapper;
const matches = new Map();
function process(entry) {
const { attribs, children } = entry;
if (matches.has(entry)) return;
matches.set(entry, true);
// Change aria
if (attribs && attribs['aria-controls']) {
attribs['aria-controls'] = ''; // Remove all the aria to keep render sync in jest & jest node
}
// Loop children
if (!children) return;
(Array.isArray(children) ? children : [children]).forEach(process);
}
Object.keys(wrapper).forEach(key => {
const entry = wrapper[key];
process(entry);
});
return wrapper;
}
export default function demoTest(component, options = {}) {
const files = glob.sync(`./components/${component}/demo/*.md`);
files.forEach(file => {
let testMethod = options.skip === true ? test.skip : test;
if (Array.isArray(options.skip) && options.skip.some(c => file.includes(c))) {
testMethod = test.skip;
}
testMethod(`renders ${file} correctly`, () => {
MockDate.set(moment('2016-11-22'));
const demo = require(`../.${file}`).default; // eslint-disable-line global-require, import/no-dynamic-require
const wrapper = render(demo);
// Convert aria related content
ariaConvert(wrapper);
expect(wrapper).toMatchSnapshot();
MockDate.reset();
});
});
}