Skip to content

Commit

Permalink
merge master branch and resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan-shafi committed Nov 13, 2023
2 parents dc5c625 + 312c7c8 commit 8713745
Show file tree
Hide file tree
Showing 86 changed files with 12,871 additions and 68,002 deletions.
10 changes: 5 additions & 5 deletions __tests__/js/test-inc/hooks.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable import/no-extraneous-dependencies */
const chai = require( 'chai' );
const dirtyChai = require( 'dirty-chai' );
const sinon = require( 'sinon' );
const { cleanup } = require( '@testing-library/react' );
const chai = require('chai');
const dirtyChai = require('dirty-chai');
const sinon = require('sinon');
const { cleanup } = require('@testing-library/react');

exports.mochaHooks = {
afterEach() {
Expand All @@ -14,5 +14,5 @@ exports.mochaHooks = {
exports.mochaGlobalSetup = () => {
const context = global || self;
context.expect = chai.expect;
chai.use( dirtyChai );
chai.use(dirtyChai);
};
36 changes: 16 additions & 20 deletions __tests__/js/unit/admin/js/src/components/AssetProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import sinon from 'sinon';
import * as WithStoreModule from '$HOC/withStore';
import proxyquire from 'proxyquire';

describe( 'AssetProvider', () => {
it( 'should render its child component with render props', () => {
describe('AssetProvider', () => {
it('should render its child component with render props', () => {
sinon
.stub( WithStoreModule, 'default' )
.callsFake( ( Component ) => Component );
.stub(WithStoreModule, 'default')
.callsFake((Component) => Component);

const MockedAssetProvider = proxyquire(
require.resolve( '$Components/AssetProvider' ),
require.resolve('$Components/AssetProvider'),
{}
).default;

Expand All @@ -22,28 +22,24 @@ describe( 'AssetProvider', () => {

const getAssetStub = sinon
.stub()
.callsFake( ( assetId ) => mockedStoreAssetState[ assetId ] );
.callsFake((assetId) => mockedStoreAssetState[assetId]);

render(
<MockedAssetProvider
getStoreAsset={ getAssetStub }
assetIds={ [ 'testMessage', 'testUrl' ] }
getStoreAsset={getAssetStub}
assetIds={['testMessage', 'testUrl']}
>
{ ( { testMessage, testUrl } ) => (
{({ testMessage, testUrl }) => (
<div>
<div>{ testMessage }</div>
<div data-testId={ testUrl } />
<div>{testMessage}</div>
<div data-testId={testUrl} />
</div>
) }
)}
</MockedAssetProvider>
);

expect(
screen.getByText( mockedStoreAssetState.testMessage )
).to.be.ok();
expect(screen.getByText(mockedStoreAssetState.testMessage)).to.be.ok();

expect(
screen.getByTestId( mockedStoreAssetState.testUrl )
).to.be.ok();
} );
} );
expect(screen.getByTestId(mockedStoreAssetState.testUrl)).to.be.ok();
});
});
52 changes: 26 additions & 26 deletions __tests__/js/unit/admin/js/src/components/BlockControlCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,68 @@ const defaultProps = {
iconObject: 'x',
};

const prepareProps = ( propsOverride ) => ( {
const prepareProps = (propsOverride) => ({
...defaultProps,
...propsOverride,
} );
});

describe( 'BlockControlCard', () => {
it( 'should signal its parent at block status change', async () => {
describe('BlockControlCard', () => {
it('should signal its parent at block status change', async () => {
const statusChangeSpy = sinon.spy();
const status = true;
const blockId = 'test-block';

render(
<BlockControlCard
{ ...prepareProps( {
{...prepareProps({
status,
blockId,
onStatusChange: statusChangeSpy,
} ) }
})}
/>
);
await userEvent.click( screen.getByRole( 'button' ) );
await userEvent.click(screen.getByRole('button'));

expect( statusChangeSpy.calledWith( blockId, ! status ) ).to.be.ok();
} );
it( 'should call showUpsell instead when target block is pro and plugin version is base', async () => {
expect(statusChangeSpy.calledWith(blockId, !status)).to.be.ok();
});
it('should call showUpsell instead when target block is pro and plugin version is base', async () => {
const showUpsellSpy = sinon.spy();
render(
<BlockControlCard
{ ...prepareProps( {
{...prepareProps({
showUpsell: showUpsellSpy,
proBlock: true,
} ) }
})}
/>
);

await userEvent.click( screen.getByRole( 'button' ) );
expect( showUpsellSpy.calledWith( defaultProps.blockId ) ).to.be.ok();
} );
it( 'should call status change when block is pro and plugin version is pro', async () => {
await userEvent.click(screen.getByRole('button'));
expect(showUpsellSpy.calledWith(defaultProps.blockId)).to.be.ok();
});
it('should call status change when block is pro and plugin version is pro', async () => {
const statusChangeSpy = sinon.spy();

render(
<BlockControlCard
{ ...prepareProps( {
{...prepareProps({
onStatusChange: statusChangeSpy,
proBlock: true,
proStatus: true,
} ) }
})}
/>
);

await userEvent.click( screen.getByRole( 'button' ) );
await userEvent.click(screen.getByRole('button'));

expect(
statusChangeSpy.calledWith(
defaultProps.blockId,
! defaultProps.status
!defaultProps.status
)
).to.be.ok();
} );
it( 'should not show demo link when demoUrl is not supplied', () => {
render( <BlockControlCard { ...defaultProps } /> );
expect( screen.queryByText( 'See Demo' ) ).to.be.not.ok();
} );
} );
});
it('should not show demo link when demoUrl is not supplied', () => {
render(<BlockControlCard {...defaultProps} />);
expect(screen.queryByText('See Demo')).to.be.not.ok();
});
});
36 changes: 18 additions & 18 deletions __tests__/js/unit/admin/js/src/components/BoxContent/BoxContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ import React from 'react';
import { render, screen } from '@testing-library/react';
import BoxContent from '$Components/BoxContent/BoxContent';

describe( 'BoxContent', () => {
it( 'should render title if prop supplied', () => {
describe('BoxContent', () => {
it('should render title if prop supplied', () => {
const title = 'Super important title';
render( <BoxContent title={ title } /> );
render(<BoxContent title={title} />);

const welcomeComponent = screen.getByText( title );
expect( welcomeComponent ).to.be.ok();
} );
it( 'should render content if prop supplied', () => {
const welcomeComponent = screen.getByText(title);
expect(welcomeComponent).to.be.ok();
});
it('should render content if prop supplied', () => {
const content = 'Super important content.';
render( <BoxContent content={ content } /> );
render(<BoxContent content={content} />);

const welcomeComponent = screen.getByText( content );
expect( welcomeComponent ).to.be.ok();
} );
const welcomeComponent = screen.getByText(content);
expect(welcomeComponent).to.be.ok();
});

it( 'should render its children', () => {
it('should render its children', () => {
const content = (
<div data-testid={ 'content-child' }>Super important children</div>
<div data-testid={'content-child'}>Super important children</div>
);

render( <BoxContent>{ content }</BoxContent> );
render(<BoxContent>{content}</BoxContent>);

const welcomeComponent = screen.getByTestId( 'content-child' );
expect( welcomeComponent ).to.be.ok();
} );
} );
const welcomeComponent = screen.getByTestId('content-child');
expect(welcomeComponent).to.be.ok();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,33 @@ import proxyquire from 'proxyquire';
import { render, screen } from '@testing-library/react';
import * as WithStoreModule from '$HOC/withStore';

describe( 'BoxContentProvider', () => {
it( 'should override supplied content properties with content data', async () => {
describe('BoxContentProvider', () => {
it('should override supplied content properties with content data', async () => {
const testData = {
title: 'title overwrite',
content: 'content overwrite',
};

const getCData = sinon.stub().returns( testData );
const getCData = sinon.stub().returns(testData);

sinon.stub( WithStoreModule, 'default' ).callsFake( ( Component ) => {
return ( props ) => (
<Component { ...props } getCData={ getCData } />
);
} );
sinon.stub(WithStoreModule, 'default').callsFake((Component) => {
return (props) => <Component {...props} getCData={getCData} />;
});

const BoxContentProvider = proxyquire(
require.resolve( '$Components/BoxContent/BoxContentProvider' ),
require.resolve('$Components/BoxContent/BoxContentProvider'),
{}
).default;

render(
<BoxContentProvider
title={ 'new title' }
content={ 'new content' }
contentId={ 'test' }
title={'new title'}
content={'new content'}
contentId={'test'}
/>
);

expect( screen.getByText( testData.title ) ).to.be.ok();
expect( screen.getByText( testData.content ) ).to.be.ok();
} );
} );
expect(screen.getByText(testData.title)).to.be.ok();
expect(screen.getByText(testData.content)).to.be.ok();
});
});
40 changes: 20 additions & 20 deletions __tests__/js/unit/admin/js/src/components/ButtonLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import ButtonLink from '$Components/ButtonLink';

describe( 'ButtonLink', () => {
it( 'should render with given title', () => {
describe('ButtonLink', () => {
it('should render with given title', () => {
const title = 'welcome';
render( <ButtonLink title={ title } url={ 'https://example.com' } /> );
render(<ButtonLink title={title} url={'https://example.com'} />);

const welcomeComponent = screen.getByText( title );
expect( welcomeComponent ).to.be.ok();
} );
it( 'should redirect to given url', async () => {
const welcomeComponent = screen.getByText(title);
expect(welcomeComponent).to.be.ok();
});
it('should redirect to given url', async () => {
const targetTestUrl = 'https://example.com';
render( <ButtonLink url={ targetTestUrl } /> );
render(<ButtonLink url={targetTestUrl} />);

const mockedOpen = sinon.stub( window, 'open' );
await userEvent.click( screen.getByRole( 'button' ) );
const mockedOpen = sinon.stub(window, 'open');
await userEvent.click(screen.getByRole('button'));

expect( mockedOpen.withArgs( targetTestUrl ) ).to.be.ok();
} );
it( 'should use click handler if provided and ignore url', async () => {
expect(mockedOpen.withArgs(targetTestUrl)).to.be.ok();
});
it('should use click handler if provided and ignore url', async () => {
const clickHandler = sinon.spy();

const mockedOpen = sinon.stub( window, 'open' );
render( <ButtonLink onClickHandler={ clickHandler } /> );
const mockedOpen = sinon.stub(window, 'open');
render(<ButtonLink onClickHandler={clickHandler} />);

await userEvent.click( screen.getByRole( 'button' ) );
await userEvent.click(screen.getByRole('button'));

expect( clickHandler.calledOnce ).to.be.ok();
expect( mockedOpen.called ).to.not.be.ok();
} );
} );
expect(clickHandler.calledOnce).to.be.ok();
expect(mockedOpen.called).to.not.be.ok();
});
});
Loading

0 comments on commit 8713745

Please sign in to comment.