-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from vtex-apps/feat/changeonhover
create prop change on hover for image
- Loading branch information
Showing
16 changed files
with
388 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const useDevice = () => ({ isMobile: true, device: 'desktop' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,73 @@ | ||
import React from 'react' | ||
import { render } from '@vtex/test-tools/react' | ||
import fs from 'fs' | ||
|
||
import ProductSummary from '../legacy/index' | ||
import ProductSummary from '../ProductSummaryCustom' | ||
|
||
describe('<ProductSummary /> component', () => { | ||
// TODO: Remove this later when we have a better way to resolve contentSchemas.json at test-tools | ||
const rawData = fs.readFileSync('../store/contentSchemas.json') | ||
const contentSchema = JSON.parse(rawData) | ||
const buyButtonText = | ||
contentSchema.definitions.ProductSummary.properties.buyButtonText.default | ||
|
||
const props = { | ||
runtime: { hints: {} }, | ||
buyButtonText, | ||
product: { | ||
it(`should parse a product succesfully and get sku as the first with available quantity`, () => { | ||
const product = { | ||
productId: '123456789', | ||
linkText: 'linkText', | ||
productName: 'productName', | ||
sku: { | ||
name: 'name', | ||
itemId: 'itemId', | ||
image: { | ||
imageUrl: '', | ||
items: [ | ||
{ | ||
itemId: '1', | ||
name: 'item 1', | ||
sellers: [ | ||
{ | ||
sellerId: '1', | ||
commertialOffer: { | ||
AvailableQuantity: 0, | ||
Price: 10, | ||
}, | ||
}, | ||
], | ||
images: [ | ||
{ | ||
imageUrl: 'image1', | ||
imageLabel: null, | ||
}, | ||
{ | ||
imageUrl: 'image2', | ||
imageLabel: null, | ||
}, | ||
], | ||
}, | ||
seller: { | ||
sellerId: 'sellerId', | ||
commertialOffer: { | ||
Installments: [ | ||
{ | ||
Value: 1, | ||
InterestRate: 1, | ||
NumberOfInstallments: 1, | ||
{ | ||
itemId: '2', | ||
name: 'item 2', | ||
sellers: [ | ||
{ | ||
sellerId: '1', | ||
commertialOffer: { | ||
AvailableQuantity: 3, | ||
Price: 15, | ||
}, | ||
], | ||
Price: 1, | ||
ListPrice: 1, | ||
}, | ||
}, | ||
], | ||
images: [ | ||
{ | ||
imageUrl: 'image1', | ||
imageLabel: null, | ||
}, | ||
{ | ||
imageUrl: 'image2', | ||
imageLabel: null, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
productClusters: [ | ||
{ | ||
name: 'name', | ||
}, | ||
], | ||
quantity: 1, | ||
}, | ||
} | ||
|
||
function renderComponent(customProps) { | ||
return render(<ProductSummary {...props} {...customProps} />) | ||
} | ||
|
||
it('should match the snapshot for normal mode', () => { | ||
const { asFragment } = renderComponent({ displayMode: 'normal' }) | ||
expect(asFragment()).toMatchSnapshot() | ||
}) | ||
|
||
it('should match the snapshot for small mode', () => { | ||
const { asFragment } = renderComponent({ displayMode: 'small' }) | ||
expect(asFragment()).toMatchSnapshot() | ||
}) | ||
|
||
it('should match the snapshot for inline normal mode', () => { | ||
const { asFragment } = renderComponent({ displayMode: 'inline' }) | ||
expect(asFragment()).toMatchSnapshot() | ||
}) | ||
|
||
it('should match the snapshot for inline price mode', () => { | ||
const { asFragment } = renderComponent({ displayMode: 'inlinePrice' }) | ||
expect(asFragment()).toMatchSnapshot() | ||
} | ||
const result = ProductSummary.mapCatalogProductToProductSummary(product) | ||
expect(result).toBeDefined() | ||
expect(result.sku.seller.sellerId).toBe('1') | ||
expect(result.sku.image).toBeDefined() | ||
expect(result.sku.itemId).toBe('2') | ||
}) | ||
|
||
it('should render buy button in inline, small and normal mode', () => { | ||
const { getByText, rerender, container } = renderComponent({ | ||
displayMode: 'normal', | ||
}) | ||
expect(getByText('Buy')).toBeTruthy() | ||
|
||
rerender(<ProductSummary {...props} displayMode="small" />) | ||
expect(getByText('Buy')).toBeTruthy() | ||
|
||
rerender(<ProductSummary {...props} displayMode="inline" />) | ||
expect(getByText('Buy')).toBeTruthy() | ||
|
||
rerender(<ProductSummary {...props} displayMode="inlinePrice" />) | ||
expect(container.querySelector('.buyButtonContainer')).toBeFalsy() | ||
}) | ||
|
||
it('should render quantity stepper only in inline price mode', () => { | ||
const { container, rerender } = renderComponent({ displayMode: 'normal' }) | ||
expect(container.querySelector('.quantityStepperContainer')).toBeFalsy() | ||
|
||
rerender(<ProductSummary {...props} displayMode="inlinePrice" />) | ||
expect(container.querySelector('.quantityStepperContainer')).toBeTruthy() | ||
|
||
rerender(<ProductSummary {...props} displayMode="small" />) | ||
expect(container.querySelector('.quantityStepperContainer')).toBeFalsy() | ||
|
||
rerender(<ProductSummary {...props} displayMode="inline" />) | ||
expect(container.querySelector('.quantityStepperContainer')).toBeFalsy() | ||
}) | ||
|
||
it(`should not break Shelf getSchema`, () => { | ||
it(`should not break ProductSummary getSchema`, () => { | ||
expect(ProductSummary.getSchema).toEqual(expect.any(Function)) | ||
}) | ||
|
||
describe('Site editor editable', () => { | ||
it('should export getSchema and return object with title', () => { | ||
const schema = ProductSummary.schema || ProductSummary.getSchema({}) | ||
expect(schema).toEqual( | ||
expect.objectContaining({ title: expect.any(String) }) | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import React from 'react' | ||
import { render } from '@vtex/test-tools/react' | ||
import fs from 'fs' | ||
|
||
import ProductSummary from '../legacy/index' | ||
|
||
describe('<ProductSummary /> component', () => { | ||
// TODO: Remove this later when we have a better way to resolve contentSchemas.json at test-tools | ||
const rawData = fs.readFileSync('../store/contentSchemas.json') | ||
const contentSchema = JSON.parse(rawData) | ||
const buyButtonText = | ||
contentSchema.definitions.ProductSummary.properties.buyButtonText.default | ||
|
||
const props = { | ||
runtime: { hints: {} }, | ||
buyButtonText, | ||
product: { | ||
productId: '123456789', | ||
linkText: 'linkText', | ||
productName: 'productName', | ||
sku: { | ||
name: 'name', | ||
itemId: 'itemId', | ||
image: { | ||
imageUrl: '', | ||
}, | ||
seller: { | ||
sellerId: 'sellerId', | ||
commertialOffer: { | ||
Installments: [ | ||
{ | ||
Value: 1, | ||
InterestRate: 1, | ||
NumberOfInstallments: 1, | ||
}, | ||
], | ||
Price: 1, | ||
ListPrice: 1, | ||
}, | ||
}, | ||
}, | ||
productClusters: [ | ||
{ | ||
name: 'name', | ||
}, | ||
], | ||
quantity: 1, | ||
}, | ||
} | ||
|
||
function renderComponent(customProps) { | ||
return render(<ProductSummary {...props} {...customProps} />) | ||
} | ||
|
||
it('should match the snapshot for normal mode', () => { | ||
const { asFragment } = renderComponent({ displayMode: 'normal' }) | ||
expect(asFragment()).toMatchSnapshot() | ||
}) | ||
|
||
it('should match the snapshot for small mode', () => { | ||
const { asFragment } = renderComponent({ displayMode: 'small' }) | ||
expect(asFragment()).toMatchSnapshot() | ||
}) | ||
|
||
it('should match the snapshot for inline normal mode', () => { | ||
const { asFragment } = renderComponent({ displayMode: 'inline' }) | ||
expect(asFragment()).toMatchSnapshot() | ||
}) | ||
|
||
it('should match the snapshot for inline price mode', () => { | ||
const { asFragment } = renderComponent({ displayMode: 'inlinePrice' }) | ||
expect(asFragment()).toMatchSnapshot() | ||
}) | ||
|
||
it('should render buy button in inline, small and normal mode', () => { | ||
const { getByText, rerender, container } = renderComponent({ | ||
displayMode: 'normal', | ||
}) | ||
expect(getByText('Buy')).toBeTruthy() | ||
|
||
rerender(<ProductSummary {...props} displayMode="small" />) | ||
expect(getByText('Buy')).toBeTruthy() | ||
|
||
rerender(<ProductSummary {...props} displayMode="inline" />) | ||
expect(getByText('Buy')).toBeTruthy() | ||
|
||
rerender(<ProductSummary {...props} displayMode="inlinePrice" />) | ||
expect(container.querySelector('.buyButtonContainer')).toBeFalsy() | ||
}) | ||
|
||
it('should render quantity stepper only in inline price mode', () => { | ||
const { container, rerender } = renderComponent({ displayMode: 'normal' }) | ||
expect(container.querySelector('.quantityStepperContainer')).toBeFalsy() | ||
|
||
rerender(<ProductSummary {...props} displayMode="inlinePrice" />) | ||
expect(container.querySelector('.quantityStepperContainer')).toBeTruthy() | ||
|
||
rerender(<ProductSummary {...props} displayMode="small" />) | ||
expect(container.querySelector('.quantityStepperContainer')).toBeFalsy() | ||
|
||
rerender(<ProductSummary {...props} displayMode="inline" />) | ||
expect(container.querySelector('.quantityStepperContainer')).toBeFalsy() | ||
}) | ||
|
||
it(`should not break Shelf getSchema`, () => { | ||
expect(ProductSummary.getSchema).toEqual(expect.any(Function)) | ||
}) | ||
|
||
describe('Site editor editable', () => { | ||
it('should export getSchema and return object with title', () => { | ||
const schema = ProductSummary.schema || ProductSummary.getSchema({}) | ||
expect(schema).toEqual( | ||
expect.objectContaining({ title: expect.any(String) }) | ||
) | ||
}) | ||
}) | ||
}) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.