Files
habitica/website/client/tests/unit/components/groups/myGuilds.spec.js
T
tsukimi2 519af8f1b6 Fix for search guilds result being inconsistent between "My Guilds" and "Discover Guilds" (#11903)
* Fix bug to allow guild summary and description to match against search term in MyGuilds component

* Add unit test to groupUtilities to test filterGroup function

* Changes made after running npm:run:lint

* Fix bug when filter guild function does not match against guild size correctly when the guild has member count = 100 or 1000

According to habitica wiki Guilds Guide, gold-tier guilds are guilds with 1000 or more members.  However, under the current code of filter guild function, it matches guilds as gold-tier as strictly more than 1000 members, excluding 1000 members.  Similar silver-tier guilds should have 100 to 999 members, but the current code it matches guilds as silver-tier for members between 101 and 999 members.

* Added unit tests to test the newly added code in the groupsUtilities mixin for the current issue

* Add unit testing to test search guild name, summary, and description in myGuilds component

* Add suggestions from lint

* Added searching by guild summary and white space handling in search terms.

For discover guilds component, added the following:
1) handling of searching by guild summary
2) preventing white space in search terms to display all guilds
3) added test cases for testing the search functionality in discove guilds to ensure consistent behaviour between the searching in MyGuilds and public guilds.

* Remove console statements from test file

* Implement suggestions from lint.

Co-authored-by: osiris <eynsan@yahoo.co.uk>
2020-03-16 20:03:48 +01:00

108 lines
2.6 KiB
JavaScript

import { shallowMount, createLocalVue } from '@vue/test-utils';
import Store from '@/libs/store';
import myGuilds from '@/components/groups/myGuilds';
import PublicGuildItem from '@/components/groups/publicGuildItem';
const localVue = createLocalVue();
localVue.use(Store);
describe('myGuilds component', () => {
let computed;
const guilds = [{
_id: '1',
type: 'guild',
name: 'Crimson Vow',
summary: 'testing',
description: 'testing',
}, {
_id: '2',
type: 'guild',
name: 'Log Horizon',
summary: 'testing',
description: 'testing',
}, {
_id: '3',
type: 'guild',
name: 'CAD Cads',
summary: '3D',
description: '3D',
}, {
_id: '4',
type: 'guild',
name: 'Santa Claus',
summary: '3d',
description: 'hohoho',
}];
const store = new Store({
state: {
user: {
data: {
_id: '999',
guilds: ['1', '2', '3', '4'],
},
},
editingGroup: {},
constants: {
TAVERN_ID: '9999',
},
},
getters: {},
actions: {
'guilds:getMyGuilds': () => guilds,
},
});
function makeWrapper (opts = {}) {
return shallowMount(myGuilds, {
data () {
return {
filter: {},
search: '',
};
},
store,
localVue,
...opts,
});
}
before(() => {
computed = {
guilds: () => guilds,
};
});
it('renders all guilds with no filter and no search', () => {
const wrapper = makeWrapper({ computed });
expect(wrapper.findAll(PublicGuildItem).length).to.equal(4);
});
it('renders guilds with name matching against a single-word search term', () => {
const search = 'vow';
const wrapper = makeWrapper({ computed });
wrapper.setData({ search });
expect(wrapper.findAll(PublicGuildItem).length).to.equal(1);
});
it('renders guilds with summary matching against a single-word search term', () => {
const search = '3d';
const wrapper = makeWrapper({ computed });
wrapper.setData({ search });
expect(wrapper.findAll(PublicGuildItem).length).to.equal(2);
});
it('renders guilds with description matching against a single-word search term', () => {
const search = 'hoho';
const wrapper = makeWrapper({ computed });
wrapper.setData({ search });
expect(wrapper.findAll(PublicGuildItem).length).to.equal(1);
});
it('renders guilds with summary matching against two search terms with space in between', () => {
const search = '3d ohayou';
const wrapper = makeWrapper({ computed });
wrapper.setData({ search });
expect(wrapper.findAll(PublicGuildItem).length).to.equal(2);
});
});