|
| 1 | +import React from 'react'; |
| 2 | +import renderer from 'react-test-renderer'; |
| 3 | + |
| 4 | +import Comments from './Comments'; |
| 5 | + |
| 6 | +const sentence = { |
| 7 | + $: { n: '1' }, |
| 8 | + wds: [ |
| 9 | + { |
| 10 | + $: { lnum: 'L1' }, |
| 11 | + w: [ |
| 12 | + { $: { n: '1-1' }, text: [{ _: 'A' }], refs: [{ $: { nrefs: '1-1' } }] }, |
| 13 | + { $: { n: '1-2' }, text: [{ _: 'BC' }], refs: [{ $: { nrefs: '1-2 1-3' } }] }, |
| 14 | + { |
| 15 | + $: { n: '1-3' }, |
| 16 | + text: [{ _: 'D' }], |
| 17 | + comment: [{ _: 'Test', $: { class: 'mark' } }], |
| 18 | + refs: [{ $: { nrefs: '1-3 1-4' } }], |
| 19 | + }, |
| 20 | + { $: { n: '1-4' }, text: [{ _: 'E' }], refs: [{ $: { nrefs: '1-4' } }] }, |
| 21 | + { $: { n: '1-5' }, text: [{ _: 'F' }], refs: [{ $: { nrefs: '1-5 1-6' } }] }, |
| 22 | + { $: { n: '1-6' }, text: [{ _: 'G' }], refs: [{ $: { nrefs: '1-5 1-6' } }] }, |
| 23 | + ], |
| 24 | + }, |
| 25 | + { |
| 26 | + $: { lnum: 'L2' }, |
| 27 | + w: [ |
| 28 | + { $: { n: '1-1' }, text: [{ _: 'A' }], refs: [{ $: { nrefs: '1-1' } }] }, |
| 29 | + { $: { n: '1-2' }, text: [{ _: 'B' }], refs: [{ $: { nrefs: '1-2' } }] }, |
| 30 | + { |
| 31 | + $: { n: '1-3' }, |
| 32 | + text: [{ _: 'C' }], |
| 33 | + comment: [{ _: 'Other languge test', $: { class: 'mark' } }], |
| 34 | + refs: [{ $: { nrefs: '1-3' } }], |
| 35 | + }, |
| 36 | + { $: { n: '1-4' }, text: [{ _: 'DE' }], refs: [{ $: { nrefs: '1-3' } }] }, |
| 37 | + { $: { n: '1-5' }, text: [{ _: 'F' }], refs: [{ $: { nrefs: '1-5 1-6' } }] }, |
| 38 | + { $: { n: '1-6' }, text: [{ _: 'G' }], refs: [{ $: { nrefs: '1-5 1-6' } }] }, |
| 39 | + ], |
| 40 | + }, |
| 41 | + ], |
| 42 | +}; |
| 43 | + |
| 44 | +it('does not render when there is no active', () => { |
| 45 | + const component = ( |
| 46 | + <Comments sentence={sentence} /> |
| 47 | + ); |
| 48 | + const tree = renderer.create(component).toJSON(); |
| 49 | + |
| 50 | + expect(tree).toMatchSnapshot(); |
| 51 | +}); |
| 52 | + |
| 53 | +it('does not render when the active has no comment', () => { |
| 54 | + const active = { |
| 55 | + selected: { lnum: 'L1', n: '1-1' }, |
| 56 | + aligned: { |
| 57 | + L1: new Set(['1-1']), |
| 58 | + L2: new Set(['1-1']), |
| 59 | + }, |
| 60 | + }; |
| 61 | + |
| 62 | + const component = ( |
| 63 | + <Comments |
| 64 | + sentence={sentence} |
| 65 | + active={active} |
| 66 | + /> |
| 67 | + ); |
| 68 | + const tree = renderer.create(component).toJSON(); |
| 69 | + |
| 70 | + expect(tree).toMatchSnapshot(); |
| 71 | +}); |
| 72 | + |
| 73 | +it('displays all comments associated with active words', () => { |
| 74 | + const active = { |
| 75 | + selected: { lnum: 'L1', n: '1-1' }, |
| 76 | + aligned: { |
| 77 | + L1: new Set(['1-3']), |
| 78 | + L2: new Set(['1-3', '1-4']), |
| 79 | + }, |
| 80 | + }; |
| 81 | + |
| 82 | + const component = ( |
| 83 | + <Comments |
| 84 | + sentence={sentence} |
| 85 | + active={active} |
| 86 | + /> |
| 87 | + ); |
| 88 | + const tree = renderer.create(component).toJSON(); |
| 89 | + |
| 90 | + expect(tree).toMatchSnapshot(); |
| 91 | +}); |
0 commit comments