@@ -4046,6 +4046,109 @@ describe('control flow migration', () => {
40464046 `}` ,
40474047 ] . join ( '\n' ) ) ;
40484048 } ) ;
4049+
4050+ it ( 'should handle OR logic in ngIf else case' , async ( ) => {
4051+ writeFile ( '/comp.ts' , `
4052+ import {Component} from '@angular/core';
4053+ import {NgIf} from '@angular/common';
4054+
4055+ @Component({
4056+ templateUrl: './comp.html'
4057+ })
4058+ class Comp {
4059+ show = false;
4060+ }
4061+ ` ) ;
4062+
4063+ writeFile ( '/comp.html' , [
4064+ `<div *ngIf="condition; else titleTemplate || defaultTemplate">Hello!</div>` ,
4065+ `<ng-template #defaultTemplate> Default </ng-template>` ,
4066+ ] . join ( '\n' ) ) ;
4067+
4068+ await runMigration ( ) ;
4069+ const content = tree . readContent ( '/comp.html' ) ;
4070+
4071+ expect ( content ) . toBe ( [
4072+ `@if (condition) {` ,
4073+ ` <div>Hello!</div>` ,
4074+ `} @else {` ,
4075+ ` <ng-template [ngTemplateOutlet]="titleTemplate || defaultTemplate"></ng-template>` ,
4076+ `}` ,
4077+ `<ng-template #defaultTemplate> Default </ng-template>` ,
4078+ ] . join ( '\n' ) ) ;
4079+ } ) ;
4080+
4081+ it ( 'should handle ternaries in ngIfElse' , async ( ) => {
4082+ writeFile ( '/comp.ts' , `
4083+ import {Component} from '@angular/core';
4084+ import {NgIf} from '@angular/common';
4085+
4086+ @Component({
4087+ templateUrl: './comp.html'
4088+ })
4089+ class Comp {
4090+ show = false;
4091+ }
4092+ ` ) ;
4093+
4094+ writeFile ( '/comp.html' , [
4095+ `<ng-template` ,
4096+ ` [ngIf]="customClearTemplate"` ,
4097+ ` [ngIfElse]="isSidebarV3 || variant === 'v3' ? clearTemplateV3 : clearTemplate"` ,
4098+ ` [ngTemplateOutlet]="customClearTemplate"` ,
4099+ `></ng-template>` ,
4100+ `<ng-template #clearTemplateV3>v3</ng-template>` ,
4101+ `<ng-template #clearTemplate>clear</ng-template>` ,
4102+ ] . join ( '\n' ) ) ;
4103+
4104+ await runMigration ( ) ;
4105+ const content = tree . readContent ( '/comp.html' ) ;
4106+
4107+ expect ( content ) . toBe ( [
4108+ `@if (customClearTemplate) {` ,
4109+ ` <ng-template` ,
4110+ ` [ngTemplateOutlet]="customClearTemplate"` ,
4111+ ` ></ng-template>` ,
4112+ `} @else {` ,
4113+ ` <ng-template [ngTemplateOutlet]="isSidebarV3 || variant === 'v3' ? clearTemplateV3 : clearTemplate"></ng-template>` ,
4114+ `}` ,
4115+ `<ng-template #clearTemplateV3>v3</ng-template>` ,
4116+ `<ng-template #clearTemplate>clear</ng-template>` ,
4117+ ] . join ( '\n' ) ) ;
4118+ } ) ;
4119+
4120+ it ( 'should handle ternaries in ngIf' , async ( ) => {
4121+ writeFile ( '/comp.ts' , `
4122+ import {Component} from '@angular/core';
4123+ import {NgIf} from '@angular/common';
4124+
4125+ @Component({
4126+ templateUrl: './comp.html'
4127+ })
4128+ class Comp {
4129+ show = false;
4130+ }
4131+ ` ) ;
4132+
4133+ writeFile ( '/comp.html' , [
4134+ `<div *ngIf="!vm.isEmpty; else vm.loading ? loader : empty"></div>` ,
4135+ `<ng-template #loader>Loading</ng-template>` ,
4136+ `<ng-template #empty>Empty</ng-template>` ,
4137+ ] . join ( '\n' ) ) ;
4138+
4139+ await runMigration ( ) ;
4140+ const content = tree . readContent ( '/comp.html' ) ;
4141+
4142+ expect ( content ) . toBe ( [
4143+ `@if (!vm.isEmpty) {` ,
4144+ ` <div></div>` ,
4145+ `} @else {` ,
4146+ ` <ng-template [ngTemplateOutlet]="vm.loading ? loader : empty"></ng-template>` ,
4147+ `}` ,
4148+ `<ng-template #loader>Loading</ng-template>` ,
4149+ `<ng-template #empty>Empty</ng-template>` ,
4150+ ] . join ( '\n' ) ) ;
4151+ } ) ;
40494152 } ) ;
40504153
40514154 describe ( 'formatting' , ( ) => {
0 commit comments