first commit

This commit is contained in:
2024-11-05 12:22:50 +01:00
commit e5682a3912
19641 changed files with 2948548 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
import Vue from 'vue';
import {shallowMount} from '@vue/test-utils';
import Button from '@components/Button/Button.vue';
import EventBus from '@components/EventBus';
describe('Button.vue', () => {
it('should stay unchecked if user is not logged in', async () => {
const wrapper = shallowMount(Button);
expect(wrapper.vm.isChecked).toBe(false);
wrapper.find('button').trigger('click');
await Vue.nextTick();
expect(wrapper.vm.isChecked).toBe(false);
});
it('should be checked if it receive the event addedToWishlist', async () => {
const wrapper = shallowMount(Button, {
propsData: {
productId: 1
}
});
EventBus.$emit('addedToWishlist', {
detail: {productId: 1, listId: 1}
});
expect(wrapper.vm.isChecked).toBe(true);
});
it('should be checked if we passe checked as a prop', async () => {
const wrapper = shallowMount(Button, {
propsData: {
productId: 1,
checked: 'true'
}
});
expect(wrapper.vm.isChecked).toBe(true);
});
});

View File

@@ -0,0 +1,22 @@
import Vue from 'vue';
import {shallowMount, mount} from '@vue/test-utils';
import Create from '@components/Create/Create.vue';
import EventBus from '@components/EventBus';
describe('Create.vue', () => {
it(`should'nt be hidden if it receive the event showCreateWishlist`, async () => {
const wrapper = shallowMount(Create);
EventBus.$emit('showCreateWishlist');
expect(wrapper.vm.isHidden).toBe(false);
});
it('value should be empty if it receive the event addedToWishlist', async () => {
const wrapper = shallowMount(Create);
EventBus.$emit('showCreateWishlist');
expect(wrapper.vm.value).toBe('');
});
});

View File

@@ -0,0 +1,19 @@
import {shallowMount} from '@vue/test-utils';
import Delete from '@components/Delete/Delete.vue';
import EventBus from '@components/EventBus';
describe('Delete.vue', () => {
it(`should'nt be hidden if it receive the event showDelete`, async () => {
const wrapper = shallowMount(Delete);
EventBus.$emit('showDeleteWishlist', {
detail: {
listId: 1,
productId: 1,
productAttributeId: 1
}
});
expect(wrapper.vm.isHidden).toBe(false);
});
});

View File

@@ -0,0 +1,112 @@
import Vue from 'vue';
import { shallowMount, mount } from '@vue/test-utils';
import List from '@components/List/List.vue';
import EventBus from '@components/EventBus';
const items = [
{
id_wishlist: 1,
nbProducts: 2,
name: 'Test of list number one',
listUrl: '#'
},
{
id_wishlist: 2,
nbProducts: 2,
name: 'Test of list 2',
listUrl: '#'
}
];
describe('List.vue', () => {
it('should be loading if no items are provided', async () => {
const wrapper = shallowMount(List);
expect(wrapper.vm.loading).toBe(true);
});
it('should render a list of items if they are provided', async () => {
const wrapper = shallowMount(List, {
propsData: {
loading: false,
items
}
});
expect(wrapper.vm.loading).toBe(false);
expect(wrapper.find('ul li').exists()).toBe(true);
expect(wrapper.findAll('li')).toHaveLength(2);
});
it('should open links popup', async () => {
const wrapper = mount(List, {
propsData: {
loading: false,
items
}
});
expect(wrapper.vm.loading).toBe(false);
const lists = wrapper.findAll('li');
lists.wrappers.forEach(list => {
list.find('.wishlist-list-item-actions').trigger('click');
});
expect(wrapper.vm.activeDropdowns.length).toBe(1);
});
it('should click on share and open share modal', async () => {
EventBus.$on('showShareWishlist', e => {
expect(e.detail.listId).toBe(1);
});
const wrapper = mount(List, {
propsData: {
loading: false,
items,
listId: 1
}
});
expect(wrapper.vm.loading).toBe(false);
const list = wrapper.find('li:first-child');
list.find('.wishlist-list-item-actions').trigger('click');
await Vue.nextTick();
list.find('.dropdown-menu button:last-child').trigger('click');
await Vue.nextTick();
expect(wrapper.vm.activeDropdowns.length).toBe(1);
});
it('should click on rename and open rename modal', async () => {
EventBus.$on('showRenameWishlist', e => {
expect(e.detail.listId).toBe(1);
});
const wrapper = mount(List, {
propsData: {
loading: false,
items,
listId: 1
}
});
expect(wrapper.vm.loading).toBe(false);
const list = wrapper.find('li:first-child');
list.find('.wishlist-list-item-actions').trigger('click');
await Vue.nextTick();
list.find('.dropdown-menu button:first-child').trigger('click');
await Vue.nextTick();
expect(wrapper.vm.activeDropdowns.length).toBe(1);
});
});

View File

@@ -0,0 +1,14 @@
import Vue from 'vue';
import {shallowMount, mount} from '@vue/test-utils';
import Login from '@components/Login/Login.vue';
import EventBus from '@components/EventBus';
describe('Login.vue', () => {
it(`should'nt be hidden if it receive the event showLogin`, async () => {
const wrapper = shallowMount(Login);
EventBus.$emit('showLogin');
expect(wrapper.vm.isHidden).toBe(false);
});
});

View File

@@ -0,0 +1,19 @@
import Vue from 'vue';
import {shallowMount, mount} from '@vue/test-utils';
import Rename from '@components/Rename/Rename.vue';
import EventBus from '@components/EventBus';
describe('Rename.vue', () => {
it(`should'nt be hidden if it receive the event showRenameWishlist`, async () => {
const wrapper = shallowMount(Rename);
EventBus.$emit('showRenameWishlist', {
detail: {
listId: 1,
title: 'Test of title'
}
});
expect(wrapper.vm.isHidden).toBe(false);
});
});

View File

@@ -0,0 +1,48 @@
import Vue from 'vue';
import {shallowMount, mount} from '@vue/test-utils';
import Toast from '@components/Toast/Toast.vue';
import EventBus from '@components/EventBus';
describe('Toast.vue', () => {
it(`should'nt be hidden if it receive the event showToast`, async () => {
const wrapper = shallowMount(Toast);
EventBus.$emit('showToast', {
detail: {
message: 'Test of message'
}
});
expect(wrapper.vm.active).toBe(true);
});
it(`should have a custom message`, async () => {
const wrapper = shallowMount(Toast);
EventBus.$emit('showToast', {
detail: {
message: 'custom'
}
});
expect(wrapper.vm.text).toBe('custom');
});
it(`should be hidden after 2.5s`, function(done) {
const wrapper = shallowMount(Toast);
this.timeout(4000);
EventBus.$emit('showToast', {
detail: {
message: 'Test of message'
}
});
expect(wrapper.vm.active).toBe(true);
setTimeout(() => {
expect(wrapper.vm.active).toBe(false);
done();
}, 3000);
});
});

View File

@@ -0,0 +1,8 @@
require('jsdom-global')();
global.productsAlreadyTagged = [];
global.window.prestashop = {
customer: {
is_logged: false
}
};
global.expect = require('expect');