File size: 2,934 Bytes
11486ce
 
b1cfe1b
11486ce
704e84f
11486ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
704e84f
 
 
 
 
 
 
 
 
 
 
 
 
11486ce
 
 
 
 
 
 
b1cfe1b
 
 
 
 
 
 
 
11486ce
 
 
 
 
 
 
 
 
 
 
 
e4e0afe
11486ce
 
 
 
 
 
 
 
 
 
 
704e84f
11486ce
 
 
b1cfe1b
704e84f
 
 
 
 
 
 
 
b1cfe1b
 
 
 
 
 
 
11486ce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import {
    DEFAULT_SHARE_EXPIRY_VALUE,
    ShareDialogFooterActions,
    ShareExpiryField,
    ShareLinkField,
    getShareExpiryMinutes
} from './share-dialog';
import { I18nProvider, useI18n } from '@/lib/i18n';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { renderToStaticMarkup } from 'react-dom/server';

function ShareRiskHintProbe() {
    const { t } = useI18n();
    return <p>{t('share.publicRiskHint')}</p>;
}

function renderShareRiskHint() {
    return renderToStaticMarkup(
        <I18nProvider>
            <ShareRiskHintProbe />
        </I18nProvider>
    );
}

function renderShareLinkField() {
    return renderToStaticMarkup(
        <I18nProvider>
            <ShareLinkField
                shareUrl='https://images.example.test/share/token'
                copyStatus={{ url: 'https://images.example.test/share/token', result: 'copied' }}
                onCopy={noop}
            />
        </I18nProvider>
    );
}

function renderShareExpiryField() {
    return renderToStaticMarkup(
        <I18nProvider>
            <ShareExpiryField expiry='1440' onExpiryChange={noop} />
        </I18nProvider>
    );
}

function renderShareDialogFooterActions() {
    return renderToStaticMarkup(
        <I18nProvider>
            <ShareDialogFooterActions isCreating={false} accessCodeError={null} onClose={noop} onCreate={noop} />
        </I18nProvider>
    );
}

const noop = () => {};

describe('ShareDialog', () => {
    it('defaults to a one-day time-limited share', () => {
        assert.equal(DEFAULT_SHARE_EXPIRY_VALUE, '1440');
        assert.equal(getShareExpiryMinutes(DEFAULT_SHARE_EXPIRY_VALUE), 1440);
    });

    it('falls back to the one-day default for unknown expiry values', () => {
        assert.equal(getShareExpiryMinutes('unexpected'), 1440);
    });

    it('allows an explicit share without an expiry when selected', () => {
        assert.equal(getShareExpiryMinutes('none'), null);
    });

    it('explains public sharing risk for no-access-code links', () => {
        const html = renderShareRiskHint();

        assert.match(html, /无访问码/);
        assert.match(html, /链接获得者/);
    });

    it('associates the expiry label with the select trigger', () => {
        const html = renderShareExpiryField();

        assert.match(html, /share-expiry/);
    });

    it('associates the generated link with its read-only input and announces share feedback', () => {
        const html = renderShareLinkField();

        assert.match(html, /for="share-link"/);
        assert.match(html, /id="share-link"/);
        assert.match(html, /aria-live="polite"/);
    });

    it('renders an explicit footer close action', () => {
        const html = renderShareDialogFooterActions();

        assert.match(html, /type="button"/);
        assert.match(html, />关闭</);
        assert.match(html, />创建分享</);
    });
});