Skip to content

Commit 8da073e

Browse files
sammy-SCzoontek
authored andcommitted
Add reset tests for View prop transformations (facebook#55893)
Summary: Pull Request resolved: facebook#55893 add tests to validate that aria-* props are set back to default correctly when set to undefined Changelog: [Internal] Reviewed By: javache Differential Revision: D95061571 fbshipit-source-id: c035132638fe7223ef544fb422c1a12f57c5fdb6
1 parent 9d4020e commit 8da073e

File tree

1 file changed

+169
-1
lines changed
  • packages/react-native/Libraries/Components/View/__tests__

1 file changed

+169
-1
lines changed

packages/react-native/Libraries/Components/View/__tests__/View-itest.js

Lines changed: 169 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,35 @@ describe('<View>', () => {
403403
root.render(<View aria-hidden={true} collapsable={false} />);
404404
});
405405

406-
expect(root.getRenderedOutput().toJSX()).toEqual(
406+
expect(
407+
root
408+
.getRenderedOutput({props: ['importantForAccessibility']})
409+
.toJSX(),
410+
).toEqual(
411+
<rn-view importantForAccessibility="no-hide-descendants" />,
412+
);
413+
});
414+
415+
it('resets importantForAccessibility when set to undefined', () => {
416+
const root = Fantom.createRoot();
417+
Fantom.runTask(() => {
418+
root.render(<View aria-hidden={true} collapsable={false} />);
419+
});
420+
expect(
421+
root
422+
.getRenderedOutput({props: ['importantForAccessibility']})
423+
.toJSX(),
424+
).toEqual(
407425
<rn-view importantForAccessibility="no-hide-descendants" />,
408426
);
427+
Fantom.runTask(() => {
428+
root.render(<View collapsable={false} />);
429+
});
430+
expect(
431+
root
432+
.getRenderedOutput({props: ['importantForAccessibility']})
433+
.toJSX(),
434+
).toEqual(<rn-view />);
409435
});
410436
});
411437

@@ -534,6 +560,22 @@ describe('<View>', () => {
534560
root.getRenderedOutput({props: ['accessibilityLabel']}).toJSX(),
535561
).toEqual(<rn-view accessibilityLabel="custom label" />);
536562
});
563+
564+
it('resets accessibilityLabel when set to undefined', () => {
565+
const root = Fantom.createRoot();
566+
Fantom.runTask(() => {
567+
root.render(<View aria-label="custom label" accessible={true} />);
568+
});
569+
expect(
570+
root.getRenderedOutput({props: ['accessibilityLabel']}).toJSX(),
571+
).toEqual(<rn-view accessibilityLabel="custom label" />);
572+
Fantom.runTask(() => {
573+
root.render(<View accessible={true} />);
574+
});
575+
expect(
576+
root.getRenderedOutput({props: ['accessibilityLabel']}).toJSX(),
577+
).toEqual(<rn-view />);
578+
});
537579
});
538580

539581
describe('aria-live', () => {
@@ -550,6 +592,26 @@ describe('<View>', () => {
550592
.toJSX(),
551593
).toEqual(<rn-view accessibilityLiveRegion="polite" />);
552594
});
595+
596+
it('resets accessibilityLiveRegion when set to undefined', () => {
597+
const root = Fantom.createRoot();
598+
Fantom.runTask(() => {
599+
root.render(<View aria-live="polite" accessible={true} />);
600+
});
601+
expect(
602+
root
603+
.getRenderedOutput({props: ['accessibilityLiveRegion']})
604+
.toJSX(),
605+
).toEqual(<rn-view accessibilityLiveRegion="polite" />);
606+
Fantom.runTask(() => {
607+
root.render(<View accessible={true} />);
608+
});
609+
expect(
610+
root
611+
.getRenderedOutput({props: ['accessibilityLiveRegion']})
612+
.toJSX(),
613+
).toEqual(<rn-view />);
614+
});
553615
});
554616

555617
describe('aria-busy', () => {
@@ -566,6 +628,24 @@ describe('<View>', () => {
566628
<rn-view accessibilityState="{disabled:false,selected:false,checked:None,busy:true,expanded:null}" />,
567629
);
568630
});
631+
632+
it('resets accessibilityState when set to undefined', () => {
633+
const root = Fantom.createRoot();
634+
Fantom.runTask(() => {
635+
root.render(<View aria-busy={true} accessible={true} />);
636+
});
637+
expect(
638+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
639+
).toEqual(
640+
<rn-view accessibilityState="{disabled:false,selected:false,checked:None,busy:true,expanded:null}" />,
641+
);
642+
Fantom.runTask(() => {
643+
root.render(<View accessible={true} />);
644+
});
645+
expect(
646+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
647+
).toEqual(<rn-view />);
648+
});
569649
});
570650

571651
describe('aria-disabled', () => {
@@ -582,6 +662,24 @@ describe('<View>', () => {
582662
<rn-view accessibilityState="{disabled:true,selected:false,checked:None,busy:false,expanded:null}" />,
583663
);
584664
});
665+
666+
it('resets accessibilityState when set to undefined', () => {
667+
const root = Fantom.createRoot();
668+
Fantom.runTask(() => {
669+
root.render(<View aria-disabled={true} accessible={true} />);
670+
});
671+
expect(
672+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
673+
).toEqual(
674+
<rn-view accessibilityState="{disabled:true,selected:false,checked:None,busy:false,expanded:null}" />,
675+
);
676+
Fantom.runTask(() => {
677+
root.render(<View accessible={true} />);
678+
});
679+
expect(
680+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
681+
).toEqual(<rn-view />);
682+
});
585683
});
586684

587685
describe('aria-expanded', () => {
@@ -598,6 +696,24 @@ describe('<View>', () => {
598696
<rn-view accessibilityState="{disabled:false,selected:false,checked:None,busy:false,expanded:true}" />,
599697
);
600698
});
699+
700+
it('resets accessibilityState when set to undefined', () => {
701+
const root = Fantom.createRoot();
702+
Fantom.runTask(() => {
703+
root.render(<View aria-expanded={true} accessible={true} />);
704+
});
705+
expect(
706+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
707+
).toEqual(
708+
<rn-view accessibilityState="{disabled:false,selected:false,checked:None,busy:false,expanded:true}" />,
709+
);
710+
Fantom.runTask(() => {
711+
root.render(<View accessible={true} />);
712+
});
713+
expect(
714+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
715+
).toEqual(<rn-view />);
716+
});
601717
});
602718

603719
describe('aria-selected', () => {
@@ -614,6 +730,24 @@ describe('<View>', () => {
614730
<rn-view accessibilityState="{disabled:false,selected:true,checked:None,busy:false,expanded:null}" />,
615731
);
616732
});
733+
734+
it('resets accessibilityState when set to undefined', () => {
735+
const root = Fantom.createRoot();
736+
Fantom.runTask(() => {
737+
root.render(<View aria-selected={true} accessible={true} />);
738+
});
739+
expect(
740+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
741+
).toEqual(
742+
<rn-view accessibilityState="{disabled:false,selected:true,checked:None,busy:false,expanded:null}" />,
743+
);
744+
Fantom.runTask(() => {
745+
root.render(<View accessible={true} />);
746+
});
747+
expect(
748+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
749+
).toEqual(<rn-view />);
750+
});
617751
});
618752

619753
describe('aria-checked', () => {
@@ -630,6 +764,24 @@ describe('<View>', () => {
630764
<rn-view accessibilityState="{disabled:false,selected:false,checked:Checked,busy:false,expanded:null}" />,
631765
);
632766
});
767+
768+
it('resets accessibilityState when set to undefined', () => {
769+
const root = Fantom.createRoot();
770+
Fantom.runTask(() => {
771+
root.render(<View aria-checked={true} accessible={true} />);
772+
});
773+
expect(
774+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
775+
).toEqual(
776+
<rn-view accessibilityState="{disabled:false,selected:false,checked:Checked,busy:false,expanded:null}" />,
777+
);
778+
Fantom.runTask(() => {
779+
root.render(<View accessible={true} />);
780+
});
781+
expect(
782+
root.getRenderedOutput({props: ['accessibilityState']}).toJSX(),
783+
).toEqual(<rn-view />);
784+
});
633785
});
634786
});
635787

@@ -669,6 +821,22 @@ describe('<View>', () => {
669821
<rn-view nativeID="my-id" />,
670822
);
671823
});
824+
825+
it('resets nativeID when set to undefined', () => {
826+
const root = Fantom.createRoot();
827+
Fantom.runTask(() => {
828+
root.render(<View id="my-id" collapsable={false} />);
829+
});
830+
expect(root.getRenderedOutput({props: ['nativeID']}).toJSX()).toEqual(
831+
<rn-view nativeID="my-id" />,
832+
);
833+
Fantom.runTask(() => {
834+
root.render(<View collapsable={false} />);
835+
});
836+
expect(root.getRenderedOutput({props: ['nativeID']}).toJSX()).toEqual(
837+
<rn-view />,
838+
);
839+
});
672840
});
673841

674842
describe('nativeID', () => {

0 commit comments

Comments
 (0)