|
1 | | -import { createElementFromHTML, dealoc } from "../../shared/dom.ts"; |
| 1 | +import { |
| 2 | + createElementFromHTML, |
| 3 | + dealoc, |
| 4 | + getCacheData, |
| 5 | +} from "../../shared/dom.ts"; |
2 | 6 | import { Angular } from "../../angular.ts"; |
3 | 7 | import { wait } from "../../shared/test-utils.ts"; |
4 | 8 |
|
@@ -366,6 +370,65 @@ describe("ngView", () => { |
366 | 370 | expect(elem.textContent).toBe("mState"); |
367 | 371 | }); |
368 | 372 |
|
| 373 | + it("should do transition animations", async () => { |
| 374 | + elem.innerHTML = "<div><ng-view></ng-view></div>"; |
| 375 | + $compile(elem)(scope); |
| 376 | + |
| 377 | + await $state.transitionTo("n"); |
| 378 | + await wait(100); |
| 379 | + expect(elem.querySelector("ng-view").textContent).toBe(nState.template); |
| 380 | + |
| 381 | + await $state.transitionTo("a"); |
| 382 | + await wait(100); |
| 383 | + expect(elem.querySelector("ng-view").textContent).toBe(aState.template); |
| 384 | + expect(log).toContain("animEnter;"); |
| 385 | + expect(log).toContain("animLeave;"); |
| 386 | + }); |
| 387 | + |
| 388 | + it("should expose real ngView animation promises to controllers", async () => { |
| 389 | + elem.innerHTML = "<div><ng-view></ng-view></div>"; |
| 390 | + $compile(elem)(scope); |
| 391 | + |
| 392 | + await $state.transitionTo("n"); |
| 393 | + await wait(100); |
| 394 | + expect(log).toContain("animEnter;"); |
| 395 | + |
| 396 | + await $state.transitionTo("a"); |
| 397 | + await wait(100); |
| 398 | + expect(log).toContain("destroy;"); |
| 399 | + expect(log).toContain("animLeave;"); |
| 400 | + }); |
| 401 | + |
| 402 | + it("should do ngClass animations", async () => { |
| 403 | + scope.classOn = false; |
| 404 | + elem.innerHTML = |
| 405 | + '<div><ng-view ng-class="{ yay: classOn }">Initial Content</ng-view></div>'; |
| 406 | + $compile(elem)(scope); |
| 407 | + |
| 408 | + scope.classOn = true; |
| 409 | + await wait(100); |
| 410 | + expect(elem.querySelector("ng-view").classList.contains("yay")).toBeTrue(); |
| 411 | + |
| 412 | + scope.classOn = false; |
| 413 | + await wait(100); |
| 414 | + expect(elem.querySelector("ng-view").classList.contains("yay")).toBeFalse(); |
| 415 | + }); |
| 416 | + |
| 417 | + it("should do ngIf animations", async () => { |
| 418 | + scope.shouldShow = false; |
| 419 | + elem.innerHTML = |
| 420 | + '<div><ng-view ng-if="shouldShow">Initial Content</ng-view></div>'; |
| 421 | + $compile(elem)(scope); |
| 422 | + |
| 423 | + scope.shouldShow = true; |
| 424 | + await wait(100); |
| 425 | + expect(elem.querySelector("ng-view").textContent).toBe("Initial Content"); |
| 426 | + |
| 427 | + scope.shouldShow = false; |
| 428 | + await wait(100); |
| 429 | + expect(elem.querySelector("ng-view")).toBeNull(); |
| 430 | + }); |
| 431 | + |
369 | 432 | describe("(resolved data)", () => { |
370 | 433 | let _scope; |
371 | 434 | function controller($scope) { |
@@ -642,160 +705,6 @@ describe("ngView", () => { |
642 | 705 | }); |
643 | 706 | }); |
644 | 707 | }); |
645 | | - |
646 | | - // describe("AngularTS Animations", () => { |
647 | | - // it("should do transition animations", async () => { |
648 | | - // let content = "Initial Content", |
649 | | - // animation; |
650 | | - // elem.append( |
651 | | - // $compile("<div><ng-view>" + content + "</ng-view></div>")(scope), |
652 | | - // ); |
653 | | - |
654 | | - // // Enter Animation |
655 | | - // animation = $animate.queue.shift(); |
656 | | - // expect(animation.event).toBe("enter"); |
657 | | - // expect(animation.element.textContent + "-1").toBe(content + "-1"); |
658 | | - |
659 | | - // $state.transitionTo(aState); |
660 | | - // await wait(100); |
661 | | - |
662 | | - // // Enter Animation |
663 | | - // animation = $animate.queue.shift(); |
664 | | - // expect(animation.event).toBe("enter"); |
665 | | - // expect(animation.element.textContent + "-2").toBe(aState.template + "-2"); |
666 | | - // // Leave Animation |
667 | | - // animation = $animate.queue.shift(); |
668 | | - // expect(animation.event).toBe("leave"); |
669 | | - // expect(animation.element.textContent + "-3").toBe(content + "-3"); |
670 | | - |
671 | | - // $state.transitionTo(bState); |
672 | | - // await wait(100); |
673 | | - |
674 | | - // // Enter Animation |
675 | | - // animation = $animate.queue.shift(); |
676 | | - // expect(animation.event).toBe("enter"); |
677 | | - // expect(animation.element.textContent + "-4").toBe(bState.template + "-4"); |
678 | | - // // Leave Animation |
679 | | - // animation = $animate.queue.shift(); |
680 | | - // expect(animation.event).toBe("leave"); |
681 | | - // expect(animation.element.textContent + "-5").toBe(aState.template + "-5"); |
682 | | - |
683 | | - // // No more animations |
684 | | - // expect($animate.queue.length).toBe(0); |
685 | | - // }); |
686 | | - |
687 | | - // it("should do ngClass animations", async () => { |
688 | | - // scope.classOn = false; |
689 | | - // let content = "Initial Content", |
690 | | - // className = "yay", |
691 | | - // animation; |
692 | | - // elem.append( |
693 | | - // $compile( |
694 | | - // "<div><ng-view ng-class=\"{'" + |
695 | | - // className + |
696 | | - // "': classOn}\">" + |
697 | | - // content + |
698 | | - // "</ng-view></div>", |
699 | | - // )(scope), |
700 | | - // ); |
701 | | - // // Don't care about enter class |
702 | | - // $animate.queue.shift(); |
703 | | - |
704 | | - // scope.classOn = true; |
705 | | - // ; |
706 | | - |
707 | | - // animation = $animate.queue.shift(); |
708 | | - // expect(animation.event).toBe("addClass"); |
709 | | - // expect(animation.element.textContent).toBe(content); |
710 | | - |
711 | | - // scope.classOn = false; |
712 | | - // ; |
713 | | - |
714 | | - // animation = $animate.queue.shift(); |
715 | | - // expect(animation.event).toBe("removeClass"); |
716 | | - // expect(animation.element.textContent).toBe(content); |
717 | | - |
718 | | - // // No more animations |
719 | | - // expect($animate.queue.length).toBe(0); |
720 | | - // }); |
721 | | - |
722 | | - // it("should do ngIf animations", async () => { |
723 | | - // scope.shouldShow = false; |
724 | | - // let content = "Initial Content", |
725 | | - // animation; |
726 | | - // elem.append( |
727 | | - // $compile( |
728 | | - // '<div><ng-view ng-if="shouldShow">' + content + "</ng-view></div>", |
729 | | - // )(scope), |
730 | | - // ); |
731 | | - |
732 | | - // // No animations yet |
733 | | - // expect($animate.queue.length).toBe(0); |
734 | | - |
735 | | - // scope.shouldShow = true; |
736 | | - // ; |
737 | | - |
738 | | - // // ViewDirective enter animation - Basically it's just the <!-- ngView --> comment |
739 | | - // animation = $animate.queue.shift(); |
740 | | - // expect(animation.event).toBe("enter"); |
741 | | - // expect(animation.element.textContent).toBe(""); |
742 | | - |
743 | | - // // ViewDirectiveFill enter animation - The second ngView directive that files in the content |
744 | | - // animation = $animate.queue.shift(); |
745 | | - // expect(animation.event).toBe("enter"); |
746 | | - // expect(animation.element.textContent).toBe(content); |
747 | | - |
748 | | - // scope.shouldShow = false; |
749 | | - // ; |
750 | | - |
751 | | - // // ngView leave animation |
752 | | - // animation = $animate.queue.shift(); |
753 | | - // expect(animation.event).toBe("leave"); |
754 | | - // expect(animation.element.textContent).toBe(content); |
755 | | - |
756 | | - // // No more animations |
757 | | - // expect($animate.queue.length).toBe(0); |
758 | | - // }); |
759 | | - |
760 | | - // it("should expose animation promises to controllers", async () => { |
761 | | - // $transitions.onStart({}, function ($transition$) { |
762 | | - // log += "start:" + $transition$.to().name + ";"; |
763 | | - // }); |
764 | | - // $transitions.onFinish({}, function ($transition$) { |
765 | | - // log += "finish:" + $transition$.to().name + ";"; |
766 | | - // }); |
767 | | - // $transitions.onSuccess({}, function ($transition$) { |
768 | | - // log += "success:" + $transition$.to().name + ";"; |
769 | | - // }); |
770 | | - |
771 | | - // const content = "Initial Content"; |
772 | | - // elem.append( |
773 | | - // $compile("<div><ng-view>" + content + "</ng-view></div>")(scope), |
774 | | - // ); |
775 | | - // $state.transitionTo("n"); |
776 | | - // await wait(100); |
777 | | - |
778 | | - // expect($state.current.name).toBe("n"); |
779 | | - // expect(log).toBe("start:n;finish:n;success:n;"); |
780 | | - |
781 | | - // // animateFlush($animate); |
782 | | - // await wait(100); |
783 | | - // expect(log).toBe("start:n;finish:n;success:n;animEnter;"); |
784 | | - |
785 | | - // $state.transitionTo("a"); |
786 | | - // await wait(100); |
787 | | - // expect($state.current.name).toBe("a"); |
788 | | - // expect(log).toBe( |
789 | | - // "start:n;finish:n;success:n;animEnter;start:a;finish:a;destroy;success:a;", |
790 | | - // ); |
791 | | - |
792 | | - // // animateFlush($animate); |
793 | | - // await wait(100); |
794 | | - // expect(log).toBe( |
795 | | - // "start:n;finish:n;success:n;animEnter;start:a;finish:a;destroy;success:a;animLeave;", |
796 | | - // ); |
797 | | - // }); |
798 | | - // }); |
799 | 708 | }); |
800 | 709 |
|
801 | 710 | describe("ngView named", () => { |
|
0 commit comments