<commit_before>'use strict';


describe('RouteHolder', () => {

    it('should exists', () => {
        expect(JSWorks.Internal.RouteHolder).is.exist;
    });

    it('should created at appContext', () => {
        const appContext = JSWorks.applicationContext;
        const routeHolder = appContext.router.routeHolder;

        expect(routeHolder).is.exist;
        console.dir(routeHolder);
    });

    it('should load routes', done => {
        const routeHolder = new JSWorks.Internal.RouteHolder();

        JSWorks.EventManager.subscribe({}, routeHolder, JSWorks.EventType.LOAD, (event) => {
            const apiRoute = routeHolder.root.children['api'];
            expect(apiRoute).is.ok;
            expect(apiRoute.match).to.equal('api');
            expect(apiRoute.path).to.equal('/api');

            const usersRoute = apiRoute.children['users'];
            expect(usersRoute.name).to.equal('UsersRoute');
            expect(usersRoute.pageName).to.equal('UsersPage');
            expect(usersRoute.path).to.equal('/api/users');

            const profileRoute = usersRoute.children['*'];
            expect(profileRoute.name).to.equal('ProfileRoute');
            expect(profileRoute.pageName).to.equal('ProfilePage');
            expect(profileRoute.pathVariableName).to.equal(':id');
            expect(profileRoute.path).to.equal('/api/users/:id');

            const editRoute = profileRoute.children['edit'];
            expect(editRoute.name).to.equal('EditProfileRoute');
            expect(editRoute.pageName).to.equal('EditProfilePage');
            expect(editRoute.path).to.equal('/api/users/:id/edit');

            const postsRoute = usersRoute.children['posts'];
            expect(postsRoute.match).to.equal('posts');
            expect(postsRoute.path).to.equal('/api/users/posts');
            expect(postsRoute.name).is.undefined;

            const allPostsRoute = postsRoute.children['all'];
            expect(allPostsRoute.name).to.equal('UserPostsAllRoute');
            expect(allPostsRoute.pageName).to.equal('UserPostsAllPage');
            expect(allPostsRoute.path).to.equal('/api/users/posts/all');

            const postRoute = postsRoute.children['*'];
            expect(postRoute.name).to.equal('UserPostRoute');
            expect(postRoute.pageName).to.equal('UserPostPage');
            expect(postRoute.pathVariableName).to.equal(':slug');
            expect(postRoute.path).to.equal('/api/users/posts/:slug');

            done();
        });

        routeHolder.load();
    });

    it('should gets routes by name', done => {
        const routeHolder = new JSWorks.Internal.RouteHolder();

        JSWorks.EventManager.subscribe({}, routeHolder, JSWorks.EventType.LOAD, (event) => {
            expect(routeHolder.getRoute('UsersRoute')).is.exist;
            done();
        });

        routeHolder.load();
    });
<commit_msg>Added tests for routeHolder<commit_after>'use strict';


describe('RouteHolder', () => {

    it('should exists', () => {
        expect(JSWorks.Internal.RouteHolder).is.exist;
    });

    it('should created at appContext', () => {
        const appContext = JSWorks.applicationContext;
        const routeHolder = appContext.router.routeHolder;

        expect(routeHolder).is.exist;
        console.dir(routeHolder);
    });

    it('should load routes', done => {
        const routeHolder = new JSWorks.Internal.RouteHolder();

        JSWorks.EventManager.subscribe({}, routeHolder, JSWorks.EventType.LOAD, (event) => {
            const apiRoute = routeHolder.root.children['api'];
            expect(apiRoute).is.ok;
            expect(apiRoute.match).to.equal('api');
            expect(apiRoute.path).to.equal('/api');

            const usersRoute = apiRoute.children['users'];
            expect(usersRoute.name).to.equal('UsersRoute');
            expect(usersRoute.pageName).to.equal('UsersPage');
            expect(usersRoute.path).to.equal('/api/users');

            const profileRoute = usersRoute.children['*'];
            expect(profileRoute.name).to.equal('ProfileRoute');
            expect(profileRoute.pageName).to.equal('ProfilePage');
            expect(profileRoute.pathVariableName).to.equal(':id');
            expect(profileRoute.path).to.equal('/api/users/:id');

            const editRoute = profileRoute.children['edit'];
            expect(editRoute.name).to.equal('EditProfileRoute');
            expect(editRoute.pageName).to.equal('EditProfilePage');
            expect(editRoute.path).to.equal('/api/users/:id/edit');

            const postsRoute = usersRoute.children['posts'];
            expect(postsRoute.match).to.equal('posts');
            expect(postsRoute.path).to.equal('/api/users/posts');
            expect(postsRoute.name).is.undefined;

            const allPostsRoute = postsRoute.children['all'];
            expect(allPostsRoute.name).to.equal('UserPostsAllRoute');
            expect(allPostsRoute.pageName).to.equal('UserPostsAllPage');
            expect(allPostsRoute.path).to.equal('/api/users/posts/all');

            const postRoute = postsRoute.children['*'];
            expect(postRoute.name).to.equal('UserPostRoute');
            expect(postRoute.pageName).to.equal('UserPostPage');
            expect(postRoute.pathVariableName).to.equal(':slug');
            expect(postRoute.path).to.equal('/api/users/posts/:slug');

            done();
        });

        routeHolder.load();
    });

    it('should gets routes by name', done => {
        const routeHolder = new JSWorks.Internal.RouteHolder();

        JSWorks.EventManager.subscribe({}, routeHolder, JSWorks.EventType.LOAD, (event) => {
            expect(routeHolder.getRoute('UsersRoute')).is.exist;
            expect(routeHolder.getRoute('UsersRoute').match).to.equal('users');
            done();
        });

        routeHolder.load();
    });



{'fraction_non_alphanumeric': 0.1567926455566905, 'fraction_numerical': 0.0, 'mean_word_length': 2.6153846153846154, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, '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': '5252916', 'n_tokens_mistral': 1622, 'n_tokens_neox': 1583, 'n_words': 190}