// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Host App Generator --ssr should generate the correct files 1`] = `
"import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';
import { NxWelcomeComponent } from './nx-welcome.component';
import { RouterModule } from '@angular/router';
import { appRoutes } from './app.routes';

@NgModule({
  declarations: [
    AppComponent,
    NxWelcomeComponent
  ],
  imports: [
    BrowserModule.withServerTransition({ appId: 'serverApp' }),
    RouterModule.forRoot(appRoutes, {initialNavigation: 'enabledBlocking'})
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
"
`;

exports[`Host App Generator --ssr should generate the correct files 2`] = `
"import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';

function bootstrap() {
  platformBrowserDynamic()
  .bootstrapModule(AppModule)
  .catch((err) => console.error(err));
};


 if (document.readyState !== 'loading') {
   bootstrap();
 } else {
   document.addEventListener('DOMContentLoaded', bootstrap);
 }"
`;

exports[`Host App Generator --ssr should generate the correct files 3`] = `
"/***************************************************************************************************
 * Initialize the server environment - for example, adding DOM built-in types to the global scope.
 *
 * NOTE:
 * This import must come before any imports (direct or transitive) that rely on DOM built-ins being
 * available, such as \`@angular/elements\`.
 */
import '@angular/platform-server/init';

export { AppServerModule } from './app/app.server.module';
export { renderModule } from '@angular/platform-server';"
`;

exports[`Host App Generator --ssr should generate the correct files 4`] = `
"import 'zone.js/dist/zone-node';

import { APP_BASE_HREF } from '@angular/common';
import { ngExpressEngine } from '@nguniversal/express-engine';
import * as express from 'express';
import * as cors from 'cors';
import { existsSync } from 'fs';
import { join } from 'path';

import { AppServerModule } from './bootstrap.server';

// The Express app is exported so that it can be used by serverless Functions.
export function app(): express.Express {
  const server = express();
  const browserBundles = join(process.cwd(), 'dist/apps/test/browser');

  server.use(cors());
  const indexHtml = existsSync(join(browserBundles, 'index.original.html'))
    ? 'index.original.html'
    : 'index';

  // Our Universal express-engine (found @ https://github.com/angular/universal/tree/main/modules/express-engine)
  server.engine(
    'html',
    ngExpressEngine({
      bootstrap: AppServerModule,
    })
  );

  server.set('view engine', 'html');
  server.set('views', browserBundles);

  // Serve static files from /browser
  server.get(
    '*.*',
    express.static(browserBundles, {
      maxAge: '1y',
    })
  );

  // All regular routes use the Universal engine
  server.get('*', (req, res) => {
    // keep it async to avoid blocking the server thread

    res.render(indexHtml, {
      providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }],
      req,
    });
  });

  return server;
}

function run(): void {
  const port = process.env['PORT'] || 4000;

  // Start up the Node server
  const server = app();
  server.listen(port, () => {
    console.log(\`Node Express server listening on http://localhost:\${port}\`);
  });
}

run();

export * from './bootstrap.server';"
`;

exports[`Host App Generator --ssr should generate the correct files 5`] = `"import('./src/main.server');"`;

exports[`Host App Generator --ssr should generate the correct files 6`] = `
"module.exports = {
  name: 'test',
  remotes: []
}"
`;

exports[`Host App Generator --ssr should generate the correct files 7`] = `
"const { withModuleFederationForSSR } = require('@nrwl/angular/module-federation');
const config = require('./module-federation.config');
module.exports = withModuleFederationForSSR(config)"
`;

exports[`Host App Generator --ssr should generate the correct files 8`] = `
"import { NxWelcomeComponent } from './nx-welcome.component';
    import { Route } from '@angular/router';

export const appRoutes: Route[] = [
    {
      path: '',
      component: NxWelcomeComponent
    },]"
`;

exports[`Host App Generator --ssr should generate the correct files 9`] = `
Object {
  "configurations": Object {
    "development": Object {
      "extractLicenses": false,
      "optimization": false,
      "sourceMap": true,
    },
    "production": Object {
      "outputHashing": "media",
    },
  },
  "defaultConfiguration": "production",
  "dependsOn": Array [
    "build",
  ],
  "executor": "@nrwl/angular:webpack-server",
  "options": Object {
    "customWebpackConfig": Object {
      "path": "apps/test/webpack.server.config.js",
    },
    "main": "apps/test/server.ts",
    "outputPath": "dist/apps/test/server",
    "tsConfig": "apps/test/tsconfig.server.json",
  },
}
`;

exports[`Host App Generator --ssr should generate the correct files 10`] = `
Object {
  "configurations": Object {
    "development": Object {
      "browserTarget": "test:build:development",
      "serverTarget": "test:server:development",
    },
    "production": Object {
      "browserTarget": "test:build:production",
      "serverTarget": "test:server:production",
    },
  },
  "defaultConfiguration": "development",
  "executor": "@nrwl/angular:module-federation-dev-ssr",
}
`;

exports[`Host App Generator should generate a host app with a remote 1`] = `
"const { withModuleFederation } = require('@nrwl/angular/module-federation');
const config = require('./module-federation.config');
module.exports = withModuleFederation(config);"
`;

exports[`Host App Generator should generate a host app with a remote 2`] = `
"const { withModuleFederation } = require('@nrwl/angular/module-federation');
const config = require('./module-federation.config');
module.exports = withModuleFederation(config);"
`;

exports[`Host App Generator should generate a host app with no remotes 1`] = `
"const { withModuleFederation } = require('@nrwl/angular/module-federation');
const config = require('./module-federation.config');
module.exports = withModuleFederation(config);"
`;

exports[`Host App Generator should generate a host with remotes using standalone components 1`] = `
"import { bootstrapApplication } from '@angular/platform-browser';
import { provideRouter, withEnabledBlockingInitialNavigation } from '@angular/router';
import { AppComponent } from './app/app.component';
import { appRoutes } from './app/app.routes';

bootstrapApplication(AppComponent, {
  providers: [provideRouter(appRoutes, withEnabledBlockingInitialNavigation())],
}).catch((err) => console.error(err));"
`;

exports[`Host App Generator should generate a host with remotes using standalone components 2`] = `
"
declare module 'remote1/Routes';"
`;

exports[`Host App Generator should generate a host with remotes using standalone components 3`] = `
"import { NxWelcomeComponent } from './nx-welcome.component';
import { RouterModule } from '@angular/router';
import { Component } from '@angular/core';

@Component({
  standalone: true,
  imports: [NxWelcomeComponent, RouterModule],
  selector: 'proj-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'host';
}"
`;

exports[`Host App Generator should generate the correct app component spec file 1`] = `
"import { fakeAsync, TestBed, tick } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { NxWelcomeComponent } from './nx-welcome.component';
import { RouterTestingModule } from '@angular/router/testing';
import { Router } from '@angular/router';

describe('AppComponent', () => {
  beforeEach(async () => {
    await TestBed.configureTestingModule({
      imports: [
        RouterTestingModule.withRoutes([
          { path: '', component: NxWelcomeComponent },
        ]),
      ],
      declarations: [AppComponent, NxWelcomeComponent],
    }).compileComponents();
  });

  it('should create the app', () => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.componentInstance;
    expect(app).toBeTruthy();
  });

  it(\`should have as title 'host'\`, () => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.componentInstance;
    expect(app.title).toEqual('host');
  });

  it('should render title', fakeAsync(() => {
    const fixture = TestBed.createComponent(AppComponent);
    const router = TestBed.inject(Router);
    fixture.ngZone?.run(() => router.navigate(['']));
    tick();
    fixture.detectChanges();
    const compiled = fixture.nativeElement as HTMLElement;
    expect(compiled.querySelector('h1')?.textContent).toContain('Welcome host');
  }));
});"
`;

exports[`Host App Generator should generate the correct app component spec file with a directory 1`] = `
"import { fakeAsync, TestBed, tick } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { NxWelcomeComponent } from './nx-welcome.component';
import { RouterTestingModule } from '@angular/router/testing';
import { Router } from '@angular/router';

describe('AppComponent', () => {
  beforeEach(async () => {
    await TestBed.configureTestingModule({
      imports: [
        RouterTestingModule.withRoutes([
          { path: '', component: NxWelcomeComponent },
        ]),
      ],
      declarations: [AppComponent, NxWelcomeComponent],
    }).compileComponents();
  });

  it('should create the app', () => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.componentInstance;
    expect(app).toBeTruthy();
  });

  it(\`should have as title 'test-dashboard'\`, () => {
    const fixture = TestBed.createComponent(AppComponent);
    const app = fixture.componentInstance;
    expect(app.title).toEqual('test-dashboard');
  });

  it('should render title', fakeAsync(() => {
    const fixture = TestBed.createComponent(AppComponent);
    const router = TestBed.inject(Router);
    fixture.ngZone?.run(() => router.navigate(['']));
    tick();
    fixture.detectChanges();
    const compiled = fixture.nativeElement as HTMLElement;
    expect(compiled.querySelector('h1')?.textContent).toContain('Welcome test-dashboard');
  }));
});"
`;
