Files
habitica/website/client/tests/unit/components/chat/chatCard.spec.js
Bart Enkelaar 32ac00b417 Fix vue test stacktraces (#12612)
* Issue 10786 - Add unit test for Home component

* Issue 10786 - Improve test setup and test invite parameter variations

* Issue 10786 - Improve Vue.js test isolation by adding async keyword to dispatch function

* Issue 10786 - Missing action does not need to be awaited

* fix(vuejs-unit-tests): Fewer stacktraces in avatar.spec.js

* No more stacktraces in avatar.spec.js

* Register dummy directive in chatCard.spec.js

* Resolve stacktraces in column.spec.js

* Resolve stacktrace in notifications.spec.js

* Resolve warnings in user.spec.js

* Resolve asynchronous stacktrace from home.spec.js

* Remove unnecessary mount call.

* Clear up some let clutter in column.spec.js
2020-10-01 19:08:34 +02:00

61 lines
1.5 KiB
JavaScript

import Vue from 'vue';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import ChatCard from '@/components/chat/chatCard.vue';
import Store from '@/libs/store';
const localVue = createLocalVue();
localVue.use(Store);
localVue.use(Vue.directive('b-tooltip', {}));
describe('ChatCard', () => {
function createMessage (text) {
return { text, likes: {} };
}
function createUser (username) {
return {
auth: { local: { username } },
profile: { name: username },
contributor: {},
flags: {},
};
}
const message = createMessage('test');
let wrapper;
beforeEach(() => {
wrapper = shallowMount(ChatCard, {
propsData: { msg: message },
store: new Store({
state: {
user: { data: createUser('Tester') },
},
getters: {},
actions: {},
}),
localVue,
mocks: { $t: string => string },
});
});
it('shows the message text', () => {
expect(wrapper.find('div.text').text()).to.equal(message.text);
expect(wrapper.find('div.mentioned-icon').exists()).to.be.false;
});
it('shows mention dot if user is mentioned', () => {
wrapper.setProps({ msg: createMessage('@Tester') });
expect(wrapper.find('div.mentioned-icon').exists()).to.be.true;
});
// Bug fixed by https://github.com/HabitRPG/habitica/pull/12177
it('shows mention dot if user is mentioned after almostmention', () => {
wrapper.setProps({ msg: createMessage('thetester @Tester') });
expect(wrapper.find('div.mentioned-icon').exists()).to.be.true;
});
});