Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.org Plans: Fix site slug in plan cancellation survey #9207

Merged
merged 2 commits into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions client/lib/url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ function urlToSlug( url ) {
return withoutHttp( url ).replace( /\//g, '::' );
}

function slugToUrl( slug ) {
if ( ! slug ) {
return null;
}

return slug.replace( /::/g, '/' );
}

export default {
isOutsideCalypso,
isExternal,
Expand All @@ -99,4 +107,5 @@ export default {
addSchemeIfMissing,
setUrlScheme,
urlToSlug,
slugToUrl,
};
20 changes: 19 additions & 1 deletion client/lib/url/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
addSchemeIfMissing,
setUrlScheme,
urlToSlug,
slugToUrl,
} from '../';

describe( 'withoutHttp', () => {
Expand Down Expand Up @@ -197,7 +198,7 @@ describe( 'urlToSlug()', () => {
expect( urlToSlug() ).to.be.null;
} );

it( 'should return empty string if URL is empty string', () => {
it( 'should return null if URL is empty string', () => {
const urlEmptyString = '';

expect( urlToSlug( urlEmptyString ) ).to.be.null;
Expand Down Expand Up @@ -237,3 +238,20 @@ describe( 'urlToSlug()', () => {
expect( urlWithoutHttp ).to.equal( 'example.com::example::test123' );
} );
} );

describe( 'slugToUrl()', () => {
it( 'should return null if slug is not provided', () => {
expect( slugToUrl() ).to.be.null;
} );

it( 'should return null if slug is empty string', () => {
expect( slugToUrl( '' ) ).to.be.null;
} );

it( 'should return null convert double colons to forward slashes', () => {
const slug = 'example.com::example::test123';
const expected = 'example.com/example/test123';

expect( slugToUrl( slug ) ).to.equal( expected );
} );
} );
5 changes: 3 additions & 2 deletions client/me/purchases/remove-purchase/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import purchasePaths from '../paths';
import { removePurchase } from 'state/purchases/actions';
import FormSectionHeading from 'components/forms/form-section-heading';
import userFactory from 'lib/user';
import { slugToUrl } from 'lib/url';

const user = userFactory();

Expand Down Expand Up @@ -130,7 +131,7 @@ const RemovePurchase = React.createClass( {
notices.success(
this.translate( '%(productName)s was removed from {{siteName/}}.', {
args: { productName },
components: { siteName: <em>{ selectedSite.slug }</em> }
components: { siteName: <em>{ slugToUrl( selectedSite.slug ) }</em> }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is doing exactly the same as the domain attribute of the site entity, which is what should be used instead.

selectedSite.domain instead of slugToUrl( selectedSite.slug ).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, thanks for noticing @mtias 👍 Fixing in #9338.

} ),
{ persistent: true }
);
Expand Down Expand Up @@ -287,7 +288,7 @@ const RemovePurchase = React.createClass( {
'Are you sure you want to remove %(productName)s from {{siteName/}}?',
{
args: { productName },
components: { siteName: <em>{ this.props.selectedSite.slug }</em> }
components: { siteName: <em>{ slugToUrl( this.props.selectedSite.slug ) }</em> }
}
)
}
Expand Down