Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lsl committed Oct 1, 2020
1 parent 2dccf13 commit 8ff99cd
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion client/my-sites/site-settings/test/form-general.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ jest.mock(
}
);

jest.mock( 'config', () => {
const mock = jest.fn();
mock.isEnabled = jest.fn();

return mock;
} );

/**
* External dependencies
*/
Expand All @@ -43,9 +50,12 @@ import {
* Internal dependencies
*/
import { SiteSettingsFormGeneral } from '../form-general';

import config from 'config';
import moment from 'moment';

const configMock = ( values ) => ( key ) => values[ key ];
config.isEnabled.mockImplementation( configMock( { 'coming-soon-v2': false } ) );

moment.tz = {
guess: () => moment(),
};
Expand Down Expand Up @@ -203,5 +213,44 @@ describe( 'SiteSettingsFormGeneral ', () => {
wpcom_coming_soon: 0,
} );
} );

test( 'Check Coming Soon radio option remains clickable with v2 not enabled', () => {
config.isEnabled.mockImplementation( configMock( { 'coming-soon-v2': false } ) );

testProps.fields.blog_public = -1;
testProps.fields.wpcom_coming_soon = 0;

const { getByLabelText } = renderWithRedux( <SiteSettingsFormGeneral { ...testProps } /> );

const radioButton = getByLabelText( 'Coming Soon', { exact: false } );

expect( radioButton ).not.toBeChecked();

fireEvent.click( radioButton );

expect( testProps.updateFields ).toBeCalledWith( { blog_public: -1, wpcom_coming_soon: 1 } );
} );

test( 'Check Coming Soon disappears with v2 enabled', () => {
config.isEnabled.mockImplementation( configMock( { 'coming-soon-v2': true } ) );

testProps.fields.blog_public = -1;
testProps.fields.wpcom_coming_soon = 0;

const { queryByLabelText } = renderWithRedux( <SiteSettingsFormGeneral { ...testProps } /> );
expect( queryByLabelText( 'Coming Soon', { exact: false } ) ).toBe( null );
} );

test( 'Check Coming Soon disappears with v2 enabled unless Coming Soon is currently set', () => {
config.isEnabled.mockImplementation( configMock( { 'coming-soon-v2': true } ) );

testProps.fields.blog_public = -1; // v1 coming soon requires private
testProps.fields.wpcom_coming_soon = 1;

const { getByLabelText } = renderWithRedux( <SiteSettingsFormGeneral { ...testProps } /> );

const comingSoonRadio1 = getByLabelText( 'Coming Soon', { exact: false } );
expect( comingSoonRadio1 ).toBeChecked();
} );
} );
} );

0 comments on commit 8ff99cd

Please sign in to comment.