Skip to content

Commit

Permalink
Rasa UI: Add unit tests (#59)
Browse files Browse the repository at this point in the history
* RasaFileDownloadMessage: Add test to verify fileDownloadStarted event emission on click

* RasaText: Add test to ensure linkClicked event is emitted on link click
  • Loading branch information
sava-vidakovic authored Jul 22, 2024
1 parent faa4837 commit c939779
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,19 @@ describe('rasa-file-download-message', () => {
expect(anchorElement.getAttribute('href')).toBe('http://example.com/file.pdf');
expect(anchorElement.getAttribute('download')).toBe('example.pdf');
});

it('should emit fileDownloadStarted event on click', async () => {
const page = await newSpecPage({
components: [RasaFileDownloadMessage],
html: `<rasa-file-download-message file-url="https://example.com/file.pdf" file-name="file.pdf"></rasa-file-download-message>`,
});

const component = page.rootInstance;
const spy = jest.spyOn(component.fileDownloadStarted, 'emit');

const anchor = page.root.shadowRoot.querySelector('a');
anchor.click();

expect(spy).toHaveBeenCalled();
});
});
17 changes: 17 additions & 0 deletions packages/ui/src/components/text/text.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,21 @@ describe('rasa-text', () => {
</rasa-text>
`);
});

it('should emit linkClicked event when a link is clicked', async () => {
const page = await newSpecPage({
components: [RasaText],
html: `<rasa-text value="This is **bold**, an _italic_ link [Google](https://google.com)"></rasa-text>`,
});

const linkClickedSpy = jest.fn();
page.root.addEventListener('linkClicked', linkClickedSpy);

await page.waitForChanges();

const linkElement = page.root.shadowRoot.querySelector('a');
linkElement.click();

expect(linkClickedSpy).toHaveBeenCalled();
});
});

0 comments on commit c939779

Please sign in to comment.