|
1 | 1 | import { describe, expect, it } from 'vitest'; |
2 | 2 |
|
3 | 3 | import { createStartMiningToastPayload } from '@/utils/extras'; |
| 4 | +import { |
| 5 | + getToastHasLinksDetailMessage, |
| 6 | + hasToastHasLinksButtonAction, |
| 7 | + hasToastHasLinksLink, |
| 8 | +} from '@/utils/toast'; |
4 | 9 |
|
5 | 10 | describe('createStartMiningToastPayload', () => { |
6 | 11 | const translations: Record<string, string> = { |
@@ -48,3 +53,40 @@ describe('createStartMiningToastPayload', () => { |
48 | 53 | }); |
49 | 54 | }); |
50 | 55 | }); |
| 56 | + |
| 57 | +describe('toast has-links detail helpers', () => { |
| 58 | + it('returns message when detail is a string', () => { |
| 59 | + expect(getToastHasLinksDetailMessage('Simple detail')).toBe( |
| 60 | + 'Simple detail', |
| 61 | + ); |
| 62 | + }); |
| 63 | + |
| 64 | + it('returns message when detail is an object', () => { |
| 65 | + expect( |
| 66 | + getToastHasLinksDetailMessage({ |
| 67 | + message: 'Object detail', |
| 68 | + }), |
| 69 | + ).toBe('Object detail'); |
| 70 | + }); |
| 71 | + |
| 72 | + it('returns empty string for unsupported detail values', () => { |
| 73 | + expect(getToastHasLinksDetailMessage(undefined)).toBe(''); |
| 74 | + expect(getToastHasLinksDetailMessage(null)).toBe(''); |
| 75 | + }); |
| 76 | + |
| 77 | + it('detects object link and button action safely', () => { |
| 78 | + const withAction = { |
| 79 | + message: 'x', |
| 80 | + button: { text: 'Retry', action: () => true }, |
| 81 | + }; |
| 82 | + const withLink = { |
| 83 | + message: 'x', |
| 84 | + link: { text: 'More', url: 'https://example.com' }, |
| 85 | + }; |
| 86 | + |
| 87 | + expect(hasToastHasLinksButtonAction(withAction)).toBe(true); |
| 88 | + expect(hasToastHasLinksButtonAction(withLink)).toBe(false); |
| 89 | + expect(hasToastHasLinksLink(withLink)).toBe(true); |
| 90 | + expect(hasToastHasLinksLink('plain detail')).toBe(false); |
| 91 | + }); |
| 92 | +}); |
0 commit comments