{"size": 3319, "ext": "js", "max_stars_repo_path": "web/src/app/components/__test__/msgPageTest.js", "max_stars_repo_name": "stephenlawrence/gravity", "max_stars_repo_stars_event_min_datetime": "2022-03-24T10:42:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-24T10:42:58.000Z", "max_issues_repo_path": "web/src/app/components/__test__/msgPageTest.js", "max_issues_repo_name": "stephenlawrence/gravity", "max_issues_repo_issues_event_min_datetime": "2020-07-21T12:08:05.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T08:20:16.000Z", "max_forks_repo_path": "web/src/app/components/__test__/msgPageTest.js", "max_forks_repo_name": "stephenlawrence/gravity", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 7, "max_forks_count": null, "avg_line_length": 28.6120689655, "max_line_length": 85, "alphanum_fraction": 0.6779150346}
/*
Copyright 2018 Gravitational, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React from 'react';
import * as ReactDOM from 'react-dom';
import { Router, createMemoryHistory } from 'react-router';
import expect from 'expect';
import DocumentTitle from 'app/components/common/documentTitle';
import cfg from 'app/config';
import * as Messages from 'app/components/msgPage'
import { $ } from 'app/__tests__/';
import { makeHelper } from 'app/__tests__/domUtils';

const $node = $('<div>');
const helper = makeHelper($node);

let rootRoutes = [
  {
    component: DocumentTitle,
    childRoutes: [
      { path: cfg.routes.errorPage, component: Messages.ErrorPage },
      { path: cfg.routes.infoPage, component: Messages.InfoPage }
    ]
  }
]

describe('components/msgPage', function () {

  const history = new createMemoryHistory();

  beforeEach(()=>{
    helper.setup()
  });

  afterEach(() => {
    helper.clean();
  })

  it('should render default error', () => {
    history.push('/web/msg/error')
    render();
    expectHeaderText(Messages.MSG_ERROR_DEFAULT)
    expectDetailsText('')
  });

  it('should render login failed', () => {
    history.push('/web/msg/error/login_failed?details=test')
    render();
    expectHeaderText(Messages.MSG_ERROR_LOGIN_FAILED)
    expectDetailsText('test')
  });

  it('should render expired link', () => {
    history.push('/web/msg/error/expired_link')
    render();
    expectHeaderText(Messages.MSG_ERROR_LINK_EXPIRED)
  });

  it('should render invalid user', () => {
    history.push('/web/msg/error/invalid_user')
    render();
    expectHeaderText(Messages.MSG_ERROR_INVALID_USER)
  });

  it('should render not found', () => {
    history.push('/web/msg/error/not_found')
    render();
    expectHeaderText(Messages.MSG_ERROR_NOT_FOUND)
  });

  it('should render login succesfull', () => {
    history.push('/web/msg/info/login_success')
    render();
    expectHeaderText(Messages.MSG_INFO_LOGIN_SUCCESS)
  });

  it('should render site offline', () => {
    ReactDOM.render(( <Messages.SiteOffline siteId="hello"/> ) , $node[0]);
    expect($node.find('.grv-msg-page h3:first').text())
      .toEqual('This cluster is not available from Gravity.')
  });

  it('should render site is scheduled for uninstall', () => {
    ReactDOM.render(( <Messages.SiteUninstall siteId="hello"/> ) , $node[0]);
    expect($node.find('.grv-msg-page h3:first').text())
      .toEqual('This cluster has been scheduled for deletion.')
  });

  const expectDetailsText = text => {
    expect($node.find('.grv-msg-page small').text()).toEqual(text)
  }

  const expectHeaderText = text => {
    expect($node.find('.grv-msg-page h1:first').text()).toEqual(text)
  }

  const render = () => {
    ReactDOM.render(( <Router history={history} routes={rootRoutes} /> ) , $node[0]);
  }

});

