Best JavaScript code snippet using tracetest
local_storage_store.test.jsx
Source:local_storage_store.test.jsx
1// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.2// See LICENSE.txt for license information.3import assert from 'assert';4import LocalStorageStore, {getPenultimateChannelNameKey} from 'stores/local_storage_store';5describe('stores/LocalStorageStore', () => {6 test('should persist previous team id per user', () => {7 const userId1 = 'userId1';8 const userId2 = 'userId2';9 const teamId1 = 'teamId1';10 const teamId2 = 'teamId2';11 LocalStorageStore.setPreviousTeamId(userId1, teamId1);12 LocalStorageStore.setPreviousTeamId(userId2, teamId2);13 assert.equal(LocalStorageStore.getPreviousTeamId(userId1), teamId1);14 assert.equal(LocalStorageStore.getPreviousTeamId(userId2), teamId2);15 });16 test('should persist previous channel name per team and user', () => {17 const userId1 = 'userId1';18 const userId2 = 'userId2';19 const teamId1 = 'teamId1';20 const teamId2 = 'teamId2';21 const channel1 = 'channel1';22 const channel2 = 'channel2';23 const channel3 = 'channel3';24 LocalStorageStore.setPreviousChannelName(userId1, teamId1, channel1);25 LocalStorageStore.setPreviousChannelName(userId2, teamId1, channel2);26 LocalStorageStore.setPreviousChannelName(userId2, teamId2, channel3);27 assert.equal(LocalStorageStore.getPreviousChannelName(userId1, teamId1), channel1);28 assert.equal(LocalStorageStore.getPreviousChannelName(userId2, teamId1), channel2);29 assert.equal(LocalStorageStore.getPreviousChannelName(userId2, teamId2), channel3);30 });31 test('should persist recent emojis per user', () => {32 const userId1 = 'userId1';33 const userId2 = 'userId2';34 const recentEmojis1 = ['smile', 'joy', 'grin'];35 const recentEmojis2 = ['customEmoji', '+1', 'mattermost'];36 assert.equal(LocalStorageStore.getRecentEmojis(userId1), null);37 assert.equal(LocalStorageStore.getRecentEmojis(userId2), null);38 LocalStorageStore.setRecentEmojis(userId1, []);39 LocalStorageStore.setRecentEmojis(userId2, []);40 assert.equal(LocalStorageStore.getRecentEmojis(userId1), null);41 assert.equal(LocalStorageStore.getRecentEmojis(userId2), null);42 LocalStorageStore.setRecentEmojis(userId1, recentEmojis1);43 LocalStorageStore.setRecentEmojis(userId2, recentEmojis2);44 const recentEmojisForUser1 = JSON.parse(LocalStorageStore.getRecentEmojis(userId1));45 assert.deepEqual(recentEmojisForUser1, recentEmojis1);46 const recentEmojisForUser2 = JSON.parse(LocalStorageStore.getRecentEmojis(userId2));47 assert.deepEqual(recentEmojisForUser2, recentEmojis2);48 });49 describe('should persist separately for different subpaths', () => {50 test('getWasLoggedIn', () => {51 delete window.basename;52 // Initially false53 assert.equal(LocalStorageStore.getWasLoggedIn(), false);54 // True after set55 LocalStorageStore.setWasLoggedIn(true);56 assert.equal(LocalStorageStore.getWasLoggedIn(), true);57 // Still true when basename explicitly set58 window.basename = '/';59 assert.equal(LocalStorageStore.getWasLoggedIn(), true);60 // Different with different basename61 window.basename = '/subpath';62 assert.equal(LocalStorageStore.getWasLoggedIn(), false);63 LocalStorageStore.setWasLoggedIn(true);64 assert.equal(LocalStorageStore.getWasLoggedIn(), true);65 // Back to old value with original basename66 window.basename = '/';67 assert.equal(LocalStorageStore.getWasLoggedIn(), true);68 LocalStorageStore.setWasLoggedIn(false);69 assert.equal(LocalStorageStore.getWasLoggedIn(), false);70 // Value with different basename remains unchanged.71 window.basename = '/subpath';72 assert.equal(LocalStorageStore.getWasLoggedIn(), true);73 });74 test('recentEmojis', () => {75 delete window.basename;76 const userId = 'userId';77 const recentEmojis1 = ['smile', 'joy', 'grin'];78 const recentEmojis2 = ['customEmoji', '+1', 'mattermost'];79 // Initially empty80 assert.equal(LocalStorageStore.getRecentEmojis(userId), null);81 // After set82 LocalStorageStore.setRecentEmojis(userId, recentEmojis1);83 assert.deepEqual(JSON.parse(LocalStorageStore.getRecentEmojis(userId)), recentEmojis1);84 // Still set when basename explicitly set85 window.basename = '/';86 assert.deepEqual(JSON.parse(LocalStorageStore.getRecentEmojis(userId)), recentEmojis1);87 // Different with different basename88 window.basename = '/subpath';89 assert.equal(LocalStorageStore.getRecentEmojis(userId), null);90 LocalStorageStore.setRecentEmojis(userId, recentEmojis2);91 assert.deepEqual(JSON.parse(LocalStorageStore.getRecentEmojis(userId)), recentEmojis2);92 // Back to old value with original basename93 window.basename = '/';94 assert.deepEqual(JSON.parse(LocalStorageStore.getRecentEmojis(userId)), recentEmojis1);95 });96 });97 describe('testing previous channel', () => {98 test('should remove previous channel without subpath', () => {99 const userId1 = 'userId1';100 const teamId1 = 'teamId1';101 const channel1 = 'channel1';102 const channel2 = 'channel2';103 LocalStorageStore.setPreviousChannelName(userId1, teamId1, channel1);104 assert.equal(LocalStorageStore.getPreviousChannelName(userId1, teamId1), channel1);105 LocalStorageStore.setPenultimateChannelName(userId1, teamId1, channel2);106 assert.equal(LocalStorageStore.getPenultimateChannelName(userId1, teamId1), channel2);107 LocalStorageStore.removePreviousChannelName(userId1, teamId1);108 assert.equal(LocalStorageStore.getPreviousChannelName(userId1, teamId1), channel2);109 });110 test('should remove previous channel using subpath', () => {111 const userId1 = 'userId1';112 const teamId1 = 'teamId1';113 const channel1 = 'channel1';114 const channel2 = 'channel2';115 window.basename = '/subpath';116 LocalStorageStore.setPreviousChannelName(userId1, teamId1, channel1);117 assert.equal(LocalStorageStore.getPreviousChannelName(userId1, teamId1), channel1);118 LocalStorageStore.setPenultimateChannelName(userId1, teamId1, channel2);119 assert.equal(LocalStorageStore.getPenultimateChannelName(userId1, teamId1), channel2);120 LocalStorageStore.removePreviousChannelName(userId1, teamId1);121 assert.equal(LocalStorageStore.getPreviousChannelName(userId1, teamId1), channel2);122 });123 });124 describe('test removing penultimate channel', () => {125 test('should remove previous channel without subpath', () => {126 const userId1 = 'userId1';127 const teamId1 = 'teamId1';128 const channel1 = 'channel1';129 const channel2 = 'channel2';130 LocalStorageStore.setPreviousChannelName(userId1, teamId1, channel1);131 assert.equal(LocalStorageStore.getPreviousChannelName(userId1, teamId1), channel1);132 LocalStorageStore.setPenultimateChannelName(userId1, teamId1, channel2);133 assert.equal(LocalStorageStore.getPenultimateChannelName(userId1, teamId1), channel2);134 LocalStorageStore.removePenultimateChannelName(userId1, teamId1);135 assert.equal(LocalStorageStore.getPreviousChannelName(userId1, teamId1), channel1);136 assert.equal(LocalStorageStore.getItem(getPenultimateChannelNameKey(userId1, teamId1)), undefined);137 });138 });...
threadsInTeam.test.ts
Source:threadsInTeam.test.ts
1// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.2// See LICENSE.txt for license information.3import {ThreadTypes} from 'mattermost-redux/action_types';4import deepFreeze from 'mattermost-redux/utils/deep_freeze';5import {ExtraData} from './types';6import {handleFollowChanged} from './threadsInTeam';7describe('handleFollowChanged', () => {8 const state = deepFreeze({9 team_id1: ['id1_1', 'id1_2'],10 team_id2: ['id2_1', 'id2_2'],11 });12 const makeAction = (id: string, following: boolean) => ({13 type: ThreadTypes.FOLLOW_CHANGED_THREAD,14 data: {15 team_id: 'team_id1',16 id,17 following,18 },19 });20 const extra = {21 threads: {22 id1_0: {23 id: 'id1_0',24 last_reply_at: 0,25 },26 id1_1: {27 id: 'id1_1',28 last_reply_at: 10,29 },30 id1_2: {31 id: 'id1_1',32 last_reply_at: 20,33 },34 id1_3: {35 id: 'id1_3',36 last_reply_at: 30,37 },38 id2_1: {39 id: 'id2_1',40 last_reply_at: 100,41 },42 id2_2: {43 id: 'id2_2',44 last_reply_at: 200,45 },46 },47 } as unknown as ExtraData;48 test('follow existing thread', () => {49 const action = makeAction('id1_1', true);50 expect(handleFollowChanged(state, action, extra)).toEqual({51 team_id1: ['id1_1', 'id1_2'],52 team_id2: ['id2_1', 'id2_2'],53 });54 });55 test.each([56 ['id1_1', false, ['id1_2']],57 ['id1_3', false, ['id1_1', 'id1_2']],58 ['id1_1', true, ['id1_1', 'id1_2']],59 ['id1_3', true, ['id1_1', 'id1_2', 'id1_3']],60 ['id1_0', true, ['id1_1', 'id1_2']],61 ])('should return correct state for thread id %s and following state of %s', (id, following, expected) => {62 const action = makeAction(id, following);63 expect(handleFollowChanged(state, action, extra)).toEqual({64 team_id1: expected,65 team_id2: ['id2_1', 'id2_2'],66 });67 });...
Using AI Code Generation
1var id1 = require('tracetest').id1;2var id2 = require('tracetest').id2;3var id3 = require('tracetest').id3;4var id4 = require('tracetest').id4;5var a = id1(1);6var b = id2(2);7var c = id3(3);8var d = id4(4);9exports.id1 = function(id) {10 return id;11};12exports.id2 = function(id) {13 return id;14};15exports.id3 = function(id) {16 return id;17};18exports.id4 = function(id) {19 return id;20};21function id1(id) {22 return id;23}24function id2(id) {25 return id;26}27function id3(id) {28 return id;29}30function id4(id) {31 return id;32}
Using AI Code Generation
1const tracetest1 = require('tracetest1');2tracetest1.id1(1);3const tracetest2 = require('tracetest2');4tracetest2.id2(2);5const tracetest3 = require('tracetest3');6tracetest3.id3(3);7const tracetest4 = require('tracetest4');8tracetest4.id4(4);9const tracetest5 = require('tracetest5');10tracetest5.id5(5);11const tracetest6 = require('tracetest6');12tracetest6.id6(6);13const tracetest7 = require('tracetest7');14tracetest7.id7(7);15const tracetest8 = require('tracetest8');16tracetest8.id8(8);17const tracetest9 = require('tracetest9');18tracetest9.id9(9);19const tracetest10 = require('tracetest10');20tracetest10.id10(10);21const tracetest11 = require('tracetest11');22tracetest11.id11(11);23const tracetest12 = require('tracetest12');24tracetest12.id12(12);
Using AI Code Generation
1var tracetest = require('tracetest');2tracetest.id1();3exports.id1 = function() {4 console.log('id1');5};6exports.id2 = function() {7 console.log('id2');8};9exports.id3 = function() {10 console.log('id3');11};12var tracetest = require('tracetest').id1;13tracetest();14exports.id1 = function() {15 console.log('id1');16};17exports.id2 = function() {18 console.log('id2');19};20exports.id3 = function() {21 console.log('id3');22};
Using AI Code Generation
1var tracetest = require('./tracetest');2console.log(tracetest.id1('test'));3module.exports = {4 id1: function (id) {5 return id;6 }7};
Using AI Code Generation
1var tracetest = require('./tracetest');2tracetest.id1('hello');3exports.id1 = function(id) {4 console.log(id);5};6var http = require('http');7var express = require('express');8var app = express();9var server = http.createServer(app);10var io = require('socket.io').listen(server);11app.use(express.static(__dirname + '/public'));12app.get('/', function(req, res) {13 res.sendfile(__dirname + '/public/index.html');14});15io.sockets.on('connection', function(socket) {16 socket.emit('news', { hello: 'world' });17 socket.on('my other event', function(data) {18 console.log(data);19 });20});21server.listen(3000);22socket.on('news', function (data) {23 console.log(data);24 socket.emit('my other event', { my: 'data' });25});
Using AI Code Generation
1var tracetest = {2 id1: function() {3 var id = 1;4 return id;5 },6 id2: function() {7 var id = 2;8 return id;9 }10}11module.exports = tracetest;
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!!