101 lines
3.9 KiB
JavaScript
101 lines
3.9 KiB
JavaScript
import { basicDocumentsListArch } from "@documents/../tests/helpers/views/list";
|
|
import { defineDocumentSpreadsheetModels } from "@documents_spreadsheet/../tests/helpers/data";
|
|
import { makeDocumentsSpreadsheetMockEnv } from "@documents_spreadsheet/../tests/helpers/model";
|
|
import { mockActionService } from "@documents_spreadsheet/../tests/helpers/spreadsheet_test_utils";
|
|
import { expect, test } from "@odoo/hoot";
|
|
import { contains, mountView } from "@web/../tests/web_test_helpers";
|
|
import { getEnrichedSearchArch } from "@documents/../tests/helpers/views/search";
|
|
import { getDocumentsTestServerModelsData } from "@documents/../tests/helpers/data";
|
|
import { browser } from "@web/core/browser/browser";
|
|
|
|
defineDocumentSpreadsheetModels();
|
|
|
|
async function mountListView() {
|
|
await mountView({
|
|
type: "list",
|
|
resModel: "documents.document",
|
|
arch: basicDocumentsListArch,
|
|
searchViewArch: getEnrichedSearchArch(),
|
|
});
|
|
}
|
|
|
|
test("opening csv triggers conversion dialog and confirms conversion to spreadsheet", async function () {
|
|
const spreadsheetId = 2;
|
|
const spreadsheetCopyId = 99;
|
|
const documentModels = getDocumentsTestServerModelsData([
|
|
{
|
|
id: spreadsheetId,
|
|
name: "My CSV file",
|
|
mimetype: "text/csv",
|
|
thumbnail_status: "present",
|
|
attachment_id: 1, // Necessary to not be considered as a request
|
|
},
|
|
]);
|
|
documentModels["ir.attachment"] = [{ id: 1 }];
|
|
await makeDocumentsSpreadsheetMockEnv({
|
|
serverData: {
|
|
models: Object.fromEntries(
|
|
Object.entries(documentModels).map(([name, records]) => [name, { records }])
|
|
),
|
|
},
|
|
mockRPC: async (route, args) => {
|
|
if (args.method === "import_to_spreadsheet") {
|
|
expect.step("spreadsheet_cloned");
|
|
expect(args.model).toBe("documents.document");
|
|
expect(args.args).toEqual([spreadsheetId]);
|
|
return spreadsheetCopyId;
|
|
}
|
|
},
|
|
});
|
|
mockActionService((action) => {
|
|
expect.step(action.tag);
|
|
expect(action.params.spreadsheet_id).toEqual(spreadsheetCopyId);
|
|
});
|
|
await mountListView();
|
|
await contains(
|
|
".o_data_row:contains('My CSV file') .o_field_cell .o_field_documents_type_icon"
|
|
).click();
|
|
await contains(".modal-content .btn.btn-primary").click();
|
|
expect.verifySteps(["spreadsheet_cloned", "action_open_spreadsheet"]);
|
|
});
|
|
|
|
test("opening trashed csv prompts restore dialog and restores file on confirm", async () => {
|
|
const spreadsheetId = 2;
|
|
const documentModels = getDocumentsTestServerModelsData([
|
|
{
|
|
id: spreadsheetId,
|
|
name: "Trashed CSV file",
|
|
mimetype: "text/csv",
|
|
thumbnail_status: "present",
|
|
active: false,
|
|
attachment_id: 1, // Necessary to not be considered as a request
|
|
},
|
|
]);
|
|
documentModels["ir.attachment"] = [{ id: 1 }];
|
|
await makeDocumentsSpreadsheetMockEnv({
|
|
serverData: {
|
|
models: Object.fromEntries(
|
|
Object.entries(documentModels).map(([name, records]) => [name, { records }])
|
|
),
|
|
},
|
|
mockRPC: async (route, args) => {
|
|
if (args.method === "action_unarchive") {
|
|
expect.step("spreadsheet_restored");
|
|
expect(args.model).toBe("documents.document");
|
|
expect(args.args).toEqual([spreadsheetId]);
|
|
}
|
|
return null;
|
|
},
|
|
});
|
|
|
|
// Set the document folder in localStorage to "TRASH" so the trash view opens by default
|
|
browser.localStorage.setItem("searchpanel_documents_document", "TRASH");
|
|
|
|
await mountListView();
|
|
await contains(
|
|
".o_data_row:contains('Trashed CSV file') .o_field_cell .o_field_documents_type_icon"
|
|
).click();
|
|
await contains(".modal-content .btn.btn-primary:contains('Restore')").click();
|
|
expect.verifySteps(["spreadsheet_restored"]);
|
|
});
|