Skip to content

Commit

Permalink
Update formatPattern tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Aug 1, 2015
1 parent 861e9ea commit e25d468
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions modules/__tests__/formatPattern-test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import expect from 'expect';
import { formatPattern } from '../URLUtils';
import { formatPattern } from '../PatternUtils';

describe('formatPattern', function () {
describe('when a pattern does not have dynamic segments', function () {
var pattern = 'a/b/c';
var pattern = '/a/b/c';

it('returns the pattern', function () {
expect(formatPattern(pattern, {})).toEqual(pattern);
});
});

describe('when a pattern has dynamic segments', function () {
var pattern = 'comments/:id/edit';
var pattern = '/comments/:id/edit';

describe('and a param is missing', function () {
it('throws an Error', function () {
Expand All @@ -22,60 +22,60 @@ describe('formatPattern', function () {
});

describe('and a param is optional', function () {
var pattern = 'comments/(:id)/edit';
var pattern = '/comments/(:id)/edit';

it('returns the correct path when param is supplied', function () {
expect(formatPattern(pattern, { id:'123' })).toEqual('comments/123/edit');
expect(formatPattern(pattern, { id:'123' })).toEqual('/comments/123/edit');
});

it('returns the correct path when param is not supplied', function () {
expect(formatPattern(pattern, {})).toEqual('comments/edit');
expect(formatPattern(pattern, {})).toEqual('/comments/edit');
});
});

describe('and a param and forward slash are optional', function () {
var pattern = 'comments(/:id)/edit';
var pattern = '/comments(/:id)/edit';

it('returns the correct path when param is supplied', function () {
expect(formatPattern(pattern, { id:'123' })).toEqual('comments/123/edit');
expect(formatPattern(pattern, { id:'123' })).toEqual('/comments/123/edit');
});

it('returns the correct path when param is not supplied', function () {
expect(formatPattern(pattern, {})).toEqual('comments/edit');
expect(formatPattern(pattern, {})).toEqual('/comments/edit');
});
});

describe('and all params are present', function () {
it('returns the correct path', function () {
expect(formatPattern(pattern, { id: 'abc' })).toEqual('comments/abc/edit');
expect(formatPattern(pattern, { id: 'abc' })).toEqual('/comments/abc/edit');
});

it('returns the correct path when the value is 0', function () {
expect(formatPattern(pattern, { id: 0 })).toEqual('comments/0/edit');
expect(formatPattern(pattern, { id: 0 })).toEqual('/comments/0/edit');
});
});

describe('and some params have special URL encoding', function () {
it('returns the correct path', function () {
expect(formatPattern(pattern, { id: 'one, two' })).toEqual('comments/one%2C+two/edit');
expect(formatPattern(pattern, { id: 'one, two' })).toEqual('/comments/one%2C+two/edit');
});
});

describe('and a param has a forward slash', function () {
it('preserves the forward slash', function () {
expect(formatPattern(pattern, { id: 'the/id' })).toEqual('comments/the%2Fid/edit');
expect(formatPattern(pattern, { id: 'the/id' })).toEqual('/comments/the%2Fid/edit');
});
});

describe('and some params contain dots', function () {
it('returns the correct path', function () {
expect(formatPattern(pattern, { id: 'alt.black.helicopter' })).toEqual('comments/alt.black.helicopter/edit');
expect(formatPattern(pattern, { id: 'alt.black.helicopter' })).toEqual('/comments/alt.black.helicopter/edit');
});
});

describe('and some params contain special characters', function () {
it('returns the correct path', function () {
expect(formatPattern(pattern, { id: '?not=confused&with=query#string' })).toEqual('comments/%3Fnot%3Dconfused%26with%3Dquery%23string/edit');
expect(formatPattern(pattern, { id: '?not=confused&with=query#string' })).toEqual('/comments/%3Fnot%3Dconfused%26with%3Dquery%23string/edit');
});
});
});
Expand Down

0 comments on commit e25d468

Please sign in to comment.