Best JavaScript code snippet using storybook-root
Graph.spec.ts
Source:Graph.spec.ts
1import { flushPromises, shallowMount } from "@vue/test-utils";2import Graph from "@/components/concept/Graph.vue";3import ProgressSpinner from "primevue/progressspinner";4import OrganizationChart from "primevue/organizationchart";5import EntityService from "@/services/EntityService";6import LoggerService from "@/services/LoggerService";7describe("Graph.vue", () => {8 let wrapper: any;9 let mockRoute: any;10 let mockRouter: any;11 let mockToast: any;12 beforeEach(() => {13 jest.resetAllMocks();14 EntityService.getEntityGraph = jest.fn().mockResolvedValue({ data: {"key":"0","name":"Accident and emergency encounter (record type)","iri":"http://endhealth.info/im#AccidentAndEmergencyEncounter","children":[{"key":"0_0","name":"Is a","children":[{"key":"0_0_0","type":"ISA","children":[],"leafNodes":[{"name":"Hospital encounter","iri":"http://endhealth.info/im#1161000252102","children":[],"leafNodes":[]}]}],"leafNodes":[]},{"key":"0_1","name":"Subtypes","children":[{"key":"0_1_0","type":"SUBTYPE","children":[],"leafNodes":[{"name":"Accident and emergency encounter discharge","iri":"http://endhealth.info/im#2541000252100","children":[],"leafNodes":[]}]}],"leafNodes":[]},{"key":"0_2","name":"Semantic properties","children":[{"key":"0_2_0","type":"PROPERTIES","children":[],"leafNodes":[{"name":"takes place in care setting","iri":"http://endhealth.info/im#51000252106","valueTypeIri":"http://endhealth.info/im#651000252108","valueTypeName":"Accident and emergency (setting)"}]}],"leafNodes":[]},{"key":"0_3","name":"Data model properties","children":[{"key":"0_3_0","name":"Direct","children":[{"key":"0_3_0_0","type":"PROPERTIES","children":[],"leafNodes":[{"name":"a&e department type","iri":"http://endhealth.info/im#aAndeDepartmentType","valueTypeIri":"http://endhealth.info/im#651000252108","valueTypeName":"Accident and emergency (setting)"},{"name":"has a&e attendance source of","iri":"http://endhealth.info/im#hasAandeAttendanceSourceOf","valueTypeIri":"http://snomed.info/sct#999002991000000109"},{"name":"has a&e category of attendance of","iri":"http://endhealth.info/im#hasAandeCategoryOfAttendanceOf","valueTypeIri":"http://endhealth.info/im#461000252108","valueTypeName":"Accident and emergency attendance or follow up"},{"name":"has arrival mode","iri":"http://endhealth.info/im#hasArrivalMode","valueTypeIri":"http://snomed.info/sct#999002981000000107"},{"name":"treatment function for service for which admitted","iri":"http://endhealth.info/im#treatmentFunctionForServiceForWhichAdmitted","valueTypeIri":"http://snomed.info/sct#224930009","valueTypeName":"Services (qualifier value)"}]}],"leafNodes":[]},{"key":"0_3_1","name":"Inherited","children":[{"key":"0_3_1_0","type":"PROPERTIES","children":[],"leafNodes":[{"name":"additional Practitioners","iri":"http://endhealth.info/im#additionalPractitioners","valueTypeIri":"http://endhealth.info/im#ThePractitionerInRole","valueTypeName":"Practitioner in role (record type)","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"completion Status","iri":"http://endhealth.info/im#completionStatus","valueTypeIri":"http://endhealth.info/im#894281000252100","valueTypeName":"Concept class","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"duration","iri":"http://endhealth.info/im#duration","valueTypeIri":"http://endhealth.info/im#894281000252100","valueTypeName":"Concept class","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"has section","iri":"http://endhealth.info/im#hasSection","valueTypeIri":"http://endhealth.info/im#Section","valueTypeName":"Section (structural)","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"linked appointment","iri":"http://endhealth.info/im#linkedAppointment","valueTypeIri":"http://endhealth.info/im#Appointment","valueTypeName":"Appointment (slot) (record type)","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"linked care episode","iri":"http://endhealth.info/im#linkedCareEpisode","valueTypeIri":"http://endhealth.info/im#EpisodeOfCare","valueTypeName":"Episode of care (record type)","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"location","iri":"http://endhealth.info/im#location","valueTypeIri":"http://endhealth.info/im#Location","valueTypeName":"Location (record type)","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"providing Organisation/ services or departments","iri":"http://endhealth.info/im#providingOrganisation_ServicesOrDepartments","valueTypeIri":"http://endhealth.info/im#Organisation","valueTypeName":"Organisation (record type)","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"is subencounter of","iri":"http://endhealth.info/im#isSubEnctounterOf","valueTypeIri":"http://endhealth.info/im#Encounter","valueTypeName":"Encounter (record type)","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"has subject","iri":"http://endhealth.info/im#hasSubject","valueTypeIri":"http://snomed.info/sct#116154003","valueTypeName":"Patient (person)","inheritedFromIri":"http://endhealth.info/im#PatientHealthEvent","inheritedFromName":"Patient health event (record type)"},{"name":"practitioner","iri":"http://endhealth.info/im#hasPractitioner","valueTypeIri":"http://endhealth.info/im#ThePractitionerInRole","valueTypeName":"Practitioner in role (record type)","inheritedFromIri":"http://endhealth.info/im#PatientHealthEvent","inheritedFromName":"Patient health event (record type)"},{"name":"date","iri":"http://endhealth.info/im#date","valueTypeIri":"http://www.w3.org/2001/XMLSchema#string","valueTypeName":"string","inheritedFromIri":"http://endhealth.info/im#HealthEvent","inheritedFromName":"Health event (record type)"},{"name":"end date","iri":"http://endhealth.info/im#endDate","valueTypeIri":"http://www.w3.org/2001/XMLSchema#string","valueTypeName":"string","inheritedFromIri":"http://endhealth.info/im#HealthEvent","inheritedFromName":"Health event (record type)"}]}],"leafNodes":[]}],"leafNodes":[]}],"leafNodes":[]}});15 mockRoute = {16 name: "Concept"17 };18 mockRouter = {19 push: jest.fn()20 };21 mockToast = {22 add: jest.fn()23 }24 wrapper = shallowMount(Graph, {25 global: {26 components: { ProgressSpinner, OrganizationChart },27 mocks: { $route: mockRoute, $router: mockRouter, $toast: mockToast }28 },29 props: { conceptIri: "http://endhealth.info/im#AccidentAndEmergencyEncounter" }30 });31 });32 it("starts with empty values", async() => {33 await flushPromises();34 expect(wrapper.vm.loading).toBe(false);35 expect(wrapper.vm.conceptIri).toBe("http://endhealth.info/im#AccidentAndEmergencyEncounter");36 });37 it("can watch conceptIri", () => {38 wrapper.vm.getGraph = jest.fn()39 wrapper.vm.$options.watch.conceptIri.call(wrapper.vm, "http://endhealth.info/im#DiscoveryOntology");40 expect(wrapper.vm.getGraph).toHaveBeenCalledTimes(1);41 expect(wrapper.vm.getGraph).toHaveBeenCalledWith("http://endhealth.info/im#DiscoveryOntology");42 });43 it("calls getGraph on mounted", () => {44 expect(EntityService.getEntityGraph).toHaveBeenCalledTimes(1);45 expect(EntityService.getEntityGraph).toHaveBeenCalledWith("http://endhealth.info/im#AccidentAndEmergencyEncounter");46 });47 it("can getGraph", async() => {48 await flushPromises();49 await wrapper.vm.$nextTick();50 wrapper.vm.getGraph("http://snomed.info/sct#298382003");51 expect(wrapper.vm.loading).toBe(true);52 expect(EntityService.getEntityGraph).toHaveBeenCalledTimes(2);53 expect(EntityService.getEntityGraph).toHaveBeenLastCalledWith("http://snomed.info/sct#298382003");54 await flushPromises();55 await wrapper.vm.$nextTick();56 expect(wrapper.vm.loading).toBe(false);57 expect(mockToast.add).not.toHaveBeenCalled();58 expect(wrapper.vm.graph).toStrictEqual({"key":"0","name":"Accident and emergency encounter (record type)","iri":"http://endhealth.info/im#AccidentAndEmergencyEncounter","children":[{"key":"0_0","name":"Is a","children":[{"key":"0_0_0","type":"ISA","children":[],"leafNodes":[{"name":"Hospital encounter","iri":"http://endhealth.info/im#1161000252102","children":[],"leafNodes":[]}]}],"leafNodes":[]},{"key":"0_1","name":"Subtypes","children":[{"key":"0_1_0","type":"SUBTYPE","children":[],"leafNodes":[{"name":"Accident and emergency encounter discharge","iri":"http://endhealth.info/im#2541000252100","children":[],"leafNodes":[]}]}],"leafNodes":[]},{"key":"0_2","name":"Semantic properties","children":[{"key":"0_2_0","type":"PROPERTIES","children":[],"leafNodes":[{"name":"takes place in care setting","iri":"http://endhealth.info/im#51000252106","valueTypeIri":"http://endhealth.info/im#651000252108","valueTypeName":"Accident and emergency (setting)"}]}],"leafNodes":[]},{"key":"0_3","name":"Data model properties","children":[{"key":"0_3_0","name":"Direct","children":[{"key":"0_3_0_0","type":"PROPERTIES","children":[],"leafNodes":[{"name":"a&e department type","iri":"http://endhealth.info/im#aAndeDepartmentType","valueTypeIri":"http://endhealth.info/im#651000252108","valueTypeName":"Accident and emergency (setting)"},{"name":"has a&e attendance source of","iri":"http://endhealth.info/im#hasAandeAttendanceSourceOf","valueTypeIri":"http://snomed.info/sct#999002991000000109"},{"name":"has a&e category of attendance of","iri":"http://endhealth.info/im#hasAandeCategoryOfAttendanceOf","valueTypeIri":"http://endhealth.info/im#461000252108","valueTypeName":"Accident and emergency attendance or follow up"},{"name":"has arrival mode","iri":"http://endhealth.info/im#hasArrivalMode","valueTypeIri":"http://snomed.info/sct#999002981000000107"},{"name":"treatment function for service for which admitted","iri":"http://endhealth.info/im#treatmentFunctionForServiceForWhichAdmitted","valueTypeIri":"http://snomed.info/sct#224930009","valueTypeName":"Services (qualifier value)"}]}],"leafNodes":[]},{"key":"0_3_1","name":"Inherited","children":[{"key":"0_3_1_0","type":"PROPERTIES","children":[],"leafNodes":[{"name":"additional Practitioners","iri":"http://endhealth.info/im#additionalPractitioners","valueTypeIri":"http://endhealth.info/im#ThePractitionerInRole","valueTypeName":"Practitioner in role (record type)","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"completion Status","iri":"http://endhealth.info/im#completionStatus","valueTypeIri":"http://endhealth.info/im#894281000252100","valueTypeName":"Concept class","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"duration","iri":"http://endhealth.info/im#duration","valueTypeIri":"http://endhealth.info/im#894281000252100","valueTypeName":"Concept class","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"has section","iri":"http://endhealth.info/im#hasSection","valueTypeIri":"http://endhealth.info/im#Section","valueTypeName":"Section (structural)","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"linked appointment","iri":"http://endhealth.info/im#linkedAppointment","valueTypeIri":"http://endhealth.info/im#Appointment","valueTypeName":"Appointment (slot) (record type)","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"linked care episode","iri":"http://endhealth.info/im#linkedCareEpisode","valueTypeIri":"http://endhealth.info/im#EpisodeOfCare","valueTypeName":"Episode of care (record type)","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"location","iri":"http://endhealth.info/im#location","valueTypeIri":"http://endhealth.info/im#Location","valueTypeName":"Location (record type)","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"providing Organisation/ services or departments","iri":"http://endhealth.info/im#providingOrganisation_ServicesOrDepartments","valueTypeIri":"http://endhealth.info/im#Organisation","valueTypeName":"Organisation (record type)","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"is subencounter of","iri":"http://endhealth.info/im#isSubEnctounterOf","valueTypeIri":"http://endhealth.info/im#Encounter","valueTypeName":"Encounter (record type)","inheritedFromIri":"http://endhealth.info/im#Encounter","inheritedFromName":"Encounter (record type)"},{"name":"has subject","iri":"http://endhealth.info/im#hasSubject","valueTypeIri":"http://snomed.info/sct#116154003","valueTypeName":"Patient (person)","inheritedFromIri":"http://endhealth.info/im#PatientHealthEvent","inheritedFromName":"Patient health event (record type)"},{"name":"practitioner","iri":"http://endhealth.info/im#hasPractitioner","valueTypeIri":"http://endhealth.info/im#ThePractitionerInRole","valueTypeName":"Practitioner in role (record type)","inheritedFromIri":"http://endhealth.info/im#PatientHealthEvent","inheritedFromName":"Patient health event (record type)"},{"name":"date","iri":"http://endhealth.info/im#date","valueTypeIri":"http://www.w3.org/2001/XMLSchema#string","valueTypeName":"string","inheritedFromIri":"http://endhealth.info/im#HealthEvent","inheritedFromName":"Health event (record type)"},{"name":"end date","iri":"http://endhealth.info/im#endDate","valueTypeIri":"http://www.w3.org/2001/XMLSchema#string","valueTypeName":"string","inheritedFromIri":"http://endhealth.info/im#HealthEvent","inheritedFromName":"Health event (record type)"}]}],"leafNodes":[]}],"leafNodes":[]}],"leafNodes":[]});59 });60 it("can get graph ___ request fail", async() => {61 console.error = jest.fn();62 EntityService.getEntityGraph = jest.fn().mockRejectedValue({ code: 403, message: "Test error" });63 wrapper.vm.getGraph();64 await flushPromises();65 expect(mockToast.add).toHaveBeenCalledTimes(1);66 expect(mockToast.add).toHaveBeenCalledWith(LoggerService.error("Failed to get entity graph data from server", "Test error"));67 });68 it("can navigate", () => {69 wrapper.vm.navigate("http://endhealth.info/im#12345678");70 expect(mockRouter.push).toHaveBeenCalledTimes(1);71 expect(mockRouter.push).toHaveBeenCalledWith({ name: "Concept", params: { selectedIri: "http://endhealth.info/im#12345678" } });72 });73 it("can navigate __ no Iri", () => {74 wrapper.vm.navigate();75 expect(mockRouter.push).not.toHaveBeenCalled();76 });77});78describe("Graph.vue ___ no iri", () => {79 let wrapper: any;80 let mockRoute: any;81 let mockRouter: any;82 beforeEach(() => {83 jest.resetAllMocks();84 EntityService.getEntityGraph = jest.fn();85 mockRoute = {86 name: "Concept"87 };88 mockRouter = {89 push: jest.fn()90 };91 wrapper = shallowMount(Graph, {92 global: {93 components: { ProgressSpinner, OrganizationChart },94 mocks: { $route: mockRoute, $router: mockRouter }95 },96 props: { conceptIri: undefined }97 });98 });99 it("doesnt call getGraph on mounted", () => {100 expect(EntityService.getEntityGraph).toHaveBeenCalledTimes(0);101 });...
skill-value-creation.directive.js
Source:skill-value-creation.directive.js
1/**2 * @author v.lugovksy3 * created on 16.12.20154 */5(function () {6 'use strict';7 angular.module('app.knowledgeDiscovery')8 .directive('skillValueCreation', skillValueCreation);9 /** @ngInject */10 function skillValueCreation() {11 return {12 restrict: 'AE',13 scope: {14 kdId: '<',15 },16 controller: function ($scope, KnowledgeDocumentApi, TranslatorApi) {17 $scope.valueCreationPV = [];18 $scope.valueCreationRV = [];19 $scope.remarks = [];20 $scope.remarksRV = [];21 $scope.selectedChart;22 $scope.Questions = {};23 $scope.Questions.valueAmplified = $scope.$parent.Questions.valueAmplified;24 if($scope.$parent.Questions.vlPotentialValue && $scope.$parent.Questions.vlValueRealised){25 $scope.Questions.potentialValue = $scope.$parent.Questions.vlPotentialValue;26 $scope.Questions.valueRealised = $scope.$parent.Questions.vlValueRealised;27 }28 else{29 $scope.Questions.potentialValue = "Potential Value";30 $scope.Questions.valueRealised = "Value Realised";31 }32 33 $scope.Questions.valueAmplifiedByType = $scope.$parent.Questions.valueAmplifiedByType;34 $scope.Questions.remarks = $scope.$parent.Questions.remarks;35 $scope.$on('changeQuestionsLanguage', function (event, data) {36 $scope.Questions.valueAmplified = $scope.$parent.Questions.valueAmplified;37 $scope.Questions.valueAmplifiedByType = $scope.$parent.Questions.valueAmplifiedByType;38 $scope.Questions.potentialValue = $scope.$parent.Questions.vlPotentialValue;39 $scope.Questions.valueRealised = $scope.$parent.Questions.vlValueRealised;40 $scope.Questions.remarks = $scope.$parent.Questions.remarks;41 });42 var donutChart;43 $scope.$on('chart-create', function (evt, chart) {44 if (chart.config.type == 'doughnut') donutChart = chart;45 });46 $scope.valueCreationLabels = [];47 $scope.valueCreationColors = [{48 backgroundColor: '#FD1F5E',49 pointBackgroundColor: '#FD1F5E'50 }, {51 backgroundColor: '#9400D3',52 pointBackgroundColor: '#9400D3'53 }, {54 backgroundColor: '#6B8E23',55 pointBackgroundColor: '#6B8E23'56 }, {57 backgroundColor: '#68F000',58 pointBackgroundColor: '#68F000'59 }];60 $scope.valueCreationRvLabels = [];61 $scope.valueCreationRvColors = [62 {63 backgroundColor: '#9400D3',64 pointBackgroundColor: '#9400D3'65 },66 {67 backgroundColor: '#6B8E23',68 pointBackgroundColor: '#6B8E23'69 },70 {71 backgroundColor: '#68F000',72 pointBackgroundColor: '#68F000'73 },74 {75 backgroundColor: '#FD1F5E',76 pointBackgroundColor: '#FD1F5E'77 }];78 $scope.valueCreationData = [];79 $scope.valueCreationOptions = {80 legend: { display: true, position: 'top', labels: {fontColor: "#fff"} },81 tooltips: {82 callbacks: {83 label: function (tooltipItem, data) {84 var allData = data.datasets[tooltipItem.datasetIndex].data;85 var tooltipLabel = data.labels[tooltipItem.index];86 var tooltipData = allData[tooltipItem.index];87 return tooltipLabel + ': RM ' + tooltipData + ' K';88 }89 }90 },91 onClick: function (event, elements) {92 $scope.$apply(function () {93 //$scope.remarks = $scope.valueCreation[elements[0]._index].remarks;94 });95 },96 onHover: function (event, elements) {97 },98 events: ["mousemove", "touchstart", "touchmove", "click"]99 };100 $scope.changeChartView = function(data) {101 $scope.selectedChart = data;102 }103 $scope.valueCreationRvData = [];104 $scope.valueCreationRvOptions = {105 legend: { display: true, position: 'top', labels: {fontColor: "#fff"} },106 tooltips: {107 callbacks: {108 label: function (tooltipItem, data) {109 var allData = data.datasets[tooltipItem.datasetIndex].data;110 var tooltipLabel = data.labels[tooltipItem.index];111 var tooltipData = allData[tooltipItem.index];112 return tooltipLabel + ': RM ' + tooltipData + ' K';113 }114 }115 },116 onClick: function (event, elements) {117 $scope.$apply(function () {118 //$scope.remarks = $scope.valueCreation[elements[0]._index].remarks;119 });120 },121 onHover: function (event, elements) {122 },123 events: ["mousemove", "touchstart", "touchmove", "click"]124 };125 var _getValueCreation = function () {126 KnowledgeDocumentApi.ValueCreationGroup($scope.kdId).then(function (response) {127 $scope.valueCreationPV = response.potentialValue;128 $scope.valueCreationRV = response.valueRealized;129 if($scope.valueCreationRV.length > 0) {130 $scope.selectedChart = 'rv';131 }132 else{133 $scope.selectedChart = 'pv';134 }135 for (var i = 0; i < response.potentialValue.length; i++) {136 $scope.valueCreationLabels.push(response.potentialValue[i].valueTypeName);137 $scope.valueCreationData.push(response.potentialValue[i].impactValue);138 $scope.remarks.push({139 valueTypeName: response.potentialValue[i].valueTypeName,140 remarks: response.potentialValue[i].remarks,141 translatedvalueTypeName: response.potentialValue[i].valueTypeName,142 translatedremarks: response.potentialValue[i].remarks143 });144 }145 for (var i = 0; i < response.valueRealized.length; i++) {146 147 $scope.valueCreationRvLabels.push(response.valueRealized[i].valueTypeName);148 $scope.valueCreationRvData.push(response.valueRealized[i].impactValue);149 $scope.remarksRV.push({150 valueTypeName: response.valueRealized[i].valueTypeName,151 remarks: response.valueRealized[i].remarks,152 translatedvalueTypeName: response.valueRealized[i].valueTypeName,153 translatedremarks: response.valueRealized[i].remarks154 });155 }156 157 // for (var i = 0; i < response.length; i++) {158 // $scope.valueCreationLabels.push(response[i].valueTypeName);159 // $scope.valueCreationData.push(response[i].impactValue);160 // $scope.remarks.push({161 // valueTypeName: response[i].valueTypeName,162 // remarks: response[i].remarks,163 // translatedvalueTypeName: response[i].valueTypeName,164 // translatedremarks: response[i].remarks165 // });166 // }167 $scope.remarksOriginal = $scope.remarks;168 $scope.remarksOriginalRV = $scope.remarksRV;169 });170 };171 $scope.getValueCreation = _getValueCreation;172 $scope.getValueCreation();173 $scope.$on('changeInputLanguage', function (event, data) {174 var inputLanguage = data.inputLanguage;175 var originalLanguage = data.originalLanguage;176 _languageChange(inputLanguage, originalLanguage);177 });178 function _languageChange(inputLanguage, originalLanguage) {179 if (inputLanguage == originalLanguage) {180 angular.forEach($scope.remarksOriginal, function (value, key) {181 value.translatedvalueTypeName = value.valueTypeName;182 value.translatedremarks = value.remarks;183 });184 angular.forEach($scope.remarksOriginalRV, function (value, key) {185 value.translatedvalueTypeName = value.valueTypeName;186 value.translatedremarks = value.remarks;187 });188 return;189 }190 angular.forEach($scope.remarksOriginal, function (value, key) {191 if (value.remarks != null && value.remarks != undefined && value.remarks != '') {192 TranslatorApi.api.TranslateSingleText.save({}, {193 textToTranslate: value.remarks,194 fromLanguage: originalLanguage,195 toLanguage: inputLanguage196 },197 function (response) {198 value.translatedremarks = response.translatedText;199 },200 function (response) {201 if (response.status !== 404)202 logger.error(response.data.errorMessage);203 });204 }205 if (value.valueTypeName != null && value.valueTypeName != undefined && value.valueTypeName != '') {206 TranslatorApi.api.TranslateSingleText.save({}, {207 textToTranslate: value.valueTypeName,208 fromLanguage: originalLanguage,209 toLanguage: inputLanguage210 },211 function (response) {212 value.translatedvalueTypeName = response.translatedText;213 },214 function (response) {215 if (response.status !== 404)216 logger.error(response.data.errorMessage);217 });218 }219 });220 angular.forEach($scope.remarksOriginalRV, function (value, key) {221 if (value.remarks != null && value.remarks != undefined && value.remarks != '') {222 TranslatorApi.api.TranslateSingleText.save({}, {223 textToTranslate: value.remarks,224 fromLanguage: originalLanguage,225 toLanguage: inputLanguage226 },227 function (response) {228 value.translatedremarks = response.translatedText;229 },230 function (response) {231 if (response.status !== 404)232 logger.error(response.data.errorMessage);233 });234 }235 if (value.valueTypeName != null && value.valueTypeName != undefined && value.valueTypeName != '') {236 TranslatorApi.api.TranslateSingleText.save({}, {237 textToTranslate: value.valueTypeName,238 fromLanguage: originalLanguage,239 toLanguage: inputLanguage240 },241 function (response) {242 value.translatedvalueTypeName = response.translatedText;243 },244 function (response) {245 if (response.status !== 404)246 logger.error(response.data.errorMessage);247 });248 }249 });250 $scope.$on('chart-create', function (evt, chart) {251 if (chart.config.type == 'pie') donutChart = chart;252 });253 }254 },255 templateUrl: 'app/main/apps/knowledge-discovery/_directives/skill-value-creation.html',256 };257 }...
Checkpoints.js
Source:Checkpoints.js
1const format = require('../format-lines');2const VALUE_SIZES = [ 224, 160 ];3const header = `\4pragma solidity ^0.8.0;5import "./math/Math.sol";6import "./math/SafeCast.sol";7/**8 * @dev This library defines the \`History\` struct, for checkpointing values as they change at different points in9 * time, and later looking up past values by block number. See {Votes} as an example.10 *11 * To create a history of checkpoints define a variable type \`Checkpoints.History\` in your contract, and store a new12 * checkpoint for the current transaction block using the {push} function.13 *14 * _Available since v4.5._15 */16`;17const types = opts => `\18struct ${opts.historyTypeName} {19 ${opts.checkpointTypeName}[] ${opts.checkpointFieldName};20}21struct ${opts.checkpointTypeName} {22 ${opts.keyTypeName} ${opts.keyFieldName};23 ${opts.valueTypeName} ${opts.valueFieldName};24}25`;26/* eslint-disable max-len */27const operations = opts => `\28/**29 * @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.30 */31function latest(${opts.historyTypeName} storage self) internal view returns (${opts.valueTypeName}) {32 uint256 pos = self.${opts.checkpointFieldName}.length;33 return pos == 0 ? 0 : _unsafeAccess(self.${opts.checkpointFieldName}, pos - 1).${opts.valueFieldName};34}35/**36 * @dev Pushes a (\`key\`, \`value\`) pair into a ${opts.historyTypeName} so that it is stored as the checkpoint.37 *38 * Returns previous value and new value.39 */40function push(41 ${opts.historyTypeName} storage self,42 ${opts.keyTypeName} key,43 ${opts.valueTypeName} value44) internal returns (${opts.valueTypeName}, ${opts.valueTypeName}) {45 return _insert(self.${opts.checkpointFieldName}, key, value);46}47/**48 * @dev Returns the value in the oldest checkpoint with key greater or equal than the search key, or zero if there is none.49 */50function lowerLookup(${opts.historyTypeName} storage self, ${opts.keyTypeName} key) internal view returns (${opts.valueTypeName}) {51 uint256 length = self.${opts.checkpointFieldName}.length;52 uint256 pos = _lowerBinaryLookup(self.${opts.checkpointFieldName}, key, 0, length);53 return pos == length ? 0 : _unsafeAccess(self.${opts.checkpointFieldName}, pos).${opts.valueFieldName};54}55/**56 * @dev Returns the value in the most recent checkpoint with key lower or equal than the search key.57 */58function upperLookup(${opts.historyTypeName} storage self, ${opts.keyTypeName} key) internal view returns (${opts.valueTypeName}) {59 uint256 length = self.${opts.checkpointFieldName}.length;60 uint256 pos = _upperBinaryLookup(self.${opts.checkpointFieldName}, key, 0, length);61 return pos == 0 ? 0 : _unsafeAccess(self.${opts.checkpointFieldName}, pos - 1).${opts.valueFieldName};62}63/**64 * @dev Returns the value in the most recent checkpoint with key lower or equal than the search key (similarly to65 * {upperLookup}), optimized for the case when the search key is known to be recent.66 */67function upperLookupRecent(${opts.historyTypeName} storage self, ${opts.keyTypeName} key) internal view returns (${opts.valueTypeName}) {68 uint256 length = self.${opts.checkpointFieldName}.length;69 uint256 offset = 1;70 while (offset <= length && _unsafeAccess(self.${opts.checkpointFieldName}, length - offset).${opts.keyFieldName} > key) {71 offset <<= 1;72 }73 uint256 low = 0 < offset && offset < length ? length - offset : 0;74 uint256 high = length - (offset >> 1);75 uint256 pos = _upperBinaryLookup(self.${opts.checkpointFieldName}, key, low, high);76 return pos == 0 ? 0 : _unsafeAccess(self.${opts.checkpointFieldName}, pos - 1).${opts.valueFieldName};77}78`;79const legacyOperations = opts => `\80/**81 * @dev Returns the value in the latest checkpoint, or zero if there are no checkpoints.82 */83function latest(${opts.historyTypeName} storage self) internal view returns (uint256) {84 uint256 pos = self.${opts.checkpointFieldName}.length;85 return pos == 0 ? 0 : _unsafeAccess(self.${opts.checkpointFieldName}, pos - 1).${opts.valueFieldName};86}87/**88 * @dev Returns the value at a given block number. If a checkpoint is not available at that block, the closest one89 * before it is returned, or zero otherwise.90 */91function getAtBlock(${opts.historyTypeName} storage self, uint256 blockNumber) internal view returns (uint256) {92 require(blockNumber < block.number, "Checkpoints: block not yet mined");93 uint32 key = SafeCast.toUint32(blockNumber);94 uint256 length = self.${opts.checkpointFieldName}.length;95 uint256 pos = _upperBinaryLookup(self.${opts.checkpointFieldName}, key, 0, length);96 return pos == 0 ? 0 : _unsafeAccess(self.${opts.checkpointFieldName}, pos - 1).${opts.valueFieldName};97}98/**99 * @dev Returns the value at a given block number. If a checkpoint is not available at that block, the closest one100 * before it is returned, or zero otherwise. Similarly to {upperLookup} but optimized for the case when the search101 * key is known to be recent.102 */103function getAtRecentBlock(${opts.historyTypeName} storage self, uint256 blockNumber) internal view returns (uint256) {104 require(blockNumber < block.number, "Checkpoints: block not yet mined");105 uint32 key = SafeCast.toUint32(blockNumber);106 uint256 length = self.${opts.checkpointFieldName}.length;107 uint256 offset = 1;108 while (offset <= length && _unsafeAccess(self.${opts.checkpointFieldName}, length - offset).${opts.keyFieldName} > key) {109 offset <<= 1;110 }111 uint256 low = offset < length ? length - offset : 0;112 uint256 high = length - (offset >> 1);113 uint256 pos = _upperBinaryLookup(self.${opts.checkpointFieldName}, key, low, high);114 return pos == 0 ? 0 : _unsafeAccess(self.${opts.checkpointFieldName}, pos - 1).${opts.valueFieldName};115}116/**117 * @dev Pushes a value onto a History so that it is stored as the checkpoint for the current block.118 *119 * Returns previous value and new value.120 */121function push(${opts.historyTypeName} storage self, uint256 value) internal returns (uint256, uint256) {122 return _insert(self.${opts.checkpointFieldName}, SafeCast.toUint32(block.number), SafeCast.toUint224(value));123}124/**125 * @dev Pushes a value onto a History, by updating the latest value using binary operation \`op\`. The new value will126 * be set to \`op(latest, delta)\`.127 *128 * Returns previous value and new value.129 */130function push(131 ${opts.historyTypeName} storage self,132 function(uint256, uint256) view returns (uint256) op,133 uint256 delta134) internal returns (uint256, uint256) {135 return push(self, op(latest(self), delta));136}137`;138const helpers = opts => `\139/**140 * @dev Pushes a (\`key\`, \`value\`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,141 * or by updating the last one.142 */143function _insert(144 ${opts.checkpointTypeName}[] storage self,145 ${opts.keyTypeName} key,146 ${opts.valueTypeName} value147) private returns (${opts.valueTypeName}, ${opts.valueTypeName}) {148 uint256 pos = self.length;149 if (pos > 0) {150 // Copying to memory is important here.151 ${opts.checkpointTypeName} memory last = _unsafeAccess(self, pos - 1);152 // Checkpoints keys must be increasing.153 require(last.${opts.keyFieldName} <= key, "Checkpoint: invalid key");154 // Update or push new checkpoint155 if (last.${opts.keyFieldName} == key) {156 _unsafeAccess(self, pos - 1).${opts.valueFieldName} = value;157 } else {158 self.push(${opts.checkpointTypeName}({${opts.keyFieldName}: key, ${opts.valueFieldName}: value}));159 }160 return (last.${opts.valueFieldName}, value);161 } else {162 self.push(${opts.checkpointTypeName}({${opts.keyFieldName}: key, ${opts.valueFieldName}: value}));163 return (0, value);164 }165}166/**167 * @dev Return the index of the oldest checkpoint whose key is greater than the search key, or \`high\` if there is none.168 * \`low\` and \`high\` define a section where to do the search, with inclusive \`low\` and exclusive \`high\`.169 *170 * WARNING: \`high\` should not be greater than the array's length.171 */172function _upperBinaryLookup(173 ${opts.checkpointTypeName}[] storage self,174 ${opts.keyTypeName} key,175 uint256 low,176 uint256 high177) private view returns (uint256) {178 while (low < high) {179 uint256 mid = Math.average(low, high);180 if (_unsafeAccess(self, mid).${opts.keyFieldName} > key) {181 high = mid;182 } else {183 low = mid + 1;184 }185 }186 return high;187}188/**189 * @dev Return the index of the oldest checkpoint whose key is greater or equal than the search key, or \`high\` if there is none.190 * \`low\` and \`high\` define a section where to do the search, with inclusive \`low\` and exclusive \`high\`.191 *192 * WARNING: \`high\` should not be greater than the array's length.193 */194function _lowerBinaryLookup(195 ${opts.checkpointTypeName}[] storage self,196 ${opts.keyTypeName} key,197 uint256 low,198 uint256 high199) private view returns (uint256) {200 while (low < high) {201 uint256 mid = Math.average(low, high);202 if (_unsafeAccess(self, mid).${opts.keyFieldName} < key) {203 low = mid + 1;204 } else {205 high = mid;206 }207 }208 return high;209}210function _unsafeAccess(${opts.checkpointTypeName}[] storage self, uint256 pos)211 private212 view213 returns (${opts.checkpointTypeName} storage result)214{215 assembly {216 mstore(0, self.slot)217 result.slot := add(keccak256(0, 0x20), pos)218 }219}220`;221/* eslint-enable max-len */222// OPTIONS223const defaultOpts = (size) => ({224 historyTypeName: `Trace${size}`,225 checkpointTypeName: `Checkpoint${size}`,226 checkpointFieldName: '_checkpoints',227 keyTypeName: `uint${256 - size}`,228 keyFieldName: '_key',229 valueTypeName: `uint${size}`,230 valueFieldName: '_value',231});232const OPTS = VALUE_SIZES.map(size => defaultOpts(size));233const LEGACY_OPTS = {234 ...defaultOpts(224),235 historyTypeName: 'History',236 checkpointTypeName: 'Checkpoint',237 keyFieldName: '_blockNumber',238};239// GENERATE240module.exports = format(241 header.trimEnd(),242 'library Checkpoints {',243 [244 // Legacy types & functions245 types(LEGACY_OPTS),246 legacyOperations(LEGACY_OPTS),247 helpers(LEGACY_OPTS),248 // New flavors249 ...OPTS.flatMap(opts => [250 types(opts),251 operations(opts),252 helpers(opts),253 ]),254 ],255 '}',...
Using AI Code Generation
1const { valueTypeName } = require('storybook-root');2const { valueTypeName } = require('storybook-root');3const { valueTypeName } = require('storybook-root');4const { valueTypeName } = require('storybook-root');5const { valueTypeName } = require('storybook-root');6console.log(valueTypeName('test
Using AI Code Generation
1var root = require('storybook-root');2var valueTypeName = root.valueTypeName;3import { configure } from '@storybook/react';4import requireContext from 'require-context.macro';5const req = requireContext('../src', true, /\.stories\.js$/);6function loadStories() {7 req.keys().forEach(filename => req(filename));8 require('../test');9}10configure(loadStories, module);11const path = require('path');12const root = path.resolve(__dirname, '../');13module.exports = {14 resolve: {15 alias: {16 }17 }18};19import { storiesOf } from '@storybook/react';20import React from 'react';21import { withInfo } from '@storybook/addon-info';22import { withKnobs } from '@storybook/addon-knobs';23import { withNotes } from '@storybook/addon-notes';24import { withTests } from '@storybook/addon-jest';25import results from '../.jest-test-results.json';26storiesOf('test', module)27 .addDecorator(withInfo)28 .addDecorator(withKnobs)29 .addDecorator(withNotes)30 .addDecorator(withTests({ results }))31 .add('test', () => {32 return <div>test</div>;33 });
Using AI Code Generation
1var storybook = require('storybook-root');2console.log(storybook.valueTypeName(1));3var storybook = require('storybook-root');4console.log(storybook.valueTypeName(1));5var storybook = require('storybook-root');6console.log(storybook.valueTypeName(1));7var storybook = require('storybook-root');8console.log(storybook.valueTypeName(1));9var storybook = require('storybook-root');10console.log(storybook.valueTypeName(1));11var storybook = require('storybook-root');12console.log(storybook.valueTypeName(1));13var storybook = require('storybook-root');14console.log(storybook.valueTypeName(1));15var storybook = require('storybook-root');16console.log(storybook.valueTypeName(1));17var storybook = require('storybook-root');18console.log(storybook.valueTypeName(1));19var storybook = require('storybook-root');20console.log(storybook.valueTypeName(1));21var storybook = require('storybook-root');22console.log(storybook.valueTypeName(1));23var storybook = require('storybook-root');24console.log(storybook.valueTypeName(1));
Using AI Code Generation
1import { valueTypeName } from 'storybook-root';2export { valueTypeName } from './lib/util';3export function valueTypeName(value) {4 return Object.prototype.toString.call(value).slice(8, -1);5}6{7}8import { valueTypeName } from 'storybook-root';9export { valueTypeName } from './lib/util';10export function valueTypeName(value) {11 return Object.prototype.toString.call(value).slice(8, -1);12}13{14}15Now, the "main" field tells Node that the main entry point of the package is in the index.js file. This means that we can import the valueTypeName method like so:16import { valueTypeName } from 'storybook-root';
Using AI Code Generation
1import { valueTypeName } from 'storybook-root';2const type = valueTypeName(123);3import { valueTypeName } from 'storybook-root';4const type = valueTypeName(123);5import { valueTypeName } from 'storybook-root';6const type = valueTypeName(123);7import { valueTypeName } from 'storybook-root';8const type = valueTypeName(123);9import { valueTypeName } from 'storybook-root';10const type = valueTypeName(123);11import { valueTypeName } from 'storybook-root';12const type = valueTypeName(123);13import { valueTypeName } from 'storybook-root';14const type = valueTypeName(123);15import { valueTypeName } from 'storybook-root';16const type = valueTypeName(123);17import { valueTypeName } from 'storybook-root';18const type = valueTypeName(123);19import { valueTypeName } from 'storybook-root';20const type = valueTypeName(123);21import { valueTypeName } from 'storybook-root';22const type = valueTypeName(123);23import { valueTypeName } from 'storybook-root';24const type = valueTypeName(123);
Using AI Code Generation
1var root = require("storyboard-root");2var valueTypeName = root.valueTypeName;3var value = 5;4var valueType = valueTypeName(value);5console.log(valueType);6var root = require("storyboard-root");7var valueTypeName = root.valueTypeName;8var value = "hello";9var valueType = valueTypeName(value);10console.log(valueType);11var root = require("storyboard-root");12var valueTypeName = root.valueTypeName;13var value = true;14var valueType = valueTypeName(value);15console.log(valueType);16var root = require("storyboard-root");17var valueTypeName = root.valueTypeName;18var value = [1, 2, 3];19var valueType = valueTypeName(value);20console.log(valueType);21var root = require("storyboard-root");22var valueTypeName = root.valueTypeName;23var value = {a: 1, b: 2};24var valueType = valueTypeName(value);25console.log(valueType);26var root = require("storyboard-root");27var valueTypeName = root.valueTypeName;28var value = function() {};29var valueType = valueTypeName(value);30console.log(valueType);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!