Best JavaScript code snippet using cypress
projects_list_spec.js
Source:projects_list_spec.js
1describe('Projects List', function () {2 beforeEach(function () {3 cy.fixture('user').as('user')4 cy.fixture('projects').as('projects')5 cy.fixture('projects_statuses').as('projectStatuses')6 cy.fixture('config').as('config')7 cy.fixture('specs').as('specs')8 this.dropEvent = {9 dataTransfer: {10 files: [{ path: '/foo/bar' }],11 },12 }13 this.getLocalStorageProjects = () => {14 return JSON.parse(localStorage.projects || '[]')15 }16 this.setLocalStorageProjects = (projects) => {17 return localStorage.projects = JSON.stringify(projects)18 }19 cy.visitIndex().then(function (win) {20 ({ start: this.start, ipc: this.ipc } = win.App)21 cy.stub(this.ipc, 'getOptions').resolves({})22 cy.stub(this.ipc, 'updaterCheck').resolves(false)23 cy.stub(this.ipc, 'getCurrentUser').resolves(this.user)24 cy.stub(this.ipc, 'logOut').resolves({})25 cy.stub(this.ipc, 'addProject').resolves(this.projects[0])26 cy.stub(this.ipc, 'openProject').resolves(this.config)27 cy.stub(this.ipc, 'getSpecs').yields(null, this.specs)28 cy.stub(this.ipc, 'removeProject')29 this.getProjects = this.util.deferred()30 cy.stub(this.ipc, 'getProjects').returns(this.getProjects.promise)31 this.getProjectStatuses = this.util.deferred()32 cy.stub(this.ipc, 'getProjectStatuses').returns(this.getProjectStatuses.promise)33 })34 })35 describe('general behavior', function () {36 beforeEach(function () {37 this.start()38 })39 it('loads projects and shows loader', function () {40 cy.get('.projects-list .loader').then(() => {41 expect(this.ipc.getProjects).to.be.called42 })43 cy.percySnapshot()44 })45 describe('when loaded', function () {46 beforeEach(function () {47 this.getProjects.resolve(this.projects)48 })49 it('displays projects', function () {50 cy.get('.projects-list li').should('have.length', this.projects.length)51 cy.percySnapshot()52 })53 it('displays project name and path', function () {54 cy.get('.projects-list li:first .project-name')55 .should('have.text', 'My-Fake-Project')56 cy.get('.projects-list li:first .project-path')57 .should('have.text', '/Users/Jane/Projects/My-Fake-Project')58 })59 it('goes to project when clicked', function () {60 cy.get('.projects-list a:first').click()61 cy.shouldBeOnProjectSpecs()62 })63 it('gets project statuses', function () {64 cy.get('.projects-list li').then(() => {65 // ensures projects have loaded66 expect(this.ipc.getProjectStatuses).to.be.called67 })68 })69 describe('when project statuses have loaded', function () {70 beforeEach(function () {71 this.getProjectStatuses.resolve(this.projectStatuses)72 // ensures projects have loaded73 cy.get('.projects-list li').should('have.length', 5)74 })75 it('updates local storage with projects', function () {76 const localStorageProjects = this.getLocalStorageProjects()77 expect(localStorageProjects.length).to.equal(5)78 })79 it('updates project names', () => {80 cy.get('.projects-list li .project-name').eq(3).should('have.text', 'Client Work')81 })82 })83 describe('removing project', function () {84 beforeEach(() => {85 cy.get('.projects-list li:first button').click()86 })87 it('removes project from DOM', function () {88 cy.get('.projects-list li').should('have.length', 4)89 cy.contains(this.projects[0].path).should('not.exist')90 })91 it('removes project through ipc', function () {92 expect(this.ipc.removeProject).to.be.calledWith(this.projects[0].path)93 })94 it('removes project from local storage', function () {95 const localStorageProjects = this.getLocalStorageProjects()96 expect(localStorageProjects.length).to.equal(4)97 expect(localStorageProjects[0].path).not.to.equal(this.projects[0].path)98 })99 })100 })101 describe('when projects statuses are cached in local storage', function () {102 beforeEach(function () {103 this.setLocalStorageProjects([104 {105 id: this.projectStatuses[0].id,106 name: 'Cached name',107 path: this.projects[0].path },108 ])109 this.getProjects.resolve(this.projects)110 })111 it('displays cached name', () => {112 cy.get('.project-name:first').should('have.text', 'Cached name')113 })114 it('updates name displayed and in local storage when project statuses load', function () {115 this.getProjectStatuses.resolve(this.projectStatuses)116 cy.get('.project-name:first')117 .should('have.text', this.projectStatuses[0].name)118 .then(() => {119 const localStorageProjects = this.getLocalStorageProjects()120 expect(localStorageProjects[0].name).to.equal(this.projectStatuses[0].name)121 })122 })123 })124 describe('when there are none', function () {125 beforeEach(function () {126 this.getProjects.resolve([])127 })128 it('shows nothing', () => {129 cy.get('.projects-list').should('not.exist')130 })131 })132 describe('order', function () {133 beforeEach(function () {134 this.aCoupleProjects = [135 { id: 'id-a', path: '/project/a' },136 { id: 'id-b', path: '/project/b' },137 ]138 this.ipc.addProject.withArgs('/project/b').resolves({ id: 'id-b', path: '/project/b' })139 this.ipc.addProject.withArgs('/foo/bar').resolves({ id: 'id-bar', path: '/foo/bar' })140 this.assertOrder = (expected) => {141 const actual = this.getLocalStorageProjects().map((project) => {142 return project.id143 })144 expect(actual).to.eql(expected)145 }146 this.getProjects.resolve(this.aCoupleProjects)147 })148 it('puts project at start when dropped', function () {149 cy.get('.project-drop').trigger('drop', this.dropEvent).should(() => {150 this.assertOrder(['id-bar', 'id-a', 'id-b'])151 })152 })153 it('puts project at start when dropped and it already exists', function () {154 this.dropEvent.dataTransfer.files[0].path = '/project/b'155 cy.get('.project-drop').trigger('drop', this.dropEvent).then(() => {156 this.assertOrder(['id-b', 'id-a'])157 })158 })159 it('puts project at start when selected', function () {160 cy.stub(this.ipc, 'showDirectoryDialog').resolves('/foo/bar')161 cy.get('.project-drop a').click().then(() => {162 this.assertOrder(['id-bar', 'id-a', 'id-b'])163 })164 })165 it('puts project at start when selected and it already exists', function () {166 cy.stub(this.ipc, 'showDirectoryDialog').resolves('/project/b')167 cy.get('.project-drop a').click().then(() => {168 this.assertOrder(['id-b', 'id-a'])169 })170 })171 it('puts project at start when clicked on in list', function () {172 cy.get('.projects-list a').eq(1).click().then(() => {173 this.assertOrder(['id-b', 'id-a'])174 })175 })176 })177 describe('errors', function () {178 beforeEach(function () {179 this.getProjects.resolve(this.projects)180 this.error = {181 name: '',182 message: 'Failed to get project statuses',183 }184 })185 it('displays error above list', function () {186 this.getProjectStatuses.reject(this.error)187 cy.get('.alert').should('contain', 'Failed to get project statuses')188 cy.get('.projects-list li').should('have.length', this.projects.length)189 cy.percySnapshot()190 })191 it('does not display api errors', function () {192 this.error.isApiError = true193 this.getProjectStatuses.reject(this.error)194 cy.contains('Failed to get project statuses').should('not.exist')195 })196 })197 })198 describe('if user becomes unauthenticated', function () {199 beforeEach(function () {200 this.unauthError = { name: '', message: '', statusCode: 401 }201 // error is being caught here for some reason, so nullify it202 window.onunhandledrejection = function () {}203 this.start()204 })205 afterEach(() => {206 window.onunhandledrejection = undefined207 })208 it('logs user out when get:projects returns 401', function () {209 this.getProjects.reject(this.unauthError)210 cy.shouldBeLoggedOut()211 })212 it('logs user out when get:project:statuses returns 401', function () {213 this.getProjects.resolve([])214 this.getProjectStatuses.reject(this.unauthError)215 cy.shouldBeLoggedOut()216 })217 })218 describe('when there are projects in local storage that no longer exist', function () {219 beforeEach(function () {220 const localStorageProjects = this.util.deepClone(this.projects)221 localStorageProjects[0].path = 'has/been/moved'222 this.setLocalStorageProjects(localStorageProjects)223 this.projects.shift()224 this.getProjects.resolve(this.projects)225 this.start()226 })227 it('does not display them', () => {228 cy.get('.project-name:first').should('have.text', 'My-Other-Fake-Project')229 })230 })...
project_static.js
Source:project_static.js
...78 }79 });80}81exports._getProject = _getProject;82function getProjectStatuses(clientProjects = []) {83 return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {84 debug(`get project statuses for ${clientProjects.length} projects`);85 const authToken = yield user_1.default.ensureAuthToken();86 debug('got auth token: %o', { authToken: keys_1.default.hide(authToken) });87 const projects = ((yield api_1.default.getProjects(authToken)) || []);88 debug(`got ${projects.length} projects`);89 const projectsIndex = lodash_1.default.keyBy(projects, 'id');90 return Promise.all(lodash_1.default.map(clientProjects, (clientProject) => {91 debug('looking at', clientProject.path);92 // not a CI project, just mark as valid and return93 if (!clientProject.id) {94 debug('no project id');95 return _mergeState(clientProject, 'VALID');96 }...
enumsSelectors.js
Source:enumsSelectors.js
1import {createSelector} from "reselect";2import _ from "lodash";3export const getCreditAccountEnum = state => state.enum.enums.creditAccountEnum;4export const getProjectStatuses = state => state.enum.projectStatuses;5export const getAllProjects = state => state.enum.enums.projectsEnum;6export const getTransactionEnum = state => state.enum.enums.transactionEnum;7export const getAllEnums = state => state.enum.enums;8export const getGroupEnum = state => state.enum.enums.groupEnum;9export const getMembersEnum = state => state.enum.enums.membersEnum;10export const getSortedMembers = createSelector(11 getMembersEnum,12 (members) => {13 let data = members14 if (members) {15 data = _.orderBy(members, 'name', 'asc');16 data = data.filter(item => item.kanban === 1)17 }18 return data19 }20)21export const getUniqueEntity = createSelector(22 getCreditAccountEnum,23 (creditAccountEnum) => {24 let result = [];25 for (let item of creditAccountEnum) {26 if (!result.includes(item.entity)) {27 result.push(item.entity);28 }29 }30 return result;31 }32)33export const getProjectStatusesArray = createSelector(34 getProjectStatuses,35 (projectStatuses) => {36 let result = [];37 if (projectStatuses) {38 for (let key in projectStatuses) {39 result.push({id: key, title: projectStatuses[key]})40 }41 }42 return result;43 }44)45export const getTransactionsWithNames = createSelector(46 getTransactionEnum,47 getAllEnums,48 (transEnum, allEnums) => {49 if (transEnum && transEnum.data) {50 for (let i = 0; i < transEnum.data.length; i++) {51 let contractorName = '';52 let projectName = '';53 if (transEnum.data[i]?.contragent) {54 contractorName = allEnums.contractorEnum.find(item => item.id == transEnum.data[i].contragent)?.title || '';55 }56 if (transEnum.data[i]?.consider_id) {57 allEnums.allProjects.data.forEach(val => {58 if (val.id == transEnum.data[i].consider_id) {59 projectName = val.title60 }61 })62 }63 transEnum.data[i] = {...transEnum.data[i], contractorName, projectName}64 }65 }66 return transEnum;67 }68)69export const getMinMaxBudget = createSelector(70 getAllProjects,71 (projects) => {72 if (!projects || projects.data.length === 0) {73 return {min: 0, max: 999999}74 }75 let min = _.minBy(projects?.data, function(o) { return _.parseInt(o.budget); }).budget || 0;76 let max = _.maxBy(projects?.data, function(o) { return _.parseInt(o.budget); }).budget || 0;77 return {78 min, max79 }80 }81)82export const getFilterClientsEnum = createSelector(83 getAllProjects,84 getGroupEnum,85 (projects, clients) => {86 let uniqueEntity = [];87 projects.data.forEach(item => {88 if (!uniqueEntity.includes(item.client)) {89 uniqueEntity.push(item.client);90 }91 })92 let clientsArr = [];93 clients.forEach(item => {94 if (uniqueEntity.includes(item.id)) {95 clientsArr.push(item)96 }97 })98 return clientsArr99 }100)101export const getFilterStatusEnum = createSelector(102 getAllProjects,103 getProjectStatuses,104 (projects, statuses) => {105 let uniqueEntity = [];106 projects.data.forEach(item => {107 if (!uniqueEntity.includes(item.status)) {108 uniqueEntity.push(item.status);109 }110 })111 let result = [];112 if (statuses) {113 for (let key in statuses) {114 result.push({id: key, title: statuses[key]})115 }116 }117 let statusesArr = [];118 result.forEach(item => {119 if (uniqueEntity.includes(+item.id)) {120 statusesArr.push(item)121 }122 })123 return statusesArr124 }...
projectStatus.controller.js
Source:projectStatus.controller.js
1import {2 createProjectStatusService,3 deleteProjectStatusService,4 getProjectStatusService,5 getProjectStatusesService,6 updateProjectStatusService,7} from '../services/projectStatus.service';8export {9 getProjectStatuses,10 getProjectStatus,11 createProjectStatus,12 updateProjectStatus,13 deleteProjectStatus,14};15const getProjectStatuses = async (req, res, next) => {16 try {17 const response = await getProjectStatusesService(req.query);18 return res.status(response.status).json(response);19 } catch (error) {20 return next(error);21 }22};23const getProjectStatus = async (req, res, next) => {24 try {25 const response = await getProjectStatusService(req.params.id);26 return res.status(response.status).json(response);27 } catch (error) {28 return next(error);29 }30};31const createProjectStatus = async (req, res, next) => {32 try {33 const response = await createProjectStatusService(req.body);34 return res.status(response.status).json(response);35 } catch (error) {36 return next(error);37 }38};39const updateProjectStatus = async (req, res, next) => {40 try {41 const response = await updateProjectStatusService(req.params.id, req.body);42 return res.status(response.status).json(response);43 } catch (error) {44 return next(error);45 }46};47const deleteProjectStatus = async (req, res, next) => {48 try {49 const response = await deleteProjectStatusService(req.params.id);50 return res.status(response.status).json(response);51 } catch (error) {52 return next(error);53 }54};55// const Types = [56// {57// name: 'open',58// description: 'open',59// status: 'active',60// },61// {62// name: 'urgent',63// description: 'urgent',64// status: 'active',65// },66// {67// name: 'in progress',68// description: 'in progress',69// status: 'active',70// },71// {72// name: 'in review',73// description: 'in review',74// status: 'active',75// },76// {77// name: 'resolved',78// description: 'recolved',79// status: 'active',80// },81// {82// name: 'closed',83// description: 'closed',84// status: 'active',85// },...
ProjectCountsController.js
Source:ProjectCountsController.js
...3 // Set filter default4 var filters = {};5 filters["My Projects"] = true;6 cmp.set("v.filters", filters);7 helper.getProjectStatuses(cmp);8 helper.getNameSpace(cmp);9 var statuses = cmp.get("v.statuses"); 10 },11 update: function (component, event, helper) {12 // Get the new location token from the event if needed13 //var loc = event.getParam("token");14 if (component) {15 helper.getProjectStatuses(component);16 //$A.get('e.force:refreshView').fire(); 17 }18 },19 toggleFilter: function(cmp, event, helper) {20 // Get the current filters21 var filters = {},22 thisFilter;23 24 // Set selected element25 thisFilter = event.currentTarget;26 helper.clearSelections();27 thisFilter.className += " psbar-button_on";28 29 // Toggle the filter in the filters object...
ProjectsService.js
Source:ProjectsService.js
12const PROJECTS_SERVICE_URI = (method) => `/projects/${method}`;3const ProjectsService = {4 GetById: function (id) {5 const url = PROJECTS_SERVICE_URI(`GetById?id=${id}`)6 return axios.get(url);7 },8 Save: function (project) {9 const url = PROJECTS_SERVICE_URI(`Save`)10 return axios.post(url, project);11 },12 Search: function (categoryId, keyword, page, countPerPage) {13 const query = serialize({ categoryId, keyword, page, countPerPage })14 const url = PROJECTS_SERVICE_URI(`Search?${query}`)15 return axios.get(url);16 },17 GetStatusModifications: function (projectId) {18 const query = serialize({ projectId })19 const url = PROJECTS_SERVICE_URI(`GetStatusModifications?${query}`)20 return axios.get(url);21 },22 GetByTeam: function (teamId) {23 const query = serialize({ teamId })24 const url = PROJECTS_SERVICE_URI(`GetByTeam?${query}`)25 return axios.get(url);26 },27 GetOverview: function (projectId) {28 const query = serialize({ projectId })29 const url = PROJECTS_SERVICE_URI(`GetOverview?${query}`)30 return axios.get(url);31 },32 Delete: function (id) {33 const url = PROJECTS_SERVICE_URI(`Delete?id=${id}`)34 return axios.delete(url);35 },36 GetProjectStatuses: function () {37 const url = PROJECTS_SERVICE_URI(`GetProjectStatuses`)38 return axios.get(url);39 },...
projectStatus.route.js
Source:projectStatus.route.js
1import express from 'express';2import {3 createProjectStatus,4 getProjectStatus,5 getProjectStatuses,6 updateProjectStatus,7 deleteProjectStatus,8} from '../controllers/projectStatus.controller';9import { bearerToken, roleHandler, verifyRequest } from '../middlewares';10const router = express.Router();11router.use('/project-statuses', bearerToken);12router13 .route('/project-statuses')14 .get(roleHandler, getProjectStatuses)15 .post(roleHandler, verifyRequest, createProjectStatus);16router17 .route('/project-statuses/:id')18 .get(roleHandler, getProjectStatus)19 .put(roleHandler, verifyRequest, updateProjectStatus)20 .delete(roleHandler, deleteProjectStatus);...
index.js
Source:index.js
1module.exports = {2 generalByProject: require('./generalByProject'),3 getPeriods: require('./getPeriods'), 4 getProjects: require('./getProjects'), 5 getProjectStatuses: require('./getProjectStatuses'), 6 getProjectExecutors: require('./getProjectExecutors'), 7 findAll: require('./findAll'),8 findById: require('./findbyid'),9 create: require('./create'),10 update: require('./update'),11 remove: require('./delete'),
...
Using AI Code Generation
1describe('Cypress', () => {2 it('is working', () => {3 expect(true).to.equal(true)4 })5 it('can get project statuses', () => {6 cy.getProjectStatuses().then((statuses) => {7 expect(statuses).to.have.length(3)8 expect(statuses[0]).to.have.property('id').to.equal(1)9 expect(statuses[0]).to.have.property('name').to.equal('Open')10 expect(statuses[1]).to.have.property('id').to.equal(2)11 expect(statuses[1]).to.have.property('name').to.equal('In Progress')12 expect(statuses[2]).to.have.property('id').to.equal(3)13 expect(statuses[2]).to.have.property('name').to.equal('Closed')14 })15 })16})17Cypress.Commands.add('getProjectStatuses', () => {18 .then((response) => {19 })20})21describe('Project Statuses', () => {22 it('shows all project statuses', () => {23 cy.visit('/project-statuses')24 cy.contains('Open')25 cy.contains('In Progress')26 cy.contains('Closed')27 })28})29describe('Project Statuses', () => {30 it('shows all project statuses', () => {31 cy.visit('/project-statuses')32 cy.contains('Open')33 cy.contains('In Progress')34 cy.contains('Closed')35 })36})37describe('Project Statuses', () => {38 it('shows all project statuses', () => {39 cy.visit('/project-statuses')40 cy.contains('Open')41 cy.contains('In Progress')42 cy.contains('Closed')43 })44})45describe('Project Statuses', () => {46 it('shows all project statuses', () => {47 cy.visit('/project-statuses')48 cy.contains('Open')49 cy.contains('In Progress')50 cy.contains('Closed')51 })52})53describe('
Using AI Code Generation
1var cypress = require('cypress-api');2var config = {3}4var cypressClient = new cypress(config);5cypressClient.getProjectStatuses(function(err, data) {6 if (err) {7 return console.log(err);8 }9 console.log(data);10});11var cypress = require('cypress-api');12var config = {13}14var cypressClient = new cypress(config);15cypressClient.getProjectRuns('projectId', function(err, data) {16 if (err) {17 return console.log(err);18 }19 console.log(data);20});21var cypress = require('cypress-api');22var config = {23}24var cypressClient = new cypress(config);25cypressClient.getProjectRun('projectId', 'runId', function(err, data) {26 if (err) {27 return console.log(err);28 }29 console.log(data);30});31var cypress = require('cypress-api');32var config = {33}34var cypressClient = new cypress(config);35cypressClient.getProjectRunTests('projectId', 'runId', function(err, data) {36 if (err) {37 return console.log(err);38 }39 console.log(data);40});41var cypress = require('cypress-api');42var config = {43}44var cypressClient = new cypress(config);45cypressClient.getProjectRunTest('projectId', 'runId', 'testId', function(err, data) {46 if (err) {47 return console.log(err);48 }49 console.log(data);50});
Using AI Code Generation
1const api = new CypressTestRailApi();2api.getProjectStatuses(1).then((response) => {3 console.log(response.data);4});5const api = new CypressTestRailApi();6api.getProjectStatuses(1).then((response) => {7 console.log(response.data);8});9const api = new CypressTestRailApi();10api.getProjectStatuses(1).then((response) => {11 console.log(response.data);12});13const api = new CypressTestRailApi();14api.getProjectStatuses(1).then((response) => {15 console.log(response.data);16});17const api = new CypressTestRailApi();18api.getProjectStatuses(1).then((response) => {19 console.log(response.data);20});21const api = new CypressTestRailApi();22api.getProjectStatuses(1).then((response) => {23 console.log(response.data);24});25const api = new CypressTestRailApi();26api.getProjectStatuses(1).then((response) => {27 console.log(response.data);28});29const api = new CypressTestRailApi();30api.getProjectStatuses(1).then((response) => {31 console.log(response.data);32});33const api = new CypressTestRailApi();34api.getProjectStatuses(1).then((response) => {35 console.log(response.data);36});37const api = new CypressTestRailApi();38api.getProjectStatuses(1).then((response) => {39 console.log(response.data);40});41const api = new CypressTestRailApi();42api.getProjectStatuses(1
Using AI Code Generation
1var cypress = require('cypress-api');2api.getProjectsStatuses().then(function (data) {3 console.log(data);4});5var cypress = require('cypress-api');6api.getProjectsStatuses().then(function (data) {7 console.log(data);8});9var cypress = require('cypress-api');10api.getProjectsStatuses().then(function (data) {11 console.log(data);12});13var cypress = require('cypress-api');14api.getProjectsStatuses().then(function (data) {15 console.log(data);16});17var cypress = require('cypress-api');18api.getProjectsStatuses().then(function (data) {19 console.log(data);20});21var cypress = require('cypress-api');22api.getProjectsStatuses().then(function (data) {23 console.log(data);24});25var cypress = require('cypress-api');26api.getProjectsStatuses().then(function (data) {27 console.log(data);28});29var cypress = require('cypress-api');
Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.
You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!