Skip to content

Commit

Permalink
[Storybook] Fix postfixing of name when adding storybook variations (#…
Browse files Browse the repository at this point in the history
…165)

Co-authored-by: Logan Graham <[email protected]>
  • Loading branch information
omacranger and Logan Graham authored Nov 19, 2024
1 parent 7f47cd8 commit 0270311
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
5 changes: 5 additions & 0 deletions visual-js/.changeset/forty-bobcats-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@saucelabs/visual-storybook": patch
---

fix postfixing of storybook name when adding variations
3 changes: 2 additions & 1 deletion visual-js/visual-storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"scripts": {
"build": "tsup",
"watch": "tsc-watch --declaration -p .",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\""
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
"test": "jest --collect-coverage"
},
"dependencies": {
"@saucelabs/visual": "^0.10.0",
Expand Down
41 changes: 41 additions & 0 deletions visual-js/visual-storybook/src/api.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { augmentStoryName } from './api';
import { expect } from '@jest/globals';
import { StoryContext } from './types';

describe('augmentStoryName', () => {
const context: StoryContext = {
id: 'test-id',
name: 'Button',
title: 'Example/Button',
};

it('should prefix a value', () => {
const augmented = augmentStoryName(context, {
prefix: 'prefix ',
});
expect(augmented).toEqual({
...context,
name: 'prefix Button',
});
});

it('should postfix a value', () => {
const augmented = augmentStoryName(context, {
postfix: ' postfix',
});
expect(augmented).toEqual({
...context,
name: 'Button postfix',
});
});

it('should allow supplying a custom name', () => {
const augmented = augmentStoryName(context, {
name: 'custom name',
});
expect(augmented).toEqual({
...context,
name: 'custom name',
});
});
});
2 changes: 1 addition & 1 deletion visual-js/visual-storybook/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const augmentStoryName = (
}

if (variation.postfix) {
name = `${variation.postfix}${name}`;
name = `${name}${variation.postfix}`;
}

return {
Expand Down
7 changes: 4 additions & 3 deletions visual-js/visual-storybook/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
}
],
"types": [
"jest-playwright-preset",
],
"jest",
"jest-playwright-preset"
],
},
"include": [
"src/**/*",
"../../@types",
]
}
}

0 comments on commit 0270311

Please sign in to comment.