All files / ext.wikilambda.app/components/function/viewer FunctionTesterTable.vue

94.97% Statements 170/179
85.71% Branches 18/21
87.5% Functions 7/8
94.97% Lines 170/179

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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 1801x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 32x 32x 32x 32x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 44x 44x 44x 44x 44x 1x 1x 1x 1x 1x 1x 1x 44x     44x 12x 12x 44x 12x 12x 20x 1x 1x 1x 1x 1x 1x 1x 44x 44x   44x 12x 44x 12x 44x 20x 44x 1x 1x 1x 1x 1x 1x 1x 44x 12x 12x 44x 12x 12x 20x 20x 1x 1x 1x 1x 1x 1x 1x 44x 44x 44x 44x 44x 1x 1x 1x 1x 1x 1x 1x 1x 32x 32x 32x 32x 1x 1x 1x             1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
<!--
	WikiLambda Vue component for the details tab in the ZFunction Viewer.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<div class="ext-wikilambda-app-function-tester-table">
		<wl-status-icon
			:status="status"
			:status-icon="statusIcon"
		></wl-status-icon>
		<span class="ext-wikilambda-app-function-tester-table__status-message">
			{{ statusMessage }}
		</span>
		<wl-status-icon
			v-if="testerStatus !== undefined"
			status="info"
			@click.stop="handleMessageIconClick"
		></wl-status-icon>
		<wl-function-metadata-dialog
			:open="showMetadata"
			:header-text="implementationLabelData"
			:metadata="metadata"
			:error-id="errorId"
			@close-dialog="showMetadata = false"
		></wl-function-metadata-dialog>
	</div>
</template>
 
<script>
 
const { defineComponent } = require( 'vue' );
const FunctionMetadataDialog = require( '../../widgets/function-evaluator/FunctionMetadataDialog.vue' ),
	Constants = require( '../../../Constants.js' ),
	StatusIcon = require( '../../base/StatusIcon.vue' ),
	icons = require( '../../../../lib/icons.json' ),
	{ mapGetters } = require( 'vuex' );
 
module.exports = exports = defineComponent( {
	name: 'wl-function-tester-table',
	components: {
		'wl-function-metadata-dialog': FunctionMetadataDialog,
		'wl-status-icon': StatusIcon
	},
	props: {
		zFunctionId: {
			type: String,
			required: true
		},
		zImplementationId: {
			type: String,
			required: true
		},
		zTesterId: {
			type: String,
			required: true
		}
	},
	data: function () {
		return {
			showMetadata: false,
			errorId: Constants.errorIds.TEST_RESULTS
		};
	},
	computed: Object.assign( mapGetters( [
		'getZTesterResults',
		'getZTesterMetadata',
		'getLabelData'
	] ), {
		/**
		 * Returns whether the tester passed
		 *
		 * @return {boolean}
		 */
		testerStatus: function () {
			return this.getZTesterResults(
				this.zFunctionId,
				this.zTesterId,
				this.zImplementationId
			);
		},
		/**
		 * Returns the status of the test
		 *
		 * @return {string}
		 */
		status: function () {
			if ( !( this.zImplementationId ) || !( this.zTesterId ) ) {
				return Constants.testerStatus.READY;
			}
			if ( this.testerStatus === true ) {
				return Constants.testerStatus.PASSED;
			}
			if ( this.testerStatus === false ) {
				return Constants.testerStatus.FAILED;
			}
			return Constants.testerStatus.RUNNING;
		},
		/**
		 * Returns the status message
		 *
		 * @return {string}
		 */
		statusMessage: function () {
			switch ( this.status ) {
				case Constants.testerStatus.READY:
					return this.$i18n( 'wikilambda-tester-status-ready' ).text();
				case Constants.testerStatus.PASSED:
					return this.$i18n( 'wikilambda-tester-status-passed' ).text();
				case Constants.testerStatus.FAILED:
					return this.$i18n( 'wikilambda-tester-status-failed' ).text();
				default:
					return this.$i18n( 'wikilambda-tester-status-running' ).text();
			}
		},
		/**
		 * Returns the icon depending on the status
		 *
		 * @return {Object}
		 */
		statusIcon: function () {
			if ( this.testerStatus === true ) {
				return icons.cdxIconCheck;
			}
			if ( this.testerStatus === false ) {
				return icons.cdxIconClose;
			}
			// This will be used both for ready and running statuses
			return icons.cdxIconAlert;
		},
		/**
		 * Returns the tester metadata if stored, else returns undefined
		 *
		 * @return {Object|undefined}
		 */
		metadata: function () {
			return this.getZTesterMetadata(
				this.zFunctionId,
				this.zTesterId,
				this.zImplementationId
			);
		},
		/**
		 * Returns the LabelData object of the implementation Zid,
		 * if any, else returns undefined.
		 *
		 * @return {LabelData|undefined}
		 */
		implementationLabelData: function () {
			return this.zImplementationId ?
				this.getLabelData( this.zImplementationId ) :
				undefined;
		}
	} ),
	methods: {
		handleMessageIconClick: function () {
			if ( !this.showMetadata ) {
				this.showMetadata = true;
			} else {
				this.showMetadata = false;
			}
		}
	}
} );
</script>
 
<style lang="less">
@import '../../../ext.wikilambda.app.variables.less';
 
.ext-wikilambda-app-function-tester-table {
	display: flex;
 
	.ext-wikilambda-app-function-tester-table__status-message {
		display: inline-block;
		margin: 0 8px;
	}
}
</style>