Skip to content

Commit 557597c

Browse files
committed
test(ConfigProvider): Adjust testing spec
1 parent a6c6151 commit 557597c

File tree

2 files changed

+34
-109
lines changed

2 files changed

+34
-109
lines changed

test/dialog/index-spec.js

+5-76
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ describe('inner', () => {
356356
assert(cancel.innerHTML === 'near cancel');
357357
});
358358

359-
it('quick should obey: self.locale > nearest ConfigProvider.locale > further ConfigProvider.locale', () => {
359+
it('quick-calling should use root context\'s state if its exists', () => {
360360
wrapper = render(
361361
<ConfigProvider prefix="far-" locale={{
362362
momentLocale: 'en',
@@ -391,90 +391,19 @@ describe('inner', () => {
391391
const btn = document.querySelector('button');
392392
ReactTestUtils.Simulate.click(btn);
393393

394-
const footer = document.querySelector('.near-dialog-footer');
395-
const overlayWrapper = document.querySelector('.near-overlay-wrapper');
394+
const footer = document.querySelector('.far-dialog-footer');
395+
const overlayWrapper = document.querySelector('.far-overlay-wrapper');
396396
const ok = footer.querySelectorAll('button')[0];
397397
const cancel = footer.querySelectorAll('button')[1];
398398

399399
assert(footer);
400400
assert(overlayWrapper);
401-
assert(ok.innerHTML === 'near ok');
401+
assert(ok.innerHTML === 'far ok');
402402
assert(cancel.innerHTML === 'my cancel');
403403

404404
document.body.removeChild(overlayWrapper);
405405

406-
assert(!document.querySelector('.near-overlay-wrapper'));
407-
});
408-
409-
it('alert should obey: self.locale > nearest ConfigProvider.locale > further ConfigProvider.locale', () => {
410-
wrapper = render(
411-
<ConfigProvider prefix="far-" locale={{
412-
momentLocale: 'en',
413-
Dialog: {
414-
ok: 'far ok',
415-
cancel: 'far cancel'
416-
}
417-
}}>
418-
<ConfigProvider prefix="near-" locale={{
419-
momentLocale: 'en',
420-
Dialog: {
421-
ok: 'near ok',
422-
cancel: 'near cancel'
423-
}
424-
}}>
425-
<div>
426-
<Button
427-
type="primary"
428-
onClick={() => {
429-
Dialog.alert({
430-
locale: {
431-
ok: 'my ok'
432-
},
433-
content: <Button type="primary">test</Button>,
434-
});
435-
}}>
436-
OK
437-
</Button>
438-
<Button
439-
type="primary"
440-
onClick={() => {
441-
Dialog.alert({
442-
content: <Button type="primary">test</Button>,
443-
});
444-
}}>
445-
OK
446-
</Button>
447-
</div>
448-
</ConfigProvider>
449-
</ConfigProvider>
450-
);
451-
452-
const btn1 = document.querySelectorAll('button')[0];
453-
const btn2 = document.querySelectorAll('button')[1];
454-
ReactTestUtils.Simulate.click(btn1);
455-
let footer = document.querySelector('.near-dialog-footer');
456-
let overlayWrapper = document.querySelector('.near-overlay-wrapper');
457-
let ok = footer.querySelectorAll('button')[0];
458-
let innerBtn = document.querySelector('.near-dialog-message button.near-btn-primary');
459-
460-
assert(footer);
461-
assert(overlayWrapper);
462-
assert(innerBtn);
463-
assert(ok.innerHTML === 'my ok');
464-
document.body.removeChild(overlayWrapper);
465-
assert(!document.querySelector('.near-overlay-wrapper'));
466-
467-
ReactTestUtils.Simulate.click(btn2);
468-
footer = document.querySelector('.near-dialog-footer');
469-
overlayWrapper = document.querySelector('.near-overlay-wrapper');
470-
ok = footer.querySelectorAll('button')[0];
471-
innerBtn = document.querySelector('.near-dialog-message button.near-btn-primary');
472-
assert(footer);
473-
assert(overlayWrapper);
474-
assert(innerBtn);
475-
assert(ok.innerHTML === 'near ok');
476-
document.body.removeChild(overlayWrapper);
477-
assert(!document.querySelector('.near-overlay-wrapper'));
406+
assert(!document.querySelector('.far-overlay-wrapper'));
478407
});
479408
});
480409

test/message/index-spec.js

+29-33
Original file line numberDiff line numberDiff line change
@@ -247,31 +247,10 @@ describe('toast', done => {
247247
});
248248
});
249249

250-
describe('toast quick', () => {
251-
it('should render type message', () => {
252-
const methods = ['success', 'warning', 'error', 'notice', 'help', 'loading'];
253-
methods.forEach(method => {
254-
Message[method](method);
255-
const nodes = document.querySelectorAll(`.next-overlay-wrapper .next-message.next-message-${method}`);
256-
assert(nodes[nodes.length - 1].innerText.trim() === method);
257-
});
258-
});
259-
});
260-
261250
describe('should support configProvider', () => {
262-
263-
let wrapper;
264-
265-
afterEach(() => {
266-
if (wrapper) {
267-
wrapper.unmount();
268-
wrapper = null;
269-
}
270-
});
271-
272251
it('normal should obey: self.locale > nearest ConfigProvider.locale > further ConfigProvider.locale', () => {
273252
const methods = ['success', 'warning', 'error', 'notice', 'help', 'loading'];
274-
wrapper = render(
253+
const wrapper = render(
275254
<ConfigProvider prefix="far-" locale={{
276255
momentLocale: 'en',
277256
Dialog: {
@@ -298,12 +277,13 @@ describe('should support configProvider', () => {
298277
);
299278
const innerBtn = document.querySelectorAll('.near-message .near-message-content .near-btn-primary');
300279
assert(innerBtn.length === methods.length);
280+
wrapper.unmount();
301281
});
302282

303-
it('quick should obey: self.locale > nearest ConfigProvider.locale > further ConfigProvider.locale', () => {
283+
it('quick-calling should use root context\'s state if its exists', () => {
304284
const methods = ['success', 'warning', 'error', 'notice', 'help', 'loading'];
305285
methods.forEach(method => {
306-
wrapper = render(
286+
const wrapper = render(
307287
<ConfigProvider prefix="far-" locale={{
308288
momentLocale: 'en',
309289
Dialog: {
@@ -337,20 +317,36 @@ describe('should support configProvider', () => {
337317

338318
const btn = document.querySelector('button');
339319
ReactTestUtils.Simulate.click(btn);
340-
const overlayWrapper = document.querySelector('.near-overlay-wrapper');
341-
const icon = document.querySelector('.near-icon.near-message-symbol');
342-
const innerBtn = document.querySelector('.near-message-content .near-btn-primary');
320+
const icon = document.querySelector('.far-icon.far-message-symbol');
321+
const innerBtn = document.querySelector('.far-message-content .far-btn-primary');
343322

344-
assert(overlayWrapper);
345323
assert(icon);
346324
assert(innerBtn);
347325

348326
wrapper.unmount();
349-
wrapper = null;
350327
});
351-
352-
const lastOverlayWrapper = document.querySelector('.near-overlay-wrapper');
353-
document.body.removeChild(lastOverlayWrapper);
354-
assert(!document.querySelector('.near-overlay-wrapper'));
355328
});
356329
});
330+
331+
describe('toast quick-calling', () => {
332+
const avaliableMethods = [
333+
'success',
334+
'warning',
335+
'error',
336+
'notice',
337+
'help',
338+
'loading',
339+
];
340+
341+
for (const method of avaliableMethods) {
342+
it(`render ${method}`, (done) => {
343+
Message.show('content');
344+
assert(document.querySelector('.next-overlay-wrapper .next-message').innerText.trim() === 'content');
345+
setTimeout(() => {
346+
Message.hide();
347+
}, 500);
348+
setTimeout(done, 1000);
349+
done()
350+
})
351+
}
352+
});

0 commit comments

Comments
 (0)