Skip to content

Commit cb43286

Browse files
committed
Add all test code
1 parent 677c4bf commit cb43286

File tree

8 files changed

+663
-7
lines changed

8 files changed

+663
-7
lines changed

packages/components/src/components/Button/__tests__/__snapshots__/index.browser.test.tsx.snap

Lines changed: 514 additions & 0 deletions
Large diffs are not rendered by default.

packages/components/src/components/Select/__tests__/__snapshots__/index.browser.test.tsx.snap

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,31 @@ exports[`Select > should render with overflow screen 1`] = `
117117
</div>
118118
`;
119119

120+
exports[`Select > should render with typography prop 1`] = `
121+
<div>
122+
<div
123+
class="display-0-inline-block--1 height-0-fit-content--1 box-sizing-0-border-box-1137980104803605758-1 typo-body1 "
124+
>
125+
<button
126+
aria-expanded="false"
127+
aria-label="Select toggle"
128+
class="border-radius-0-8px--2 outline-0-2px solid-17005923944751620165-1 box-sizing-0-border-box--1 cursor-0-pointer--1 font-weight-0-700--1 outline-offset-0-2px--1 position-0-relative--1 transition-0-.25s--1 color-0-var(--text,#272727)-15425828959012638752-1 background-0-color-mix(in srgb,var(--primary,#8163E1) 20%,#FFF 80%)-15425828959012638752-1 border-0-1px solid var(--primary,#8163E1)-15425828959012638752-1 color-0-#D6D7DE-14172363753176421546-1 background-color-0-#F0F0F3-14172363753176421546-1 cursor-0-not-allowed-14172363753176421546-1 border-color-0-var(--border,#E4E4E4)-14172363753176421546-1 outline-color-0-var(--primaryFocus,#9385D3)-17005923944751620165-1 border-color-0-var(--primary,#8163E1)-8380715471663921674-1 background-0-color-mix(in srgb,var(--primary,#8163E1) 10%,#FFF 90%)-8380715471663921674-1 color-0-var(--text,#F6F6F6)-2922352740838246662-1 background-0-var(--primary,#8163E1)-2922352740838246662-1 color-0-#373737-878116160589243838-1 background-color-0-#47474A-878116160589243838-1 border-color-0-transparent-878116160589243838-1 border-color-0-var(--primary,#8163E1)-6232724021015440856-1 background-0-color-mix(in srgb,var(--primary,#674DC7) 10%,var(--inputBackground,#2E2E2E) 90%)-6232724021015440856-1 outline-color-0-var(--primaryFocus,#927CE4)-13318702800233181468-1 background-0-var(--inputBackground,#2E2E2E)-6667598448774358329-1 background-0-var(--inputBackground,#FFF)--1 border-0-1px solid var(--border,#E4E4E4)--1 border-radius-0-10px--1 color-0-var(--text,#272727)--1 font-size-0-14px--1 font-size-4-15px--1 letter-spacing-0--.02em--1 letter-spacing-4--.03em--1 padding-right-0-16px--1 padding-left-0-16px--1 padding-bottom-0-10px--1 padding-top-0-10px--1 "
129+
type="button"
130+
>
131+
<div
132+
class="max-width-0-100%--255 margin-right-0-auto--255 margin-left-0-auto--255 position-0-relative--255 width-0-fit-content--255"
133+
>
134+
<div
135+
class=" line-height-0-1.2--255 min-height-0-1.2em--255 "
136+
>
137+
Select
138+
</div>
139+
</div>
140+
</button>
141+
</div>
142+
</div>
143+
`;
144+
120145
exports[`Select > should render with x and y properties 1`] = `
121146
<div>
122147
<div

packages/components/src/components/Select/__tests__/index.browser.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,4 +463,17 @@ describe('Select', () => {
463463
expect(onChange).not.toHaveBeenCalled()
464464
expect(container.querySelector('.test')).toHaveClass('test')
465465
})
466+
467+
it('should render with typography prop', () => {
468+
const onChange = vi.fn()
469+
const { container } = render(
470+
<Select onChange={onChange} typography="body1">
471+
<SelectTrigger>Select</SelectTrigger>
472+
<SelectContainer>
473+
<SelectOption>Option 1</SelectOption>
474+
</SelectContainer>
475+
</Select>,
476+
)
477+
expect(container).toMatchSnapshot()
478+
})
466479
})

packages/components/src/components/Select/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
'use client'
22

3-
import { Box, css, DevupThemeTypography, Flex, VStack } from '@devup-ui/react'
3+
import {
4+
Box,
5+
css,
6+
type DevupThemeTypographyKeys,
7+
Flex,
8+
VStack,
9+
} from '@devup-ui/react'
410
import clsx from 'clsx'
511
import {
612
Children,
@@ -38,7 +44,7 @@ interface SelectProps extends Omit<ComponentProps<'div'>, 'onChange'> {
3844
selectDisabled?: string
3945
primaryBg?: string
4046
}
41-
typography?: keyof DevupThemeTypography
47+
typography?: DevupThemeTypographyKeys
4248
options?: {
4349
label?: string
4450
disabled?: boolean

packages/react/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export { VStack } from './components/VStack'
1111
export { useTheme } from './hooks/use-theme'
1212
export type { DevupProps } from './types/props'
1313
export type { DevupTheme, DevupThemeColors } from './types/theme'
14-
export type { DevupThemeTypography } from './types/typography'
14+
export type {
15+
DevupThemeTypography,
16+
DevupThemeTypographyKeys,
17+
} from './types/typography'
1518
export { css } from './utils/css'
1619
export { getTheme } from './utils/get-theme'
1720
export { globalCss } from './utils/global-css'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
import type { Conditional } from './utils'
2+
13
/* eslint-disable @typescript-eslint/no-empty-object-type */
24
export interface DevupThemeTypography {}
5+
6+
export type DevupThemeTypographyKeys = Conditional<DevupThemeTypography>

packages/vite-plugin/src/__tests__/plugin.test.ts

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { existsSync } from 'node:fs'
22
import { mkdir, readFile, writeFile } from 'node:fs/promises'
3-
import { dirname, join, resolve } from 'node:path'
3+
import { dirname, join, relative, resolve } from 'node:path'
44
import { fileURLToPath } from 'node:url'
55

66
import {
@@ -18,6 +18,13 @@ import { DevupUI } from '../plugin'
1818
vi.mock('@devup-ui/wasm')
1919
vi.mock('node:fs')
2020
vi.mock('node:fs/promises')
21+
vi.mock('node:path', async (original: any) => {
22+
const origin = await original()
23+
return {
24+
...origin,
25+
relative: vi.fn(origin.relative),
26+
}
27+
})
2128

2229
const _filename = fileURLToPath(import.meta.url)
2330
const _dirname = resolve(dirname(_filename), '..')
@@ -57,6 +64,12 @@ describe('devupUIVitePlugin', () => {
5764
.config()
5865
.build.rollupOptions.output.manualChunks('devup-ui.css', 'code'),
5966
).toEqual('devup-ui.css')
67+
68+
expect(
69+
(plugin as any)
70+
.config()
71+
.build.rollupOptions.output.manualChunks('other.css', 'code'),
72+
).toEqual(undefined)
6073
} else {
6174
expect((plugin as any).config().build).toBeUndefined()
6275
}
@@ -278,6 +291,10 @@ describe('devupUIVitePlugin', () => {
278291
expect(
279292
(plugin as any).resolveId('devup-ui.css', 'df/devup-ui/devup-ui.css'),
280293
).toEqual(expect.any(String))
294+
295+
expect(
296+
(plugin as any).resolveId('other.css', 'df/devup-ui/devup-ui.css'),
297+
).toEqual(undefined)
281298
}
282299

283300
{
@@ -292,9 +309,84 @@ describe('devupUIVitePlugin', () => {
292309
it('should resolve id with cssMap', () => {
293310
vi.mocked(getCss).mockReturnValue('css code')
294311
const plugin = DevupUI({})
295-
;(plugin as any).load('devup-ui.css')
312+
expect((plugin as any).load('devup-ui.css')).toEqual(expect.any(String))
313+
expect((plugin as any).load('other.css')).toEqual(undefined)
314+
296315
expect(
297316
(plugin as any).resolveId('devup-ui.css', 'df/devup-ui/devup-ui.css'),
298317
).toEqual(expect.any(String))
299318
})
319+
it('should not write interface code when no theme', async () => {
320+
vi.mocked(readFile).mockResolvedValueOnce(JSON.stringify({}))
321+
vi.mocked(getThemeInterface).mockReturnValue('')
322+
vi.mocked(existsSync).mockReturnValue(true)
323+
const plugin = DevupUI({})
324+
await (plugin as any).configResolved()
325+
expect(writeFile).not.toHaveBeenCalledWith(
326+
join('df', 'theme.d.ts'),
327+
expect.any(String),
328+
'utf-8',
329+
)
330+
})
331+
332+
it('sholud add relative path to css file', async () => {
333+
vi.mocked(getCss).mockReturnValue('css code')
334+
vi.mocked(codeExtract).mockReturnValue({
335+
css: 'css code',
336+
code: 'code',
337+
cssFile: 'devup-ui.css',
338+
map: undefined,
339+
updatedBaseStyle: false,
340+
free: vi.fn(),
341+
[Symbol.dispose]: vi.fn(),
342+
})
343+
const plugin = DevupUI({})
344+
vi.mocked(relative).mockReturnValue('./df/devup-ui/devup-ui.css')
345+
await (plugin as any).transform('code', 'foo.tsx')
346+
347+
expect(codeExtract).toHaveBeenCalledWith(
348+
'foo.tsx',
349+
'code',
350+
'@devup-ui/react',
351+
'./df/devup-ui/devup-ui.css',
352+
false,
353+
true,
354+
false,
355+
)
356+
357+
vi.mocked(relative).mockReturnValue('df/devup-ui/devup-ui.css')
358+
await (plugin as any).transform('code', 'foo.tsx')
359+
expect(codeExtract).toHaveBeenCalledWith(
360+
'foo.tsx',
361+
'code',
362+
'@devup-ui/react',
363+
'./df/devup-ui/devup-ui.css',
364+
false,
365+
true,
366+
false,
367+
)
368+
})
369+
370+
it('should not create css file when cssFile is empty', async () => {
371+
vi.mocked(getCss).mockReturnValue('css code')
372+
vi.mocked(codeExtract).mockReturnValue({
373+
css: 'css code',
374+
code: 'code',
375+
cssFile: '',
376+
map: undefined,
377+
updatedBaseStyle: false,
378+
free: vi.fn(),
379+
[Symbol.dispose]: vi.fn(),
380+
})
381+
const plugin = DevupUI({})
382+
await (plugin as any).transform('code', 'foo.tsx')
383+
expect(writeFile).not.toHaveBeenCalled()
384+
})
385+
386+
it('should not generate bundle when css file is not found', async () => {
387+
const plugin = DevupUI({})
388+
const bundle = {} as any
389+
await (plugin as any).generateBundle({}, bundle)
390+
expect(bundle).toEqual({})
391+
})
300392
})

packages/vite-plugin/src/plugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ export function DevupUI({
134134
return true
135135
},
136136
async watchChange(id) {
137-
if (resolve(id) !== resolve(devupFile)) return
138-
if (existsSync(devupFile)) {
137+
if (resolve(id) === resolve(devupFile) && existsSync(devupFile)) {
139138
try {
140139
await writeDataFiles({
141140
package: libPackage,

0 commit comments

Comments
 (0)