All files / ext.wikilambda.edit/components/widgets FunctionReportItem.vue

98.03% Statements 250/255
100% Branches 30/30
88.88% Functions 8/9
98.03% Lines 250/255

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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 2561x 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 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 218x 218x 218x 1x 1x 1x 1x 1x 1x 1x 31x 31x 1x 1x 1x 1x 1x 1x 1x 192x 192x 192x 192x 192x 1x 1x 1x 1x 1x 1x 1x 51x 11x 11x 51x 2x 2x 51x 1x 1x 51x 1x 1x 36x 1x 1x 1x 1x 1x 1x 1x 51x 51x 38x 51x 1x 51x 1x 51x 11x 51x 1x 1x 1x 1x 1x 1x 1x 51x 1x 1x 51x 1x 1x 49x 49x 1x 1x 1x 1x 1x 1x 1x 51x 1x 1x 1x 1x 1x 1x 1x 51x 51x 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 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
<!--
	WikiLambda Vue component for displaying a result item of running
	a function's testers against its implementations or a funciton's
	implementations against its testers.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<div class="ext-wikilambda-function-report-item">
		<div class="ext-wikilambda-function-report-item__header">
			<cdx-icon
				:icon="statusIcon"
				:class="statusIconClass"
				size="small"
			></cdx-icon>
			<a
				:href="titleLink"
				class="ext-wikilambda-function-report-item__title"
				:class="{ 'ext-wikilambda-function-report-item__title--no-label': titleLabelData.isUntitled }"
				:lang="titleLabelData.langCode"
				:dir="titleLabelData.langDir"
			>{{ titleLabelData.labelOrUntitled }}</a>
		</div>
 
		<div class="ext-wikilambda-function-report-item__footer">
			<span class="ext-wikilambda-function-report-item__footer-status">
				{{ statusMessage }}
			</span>
			<a
				v-if="!isRunning"
				role="button"
				@click="emitTesterKeys"
			>{{ $i18n( 'wikilambda-tester-details' ).text() }}
			</a>
		</div>
	</div>
</template>
 
<script>
const { defineComponent } = require( 'vue' );
const mapGetters = require( 'vuex' ).mapGetters,
	typeUtils = require( '../../mixins/typeUtils.js' ),
	CdxIcon = require( '@wikimedia/codex' ).CdxIcon,
	Constants = require( '../../Constants.js' ),
	icons = require( '../../../../lib/icons.json' );
 
module.exports = exports = defineComponent( {
	name: 'wl-function-report-item',
	components: {
		'cdx-icon': CdxIcon
	},
	mixins: [ typeUtils ],
	props: {
		zFunctionId: {
			type: String,
			required: true
		},
		zImplementationId: {
			type: String,
			required: true
		},
		zTesterId: {
			type: String,
			required: true
		},
		reportType: {
			type: String,
			default: Constants.Z_TESTER
		},
		fetching: {
			type: Boolean,
			default: false
		}
	},
	computed: Object.assign( mapGetters( [
		'getUserLangCode',
		'getZTesterResults',
		'getLabelData'
	] ), {
		/**
		 * Returns the label data for the item title
		 *
		 * @return {LabelData}
		 */
		titleLabelData: function () {
			return this.reportType === Constants.Z_TESTER ?
				this.getLabelData( this.zImplementationId ) :
				this.getLabelData( this.zTesterId );
		},
		/**
		 * Returns the link for the reported item
		 *
		 * @return {string}
		 */
		titleLink: function () {
			const zid = this.reportType === Constants.Z_TESTER ? this.zImplementationId : this.zTesterId;
			return '/view/' + this.getUserLangCode + '/' + zid;
		},
		/**
		 * 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.fetching ) {
				return Constants.testerStatus.RUNNING;
			}
			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.READY;
		},
		/**
		 * 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.status === Constants.testerStatus.PASSED ) {
				return icons.cdxIconSuccess;
			}
			if ( this.status === Constants.testerStatus.FAILED ) {
				return icons.cdxIconClear;
			}
			// This will be used both for ready and running statuses
			return icons.cdxIconClock;
		},
		/**
		 * Returns the class for the icon depending on the status
		 *
		 * @return {string}
		 */
		statusIconClass: function () {
			return `ext-wikilambda-function-report-item-status__${ this.status }`;
		},
		/**
		 * Returns whether the tester is currently running
		 *
		 * @return {string}
		 */
		isRunning: function () {
			return this.status === Constants.testerStatus.RUNNING;
		}
	} ),
	methods: {
		emitTesterKeys: function () {
			this.$emit( 'set-keys', {
				zImplementationId: this.zImplementationId,
				zTesterId: this.zTesterId
			} );
		}
	}
} );
</script>
 
<style lang="less">
@import '../../ext.wikilambda.edit.variables.less';
 
.ext-wikilambda-function-report-item {
	&__header {
		display: flex;
		align-items: flex-start;
 
		.cdx-icon {
			margin-top: @spacing-25;
		}
	}
 
	/* TODO: update with codex dark link when available */
	&__title {
		margin-left: @spacing-50;
		margin-right: 0;
		display: block;
		color: @color-base;
	}
 
	&__title:visited {
		color: @color-base;
	}
 
	&-status {
		&__ready {
			color: @color-disabled;
		}
 
		&__canceled {
			color: @color-subtle;
		}
 
		&__passed {
			color: @color-success;
		}
 
		&__failed {
			color: @color-error;
		}
 
		&__running {
			color: @color-warning;
		}
	}
 
	&__footer {
		margin-left: calc( @spacing-100 + @spacing-50 );
 
		&-status {
			color: @color-subtle;
			margin-right: @spacing-50;
		}
	}
}
 
.ext-wikilambda-function-report-item__title--no-label {
	&:link,
	&:visited {
		color: @color-placeholder;
	}
}
</style>