duplicate_visibility.js 2.61 KB
Newer Older
François C. committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
"use strict";
odoo.define_section('web_duplicate_visibility',
                    ['web.data', 'web.FormView'],
                    function(test, mock){

    function assertDuplicate(data, FormView, form_tag, visible){
        mock.add('test.model:read', function () {
            return [{ id: 1, a: 'foo', b: 'bar', c: 'baz' }];
        });

        mock.add('test.model:fields_view_get', function () {
            return {
                type: 'form',
                fields: {
                    a: {type: 'char', string: "A"},
                    b: {type: 'char', string: "B"},
                    c: {type: 'char', string: "C"}
                },
                arch: form_tag +
                   '    <field name="a"/>' +
                   '    <field name="b"/>' +
                   '    <field name="c"/>' +
                   '</form>',
            };
        });

        var ds = new data.DataSetStatic(null, 'test.model', null, [1]);
        ds.index = 0;
        var $fix = $( "#qunit-fixture");
        var form = new FormView(
            {},
            ds,
            false,
            {
                sidebar: true,
            }
        );
        form.appendTo($fix);
        form.do_show();
        form.render_sidebar();

        var $fix = $( "#qunit-fixture");
        var actions = $fix.find('.oe_sidebar a[data-section="other"]').filter(
            function(i, obj){
                return obj.text.trim() == "Duplicate";
            }
        );
        strictEqual(
            actions.length, visible, "duplicate state is not as expected"
        );
    };

    test('Duplicate button visible when nothing set',
         function(assert, data, FormView){
        assertDuplicate(data, FormView, '<form>', 1);
    });

    test('Duplicate button visible when create="1"',
         function(assert, data, FormView){
        assertDuplicate(data, FormView, '<form create="1">', 1);
    });

    test('Duplicate button visible when duplicate="1"',
         function(assert, data, FormView){
        assertDuplicate(data, FormView, '<form duplicate="1">', 1);
    });

    test('Duplicate button not displayed when create="0"',
         function(assert, data, FormView){
        assertDuplicate(data, FormView, '<form create="0">', 0);
    });

    test('Duplicate button not displayed when create="1" duplicate="0"',
         function(assert, data, FormView){
        assertDuplicate(data, FormView, '<form create="1" duplicate="0">', 0);
    });

    test('Duplicate button not displayed when duplicate="0"',
         function(assert, data, FormView){
        assertDuplicate(data, FormView, '<form duplicate="0">', 0);
    });
});