All files / modules/10-common/components/TestConnectionWidget TestConnectionWidget.tsx

68.18% Statements 15/22
42.86% Branches 3/7
50% Functions 2/4
66.67% Lines 14/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70              11x 11x 11x 11x   11x             11x 11x 11x 11x 11x     11x 30x   30x   30x                                                                            
/*
 * Copyright 2021 Harness Inc. All rights reserved.
 * Use of this source code is governed by the PolyForm Shield 1.0.0 license
 * that can be found in the licenses directory at the root of this repository, also available at
 * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt.
 */
 
import React from 'react'
import { Icon, Layout, Text } from '@wings-software/uicore'
import { Color } from '@harness/design-system'
import { useStrings } from 'framework/strings'
 
import css from './TestConnectionWidget.module.scss'
 
interface TestConnectionWidgetProps {
  testStatus: TestStatus
  onTest: () => Promise<void>
}
 
export enum TestStatus {
  NOT_INITIATED,
  IN_PROGRESS,
  FAILED,
  SUCCESS
}
 
export const TestConnectionWidget: React.FC<TestConnectionWidgetProps> = ({ testStatus, onTest }) => {
  const { getString } = useStrings()
 
  switch (testStatus) {
    case TestStatus.NOT_INITIATED:
      return (
        <Layout.Horizontal spacing="small" flex>
          <Icon name="test-connection" />
          <Text className={css.test} color={Color.BLUE_500} onClick={() => onTest()}>
            {getString('common.labelTestConnection')}
          </Text>
        </Layout.Horizontal>
      )
    case TestStatus.IN_PROGRESS:
      return (
        <Layout.Horizontal spacing="small" flex>
          <Icon name="steps-spinner" color={Color.PRIMARY_7} />
          <Text>{getString('common.test.inProgress')}</Text>
        </Layout.Horizontal>
      )
    case TestStatus.FAILED:
      return (
        <Layout.Horizontal spacing="small" flex>
          <Icon name="circle-cross" color={Color.RED_450} />
          <Text>{getString('common.test.connectionFailed')}</Text>
          <Icon name="test-connection" />
          <Text className={css.test} color={Color.BLUE_500} onClick={() => onTest()}>
            {getString('common.test.retest')}
          </Text>
        </Layout.Horizontal>
      )
    case TestStatus.SUCCESS:
      return (
        <Layout.Horizontal spacing="small" flex>
          <Icon name="command-artifact-check" color={Color.GREEN_450} />
          <Text>{getString('common.test.connectionSuccessful')}</Text>
        </Layout.Horizontal>
      )
    default:
      null
  }
  return null
}