Skip to content

Instantly share code, notes, and snippets.

@JVegaB
Created June 29, 2020 23:18
Show Gist options
  • Save JVegaB/1d90c330502f5de8c6c03226c5c38e0e to your computer and use it in GitHub Desktop.
Save JVegaB/1d90c330502f5de8c6c03226c5c38e0e to your computer and use it in GitHub Desktop.

Bundle para tests

    <template id="qunit_suite" inherit_id="web.qunit_suite">
        <xpath expr="//script[last()]" position="after">
            <script type="text/javascript" src="/academy/static/src/js/tools.js"></script>
            <script type="text/javascript" src="/academy/static/tests/academy_tests.js"></script>
            <script type="text/javascript" src="/academy/static/tests/academy_tests_field.js"></script>
        </xpath>
    </template>

Ejercicio 1

const { CallQueuer } = require('academy.tools');

    QUnit.module('academy', {}, function () {
        
        QUnit.module('tools', {
            beforeEach () {
                /**
                 * Stores the execution call count.
                 */
                this.executedCount = 0;
            }
        }, function () {
            QUnit.test('Tests multitples asyncronous calls', async function (assert) {
                const done = assert.async();
                assert.expect(1);
                /**
                 * Mocked backend request.
                 */
                const request = () => new Promise((resolve) => {
                    setTimeout(() => resolve('Request done.'), 1000);
                }).then(() => {
                    this.executedCount++;
                });
                
                CallQueuer(request);
                CallQueuer(request);
                CallQueuer(request);
                CallQueuer(request);
                CallQueuer(request);

                setTimeout(() => {
                    assert.equal(this.executedCount, 2);
                    done();
                }, 2100);
            });
        });
    });

Ejercicio 2

    const { createView, dom } = require('web.test_utils');
    const FormView = require('web.FormView');

    QUnit.module('academy', {}, function () {
        
        QUnit.module('tests', {
            beforeEach () {
                this.data = {
                    'product.template': {
                        fields: {
                            share_count: {string: "share count", type: "integer"},
                        },
                        records: [{
                            id: 1,
                            share_count: 420000,
                        }]
                    },
                }
            }
        }, function () {
            QUnit.test('Checks the correct display of value.', async function (assert) {
                assert.expect(1);

                const form = await createView({
                    View: FormView,
                    data: this.data,
                    model: 'product.template',
                    res_id: 1,
                    arch: `
                    <form>
                        <sheet>
                            <group>
                                <field name="share_count" widget="share_count"/>
                            </group>
                        </sheet>
                    </form>`,
                });

                assert.containsOnce(form, ".o_field_widget h1:contains('420,000')", "The string should be 420,000");

                form.destroy();
            });

            QUnit.only('Checks the value is restarting', async function (assert) {
                assert.expect(1);

                const form = await createView({
                    View: FormView,
                    data: this.data,
                    model: 'product.template',
                    res_id: 1,
                    arch: `
                    <form>
                        <sheet>
                            <group>
                                <field name="share_count" widget="share_count"/>
                            </group>
                        </sheet>
                    </form>`,
                });

                await dom.click(form.$('.js_reset_field'))

                assert.containsOnce(form, ".o_field_widget h1:contains('0')", "The string should be 0");

                form.destroy();
            });
        });
    });
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment