Skip to content

Commit 22b64ea

Browse files
committed
feat(chat): add drop accepted files test
1 parent b4fdeca commit 22b64ea

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/components/chat/chat.spec.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,43 @@ describe('Chat', () => {
917917
});
918918
});
919919

920-
describe('Drag &Drop', () => {
921-
it('should be able to drop files base on the types listed in `acceptedFiles`', () => {});
920+
describe('Drag & Drop', () => {
921+
beforeEach(async () => {
922+
const options = {
923+
acceptedFiles: '.txt',
924+
};
925+
chat = await fixture<IgcChatComponent>(
926+
html`<igc-chat .options=${options}> </igc-chat>`
927+
);
928+
});
929+
930+
it('should be able to drop files based on the types listed in `acceptedFiles`', async () => {
931+
const inputArea = chat.shadowRoot?.querySelector('igc-chat-input');
932+
const dropZone =
933+
inputArea?.shadowRoot?.querySelector('.input-container');
934+
935+
if (dropZone) {
936+
const mockDataTransfer = {
937+
files: files,
938+
} as unknown as DataTransfer;
939+
940+
const dropEvent = new DragEvent('drop', {
941+
bubbles: true,
942+
cancelable: true,
943+
});
944+
Object.defineProperty(dropEvent, 'dataTransfer', {
945+
value: mockDataTransfer,
946+
});
947+
948+
dropZone.dispatchEvent(dropEvent);
949+
await elementUpdated(chat);
950+
951+
const attachments =
952+
inputArea?.shadowRoot?.querySelectorAll('igc-chip');
953+
expect(attachments?.length).to.equal(1);
954+
expect(attachments?.[0]?.textContent?.trim()).to.equal('test.txt');
955+
}
956+
});
922957
});
923958

924959
describe('Keyboard', () => {

0 commit comments

Comments
 (0)