Skip to content

Commit

Permalink
Merge pull request #5254 from gitbutlerapp/add-tests-to-ui-slugify
Browse files Browse the repository at this point in the history
UI: add tests to slugify
  • Loading branch information
krlvi authored Oct 21, 2024
2 parents 7e7e867 + b9124e8 commit d78c77c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions apps/desktop/src/lib/utils/string.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { slugify } from '$lib/utils/string';
import { describe, expect, test } from 'vitest';

describe.concurrent('branch slugify with valid characters', () => {
test('forward slashes are fine', () => {
expect(slugify('my/branch')).toEqual('my/branch');
});

test('capitalization is fine', () => {
expect(slugify('MY/branch')).toEqual('MY/branch');
});

test('numbers are fine', () => {
expect(slugify('my/branch1')).toEqual('my/branch1');
});
});

describe.concurrent('branch slugify with replaced characters', () => {
test('whitespaces are truncated', () => {
expect(slugify(' my/branch ')).toEqual('my/branch');
});

test('whitespace in the middle becomes dash', () => {
expect(slugify('my branch')).toEqual('my-branch');
});

test('most special characters are nuked', () => {
expect(slugify('a!b@c$d;e%f^g&h*i(j)k+l=m~n`')).toEqual('abcdefghijklmn');
});
});

0 comments on commit d78c77c

Please sign in to comment.