Best JavaScript code snippet using ng-mocks
filtered_search_tokenizer_spec.js
Source:filtered_search_tokenizer_spec.js
...3describe('Filtered Search Tokenizer', () => {4 const allowedKeys = IssuableFilteredSearchTokenKeys.getKeys();5 describe('processTokens', () => {6 it('returns for input containing only search value', () => {7 const results = FilteredSearchTokenizer.processTokens('searchTerm', allowedKeys);8 expect(results.searchToken).toBe('searchTerm');9 expect(results.tokens.length).toBe(0);10 expect(results.lastToken).toBe(results.searchToken);11 });12 it('returns for input containing only tokens', () => {13 const results = FilteredSearchTokenizer.processTokens(14 'author:@root label:~"Very Important" milestone:%v1.0 assignee:none',15 allowedKeys,16 );17 expect(results.searchToken).toBe('');18 expect(results.tokens.length).toBe(4);19 expect(results.tokens[3]).toBe(results.lastToken);20 expect(results.tokens[0].key).toBe('author');21 expect(results.tokens[0].value).toBe('root');22 expect(results.tokens[0].symbol).toBe('@');23 expect(results.tokens[1].key).toBe('label');24 expect(results.tokens[1].value).toBe('"Very Important"');25 expect(results.tokens[1].symbol).toBe('~');26 expect(results.tokens[2].key).toBe('milestone');27 expect(results.tokens[2].value).toBe('v1.0');28 expect(results.tokens[2].symbol).toBe('%');29 expect(results.tokens[3].key).toBe('assignee');30 expect(results.tokens[3].value).toBe('none');31 expect(results.tokens[3].symbol).toBe('');32 });33 it('returns for input starting with search value and ending with tokens', () => {34 const results = FilteredSearchTokenizer.processTokens(35 'searchTerm anotherSearchTerm milestone:none',36 allowedKeys,37 );38 expect(results.searchToken).toBe('searchTerm anotherSearchTerm');39 expect(results.tokens.length).toBe(1);40 expect(results.tokens[0]).toBe(results.lastToken);41 expect(results.tokens[0].key).toBe('milestone');42 expect(results.tokens[0].value).toBe('none');43 expect(results.tokens[0].symbol).toBe('');44 });45 it('returns for input starting with tokens and ending with search value', () => {46 const results = FilteredSearchTokenizer.processTokens(47 'assignee:@user searchTerm',48 allowedKeys,49 );50 expect(results.searchToken).toBe('searchTerm');51 expect(results.tokens.length).toBe(1);52 expect(results.tokens[0].key).toBe('assignee');53 expect(results.tokens[0].value).toBe('user');54 expect(results.tokens[0].symbol).toBe('@');55 expect(results.lastToken).toBe(results.searchToken);56 });57 it('returns for input containing search value wrapped between tokens', () => {58 const results = FilteredSearchTokenizer.processTokens(59 'author:@root label:~"Won\'t fix" searchTerm anotherSearchTerm milestone:none',60 allowedKeys,61 );62 expect(results.searchToken).toBe('searchTerm anotherSearchTerm');63 expect(results.tokens.length).toBe(3);64 expect(results.tokens[2]).toBe(results.lastToken);65 expect(results.tokens[0].key).toBe('author');66 expect(results.tokens[0].value).toBe('root');67 expect(results.tokens[0].symbol).toBe('@');68 expect(results.tokens[1].key).toBe('label');69 expect(results.tokens[1].value).toBe('"Won\'t fix"');70 expect(results.tokens[1].symbol).toBe('~');71 expect(results.tokens[2].key).toBe('milestone');72 expect(results.tokens[2].value).toBe('none');73 expect(results.tokens[2].symbol).toBe('');74 });75 it('returns for input containing search value in between tokens', () => {76 const results = FilteredSearchTokenizer.processTokens(77 'author:@root searchTerm assignee:none anotherSearchTerm label:~Doing',78 allowedKeys,79 );80 expect(results.searchToken).toBe('searchTerm anotherSearchTerm');81 expect(results.tokens.length).toBe(3);82 expect(results.tokens[2]).toBe(results.lastToken);83 expect(results.tokens[0].key).toBe('author');84 expect(results.tokens[0].value).toBe('root');85 expect(results.tokens[0].symbol).toBe('@');86 expect(results.tokens[1].key).toBe('assignee');87 expect(results.tokens[1].value).toBe('none');88 expect(results.tokens[1].symbol).toBe('');89 expect(results.tokens[2].key).toBe('label');90 expect(results.tokens[2].value).toBe('Doing');91 expect(results.tokens[2].symbol).toBe('~');92 });93 it('returns search value for invalid tokens', () => {94 const results = FilteredSearchTokenizer.processTokens('fake:token', allowedKeys);95 expect(results.lastToken).toBe('fake:token');96 expect(results.searchToken).toBe('fake:token');97 expect(results.tokens.length).toEqual(0);98 });99 it('returns search value and token for mix of valid and invalid tokens', () => {100 const results = FilteredSearchTokenizer.processTokens('label:real fake:token', allowedKeys);101 expect(results.tokens.length).toEqual(1);102 expect(results.tokens[0].key).toBe('label');103 expect(results.tokens[0].value).toBe('real');104 expect(results.tokens[0].symbol).toBe('');105 expect(results.lastToken).toBe('fake:token');106 expect(results.searchToken).toBe('fake:token');107 });108 it('returns search value for invalid symbols', () => {109 const results = FilteredSearchTokenizer.processTokens('std::includes', allowedKeys);110 expect(results.lastToken).toBe('std::includes');111 expect(results.searchToken).toBe('std::includes');112 });113 it('removes duplicated values', () => {114 const results = FilteredSearchTokenizer.processTokens('label:~foo label:~foo', allowedKeys);115 expect(results.tokens.length).toBe(1);116 expect(results.tokens[0].key).toBe('label');117 expect(results.tokens[0].value).toBe('foo');118 expect(results.tokens[0].symbol).toBe('~');119 });120 });...
processTokens.test.mjs
Source:processTokens.test.mjs
...13import { shadowsFrame } from '../testdata/shadowsFrame.mjs';14import { zIndicesFrame } from '../testdata/zIndicesFrame.mjs';15test('It should throw an error if no parameter is provided', () => {16 expect(() => {17 processTokens();18 }).toThrow();19});20test('It should return data when passed valid color frame and valid settings', () => {21 expect(processTokens(colorFrame, 'color', defaultSettings)).toEqual(22 expect.objectContaining({23 black: 'rgba(1, 0, 45, 1)',24 blue1: 'rgba(47, 128, 237, 1)',25 blue2: 'rgba(45, 156, 219, 1)',26 blue3: 'rgba(86, 204, 242, 1)',27 gray1: 'rgba(79, 79, 79, 1)',28 gray2: 'rgba(130, 130, 130, 1)',29 gray3: 'rgba(189, 189, 189, 1)',30 gray4: 'rgba(224, 224, 224, 1)',31 gray5: 'rgba(242, 242, 242, 1)',32 green1: 'rgba(33, 150, 83, 1)',33 green2: 'rgba(39, 174, 96, 1)',34 green3: 'rgba(111, 207, 151, 1)',35 neon: 'rgba(228, 255, 193, 1)',36 orange: 'rgba(242, 153, 74, 1)',37 red: 'rgba(235, 87, 87, 1)',38 white: 'rgba(255, 255, 255, 1)',39 yellow: 'rgba(242, 201, 76, 1)'40 })41 );42});43test('It should return data when passed valid spacing frame and valid settings', () => {44 expect(processTokens(spacingFrame, 'spacing', defaultSettings)).toEqual(45 expect.objectContaining({46 huge: '5rem',47 large: '4.375rem',48 medium: '3.125rem',49 small: '1.5rem',50 tiny: '0.75rem'51 })52 );53});54test('It should return data when passed valid font families frame and valid settings', () => {55 expect(processTokens(fontFrame, 'fontfamilies', defaultSettings)).toEqual(56 expect.objectContaining({57 light: 'HelveticaNeue',58 medium: 'HelveticaNeue',59 regular: 'HelveticaNeue'60 })61 );62});63test('It should return data when passed valid font size frame and valid settings', () => {64 expect(processTokens(fontSizeFrame, 'fontsizes', defaultSettings)).toEqual(65 expect.objectContaining({66 h1: '3rem',67 h2: '2.5rem',68 h3: '2rem',69 h4: '1.25rem',70 l: '1.25rem',71 m: '1rem',72 microcopy: '0.625rem',73 s: '0.75rem'74 })75 );76});77test('It should return data when passed valid font weights frame and valid settings', () => {78 expect(processTokens(fontWeightFrame, 'fontweights', defaultSettings)).toEqual(79 expect.objectContaining({ light: 300, medium: 500, regular: 400 })80 );81});82test('It should return data when passed valid line heights frame and valid settings', () => {83 expect(processTokens(lineHeightFrame, 'lineheights', defaultSettings)).toEqual(84 expect.objectContaining({ l: '1.99', m: '1.76', s: '1.46', xs: '1.00' })85 );86});87//88test('It should return data when passed valid border width frame and valid settings', () => {89 expect(processTokens(borderWidthsFrame, 'borderwidths', defaultSettings)).toEqual(90 expect.objectContaining({ chunky: '8px', fat: '4px', hairline: '1px', regular: '2px' })91 );92});93test('It should return data when passed valid letter spacings frame and valid settings', () => {94 expect(processTokens(letterSpacingsFrame, 'letterspacings', defaultSettings)).toEqual(95 expect.objectContaining({ regular: '0px', tight: '-2.40px', wide: '3.30px' })96 );97});98test('It should return data when passed valid media queries frame and valid settings', () => {99 expect(processTokens(mediaQueriesFrame, 'mediaqueries', defaultSettings)).toEqual(100 expect.objectContaining({101 desktoplg: '1440px',102 desktopmd: '1180px',103 mobilelg: '580px',104 mobilemax: '767px',105 mobilemd: '480px',106 mobilesm: '320px',107 tabletmax: '1024px',108 tabletmin: '768px',109 wide: '1920px'110 })111 );112});113test('It should return data when passed valid radii frame and valid settings', () => {114 expect(processTokens(radiiFrame, 'radii', defaultSettings)).toEqual(115 expect.objectContaining({ circle: '100%', hard: '0%', rounded: '4%', soft: '8%' })116 );117});118test('It should return data when passed valid shadows frame and valid settings', () => {119 expect(processTokens(shadowsFrame, 'shadows', defaultSettings)).toEqual(120 expect.objectContaining({121 deep: '152px 523px 10px 10px rgba(255, 0, 0, 1)',122 medium: '152px 523px 10px 10px rgba(255, 0, 0, 1)',123 soft: '152px 523px 10px 10px rgba(255, 0, 0, 1)'124 })125 );126});127test('It should return data when passed valid Z index frame and valid settings', () => {128 expect(processTokens(zIndicesFrame, 'zindices', defaultSettings)).toEqual(129 expect.objectContaining({ focus: '10', high: '1', higher: '2', regular: '0', top: '100' })130 );...
03_flow_node_instance.js
Source:03_flow_node_instance.js
1'use strict';2// See manual:3// https://sequelize.readthedocs.io/en/latest/docs/migrations/#functions4// CHANGE NOTES:5// Changes between 7.0.0 and 8.0.0:6// - Moved the following columns from the ProcessTokenTable to the FlowNodeInstanceTable:7// - processInstanceId8// - processModelId9// - correlationId10// - identity11// - callerId => was renamend to "parentProcessInstanceId"12module.exports = {13 up: async (queryInterface, Sequelize, dialect) => {14 console.log('Running updating migrations');15 const environmentIsPostgres = dialect === 'postgres' || dialect === 'test-postgres';16 console.log('Moving unique ID columns from ProcessTokens table to FlowNodeInstance table.');17 await queryInterface.addColumn(18 'FlowNodeInstances',19 'processInstanceId',20 {21 type: Sequelize.STRING,22 allowNull: false,23 defaultValue: '',24 });25 await queryInterface.addColumn(26 'FlowNodeInstances',27 'processModelId',28 {29 type: Sequelize.STRING,30 allowNull: false,31 defaultValue: '',32 });33 await queryInterface.addColumn(34 'FlowNodeInstances',35 'correlationId',36 {37 type: Sequelize.STRING,38 allowNull: false,39 defaultValue: '',40 });41 await queryInterface.addColumn(42 'FlowNodeInstances',43 'identity',44 {45 type: Sequelize.TEXT,46 allowNull: true,47 });48 await queryInterface.addColumn(49 'FlowNodeInstances',50 'parentProcessInstanceId',51 {52 type: Sequelize.STRING,53 allowNull: true,54 });55 const updateFlowNodeInstancesQueryPostgres = `UPDATE "FlowNodeInstances"56 SET57 "processInstanceId" = (58 SELECT "processInstanceId"59 FROM "ProcessTokens"60 WHERE "FlowNodeInstances"."flowNodeInstanceId" = "ProcessTokens"."flowNodeInstanceId"61 LIMIT 1),62 "processModelId" = (63 SELECT "processModelId"64 FROM "ProcessTokens"65 WHERE "FlowNodeInstances"."flowNodeInstanceId" = "ProcessTokens"."flowNodeInstanceId"66 LIMIT 1),67 "correlationId" = (68 SELECT "correlationId"69 FROM "ProcessTokens"70 WHERE "FlowNodeInstances"."flowNodeInstanceId" = "ProcessTokens"."flowNodeInstanceId"71 LIMIT 1),72 "identity" = (73 SELECT "identity"74 FROM "ProcessTokens"75 WHERE "FlowNodeInstances"."flowNodeInstanceId" = "ProcessTokens"."flowNodeInstanceId"76 LIMIT 1),77 "parentProcessInstanceId" = (78 SELECT "caller"79 FROM "ProcessTokens"80 WHERE "FlowNodeInstances"."flowNodeInstanceId" = "ProcessTokens"."flowNodeInstanceId"81 LIMIT 1);`;82 const updateFlowNodeInstancesQueryDefault = updateFlowNodeInstancesQueryPostgres.replace(/"/gi, '');83 if (environmentIsPostgres) {84 await queryInterface.sequelize.query(updateFlowNodeInstancesQueryPostgres);85 } else {86 await queryInterface.sequelize.query(updateFlowNodeInstancesQueryDefault);87 }88 await queryInterface.removeColumn('ProcessTokens', 'processInstanceId');89 await queryInterface.removeColumn('ProcessTokens', 'processModelId');90 await queryInterface.removeColumn('ProcessTokens', 'correlationId');91 await queryInterface.removeColumn('ProcessTokens', 'identity');92 await queryInterface.removeColumn('ProcessTokens', 'caller');93 console.log('Migration successful.');94 },95 down: async (queryInterface, Sequelize) => {96 console.log('Running reverting migrations');97 return Promise.resolve();98 },...
Using AI Code Generation
1import { processTokens } from 'ng-mocks';2describe('test', () => {3 it('test', () => {4 const result = processTokens([MyService]);5 expect(result).toEqual([MyService]);6 });7});8import { processTokens } from 'ng-mocks';9describe('test', () => {10 it('test', () => {11 const result = processTokens([MyService]);12 expect(result).toEqual([MyService]);13 });14});15import { processTokens } from 'ng-mocks';16describe('test', () => {17 it('test', () => {18 const result = processTokens([MyService]);19 expect(result).toEqual([MyService]);20 });21});22import { processTokens } from 'ng-mocks';23describe('test', () => {24 it('test', () => {25 const result = processTokens([MyService]);26 expect(result).toEqual([MyService]);27 });28});29import { processTokens } from 'ng-mocks';30describe('test', () => {31 it('test', () => {32 const result = processTokens([MyService]);33 expect(result).toEqual([MyService]);34 });35});36import { processTokens } from 'ng-mocks';37describe('test', () => {38 it('test', () => {39 const result = processTokens([MyService]);40 expect(result).toEqual([MyService]);41 });42});43import { processTokens } from 'ng-mocks';44describe('test', () => {45 it('test', () => {46 const result = processTokens([MyService]);47 expect(result).toEqual([MyService]);48 });49});50import { processTokens } from 'ng-mocks';51describe('test', () => {52 it('test', () => {53 const result = processTokens([
Using AI Code Generation
1import { processTokens } from 'ng-mocks';2const mockService = {3 getHelloWorld: () => 'Hello World'4};5const testModule = processTokens({6 {7 }8});9describe('TestComponent', () => {10 let component: TestComponent;11 let fixture: ComponentFixture<TestComponent>;12 beforeEach(() => {13 TestBed.configureTestingModule({14 imports: [testModule],15 }).compileComponents();16 fixture = TestBed.createComponent(TestComponent);17 component = fixture.componentInstance;18 });19 it('should create', () => {20 expect(component).toBeTruthy();21 });22});
Using AI Code Generation
1import { ServiceToBeTested } from './service-to-be-tested';2import { mockProvider, mockReset } from 'ng-mocks';3import { Dependency1 } from './dependency1';4import { Dependency2 } from './dependency2';5describe('ServiceToBeTested', () => {6 let service: ServiceToBeTested;7 beforeEach(() => {8 mockProvider(Dependency1, { method1: () => 'mocked' });9 mockProvider(Dependency2, { method2: () => 'mocked' });10 service = mockProvider(ServiceToBeTested);11 });12 afterEach(() => {13 mockReset();14 });15 it('should be created', () => {16 expect(service).toBeTruthy();17 });18});
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!!