|
| 1 | +import React from 'react' |
| 2 | +import { render } from '@testing-library/react' |
| 3 | +import '@testing-library/jest-dom' |
| 4 | +import { Timecode } from './Timecode' |
| 5 | + |
| 6 | +describe('<Timecode />', () => { |
| 7 | + test('render markup - default component', async () => { |
| 8 | + const { container, getByText } = render(<Timecode />) |
| 9 | + |
| 10 | + expect(getByText('0:00')).toBeInTheDocument() |
| 11 | + expect(container).toMatchSnapshot() |
| 12 | + }) |
| 13 | + |
| 14 | + test('render markup - custom component', async () => { |
| 15 | + const { container } = render(<Timecode as="p" />) |
| 16 | + |
| 17 | + expect(container.firstChild.nodeName).toBe('P') |
| 18 | + }) |
| 19 | + |
| 20 | + test('render format - H:?m:ss (default)', async () => { |
| 21 | + const { getByText } = render(<Timecode />) |
| 22 | + |
| 23 | + expect(getByText('0:00')).toBeInTheDocument() |
| 24 | + }) |
| 25 | + |
| 26 | + test('render format - H:?mm:ss', async () => { |
| 27 | + const { getByText } = render(<Timecode format="H:?mm:ss" />) |
| 28 | + |
| 29 | + expect(getByText('00:00')).toBeInTheDocument() |
| 30 | + }) |
| 31 | + |
| 32 | + test('render format - HH:mm:ss.SSS', async () => { |
| 33 | + const { getByText } = render(<Timecode format="HH:mm:ss.SSS" />) |
| 34 | + |
| 35 | + expect(getByText('00:00:00.000')).toBeInTheDocument() |
| 36 | + }) |
| 37 | + |
| 38 | + test('render format - H:mm:ss.SSS', async () => { |
| 39 | + const { getByText } = render(<Timecode format="H:mm:ss.SSS" />) |
| 40 | + |
| 41 | + expect(getByText('0:00:00.000')).toBeInTheDocument() |
| 42 | + }) |
| 43 | + |
| 44 | + test('render format - H:?mm:ss.SSS', async () => { |
| 45 | + const { getByText } = render(<Timecode format="H:?mm:ss.SSS" />) |
| 46 | + |
| 47 | + expect(getByText('00:00.000')).toBeInTheDocument() |
| 48 | + }) |
| 49 | + |
| 50 | + test('render format - H:?m:ss.SSS', async () => { |
| 51 | + const { getByText } = render(<Timecode format="H:?m:ss.SSS" />) |
| 52 | + |
| 53 | + expect(getByText('0:00.000')).toBeInTheDocument() |
| 54 | + }) |
| 55 | + |
| 56 | + test('render format - HH:mm:ss', async () => { |
| 57 | + const { getByText } = render(<Timecode format="HH:mm:ss" />) |
| 58 | + |
| 59 | + expect(getByText('00:00:00')).toBeInTheDocument() |
| 60 | + }) |
| 61 | + |
| 62 | + test('render format - H:mm:ss', async () => { |
| 63 | + const { getByText } = render(<Timecode format="H:mm:ss" />) |
| 64 | + |
| 65 | + expect(getByText('0:00:00')).toBeInTheDocument() |
| 66 | + }) |
| 67 | + |
| 68 | + test('render format - H:?mm:ss', async () => { |
| 69 | + const { getByText } = render(<Timecode format="H:?mm:ss" />) |
| 70 | + |
| 71 | + expect(getByText('00:00')).toBeInTheDocument() |
| 72 | + }) |
| 73 | + |
| 74 | + test('render format - H:mm', async () => { |
| 75 | + const { getByText } = render(<Timecode format="H:mm" />) |
| 76 | + |
| 77 | + expect(getByText('0:00')).toBeInTheDocument() |
| 78 | + }) |
| 79 | + |
| 80 | + test('render format - s.SSS', async () => { |
| 81 | + const { getByText } = render(<Timecode format="s.SSS" />) |
| 82 | + |
| 83 | + expect(getByText('0.000')).toBeInTheDocument() |
| 84 | + }) |
| 85 | + |
| 86 | + test('render format - s.SS', async () => { |
| 87 | + const { getByText } = render(<Timecode format="s.SS" />) |
| 88 | + |
| 89 | + expect(getByText('0.00')).toBeInTheDocument() |
| 90 | + }) |
| 91 | + |
| 92 | + test('render format w/ time - H:?m:ss (default)', async () => { |
| 93 | + const { getByText } = render(<Timecode time={3600000} />) |
| 94 | + |
| 95 | + expect(getByText('1:00:00')).toBeInTheDocument() |
| 96 | + }) |
| 97 | + |
| 98 | + test('render format w/ time - H:?mm:ss.SSS', async () => { |
| 99 | + const { getByText } = render(( |
| 100 | + <Timecode |
| 101 | + format="H:?mm:ss.SSS" |
| 102 | + time={3600000} |
| 103 | + /> |
| 104 | + )) |
| 105 | + |
| 106 | + expect(getByText('1:00:00.000')).toBeInTheDocument() |
| 107 | + }) |
| 108 | + |
| 109 | + test('render format w/ time - H:?m:ss.SSS', async () => { |
| 110 | + const { getByText } = render(( |
| 111 | + <Timecode |
| 112 | + format="H:?m:ss.SSS" |
| 113 | + time={3600000} |
| 114 | + /> |
| 115 | + )) |
| 116 | + |
| 117 | + expect(getByText('1:00:00.000')).toBeInTheDocument() |
| 118 | + }) |
| 119 | + |
| 120 | + test('render format w/ time - H:?mm:ss', async () => { |
| 121 | + const { getByText } = render(( |
| 122 | + <Timecode |
| 123 | + format="H:?mm:ss" |
| 124 | + time={3600000} |
| 125 | + /> |
| 126 | + )) |
| 127 | + |
| 128 | + expect(getByText('1:00:00')).toBeInTheDocument() |
| 129 | + }) |
| 130 | + |
| 131 | + test('render format w/ minutes - H:?m:ss (default)', async () => { |
| 132 | + const { getByText } = render(<Timecode time={5400000} />) |
| 133 | + |
| 134 | + expect(getByText('1:30:00')).toBeInTheDocument() |
| 135 | + }) |
| 136 | + |
| 137 | + test('render format w/ seconds - H:?m:ss (default)', async () => { |
| 138 | + const { getByText } = render(<Timecode time={5430000} />) |
| 139 | + |
| 140 | + expect(getByText('1:30:30')).toBeInTheDocument() |
| 141 | + }) |
| 142 | + |
| 143 | + test('render prefix', async () => { |
| 144 | + const { getByText } = render(<Timecode prefix="-" />) |
| 145 | + |
| 146 | + expect(getByText('-0:00')).toBeInTheDocument() |
| 147 | + }) |
| 148 | + |
| 149 | + test('render postfix', async () => { |
| 150 | + const { getByText } = render(<Timecode postfix="/left" />) |
| 151 | + |
| 152 | + expect(getByText('0:00/left')).toBeInTheDocument() |
| 153 | + }) |
| 154 | +}) |
0 commit comments