<commit_before>@TestOn('browser && !js')
import "dart:async";

import 'package:angular2/angular2.dart';
import "package:angular2/src/testing/internal.dart";
import 'package:test/test.dart';

void main() {
  // Place to put reproductions for regressions
  group("regressions", () {
    group("platform pipes", () {
      beforeEachProviders(() => [
            provide(PLATFORM_PIPES, useValue: [PlatformPipe], multi: true)
          ]);
      test("should overwrite them by custom pipes", () async {
        return inject([TestComponentBuilder, AsyncTestCompleter],
            (TestComponentBuilder tcb, AsyncTestCompleter completer) {
          tcb
              .overrideView(
                  MyComp,
                  new View(
                      template: "{{true | somePipe}}", pipes: [CustomPipe]))
              .createAsync(MyComp)
              .then((fixture) {
            fixture.detectChanges();
            expect(fixture.nativeElement, hasTextContent("someCustomPipe"));
            completer.done();
          });
        });
      });
    });
    group("expressions", () {
      test(
          "should evaluate conditional and boolean operators with right precedence - #8244",
          () async {
        return inject([TestComponentBuilder, AsyncTestCompleter],
            (TestComponentBuilder tcb, AsyncTestCompleter completer) {
          tcb
              .overrideView(
                  MyComp,
                  new View(
                      template:
                          '''{{\'red\' + (true ? \' border\' : \'\')}}'''))
              .createAsync(MyComp)
              .then((fixture) {
            fixture.detectChanges();
            expect(fixture.nativeElement, hasTextContent("red border"));
            completer.done();
          });
        });
      });
    });
    group("providers", () {
      Future<Injector> createInjector(
          TestComponentBuilder tcb, List<dynamic> providers) {
        return tcb
            .overrideProviders(MyComp, [providers])
            .createAsync(MyComp)
            .then((fixture) => fixture.componentInstance.injector);
      }

      test(
          "should support providers with an OpaqueToken that contains a `.` in the name",
          () async {
        return inject([TestComponentBuilder, AsyncTestCompleter],
            (TestComponentBuilder tcb, AsyncTestCompleter completer) {
          var token = new OpaqueToken("a.b");
          var tokenValue = 1;
          createInjector(tcb, [provide(token, useValue: tokenValue)])
              .then((Injector injector) {
            expect(injector.get(token), tokenValue);
            completer.done();
          });
        });
      });
      test("should support providers with string token with a `.` in it",
          () async {
        return inject([TestComponentBuilder, AsyncTestCompleter],
            (TestComponentBuilder tcb, AsyncTestCompleter completer) {
          var token = "a.b";
          var tokenValue = 1;
          createInjector(tcb, [provide(token, useValue: tokenValue)])
              .then((Injector injector) {
            expect(injector.get(token), tokenValue);
            completer.done();
          });
        });
      });
      test("should support providers with an anonymous function", () async {
        return inject([TestComponentBuilder, AsyncTestCompleter],
            (TestComponentBuilder tcb, AsyncTestCompleter completer) {
          var token = () => true;
          var tokenValue = 1;
          createInjector(tcb, [provide(token, useValue: tokenValue)])
              .then((Injector injector) {
            expect(injector.get(token), tokenValue);
            completer.done();
          });
        });
      });
      test(
          "should support providers with an OpaqueToken that has a StringMap as value",
          () async {
        return inject([TestComponentBuilder, AsyncTestCompleter],
            (TestComponentBuilder tcb, AsyncTestCompleter completer) {
          var token1 = const OpaqueToken("someToken1");
          var token2 = const OpaqueToken("someToken2");
          var tokenValue1 = {"a": 1};
          var tokenValue2 = {"a": 1};
          createInjector(tcb, [
            provide(token1, useValue: tokenValue1),
            provide(token2, useValue: tokenValue2)
          ]).then((Injector injector) {
            expect(injector.get(token1), tokenValue1);
            expect(injector.get(token2), tokenValue2);
            completer.done();
          });
        });
      });
    });
    test(
        "should allow logging a previous elements class binding via interpolation",
        () async {
      return inject([TestComponentBuilder, AsyncTestCompleter],
          (TestComponentBuilder tcb, AsyncTestCompleter completer) {
        tcb
            .overrideTemplate(MyComp,
                '''<div [class.a]="true" #el>Class: {{el.className}}</div>''')
            .createAsync(MyComp)
            .then((fixture) {
          fixture.detectChanges();
          expect(fixture.nativeElement, hasTextContent("Class: a"));
          completer.done();
        });
      });
    });
    test(
        "should support ngClass before a component and content projection inside of an ngIf",
        () async {
      return inject([TestComponentBuilder, AsyncTestCompleter],
          (TestComponentBuilder tcb, AsyncTestCompleter completer) {
        tcb
            .overrideView(
                MyComp,
                new View(
                    template:
                        '''A<cmp-content *ngIf="true" [ngClass]="\'red\'">B</cmp-content>C''',
                    directives: [NgClass, NgIf, CmpWithNgContent]))
            .createAsync(MyComp)
            .then((fixture) {
          fixture.detectChanges();
          expect(fixture.nativeElement, hasTextContent("ABC"));
          completer.done();
        });
      });
    });
  });
}

@Component(selector: "my-comp", template: "")
class MyComp {
  final Injector injector;
  MyComp(this.injector);
}

@Pipe("somePipe", pure: true)
class PlatformPipe implements PipeTransform {
  dynamic transform(dynamic value) {
    return "somePlatformPipe";
  }
}

@Pipe("somePipe", pure: true)
class CustomPipe implements PipeTransform {
  dynamic transform(dynamic value) {
    return "someCustomPipe";
  }
}

@Component(selector: "cmp-content", template: '''<ng-content></ng-content>''')
class CmpWithNgContent {}<commit_msg>Migrate regression integration tests to package:angular_test<commit_after>@Tags(const ['codegen'])
@TestOn('browser')

import 'package:angular2/angular2.dart';
import 'package:angular_test/angular_test.dart';
import 'package:test/test.dart';

void main() {
  tearDown(disposeAnyRunningTest);

  test('should evaluate conditional operator with right precedence', () async {
    final testBed = new NgTestBed<RightPrecedenceConditionalComponent>();
    final testFixture = await testBed.create();
    expect(testFixture.text, 'red');
    await testFixture.update((component) => component.hasBorder = true);
    expect(testFixture.text, 'red border');
  });

  group('Provider', () {
    void testProvider(dynamic token, dynamic tokenValue) {
      final injector = ReflectiveInjector.resolveAndCreate([
        provide(token, useValue: tokenValue),
      ]);
      expect(injector.get(token), tokenValue);
    }

    test("should support OpaqueToken with name containing '.'", () {
      testProvider(new OpaqueToken('a.b'), 1);
    });

    test("should support string token containing '.'", () {
      testProvider('a.b', 1);
    });

    test('should support anonymous function token', () {
      testProvider(() => true, 1);
    });

    test('should support OpaqueToken with a String-keyed Map value', () {
      testProvider(const OpaqueToken('token'), {'a': 1});
    });
  });

  test("should interpolate previous element's class binding", () async {
    final testBed = new NgTestBed<InterpolateClassBindingComponent>();
    final testFixture = await testBed.create();
    expect(testFixture.text, 'foo');
  });

  test('should support ngClass before a component and transclusion inside ngIf',
      () async {
    final testBed = new NgTestBed<ContentProviderComponent>();
    final testFixture = await testBed.create();
    expect(testFixture.text, 'ABC');
  });
}

@Component(
  selector: 'right-precedence-conditional',
  template: '{{"red" + (hasBorder ? " border" : "")}}',
)
class RightPrecedenceConditionalComponent {
  bool hasBorder = false;
}

@Component(
  selector: 'interpolate-class-binding',
  template: '<div [class.foo]="true" #element>{{element.className}}</div>',
)
class InterpolateClassBindingComponent {}

@Component(
  selector: 'content-host',
  template: '<ng-content></ng-content>',
)
class ContentHostComponent {}

@Component(
  selector: 'content-provider',
  template: 'A<content-host *ngIf="true" [ngClass]="\'red\'">B</content-host>C',
  directives: const [
    ContentHostComponent,
    NgClass,
    NgIf,
  ],
)
class ContentProviderComponent {}
{'fraction_non_alphanumeric': 0.13061813339252026, 'fraction_numerical': 0.0035512151814449007, 'mean_word_length': 2.514820592823713, 'pattern_counts': {'":': 2, '<': 20, '<?xml version=': 0, '>': 25, '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': '6265138', 'n_tokens_mistral': 2539, 'n_tokens_neox': 2487, 'n_words': 542}