mirror of
https://github.com/bringout/oca-ocb-hr.git
synced 2026-04-24 09:12:03 +02:00
Initial commit: Hr packages
This commit is contained in:
commit
62531cd146
2820 changed files with 1432848 additions and 0 deletions
|
|
@ -0,0 +1,10 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import { addFakeModel, addModelNamesToFetch } from '@bus/../tests/helpers/model_definitions_helpers';
|
||||
|
||||
addModelNamesToFetch(['hr.employee.public']);
|
||||
|
||||
addFakeModel('m2x.avatar.employee', {
|
||||
employee_id: { string: "Employee", type: 'many2one', relation: 'hr.employee.public' },
|
||||
employee_ids: { string: "Employees", type: "many2many", relation: 'hr.employee.public' },
|
||||
});
|
||||
|
|
@ -0,0 +1,182 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import {
|
||||
start,
|
||||
startServer,
|
||||
} from '@mail/../tests/helpers/test_utils';
|
||||
|
||||
import { makeFakeNotificationService } from "@web/../tests/helpers/mock_services";
|
||||
|
||||
import { Many2OneAvatarEmployee } from '@hr/js/m2x_avatar_employee';
|
||||
import { dom } from 'web.test_utils';
|
||||
|
||||
QUnit.module('hr', {}, function () {
|
||||
QUnit.module('M2XAvatarEmployeeLegacy', {
|
||||
beforeEach() {
|
||||
Many2OneAvatarEmployee.prototype.partnerIds = {};
|
||||
},
|
||||
});
|
||||
|
||||
QUnit.test('many2one_avatar_employee: click on an employee not associated with a user', async function (assert) {
|
||||
assert.expect(6);
|
||||
|
||||
const pyEnv = await startServer();
|
||||
const hrEmployeePublicId1 = pyEnv['hr.employee.public'].create({ name: 'Mario' });
|
||||
const m2xHrAvatarUserId1 = pyEnv['m2x.avatar.employee'].create({ employee_id: hrEmployeePublicId1 });
|
||||
const views = {
|
||||
'm2x.avatar.employee,false,form': '<form js_class="legacy_form"><field name="employee_id" widget="many2one_avatar_employee"/></form>',
|
||||
};
|
||||
const { openView } = await start({
|
||||
mockRPC(route, args) {
|
||||
if (args.method === 'read') {
|
||||
assert.step(`read ${args.model} ${args.args[0]}`);
|
||||
}
|
||||
},
|
||||
serverData: { views },
|
||||
services: {
|
||||
notification: makeFakeNotificationService(message => {
|
||||
assert.ok(
|
||||
true,
|
||||
"should display a toast notification after failing to open chat"
|
||||
);
|
||||
assert.strictEqual(
|
||||
message,
|
||||
"You can only chat with employees that have a dedicated user.",
|
||||
"should display the correct information in the notification"
|
||||
);
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
await openView({
|
||||
res_model: 'm2x.avatar.employee',
|
||||
res_id: m2xHrAvatarUserId1,
|
||||
views: [[false, 'form']],
|
||||
});
|
||||
assert.strictEqual(document.querySelector('.o_field_widget[name=employee_id]').innerText.trim(), 'Mario');
|
||||
|
||||
await dom.click(document.querySelector('.o_m2o_avatar > img'));
|
||||
|
||||
assert.verifySteps([
|
||||
`read m2x.avatar.employee ${m2xHrAvatarUserId1}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId1}`,
|
||||
]);
|
||||
});
|
||||
|
||||
QUnit.test('many2many_avatar_employee widget in form view', async function (assert) {
|
||||
assert.expect(8);
|
||||
|
||||
const pyEnv = await startServer();
|
||||
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([{}, {}]);
|
||||
const [resUsersId1, resUsersId2] = pyEnv['res.users'].create([{}, {}]);
|
||||
const [hrEmployeePublicId1, hrEmployeePublicId2] = pyEnv['hr.employee.public'].create([
|
||||
{ user_id: resUsersId1, user_partner_id: resPartnerId1 },
|
||||
{ user_id: resUsersId2, user_partner_id: resPartnerId2 },
|
||||
]);
|
||||
const m2xAvatarEmployeeId1 = pyEnv['m2x.avatar.employee'].create(
|
||||
{ employee_ids: [hrEmployeePublicId1, hrEmployeePublicId2] },
|
||||
);
|
||||
const views = {
|
||||
'm2x.avatar.employee,false,form': '<form js_class="legacy_form"><field name="employee_ids" widget="many2many_avatar_employee"/></form>',
|
||||
};
|
||||
const { openView } = await start({
|
||||
mockRPC(route, args) {
|
||||
if (args.method === 'read') {
|
||||
assert.step(`read ${args.model} ${args.args[0]}`);
|
||||
}
|
||||
},
|
||||
serverData: { views },
|
||||
});
|
||||
|
||||
await openView({
|
||||
res_model: 'm2x.avatar.employee',
|
||||
res_id: m2xAvatarEmployeeId1,
|
||||
views: [[false, 'form']],
|
||||
});
|
||||
assert.containsN(document.body, '.o_field_many2manytags.avatar.o_field_widget .badge', 2,
|
||||
"should have 2 records");
|
||||
assert.strictEqual(document.querySelector('.o_field_many2manytags.avatar.o_field_widget .badge img').getAttribute('data-src'),
|
||||
`/web/image/hr.employee.public/${hrEmployeePublicId1}/avatar_128`,
|
||||
"should have correct avatar image");
|
||||
|
||||
await dom.click(document.querySelector('.o_field_many2manytags.avatar .badge .o_m2m_avatar'));
|
||||
await dom.click(document.querySelectorAll('.o_field_many2manytags.avatar .badge .o_m2m_avatar')[1]);
|
||||
|
||||
assert.verifySteps([
|
||||
`read m2x.avatar.employee ${m2xAvatarEmployeeId1}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId1},${hrEmployeePublicId2}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId1}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId2}`,
|
||||
]);
|
||||
|
||||
assert.containsN(
|
||||
document.body,
|
||||
'.o_ChatWindowHeader_name',
|
||||
2,
|
||||
"should have 2 chat windows"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('many2many_avatar_employee: click on an employee not associated with a user', async function (assert) {
|
||||
assert.expect(10);
|
||||
|
||||
const pyEnv = await startServer();
|
||||
const resPartnerId1 = pyEnv['res.partner'].create({});
|
||||
const resUsersId1 = pyEnv['res.users'].create({});
|
||||
const [hrEmployeePublicId1, hrEmployeePublicId2] = pyEnv['hr.employee.public'].create([
|
||||
{},
|
||||
{ user_id: resUsersId1, user_partner_id: resPartnerId1 },
|
||||
]);
|
||||
const m2xAvatarEmployeeId1 = pyEnv['m2x.avatar.employee'].create(
|
||||
{ employee_ids: [hrEmployeePublicId1, hrEmployeePublicId2] },
|
||||
);
|
||||
const views = {
|
||||
'm2x.avatar.employee,false,form': '<form js_class="legacy_form"><field name="employee_ids" widget="many2many_avatar_employee"/></form>',
|
||||
};
|
||||
const { openView } = await start({
|
||||
mockRPC(route, args) {
|
||||
if (args.method === 'read') {
|
||||
assert.step(`read ${args.model} ${args.args[0]}`);
|
||||
}
|
||||
},
|
||||
serverData: { views },
|
||||
services: {
|
||||
notification: makeFakeNotificationService(message => {
|
||||
assert.ok(
|
||||
true,
|
||||
"should display a toast notification after failing to open chat"
|
||||
);
|
||||
assert.strictEqual(
|
||||
message,
|
||||
"You can only chat with employees that have a dedicated user.",
|
||||
"should display the correct information in the notification"
|
||||
);
|
||||
}),
|
||||
},
|
||||
});
|
||||
await openView({
|
||||
res_model: 'm2x.avatar.employee',
|
||||
res_id: m2xAvatarEmployeeId1,
|
||||
views: [[false, 'form']],
|
||||
});
|
||||
|
||||
assert.containsN(document.body, '.o_field_many2manytags.avatar.o_field_widget .badge', 2,
|
||||
"should have 2 records");
|
||||
assert.strictEqual(document.querySelector('.o_field_many2manytags.avatar.o_field_widget .badge img').getAttribute('data-src'),
|
||||
`/web/image/hr.employee.public/${hrEmployeePublicId1}/avatar_128`,
|
||||
"should have correct avatar image");
|
||||
|
||||
await dom.click(document.querySelector('.o_field_many2manytags.avatar .badge .o_m2m_avatar'));
|
||||
await dom.click(document.querySelectorAll('.o_field_many2manytags.avatar .badge .o_m2m_avatar')[1]);
|
||||
|
||||
assert.verifySteps([
|
||||
`read m2x.avatar.employee ${hrEmployeePublicId1}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId1},${hrEmployeePublicId2}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId1}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId2}`
|
||||
]);
|
||||
|
||||
assert.containsOnce(document.body, '.o_ChatWindowHeader_name',
|
||||
"should have 1 chat window");
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,450 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import {
|
||||
afterNextRender,
|
||||
start,
|
||||
startServer,
|
||||
} from '@mail/../tests/helpers/test_utils';
|
||||
|
||||
import { makeFakeNotificationService } from "@web/../tests/helpers/mock_services";
|
||||
|
||||
import { Many2OneAvatarEmployee } from '@hr/js/m2x_avatar_employee';
|
||||
import { dom } from 'web.test_utils';
|
||||
|
||||
QUnit.module('hr', {}, function () {
|
||||
QUnit.module('M2XAvatarEmployee', {
|
||||
beforeEach() {
|
||||
Many2OneAvatarEmployee.prototype.partnerIds = {};
|
||||
},
|
||||
});
|
||||
|
||||
QUnit.test('many2one_avatar_employee widget in list view', async function (assert) {
|
||||
assert.expect(13);
|
||||
|
||||
const pyEnv = await startServer();
|
||||
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([
|
||||
{ display_name: "Mario" },
|
||||
{ display_name: "Luigi" },
|
||||
]);
|
||||
const [resUsersId1, resUsersId2] = pyEnv['res.users'].create([
|
||||
{ partner_id: resPartnerId1 },
|
||||
{ partner_id: resPartnerId2 },
|
||||
]);
|
||||
const [hrEmployeePublicId1, hrEmployeePublicId2] = pyEnv['hr.employee.public'].create([
|
||||
{ name: "Mario", user_id: resUsersId1, user_partner_id: resPartnerId1 },
|
||||
{ name: "Luigi", user_id: resUsersId2, user_partner_id: resPartnerId2 },
|
||||
]);
|
||||
pyEnv['m2x.avatar.employee'].create([
|
||||
{ employee_id: hrEmployeePublicId1, employee_ids: [hrEmployeePublicId1, hrEmployeePublicId2] },
|
||||
{ employee_id: hrEmployeePublicId2 },
|
||||
{ employee_id: hrEmployeePublicId1 },
|
||||
]);
|
||||
const views = {
|
||||
'm2x.avatar.employee,false,list': '<tree><field name="employee_id" widget="many2one_avatar_employee"/></tree>',
|
||||
};
|
||||
const { openView } = await start({
|
||||
mockRPC(route, args) {
|
||||
if (args.method === 'read') {
|
||||
assert.step(`read ${args.model} ${args.args[0]}`);
|
||||
}
|
||||
},
|
||||
serverData: { views },
|
||||
});
|
||||
await openView({
|
||||
res_model: 'm2x.avatar.employee',
|
||||
views: [[false, 'list']],
|
||||
});
|
||||
|
||||
assert.strictEqual(document.querySelector('.o_data_cell span:not(.o_m2o_avatar) span').innerText, 'Mario');
|
||||
assert.strictEqual(document.querySelectorAll('.o_data_cell span:not(.o_m2o_avatar) span')[1].innerText, 'Luigi');
|
||||
assert.strictEqual(document.querySelectorAll('.o_data_cell span:not(.o_m2o_avatar) span')[2].innerText, 'Mario');
|
||||
|
||||
// click on first employee
|
||||
await afterNextRender(() =>
|
||||
dom.click(document.querySelector('.o_data_cell .o_m2o_avatar > img'))
|
||||
);
|
||||
assert.verifySteps(
|
||||
[`read hr.employee.public ${hrEmployeePublicId1}`],
|
||||
"first employee should have been read to find its partner"
|
||||
);
|
||||
assert.containsOnce(
|
||||
document.body,
|
||||
'.o_ChatWindowHeader_name',
|
||||
'should have opened chat window'
|
||||
);
|
||||
assert.strictEqual(
|
||||
document.querySelector('.o_ChatWindowHeader_name').textContent,
|
||||
"Mario",
|
||||
'chat window should be with clicked employee'
|
||||
);
|
||||
|
||||
// click on second employee
|
||||
await afterNextRender(() =>
|
||||
dom.click(document.querySelectorAll('.o_data_cell .o_m2o_avatar > img')[1]
|
||||
));
|
||||
assert.verifySteps(
|
||||
[`read hr.employee.public ${hrEmployeePublicId2}`],
|
||||
"second employee should have been read to find its partner"
|
||||
);
|
||||
assert.containsN(
|
||||
document.body,
|
||||
'.o_ChatWindowHeader_name',
|
||||
2,
|
||||
'should have opened second chat window'
|
||||
);
|
||||
assert.strictEqual(
|
||||
document.querySelectorAll('.o_ChatWindowHeader_name')[1].textContent,
|
||||
"Luigi",
|
||||
'chat window should be with clicked employee'
|
||||
);
|
||||
|
||||
// click on third employee (same as first)
|
||||
await afterNextRender(() =>
|
||||
dom.click(document.querySelectorAll('.o_data_cell .o_m2o_avatar > img')[2])
|
||||
);
|
||||
assert.verifySteps(
|
||||
[],
|
||||
"employee should not have been read again because we already know its partner"
|
||||
);
|
||||
assert.containsN(
|
||||
document.body,
|
||||
'.o_ChatWindowHeader_name',
|
||||
2,
|
||||
"should still have only 2 chat windows because third is the same partner as first"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('many2one_avatar_employee widget in kanban view', async function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
const pyEnv = await startServer();
|
||||
const resPartnerId1 = pyEnv['res.partner'].create({});
|
||||
const resUsersId1 = pyEnv['res.users'].create({ partner_id: resPartnerId1 });
|
||||
const hrEmployeePublicId1 = pyEnv['hr.employee.public'].create({ user_id: resUsersId1, user_partner_id: resPartnerId1 });
|
||||
pyEnv['m2x.avatar.employee'].create({ employee_id: hrEmployeePublicId1, employee_ids: [hrEmployeePublicId1] });
|
||||
const views = {
|
||||
'm2x.avatar.employee,false,kanban':
|
||||
`<kanban>
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
<div>
|
||||
<field name="employee_id" widget="many2one_avatar_employee"/>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
</kanban>`,
|
||||
};
|
||||
const { openView } = await start({
|
||||
serverData: { views },
|
||||
});
|
||||
await openView({
|
||||
res_model: 'm2x.avatar.employee',
|
||||
views: [[false, 'kanban']],
|
||||
});
|
||||
|
||||
assert.strictEqual(document.querySelector('.o_kanban_record').innerText.trim(), '');
|
||||
assert.containsOnce(document.body, '.o_m2o_avatar');
|
||||
assert.strictEqual(document.querySelector('.o_m2o_avatar > img').getAttribute('data-src'), `/web/image/hr.employee.public/${hrEmployeePublicId1}/avatar_128`);
|
||||
});
|
||||
|
||||
QUnit.test('many2one_avatar_employee: click on an employee not associated with a user', async function (assert) {
|
||||
assert.expect(6);
|
||||
|
||||
const pyEnv = await startServer();
|
||||
const hrEmployeePublicId1 = pyEnv['hr.employee.public'].create({ name: 'Mario' });
|
||||
const m2xHrAvatarUserId1 = pyEnv['m2x.avatar.employee'].create({ employee_id: hrEmployeePublicId1 });
|
||||
const views = {
|
||||
'm2x.avatar.employee,false,form': '<form><field name="employee_id" widget="many2one_avatar_employee"/></form>',
|
||||
};
|
||||
const { openView } = await start({
|
||||
mockRPC(route, args) {
|
||||
if (args.method === 'read') {
|
||||
assert.step(`read ${args.model} ${args.args[0]}`);
|
||||
}
|
||||
},
|
||||
serverData: { views },
|
||||
services: {
|
||||
notification: makeFakeNotificationService(message => {
|
||||
assert.ok(
|
||||
true,
|
||||
"should display a toast notification after failing to open chat"
|
||||
);
|
||||
assert.strictEqual(
|
||||
message,
|
||||
"You can only chat with employees that have a dedicated user.",
|
||||
"should display the correct information in the notification"
|
||||
);
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
await openView({
|
||||
res_model: 'm2x.avatar.employee',
|
||||
res_id: m2xHrAvatarUserId1,
|
||||
views: [[false, 'form']],
|
||||
});
|
||||
assert.strictEqual(document.querySelector('.o_field_widget[name=employee_id] input').value.trim(), 'Mario');
|
||||
|
||||
await dom.click(document.querySelector('.o_m2o_avatar > img'));
|
||||
|
||||
assert.verifySteps([
|
||||
`read m2x.avatar.employee ${m2xHrAvatarUserId1}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId1}`,
|
||||
]);
|
||||
});
|
||||
|
||||
QUnit.test('many2many_avatar_employee widget in form view', async function (assert) {
|
||||
assert.expect(8);
|
||||
|
||||
const pyEnv = await startServer();
|
||||
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([{}, {}]);
|
||||
const [resUsersId1, resUsersId2] = pyEnv['res.users'].create([{}, {}]);
|
||||
const [hrEmployeePublicId1, hrEmployeePublicId2] = pyEnv['hr.employee.public'].create([
|
||||
{ user_id: resUsersId1, user_partner_id: resPartnerId1 },
|
||||
{ user_id: resUsersId2, user_partner_id: resPartnerId2 },
|
||||
]);
|
||||
const m2xAvatarEmployeeId1 = pyEnv['m2x.avatar.employee'].create(
|
||||
{ employee_ids: [hrEmployeePublicId1, hrEmployeePublicId2] },
|
||||
);
|
||||
const views = {
|
||||
'm2x.avatar.employee,false,form': '<form><field name="employee_ids" widget="many2many_avatar_employee"/></form>',
|
||||
};
|
||||
const { openView } = await start({
|
||||
mockRPC(route, args) {
|
||||
if (args.method === 'read') {
|
||||
assert.step(`read ${args.model} ${args.args[0]}`);
|
||||
}
|
||||
},
|
||||
serverData: { views },
|
||||
});
|
||||
|
||||
await openView({
|
||||
res_model: 'm2x.avatar.employee',
|
||||
res_id: m2xAvatarEmployeeId1,
|
||||
views: [[false, 'form']],
|
||||
});
|
||||
assert.containsN(document.body, '.o_field_many2many_avatar_employee .badge', 2,
|
||||
"should have 2 records");
|
||||
assert.strictEqual(document.querySelector('.o_field_many2many_avatar_employee .badge img').getAttribute('data-src'),
|
||||
`/web/image/hr.employee.public/${hrEmployeePublicId1}/avatar_128`,
|
||||
"should have correct avatar image");
|
||||
|
||||
await dom.click(document.querySelector('.o_field_many2many_avatar_employee .badge .o_m2m_avatar'));
|
||||
await dom.click(document.querySelectorAll('.o_field_many2many_avatar_employee .badge .o_m2m_avatar')[1]);
|
||||
|
||||
assert.verifySteps([
|
||||
`read m2x.avatar.employee ${m2xAvatarEmployeeId1}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId1},${hrEmployeePublicId2}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId1}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId2}`,
|
||||
]);
|
||||
|
||||
assert.containsN(
|
||||
document.body,
|
||||
'.o_ChatWindowHeader_name',
|
||||
2,
|
||||
"should have 2 chat windows"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('many2many_avatar_employee widget in list view', async function (assert) {
|
||||
assert.expect(10);
|
||||
|
||||
const pyEnv = await startServer();
|
||||
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([
|
||||
{ name: "Mario" },
|
||||
{ name: "Yoshi" },
|
||||
]);
|
||||
const [resUsersId1, resUsersId2] = pyEnv['res.users'].create([{}, {}]);
|
||||
const [hrEmployeePublicId1, hrEmployeePublicId2] = pyEnv['hr.employee.public'].create([
|
||||
{ user_id: resUsersId1, user_partner_id: resPartnerId1 },
|
||||
{ user_id: resUsersId2, user_partner_id: resPartnerId2 },
|
||||
]);
|
||||
pyEnv['m2x.avatar.employee'].create(
|
||||
{ employee_ids: [hrEmployeePublicId1, hrEmployeePublicId2] },
|
||||
);
|
||||
const views = {
|
||||
'm2x.avatar.employee,false,list': '<tree><field name="employee_ids" widget="many2many_avatar_employee"/></tree>',
|
||||
};
|
||||
const { openView } = await start({
|
||||
mockRPC(route, args) {
|
||||
if (args.method === 'read') {
|
||||
assert.step(`read ${args.model} ${args.args[0]}`);
|
||||
}
|
||||
},
|
||||
serverData: { views },
|
||||
});
|
||||
|
||||
await openView({
|
||||
res_model: 'm2x.avatar.employee',
|
||||
views: [[false, 'list']],
|
||||
});
|
||||
assert.containsN(document.body, '.o_data_cell:first .o_field_many2many_avatar_employee > div > span', 2,
|
||||
"should have two avatar");
|
||||
|
||||
// click on first employee badge
|
||||
await afterNextRender(() =>
|
||||
dom.click(document.querySelector('.o_data_cell .o_m2m_avatar'))
|
||||
);
|
||||
assert.verifySteps(
|
||||
[`read hr.employee.public ${hrEmployeePublicId1},${hrEmployeePublicId2}`, `read hr.employee.public ${hrEmployeePublicId1}`],
|
||||
"first employee should have been read to find its partner"
|
||||
);
|
||||
assert.containsOnce(
|
||||
document.body,
|
||||
'.o_ChatWindowHeader_name',
|
||||
'should have opened chat window'
|
||||
);
|
||||
assert.strictEqual(
|
||||
document.querySelector('.o_ChatWindowHeader_name').textContent,
|
||||
"Mario",
|
||||
'chat window should be with clicked employee'
|
||||
);
|
||||
|
||||
// click on second employee
|
||||
await afterNextRender(() =>
|
||||
dom.click(document.querySelectorAll('.o_data_cell .o_m2m_avatar')[1])
|
||||
);
|
||||
assert.verifySteps(
|
||||
[`read hr.employee.public ${hrEmployeePublicId2}`],
|
||||
"second employee should have been read to find its partner"
|
||||
);
|
||||
assert.containsN(
|
||||
document.body,
|
||||
'.o_ChatWindowHeader_name',
|
||||
2,
|
||||
'should have opened second chat window'
|
||||
);
|
||||
assert.strictEqual(
|
||||
document.querySelectorAll('.o_ChatWindowHeader_name')[1].textContent,
|
||||
"Yoshi",
|
||||
'chat window should be with clicked employee'
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('many2many_avatar_employee widget in kanban view', async function (assert) {
|
||||
assert.expect(7);
|
||||
|
||||
const pyEnv = await startServer();
|
||||
const [resPartnerId1, resPartnerId2] = pyEnv['res.partner'].create([{}, {}]);
|
||||
const [resUsersId1, resUsersId2] = pyEnv['res.users'].create([{}, {}]);
|
||||
const [hrEmployeePublicId1, hrEmployeePublicId2] = pyEnv['hr.employee.public'].create([
|
||||
{ user_id: resUsersId1, user_partner_id: resPartnerId1 },
|
||||
{ user_id: resUsersId2, user_partner_id: resPartnerId2 },
|
||||
]);
|
||||
pyEnv['m2x.avatar.employee'].create(
|
||||
{ employee_ids: [hrEmployeePublicId1, hrEmployeePublicId2] },
|
||||
);
|
||||
const views = {
|
||||
'm2x.avatar.employee,false,kanban':
|
||||
`<kanban>
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
<div>
|
||||
<div class="oe_kanban_footer">
|
||||
<div class="o_kanban_record_bottom">
|
||||
<div class="oe_kanban_bottom_right">
|
||||
<field name="employee_ids" widget="many2many_avatar_employee"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
</kanban>`,
|
||||
};
|
||||
const { openView } = await start({
|
||||
mockRPC(route, args) {
|
||||
if (args.method === 'read') {
|
||||
assert.step(`read ${args.model} ${args.args[0]}`);
|
||||
}
|
||||
},
|
||||
serverData: { views },
|
||||
});
|
||||
|
||||
await openView({
|
||||
res_model: 'm2x.avatar.employee',
|
||||
views: [[false, 'kanban']],
|
||||
});
|
||||
assert.containsN(document.body, '.o_kanban_record:first .o_field_many2many_avatar_employee img.o_m2m_avatar', 2,
|
||||
"should have 2 avatar images");
|
||||
assert.strictEqual(document.querySelector('.o_kanban_record .o_field_many2many_avatar_employee img.o_m2m_avatar').getAttribute('data-src'),
|
||||
`/web/image/hr.employee.public/${hrEmployeePublicId1}/avatar_128`,
|
||||
"should have correct avatar image");
|
||||
assert.strictEqual(document.querySelectorAll('.o_kanban_record .o_field_many2many_avatar_employee img.o_m2m_avatar')[1].getAttribute('data-src'),
|
||||
`/web/image/hr.employee.public/${hrEmployeePublicId2}/avatar_128`,
|
||||
"should have correct avatar image");
|
||||
|
||||
await dom.click(document.querySelector('.o_kanban_record .o_m2m_avatar'));
|
||||
await dom.click(document.querySelectorAll('.o_kanban_record .o_m2m_avatar')[1]);
|
||||
|
||||
assert.verifySteps([
|
||||
`read hr.employee.public ${hrEmployeePublicId1},${hrEmployeePublicId2}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId1}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId2}`
|
||||
]);
|
||||
});
|
||||
|
||||
QUnit.test('many2many_avatar_employee: click on an employee not associated with a user', async function (assert) {
|
||||
assert.expect(10);
|
||||
|
||||
const pyEnv = await startServer();
|
||||
const resPartnerId1 = pyEnv['res.partner'].create({});
|
||||
const resUsersId1 = pyEnv['res.users'].create({});
|
||||
const [hrEmployeePublicId1, hrEmployeePublicId2] = pyEnv['hr.employee.public'].create([
|
||||
{},
|
||||
{ user_id: resUsersId1, user_partner_id: resPartnerId1 },
|
||||
]);
|
||||
const m2xAvatarEmployeeId1 = pyEnv['m2x.avatar.employee'].create(
|
||||
{ employee_ids: [hrEmployeePublicId1, hrEmployeePublicId2] },
|
||||
);
|
||||
const views = {
|
||||
'm2x.avatar.employee,false,form': '<form><field name="employee_ids" widget="many2many_avatar_employee"/></form>',
|
||||
};
|
||||
const { openView } = await start({
|
||||
mockRPC(route, args) {
|
||||
if (args.method === 'read') {
|
||||
assert.step(`read ${args.model} ${args.args[0]}`);
|
||||
}
|
||||
},
|
||||
serverData: { views },
|
||||
services: {
|
||||
notification: makeFakeNotificationService(message => {
|
||||
assert.ok(
|
||||
true,
|
||||
"should display a toast notification after failing to open chat"
|
||||
);
|
||||
assert.strictEqual(
|
||||
message,
|
||||
"You can only chat with employees that have a dedicated user.",
|
||||
"should display the correct information in the notification"
|
||||
);
|
||||
}),
|
||||
},
|
||||
});
|
||||
await openView({
|
||||
res_model: 'm2x.avatar.employee',
|
||||
res_id: m2xAvatarEmployeeId1,
|
||||
views: [[false, 'form']],
|
||||
});
|
||||
|
||||
assert.containsN(document.body, '.o_field_many2many_avatar_employee .badge', 2,
|
||||
"should have 2 records");
|
||||
assert.strictEqual(document.querySelector('.o_field_many2many_avatar_employee .badge img').getAttribute('data-src'),
|
||||
`/web/image/hr.employee.public/${hrEmployeePublicId1}/avatar_128`,
|
||||
"should have correct avatar image");
|
||||
|
||||
await dom.click(document.querySelector('.o_field_many2many_avatar_employee .badge .o_m2m_avatar'));
|
||||
await dom.click(document.querySelectorAll('.o_field_many2many_avatar_employee .badge .o_m2m_avatar')[1]);
|
||||
|
||||
assert.verifySteps([
|
||||
`read m2x.avatar.employee ${hrEmployeePublicId1}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId1},${hrEmployeePublicId2}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId1}`,
|
||||
`read hr.employee.public ${hrEmployeePublicId2}`
|
||||
]);
|
||||
|
||||
assert.containsOnce(document.body, '.o_ChatWindowHeader_name',
|
||||
"should have 1 chat window");
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
|
||||
import AbstractRendererOwl from 'web.AbstractRendererOwl';
|
||||
import BasicView from "web.BasicView";
|
||||
import BasicRenderer from "web.BasicRenderer";
|
||||
import RendererWrapper from 'web.RendererWrapper';
|
||||
import { createView } from 'web.test_utils';
|
||||
|
||||
import StandaloneM2OAvatarEmployee from '@hr/js/standalone_m2o_avatar_employee';
|
||||
|
||||
const { xml } = owl;
|
||||
|
||||
function getHtmlRenderer(html) {
|
||||
return BasicRenderer.extend({
|
||||
start: function () {
|
||||
this.$el.html(html);
|
||||
return this._super.apply(this, arguments);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getOwlView(owlRenderer, viewType) {
|
||||
viewType = viewType || "test";
|
||||
return BasicView.extend({
|
||||
viewType: viewType,
|
||||
config: Object.assign({}, BasicView.prototype.config, {
|
||||
Renderer: owlRenderer,
|
||||
}),
|
||||
getRenderer() {
|
||||
return new RendererWrapper(null, this.config.Renderer, {});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getHtmlView(html, viewType) {
|
||||
viewType = viewType || "test";
|
||||
return BasicView.extend({
|
||||
viewType: viewType,
|
||||
config: Object.assign({}, BasicView.prototype.config, {
|
||||
Renderer: getHtmlRenderer(html)
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
QUnit.module('hr', {}, function () {
|
||||
QUnit.module('StandaloneM2OEmployeeTests', {
|
||||
beforeEach: function () {
|
||||
this.data = {
|
||||
'foo': {
|
||||
fields: {
|
||||
employee_id: {string: "Employee", type: 'many2one', relation: 'hr.employee'},
|
||||
},
|
||||
records: [],
|
||||
},
|
||||
'hr.employee': {
|
||||
fields: {},
|
||||
records: [
|
||||
{id: 10, name: "Mario"},
|
||||
{id: 20, name: "Luigi"},
|
||||
{id: 30, name: "Yoshi"}
|
||||
],
|
||||
},
|
||||
'hr.employee.public': {
|
||||
fields: {},
|
||||
records: [
|
||||
{id: 10, name: "Mario"},
|
||||
{id: 20, name: "Luigi"},
|
||||
{id: 30, name: "Yoshi"}
|
||||
],
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
QUnit.test('standalone_m2o_avatar_employee: legacy view', async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
const html = "<div class='coucou_test'></div>";
|
||||
const view = await createView({
|
||||
View: getHtmlView(html, "test"),
|
||||
data: this.data,
|
||||
model: "foo",
|
||||
arch: "<test/>"
|
||||
});
|
||||
|
||||
const avatar10 = new StandaloneM2OAvatarEmployee(view, 10);
|
||||
const avatar20 = new StandaloneM2OAvatarEmployee(view, 20);
|
||||
const avatar30 = new StandaloneM2OAvatarEmployee(view, [30, 'Bowser']);
|
||||
|
||||
await avatar10.appendTo(view.el.querySelector('.coucou_test'));
|
||||
await avatar20.appendTo(view.el.querySelector('.coucou_test'));
|
||||
await avatar30.appendTo(view.el.querySelector('.coucou_test'));
|
||||
|
||||
assert.deepEqual(
|
||||
[...view.el.querySelectorAll('.o_field_many2one_avatar span')].map(el => el.innerText),
|
||||
["Mario", "Luigi", "Bowser"]
|
||||
);
|
||||
|
||||
view.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('standalone_m2o_avatar_employee: Owl view', async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
class Renderer extends AbstractRendererOwl { }
|
||||
Renderer.template = xml`<div class='coucou_test'></div>`;
|
||||
|
||||
const view = await createView({
|
||||
View: getOwlView(Renderer, "test"),
|
||||
data: this.data,
|
||||
model: "foo",
|
||||
arch: "<test/>"
|
||||
});
|
||||
|
||||
const avatar10 = new StandaloneM2OAvatarEmployee(view, 10);
|
||||
const avatar20 = new StandaloneM2OAvatarEmployee(view, 20);
|
||||
const avatar30 = new StandaloneM2OAvatarEmployee(view, [30, 'Bowser']);
|
||||
|
||||
await avatar10.appendTo(view.el.querySelector('.coucou_test'));
|
||||
await avatar20.appendTo(view.el.querySelector('.coucou_test'));
|
||||
await avatar30.appendTo(view.el.querySelector('.coucou_test'));
|
||||
|
||||
assert.deepEqual(
|
||||
[...view.el.querySelectorAll('.o_field_many2one_avatar span')].map(el => el.innerText),
|
||||
["Mario", "Luigi", "Bowser"]
|
||||
);
|
||||
|
||||
view.destroy();
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import tour from 'web_tour.tour';
|
||||
|
||||
tour.register('hr_employee_tour', {
|
||||
test: true,
|
||||
url: '/web',
|
||||
}, [
|
||||
tour.stepUtils.showAppsMenuItem(),
|
||||
{
|
||||
content: "Open Employees app",
|
||||
trigger: ".o_app[data-menu-xmlid='hr.menu_hr_root']",
|
||||
run: 'click',
|
||||
},
|
||||
{
|
||||
content: "Open an Employee Profile",
|
||||
trigger: ".o_kanban_record_title:contains('Johnny H.')",
|
||||
run: 'click',
|
||||
},
|
||||
{
|
||||
content: "Open user account menu",
|
||||
trigger: ".o_user_menu .oe_topbar_name",
|
||||
run: 'click',
|
||||
}, {
|
||||
content: "Open My Profile",
|
||||
trigger: "[data-menu=settings]",
|
||||
run: 'click',
|
||||
},
|
||||
]);
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import tour from 'web_tour.tour';
|
||||
|
||||
/**
|
||||
* As 'hr' changes the flow a bit and displays the user preferences form in a full view instead of
|
||||
* a modal, we adapt the steps of the original tour accordingly.
|
||||
*/
|
||||
tour.tours['mail/static/tests/tours/user_modify_own_profile_tour.js'].steps = [{
|
||||
content: 'Open user account menu',
|
||||
trigger: '.o_user_menu button',
|
||||
}, {
|
||||
content: "Open preferences / profile screen",
|
||||
trigger: '[data-menu=settings]',
|
||||
}, {
|
||||
content: "Update the email address",
|
||||
trigger: 'div[name="email"] input',
|
||||
run: 'text updatedemail@example.com',
|
||||
}, ...tour.stepUtils.saveForm()];
|
||||
Loading…
Add table
Add a link
Reference in a new issue