<commit_before>define(['widgets/common/ErrorMessage', 'jsonrpc/1.1/errors', 'jsonrpc/1.1/jsonrpcErrors'], (
    $ErrorMessage,
    errors,
    jsonrpcErrors
) => {
    'use strict';
    function expectFooterMessage($node) {
        expect($node.text()).toContain('contact the KBase team');
    }

    function expectTitle($node, title = 'Error!') {
        expect($node.text()).toContain(title);
    }

    describe('The $ErrorMessage widget', () => {
        it('should be defined', () => {
            expect($ErrorMessage).toBeDefined();
        });

        it('should display a string error message', () => {
            const message = 'I am an error';
            const $testDiv = $ErrorMessage(message);
            expect($testDiv).toBeDefined();
            expect($testDiv.text()).toContain(message);
            expectTitle($testDiv);
            expectFooterMessage($testDiv);
        });

        it('should display an Error-based exception', () => {
            const message = 'I am an exception';
            try {
                throw new Error(message);
            } catch (ex) {
                const $testDiv = $ErrorMessage(ex);
                expect($testDiv).toBeDefined();
                expect($testDiv.text()).toContain(message);
                expectTitle($testDiv);
                expectFooterMessage($testDiv);
            }
        });

        it('should display a custom title', () => {
            const message = 'I am an exception';
            try {
                throw new Error(message);
            } catch (ex) {
                const $testDiv = $ErrorMessage(ex, { title: 'Foobar!' });
                expect($testDiv).toBeDefined();
                expect($testDiv.text()).toContain(message);
                expectTitle($testDiv, 'Foobar!');
                expectFooterMessage($testDiv);
            }
        });

        it('should display a simulated JSONRPCError exception', () => {
            const message = 'I am an exception';
            const errorData = {
                method: 'MyModule.my_method',
                params: {
                    param1: 'value1',
                    param2: [1, 2, true, false, null],
                },
                url: 'https://ci.kbase.us/services/MyModule',
                // originalMessage: 'why?',
                error: {
                    name: 'JSONRPCError',
                    code: 123,
                    message: 'json-rpc service error here',
                    error: {
                        some: 'error info',
                        booltrue: true,
                        boolfalse: false,
                        nullfield: null,
                        arrayfield: [
                            'value in array',
                            'bar',
                            true,
                            false,
                            null,
                            1,
                            ['array field in array'],
                            { foo: 'bar' },
                        ],
                        objectfield: {
                            foo: 'value in object',
                            is: true,
                            not: false,
                            empty: null,
                            arrayfield: ['array field in object'],
                        },
                        trace: ['line 1', 'line 2'],
                    },
                },
            };
            try {
                throw new jsonrpcErrors.JSONRPCError(message, errorData);
            } catch (ex) {
                const $testDiv = $ErrorMessage(ex);
                expect($testDiv).toBeDefined();
                expect($testDiv.text()).toContain(message);
                expect($testDiv.text()).toContain(errorData.method);
                expect($testDiv.text()).toContain(errorData.url);
                // expect($testDiv.text()).toContain(errorData.originalMessage);
                expect($testDiv.text()).toContain(errorData.error.code);
                expect($testDiv.text()).toContain(errorData.error.message);
                expect($testDiv.text()).toContain(errorData.error.error.arrayfield[0]);
                expect($testDiv.text()).toContain(errorData.error.error.objectfield.foo);
                expect($testDiv.text()).toContain(errorData.error.error.objectfield.arrayfield[0]);
                expect($testDiv.text()).toContain(errorData.error.error.trace[1]);
                expectTitle($testDiv);
                expectFooterMessage($testDiv);
            }
        });

        it('should display a simulated ClientError exception', () => {
            const message = 'I am an exception';
            const errorData = {
                method: 'MyModule.my_method',
                params: {
                    param1: 'value1',
                    param2: [1, 2, true, false, null],
                },
                url: 'https://ci.kbase.us/services/MyModule',
            };
            try {
                throw new errors.ClientError(message, errorData);
            } catch (ex) {<commit_msg>remove commented-out code<commit_after>define(['widgets/common/ErrorMessage', 'jsonrpc/1.1/errors', 'jsonrpc/1.1/jsonrpcErrors'], (
    $ErrorMessage,
    errors,
    jsonrpcErrors
) => {
    'use strict';
    function expectFooterMessage($node) {
        expect($node.text()).toContain('contact the KBase team');
    }

    function expectTitle($node, title = 'Error!') {
        expect($node.text()).toContain(title);
    }

    describe('The $ErrorMessage widget', () => {
        it('should be defined', () => {
            expect($ErrorMessage).toBeDefined();
        });

        it('should display a string error message', () => {
            const message = 'I am an error';
            const $testDiv = $ErrorMessage(message);
            expect($testDiv).toBeDefined();
            expect($testDiv.text()).toContain(message);
            expectTitle($testDiv);
            expectFooterMessage($testDiv);
        });

        it('should display an Error-based exception', () => {
            const message = 'I am an exception';
            try {
                throw new Error(message);
            } catch (ex) {
                const $testDiv = $ErrorMessage(ex);
                expect($testDiv).toBeDefined();
                expect($testDiv.text()).toContain(message);
                expectTitle($testDiv);
                expectFooterMessage($testDiv);
            }
        });

        it('should display a custom title', () => {
            const message = 'I am an exception';
            try {
                throw new Error(message);
            } catch (ex) {
                const $testDiv = $ErrorMessage(ex, { title: 'Foobar!' });
                expect($testDiv).toBeDefined();
                expect($testDiv.text()).toContain(message);
                expectTitle($testDiv, 'Foobar!');
                expectFooterMessage($testDiv);
            }
        });

        it('should display a simulated JSONRPCError exception', () => {
            const message = 'I am an exception';
            const errorData = {
                method: 'MyModule.my_method',
                params: {
                    param1: 'value1',
                    param2: [1, 2, true, false, null],
                },
                url: 'https://ci.kbase.us/services/MyModule',
                error: {
                    name: 'JSONRPCError',
                    code: 123,
                    message: 'json-rpc service error here',
                    error: {
                        some: 'error info',
                        booltrue: true,
                        boolfalse: false,
                        nullfield: null,
                        arrayfield: [
                            'value in array',
                            'bar',
                            true,
                            false,
                            null,
                            1,
                            ['array field in array'],
                            { foo: 'bar' },
                        ],
                        objectfield: {
                            foo: 'value in object',
                            is: true,
                            not: false,
                            empty: null,
                            arrayfield: ['array field in object'],
                        },
                        trace: ['line 1', 'line 2'],
                    },
                },
            };
            try {
                throw new jsonrpcErrors.JSONRPCError(message, errorData);
            } catch (ex) {
                const $testDiv = $ErrorMessage(ex);
                expect($testDiv).toBeDefined();
                expect($testDiv.text()).toContain(message);
                expect($testDiv.text()).toContain(errorData.method);
                expect($testDiv.text()).toContain(errorData.url);
                expect($testDiv.text()).toContain(errorData.error.code);
                expect($testDiv.text()).toContain(errorData.error.message);
                expect($testDiv.text()).toContain(errorData.error.error.arrayfield[0]);
                expect($testDiv.text()).toContain(errorData.error.error.objectfield.foo);
                expect($testDiv.text()).toContain(errorData.error.error.objectfield.arrayfield[0]);
                expect($testDiv.text()).toContain(errorData.error.error.trace[1]);
                expectTitle($testDiv);
                expectFooterMessage($testDiv);
            }
        });

        it('should display a simulated ClientError exception', () => {
            const message = 'I am an exception';
            const errorData = {
                method: 'MyModule.my_method',
                params: {
                    param1: 'value1',
                    param2: [1, 2, true, false, null],
                },
                url: 'https://ci.kbase.us/services/MyModule',
            };
            try {
                throw new errors.ClientError(message, errorData);
            } catch (ex) {
{'fraction_non_alphanumeric': 0.12337983575739586, 'fraction_numerical': 0.004551301078460473, 'mean_word_length': 1.2673844773441005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5445281', 'n_tokens_mistral': 2541, 'n_tokens_neox': 2386, 'n_words': 475}