Skip to content

Commit

Permalink
test(frontend): add resize image process e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MiracleHorizon committed May 31, 2024
1 parent aaf9f70 commit 21cb9b3
Show file tree
Hide file tree
Showing 26 changed files with 142 additions and 17 deletions.
2 changes: 1 addition & 1 deletion apps/frontend/cypress/e2e/convert-image.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path'

// NOTE: Backend server should be running
describe('Convert Image', () => {
describe('Convert image', () => {
before(() => {
cy.setDesktopViewport()
cy.skipTourAndAcceptCookies()
Expand Down
74 changes: 74 additions & 0 deletions apps/frontend/cypress/e2e/resize-image.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import * as path from 'path'

const testResize = () => {
// Upload an image file.
cy.get('[data-cy="image-dropzone"] input').selectFile('cypress/fixtures/test_image.png', {
force: true
})

// Set resize width and height.
cy.get('[data-cy="input-resize-width"]').type('150')
cy.get('[data-cy="input-resize-height"]').type('150')

const checkboxReduction = cy.get('[data-cy="cbox-resize-reduction"]')
checkboxReduction.click()
checkboxReduction.should('have.data', 'state', 'checked')

// Add trim operation.
cy.get('[data-cy="resize-operation-trim"]').click({
force: true
})

cy.get('[data-cy="cbox-trim-line-art"]').click()
cy.get('[data-cy="input-trim-threshold"]').clear().type('4')

cy.get('[data-cy="button-resize"]')
.click()
.then(() => {
// Simulate waiting for a server response.
cy.wait(3000)

cy.get('[data-cy="button-download"]').click()

const downloadsFolder = Cypress.config('downloadsFolder')
const outputTestFilePath = path.join(downloadsFolder, 'test_image.png')
cy.readFile(outputTestFilePath).should('exist')
})
}

// NOTE: Backend server should be running
describe('Resize image', () => {
beforeEach(() => {
cy.skipTourAndAcceptCookies()
})

context('Desktop', () => {
before(() => {
cy.setDesktopViewport()
})

it('should correctly resize image and download it', () => {
cy.visit('/')
cy.wait(1500)

cy.selectTab({ tabName: 'resize' })

testResize()
})
})

context('Mobile', () => {
before(() => {
cy.setMobileViewport()
})

it('should correctly resize image and download it', () => {
cy.visit('/')
cy.wait(1500)

cy.selectTab({ tabName: 'resize', isMobile: true })

testResize()
})
})
})
22 changes: 22 additions & 0 deletions apps/frontend/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,25 @@ Cypress.Commands.add('skipTourAndAcceptCookies' as keyof Chainable<any>, () => {
})
)
})

Cypress.Commands.add(
'selectTab' as keyof Chainable<any>,
({ tabName, isMobile = false }: { tabName: string; isMobile?: boolean }) => {
if (isMobile) {
cy.get('[data-cy="toolbar-tab-dropdown-trigger"]').click()
cy.get('[data-cy="toolbar-tab-dropdown-content"]').should('exist')

cy.get('.rt-TabsTriggerInner')
.contains(tabName, {
matchCase: false
})
.click()

return
}

const tab = cy.get(`[data-cy="tab-trigger-${tabName}"]`)
tab.click()
tab.should('have.data', 'state', 'active')
}
)
1 change: 1 addition & 0 deletions apps/frontend/cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ declare global {
setTabletViewport: VoidFunction
setMobileViewport: VoidFunction
clickOutside: (options?: Partial<Cypress.ClickOptions>) => void
selectTab: (params: { tabName: string; isMobile?: boolean }) => void
}
}
}
5 changes: 2 additions & 3 deletions apps/frontend/src/design-system/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { memo, useId } from 'react'
import { type HTMLAttributes, memo, useId } from 'react'
import { Checkbox as RadixCheckbox, Flex, Text } from '@radix-ui/themes'
import { clsx } from 'clsx'

Expand All @@ -9,10 +9,9 @@ import type { JustifyContent } from '@lib/theme'

export const rootTestId = 'checkbox-root'

export interface Props {
export interface Props extends Omit<HTMLAttributes<HTMLButtonElement>, 'color'> {
label?: string
checked?: boolean
onClick?: VoidFunction
disabled?: boolean
direction?: 'row' | 'row-reverse'
justify?: JustifyContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const ButtonResize = () => {
error={error}
isLoading={isLoading}
isDisabled={resizeSettings.queue.length === 0}
data-cy='button-resize'
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const TabResizeControl = () => {
onValueChange={onValueChange}
>
{operationList.map(value => (
<CheckboxCards.Item key={value} value={value}>
<CheckboxCards.Item key={value} value={value} data-cy={`resize-operation-${value}`}>
{capitalize(value)}
</CheckboxCards.Item>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const CheckboxEnlargement = () => {
<Checkbox
label='Without Enlarging'
checked={withoutEnlargement}
data-cy='cbox-resize-enlargement'
onClick={handleToggleWithoutEnlargement}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,12 @@ export const CheckboxFastShrink = () => {
return null
}

return <Checkbox label='Fast Shrink' checked={fastShrink} onClick={handleToggleFastShrink} />
return (
<Checkbox
label='Fast Shrink'
checked={fastShrink}
data-cy='cbox-resize-fast-shrink'
onClick={handleToggleFastShrink}
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const CheckboxReduction = () => {
<Checkbox
label='Without Reduction'
checked={withoutReduction}
data-cy='cbox-resize-reduction'
onClick={handleToggleWithoutReduction}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { Flex } from '@radix-ui/themes'
import { ResizeBackgroundPicker } from './ResizeBackgroundPicker'
import { ResizeDominantBackground } from './ResizeDominantBackground'
import { ResizeCheckboxes } from './ResizeCheckboxes'
import { ResizeSelectList } from './ResizeSelectList'
import { ResizeSelectsList } from './ResizeSelectsList'
import { useResizeStore } from '@stores/resize'

export const ResizeExtra = () => {
const background = useResizeStore(state => state.background)

return (
<Flex direction='column' gap='2' width='100%'>
<ResizeSelectList />
<ResizeSelectsList />
{background && (
<Flex direction='column' gap='3'>
<ResizeBackgroundPicker background={background} />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const direction: FlexDirection = {
xs: 'row'
} as const

export const ResizeSelectList = () => {
export const ResizeSelectsList = () => {
const fit = useResizeStore(state => state.fit)
const kernel = useResizeStore(state => state.kernel)
const position = useResizeStore(state => state.position)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const SelectResizeFit = () => {
defaultValue={DEFAULT_RESIZE_FIT}
data={data}
DetailsComponent={<ResizeFitExamplesPopover />}
triggerCySelector='sl-resize-fit-trigger'
contentCySelector='sl-resize-fit-content'
onValueChange={handleSetFit}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ export const SelectResizeKernel = () => {
return (
<Select
label='Kernel'
data={data}
value={kernel ?? DEFAULT_RESIZE_KERNEL}
defaultValue={DEFAULT_RESIZE_KERNEL}
data={data}
triggerCySelector='sl-resize-kernel-trigger'
contentCySelector='sl-resize-kernel-content'
onValueChange={handleSetKernel}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ export const SelectResizePosition = () => {
return (
<Select
label='Position'
data={data}
value={position ?? DEFAULT_RESIZE_POSITION}
defaultValue={DEFAULT_RESIZE_POSITION}
data={data}
triggerCySelector='sl-resize-position-trigger'
contentCySelector='sl-resize-position-content'
onValueChange={handleSetPosition}
/>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ResizeSelectsList } from './ResizeSelectsList'
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const ResizeSizesForm = () => {
setValue={setWidth}
max={MAX_RESIZE_WIDTH}
placeholder='1920'
data-cy='input-resize-width'
icon={<WidthIcon />}
/>
<NumberInput
Expand All @@ -43,6 +44,7 @@ export const ResizeSizesForm = () => {
setValue={setHeight}
max={MAX_RESIZE_HEIGHT}
placeholder='1080'
data-cy='input-resize-height'
icon={<HeightIcon />}
/>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,12 @@ export const CheckboxTrimLineArt = () => {
const toggleLineArt = useTrimStore(state => state.toggleLineArt)
const handleToggleLineArt = () => toggleLineArt()

return <Checkbox label='Line Art' onClick={handleToggleLineArt} checked={lineArt} />
return (
<Checkbox
label='Line Art'
checked={lineArt}
data-cy='cbox-trim-line-art'
onClick={handleToggleLineArt}
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const TrimThresholdInput = () => {
min={MIN_TRIM_THRESHOLD}
max={MAX_TRIM_THRESHOLD}
step={1}
data-cy='input-trim-threshold'
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ export const ToolbarTabDropdown = () => {

return (
<DropdownMenu.Root open={isOpen} onOpenChange={setIsOpen}>
<DropdownMenu.Trigger data-tourstep={TOUR_STEP.TOOLBAR_TAB_LIST}>
<DropdownMenu.Trigger
data-tourstep={TOUR_STEP.TOOLBAR_TAB_LIST}
data-cy='toolbar-tab-dropdown-trigger'
>
<Button radius='large' variant='soft' color='gray' onClick={handleOpen}>
Tabs
<ChevronDownIcon width='18px' height='18px' color='var(--gray-a11)' />
</Button>
</DropdownMenu.Trigger>

<DropdownMenu.Content size='1'>
<DropdownMenu.Content size='1' data-cy='toolbar-tab-dropdown-content'>
<ToolbarTabList className={styles.tabs} onClick={handleClose} />
</DropdownMenu.Content>
</DropdownMenu.Root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ interface Props extends Tab {
onClick?: VoidFunction
}

export const ToolbarTabItem = ({ value, label, icon, onClick }: Props) => (
<Tabs.Trigger key={value} value={value} onClick={onClick}>
export const ToolbarTabItem = ({ label, icon, ...props }: Props) => (
<Tabs.Trigger {...props} data-cy={`tab-trigger-${label.toLowerCase()}`}>
<MediaQuery maxWidth={BREAKPOINTS_MAX_WIDTH.xs}>{icon}</MediaQuery>

{label}
Expand Down

0 comments on commit 21cb9b3

Please sign in to comment.