Skip to content

Commit aa53fe0

Browse files
author
Luke Bowerman
authored
test: Small collection of miscellaneous test coverage fix-ups (#2083)
1 parent 68bd1a7 commit aa53fe0

File tree

7 files changed

+86
-22
lines changed

7 files changed

+86
-22
lines changed

packages/components-test-utils/src/snapshot.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,8 @@
2626

2727
import 'jest-styled-components'
2828
import { ReactElement } from 'react'
29-
import { createWithTheme, shallowWithTheme } from './create_with_theme'
29+
import { createWithTheme } from './create_with_theme'
3030

3131
export const assertSnapshot = <T extends {}>(element: ReactElement<T>) => {
3232
expect(createWithTheme(element).toJSON()).toMatchSnapshot()
3333
}
34-
35-
export const assertSnapshotShallow = <T extends {}>(
36-
element: ReactElement<T>
37-
) => {
38-
expect(shallowWithTheme(element)).toMatchSnapshot()
39-
}

packages/components/src/Dialog/Dialog.test.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ describe('Dialog', () => {
4747
expect(screen.queryByText('Dialog content')).not.toBeInTheDocument()
4848
})
4949

50+
test('Placement functions', () => {
51+
renderWithTheme(
52+
<Dialog isOpen placement="top" content={<SimpleContent />} />
53+
)
54+
expect(screen.queryByText('Dialog content')).toBeInTheDocument()
55+
})
56+
5057
test('defaultOpen', async () => {
5158
renderWithTheme(<Dialog defaultOpen content={<DialogMediumContent />} />)
5259
expect(screen.queryByText(/We the People/)).toBeInTheDocument()
@@ -274,5 +281,25 @@ describe('Dialog', () => {
274281
'24.5rem'
275282
)
276283
})
284+
285+
test('Dialog without content throws console warning', () => {
286+
const globalConsole = global.console
287+
const errorMock = jest.fn()
288+
289+
global.console = ({
290+
error: errorMock,
291+
} as unknown) as Console
292+
293+
renderWithTheme(<Dialog />)
294+
expect(errorMock.mock.calls).toMatchInlineSnapshot(`
295+
Array [
296+
Array [
297+
"Dialog cannot be used without specifying content",
298+
],
299+
]
300+
`)
301+
302+
global.console = globalConsole
303+
})
277304
})
278305
})
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2021 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
import React from 'react'
28+
import { renderWithTheme } from '@looker/components-test-utils'
29+
import { screen } from '@testing-library/react'
30+
import { Field } from './Field'
31+
32+
describe('Field', () => {
33+
test('Hidden labels', () => {
34+
renderWithTheme(
35+
<Field id="test" hideLabel label="hello!">
36+
<input id="test" type="text" />
37+
</Field>
38+
)
39+
screen.getByText('hello!')
40+
})
41+
})

packages/components/src/Form/Inputs/InputText/InputText.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ describe('InputText', () => {
7272
expect(screen.getByRole('textbox')).toHaveAttribute('readonly')
7373
})
7474

75+
test('should accept type', () => {
76+
renderWithTheme(<InputText type="tel" />)
77+
expect(screen.getByRole('textbox')).toHaveAttribute('type', 'tel')
78+
})
79+
7580
test('should accept required', () => {
7681
renderWithTheme(<InputText required />)
7782
expect(screen.getByRole('textbox')).toBeRequired()
@@ -116,6 +121,15 @@ describe('InputText', () => {
116121
expect(getByText('after')).toBeVisible()
117122
})
118123

124+
test('Simple string', () => {
125+
const { getByText } = renderWithTheme(
126+
<InputText before="before" after="after" />
127+
)
128+
129+
expect(getByText('before')).toBeVisible()
130+
expect(getByText('after')).toBeVisible()
131+
})
132+
119133
test('icons', () => {
120134
const { getByTitle } = renderWithTheme(
121135
<InputText

packages/components/src/Form/Inputs/InputTime/InputTime.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ import {
5555
SimpleLayoutProps,
5656
} from '../../../Layout/utils/simple'
5757
import { getAutoFocusProps } from '../InputProps'
58+
import { ValidationType } from '../../ValidationMessage'
5859
import {
5960
formatTimeString,
6061
TimeFormats,
6162
parseBase10Int,
6263
isValidTime,
63-
} from '../utils'
64-
import { ValidationType } from '../../ValidationMessage'
64+
} from './utils'
6565

6666
export interface InputTimeProps extends Omit<SimpleLayoutProps, 'size'> {
6767
'aria-describedby'?: string

packages/components/src/Form/Inputs/utils.ts renamed to packages/components/src/Form/Inputs/InputTime/utils.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ import map from 'lodash/map'
3030

3131
export type TimeFormats = '12h' | '24h'
3232

33-
// if format is `12h`, repeat hours 1-12 twice
34-
export const cycleHourDisplay = (format: TimeFormats, hour: number) => {
35-
if (format === '12h') {
36-
if (hour === 0) {
37-
return 12 // 12:00 am
38-
} else if (hour > 12) {
39-
return hour - 12 // 1:00 pm - 11:00 pm
40-
}
41-
}
42-
return hour
43-
}
44-
4533
// returns "01", "02", "03" instead of integers 1, 2, 3
4634
export const formatTimeString = (number: number) => {
4735
return padStart(toString(number), 2, '0')

packages/components/src/Form/Inputs/InputTimeSelect/InputTimeSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import {
6464
parseBase10Int,
6565
isValidTime,
6666
TimeFormats,
67-
} from '../utils'
67+
} from '../InputTime/utils'
6868

6969
/*
7070
* We've limited allowed intervals to a few approved options rather than

0 commit comments

Comments
 (0)