|
| 1 | +import sinon from 'sinon'; |
| 2 | + |
1 | 3 | import * as fixtures from '../../test/annotation-fixtures';
|
2 | 4 | import { AnnotationsService, $imports } from '../annotations';
|
3 | 5 |
|
@@ -67,6 +69,8 @@ describe('AnnotationsService', () => {
|
67 | 69 | selectTab: sinon.stub(),
|
68 | 70 | setExpanded: sinon.stub(),
|
69 | 71 | updateFlagStatus: sinon.stub(),
|
| 72 | + defaultAuthority: sinon.stub().returns('hypothes.is'), |
| 73 | + isFeatureEnabled: sinon.stub().returns(false), |
70 | 74 | };
|
71 | 75 |
|
72 | 76 | setLoggedIn(true);
|
@@ -506,6 +510,40 @@ describe('AnnotationsService', () => {
|
506 | 510 | });
|
507 | 511 | });
|
508 | 512 |
|
| 513 | + [ |
| 514 | + { |
| 515 | + profile: { userid: 'acct:[email protected]' }, |
| 516 | + mentionsEnabled: false, |
| 517 | + expectedText: 'hello @bob', |
| 518 | + }, |
| 519 | + { |
| 520 | + profile: { userid: 'acct:[email protected]' }, |
| 521 | + mentionsEnabled: true, |
| 522 | + expectedText: |
| 523 | + 'hello <a data-hyp-mention="" data-userid="acct:[email protected]">@bob</a>', |
| 524 | + }, |
| 525 | + { |
| 526 | + profile: { userid: 'acct:foo' }, |
| 527 | + mentionsEnabled: true, |
| 528 | + expectedText: |
| 529 | + 'hello <a data-hyp-mention="" data-userid="acct:[email protected]">@bob</a>', |
| 530 | + }, |
| 531 | + ].forEach(({ profile, mentionsEnabled, expectedText }) => { |
| 532 | + it('wraps mentions in tags when feature is enabled', async () => { |
| 533 | + fakeStore.isFeatureEnabled.returns(mentionsEnabled); |
| 534 | + fakeStore.profile.returns(profile); |
| 535 | + fakeStore.getDraft.returns({ text: 'hello @bob' }); |
| 536 | + |
| 537 | + await svc.save(fixtures.defaultAnnotation()); |
| 538 | + |
| 539 | + assert.calledWith( |
| 540 | + fakeApi.annotation.create, |
| 541 | + {}, |
| 542 | + sinon.match({ text: expectedText }), |
| 543 | + ); |
| 544 | + }); |
| 545 | + }); |
| 546 | + |
509 | 547 | context('successful save', () => {
|
510 | 548 | it('copies over internal app-specific keys to the annotation object', () => {
|
511 | 549 | fakeMetadata.isSaved.returns(true);
|
|
0 commit comments