123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- import {
- valueIsEqual,
- extractMultilineFields,
- parseRepo,
- explodeSlug,
- sortProjects,
- descopeFeatureName,
- } from 'app/utils';
- describe('utils.valueIsEqual', function() {
- it('should return true when objects are deeply equal', function() {
- const isEqual = valueIsEqual(
- {
- username: 'foo',
- teams: ['bar', 'baz'],
- avatar: {
- avatarType: 'gravatar',
- avatarUuid: null,
- },
- },
- {
- username: 'foo',
- teams: ['bar', 'baz'],
- avatar: {
- avatarType: 'gravatar',
- avatarUuid: null,
- },
- },
- true
- );
- expect(isEqual).toBe(true);
- });
- it('should return false when objects are not deeply equal', function() {
- const isEqual = valueIsEqual(
- {
- username: 'foo',
- teams: ['bar', 'baz'],
- avatar: {
- avatarType: 'gravatar',
- avatarUuid: null,
- },
- },
- {
- username: 'foo',
- teams: ['bar', 'baz'],
- avatar: {
- avatarType: 'notGravatar',
- avatarUuid: null,
- },
- },
- true
- );
- expect(isEqual).toBe(false);
- });
- it('should return true when objects are shalowly equal', function() {
- const isEqual = valueIsEqual(
- {
- username: 'foo',
- team: 'bar',
- avatar: 'gravatar',
- },
- {
- username: 'foo',
- team: 'bar',
- avatar: 'gravatar',
- },
- false
- );
- expect(isEqual).toBe(true);
- });
- it('should return false when objects are not shalowly equal', function() {
- const isEqual = valueIsEqual(
- {
- username: 'foo',
- team: 'bar',
- avatar: 'gravatar',
- },
- {
- username: 'foo',
- team: 'bar',
- avatar: 'notGravatar',
- },
- false
- );
- expect(isEqual).toBe(false);
- });
- it('should not blow up when comparing null value to an object', function() {
- let isEqual = valueIsEqual(null, {username: 'foo'}, true);
- expect(isEqual).toBe(false);
- isEqual = valueIsEqual(
- {
- username: 'foo',
- teams: ['bar', 'baz'],
- avatar: null,
- },
- {
- username: 'foo',
- teams: ['bar', 'baz'],
- avatar: {
- avatarType: 'notGravatar',
- avatarUuid: null,
- },
- },
- true
- );
- expect(isEqual).toBe(false);
- });
- });
- describe('utils.extractMultilineFields', function() {
- it('should work for basic, simple values', function() {
- expect(extractMultilineFields('one\ntwo\nthree')).toEqual(['one', 'two', 'three']);
- });
- it('should return an empty array if only whitespace', function() {
- expect(extractMultilineFields(' \n \n\n\n \n')).toEqual([]);
- });
- it('should trim values and ignore empty lines', function() {
- expect(
- extractMultilineFields(
- `one
- two
- three
- four
- five`
- )
- ).toEqual(['one', 'two', 'three', 'four', 'five']);
- });
- });
- describe('utils.parseRepo', function() {
- it('should work for simple github url', function() {
- expect(parseRepo('github.com/example/example')).toEqual('example/example');
- });
- it('should work for full github url', function() {
- expect(parseRepo('https://github.com/example/example')).toEqual('example/example');
- });
- it('should work for trailing slash', function() {
- expect(parseRepo('https://github.com/example/example/')).toEqual('example/example');
- });
- it('should work for simple BitBucket url', function() {
- expect(parseRepo('bitbucket.org/example/example')).toEqual('example/example');
- });
- it('should work for full BitBucket url', function() {
- expect(parseRepo('https://bitbucket.org/example/example')).toEqual('example/example');
- });
- it('should work for trailing Bitbucket slash', function() {
- expect(parseRepo('https://bitbucket.org/example/example/')).toEqual(
- 'example/example'
- );
- });
- it('should work for repo only', function() {
- expect(parseRepo('example/example')).toEqual('example/example');
- });
- it('should parse repo from url with extra info', function() {
- expect(parseRepo('github.com/example/example/commits/adsadsa')).toEqual(
- 'example/example'
- );
- });
- it('should work for nothing passed', function() {
- expect(parseRepo()).toEqual();
- });
- });
- describe('utils.explodeSlug', function() {
- it('replaces slug special chars with whitespace', function() {
- expect(explodeSlug('test--slug__replace-')).toEqual('test slug replace');
- });
- });
- describe('utils.projectDisplayCompare', function() {
- it('sorts by bookmark and project slug', function() {
- const projects = [
- {
- isBookmarked: true,
- slug: 'm',
- },
- {
- isBookmarked: false,
- slug: 'm',
- },
- {
- isBookmarked: false,
- slug: 'a',
- },
- {
- isBookmarked: true,
- slug: 'a',
- },
- {
- isBookmarked: true,
- slug: 'z',
- },
- {
- isBookmarked: false,
- slug: 'z',
- },
- ];
- const sortedProjects = sortProjects(projects);
- expect(sortedProjects).toEqual([
- {
- isBookmarked: true,
- slug: 'a',
- },
- {
- isBookmarked: true,
- slug: 'm',
- },
- {
- isBookmarked: true,
- slug: 'z',
- },
- {
- isBookmarked: false,
- slug: 'a',
- },
- {
- isBookmarked: false,
- slug: 'm',
- },
- {
- isBookmarked: false,
- slug: 'z',
- },
- ]);
- });
- });
- describe('utils.descopeFeatureName', function() {
- [
- ['organizations:feature', 'feature'],
- ['projects:feature', 'feature'],
- ['unknown-scope:feature', 'unknown-scope:feature'],
- ['', ''],
- ].map(([input, expected]) => expect(descopeFeatureName(input)).toEqual(expected));
- });
|