-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests for the new vue components
- Loading branch information
Showing
4 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
roomchat-frontend/src/components/Chat/ChatMessageDisplay/ChatMessageDisplay.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import ChatMessageDisplay from './ChatMessageDisplay.vue'; | ||
|
||
describe('ChatMessageDisplayVue', () => { | ||
it('renders valid message', () => { | ||
const message = { | ||
sender: 'John', | ||
message: 'Hello, world!', | ||
UTC_timestamp: '2022-03-17T12:00:00Z', | ||
}; | ||
const wrapper = mount(ChatMessageDisplay, { | ||
props: { message }, | ||
}); | ||
|
||
expect(wrapper.find('.message-container').exists()).toBe(true); | ||
expect(wrapper.find('.sender-name').text()).toBe(message.sender); | ||
expect(wrapper.find('.message-content').text()).toBe(message.message); | ||
expect(wrapper.find('.timestamp').text()).toBe(message.UTC_timestamp); | ||
}); | ||
|
||
|
||
// Add more test cases for other error scenarios... | ||
|
||
}); |
47 changes: 42 additions & 5 deletions
47
roomchat-frontend/src/components/Chat/ChatMessagesContainer/ChatMessagesContainer.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,45 @@ | ||
import { mount, shallowMount } from '@vue/test-utils'; | ||
import ChatMessagesContainer from './ChatMessagesContainer.vue'; | ||
import { ChatMessage } from '@models/ChatMessage'; | ||
|
||
describe('ChatMessagesContainer', () => { | ||
it('renders all messages', () => { | ||
// Mock messages | ||
const messages: ChatMessage[] = [{ | ||
sender:"System", | ||
message:"Hello user, this is default message!", | ||
UTC_timestamp: "2021-3-5" | ||
}, | ||
{ | ||
sender:"User", | ||
message:"Hello system, this is nice!", | ||
UTC_timestamp: "2021-3-5" | ||
}, | ||
{ | ||
sender:"Buddy", | ||
message:"Let's play football!", | ||
UTC_timestamp: "2021-3-5" | ||
} | ||
]; | ||
|
||
describe("ChatContainer", () => { | ||
// Mount the component with props | ||
const wrapper = mount(ChatMessagesContainer, { | ||
props: { | ||
messageListProp: messages, | ||
}, | ||
}); | ||
|
||
it("Contains chat messages",()=>{ | ||
|
||
}) | ||
}) | ||
// Assert that all messages are rendered | ||
const messageComponents = wrapper.findAllComponents({ name: 'ChatMessageDisplay' }); | ||
expect(messageComponents.length).toBe(messages.length); | ||
|
||
expect(messageComponents.forEach(com => { | ||
expect(com.text()).toContain(com.props().message.sender) | ||
expect(com.text()).toContain(com.props().message.message) | ||
expect(com.text()).toContain(com.props().message.UTC_timestamp) | ||
})) | ||
|
||
|
||
|
||
}); | ||
}); |
4 changes: 2 additions & 2 deletions
4
roomchat-frontend/src/components/Chat/ChatMessagesContainer/ChatMessagesContainer.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
roomchat-frontend/src/components/Chat/ChatSender/ChatSender.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// ChatSender.spec.ts | ||
import { VueWrapper, mount } from '@vue/test-utils'; | ||
import ChatSender from './ChatSender.vue'; | ||
|
||
describe('ChatSender', () => { | ||
let wrapper: VueWrapper<InstanceType<typeof ChatSender>>; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(ChatSender,{ | ||
data(){ | ||
return{ | ||
currentMessage:"" | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
wrapper.unmount(); | ||
}); | ||
|
||
it('renders input field and send button', () => { | ||
const input = wrapper.find('input[type="text"]'); | ||
const button = wrapper.find('button'); | ||
|
||
expect(input.exists()).toBe(true); | ||
expect(button.exists()).toBe(true); | ||
}); | ||
|
||
it('emits "messageSend" event with current message when Send button is clicked', async () => { | ||
const message = 'Hello, world!'; | ||
const input = wrapper.find('input[type="text"]'); | ||
await input.setValue(message); | ||
|
||
const button = wrapper.find('button'); | ||
await button.trigger('click'); | ||
|
||
expect(wrapper.emitted('messageSend')).toBeTruthy(); | ||
const eventData : any = wrapper.emitted('messageSend'); | ||
expect(eventData).toBeTruthy(); | ||
expect(eventData[0][0]).toEqual({ | ||
sender: 'default', | ||
message, | ||
UTC_timestamp: expect.any(String), | ||
}); | ||
}); | ||
|
||
|
||
|
||
}); |