Best JavaScript code snippet using cypress
setup_project_spec.js
Source:setup_project_spec.js
1const onSubmitNewProject = function (orgId) {2 it('sends existing project name, org id, and visibility: private to ipc event by default', function () {3 cy.get('.setup-project')4 .contains('.btn', 'Set up project').click()5 .then(() => {6 expect(this.ipc.setupDashboardProject).to.be.calledWith({7 projectName: this.config.projectName,8 orgId,9 public: false,10 })11 })12 })13 it('sends modified project name, org id, and public flag to ipc event', function () {14 cy.get('#projectName').clear().type('New Project')15 cy.get('.privacy-selector').find('a').click()16 cy.get('.setup-project')17 .contains('.btn', 'Set up project').click()18 .then(() => {19 expect(this.ipc.setupDashboardProject).to.be.calledWith({20 projectName: 'New Project',21 orgId,22 public: true,23 })24 })25 })26 it('disables button and shows spinner', function () {27 cy.get('.setup-project')28 .contains('.btn', 'Set up project')29 .click()30 .should('be.disabled')31 .find('i')32 .should('be.visible')33 })34 context('errors', function () {35 beforeEach(function () {36 cy.get('.setup-project')37 .contains('.btn', 'Set up project').click()38 })39 it('logs user out when 401', function () {40 this.setupDashboardProject.reject({ name: '', message: '', statusCode: 401 })41 cy.shouldBeLoggedOut()42 })43 it('displays error name and message when unexpected', function () {44 this.setupDashboardProject.reject({45 name: 'Fatal Error!',46 message: `{ "system": "down", "toxicity": "of the city" }`,47 })48 cy.contains('"system": "down"')49 cy.percySnapshot()50 })51 })52 context('after submit', function () {53 beforeEach(function () {54 this.setupDashboardProject.resolve({55 id: 'project-id-123',56 public: true,57 orgId,58 })59 cy.get('.setup-project')60 .contains('.btn', 'Set up project').click()61 })62 it('displays empty runs page', function () {63 cy.get('.setup-project').should('not.exist')64 cy.contains('To record your first')65 cy.contains('cypress run --record --key record-key-123')66 })67 it('updates localStorage projects cache', function () {68 const org = Cypress._.find(this.orgs, { id: orgId })69 expect(JSON.parse(localStorage.projects || '[]')[0].orgName).to.equal(org.name)70 })71 })72}73describe('Connect to Dashboard', function () {74 beforeEach(function () {75 cy.fixture('user').as('user')76 cy.fixture('projects').as('projects')77 cy.fixture('projects_statuses').as('projectStatuses')78 cy.fixture('config').as('config')79 cy.fixture('specs').as('specs')80 cy.fixture('organizations').as('orgs')81 cy.fixture('keys').as('keys')82 cy.fixture('dashboard_projects').as('dashboardProjects')83 cy.visitIndex().then(function (win) {84 let start = win.App.start85 this.win = win86 this.ipc = win.App.ipc87 this.config.projectName = 'my-kitchen-sink'88 cy.stub(this.ipc, 'getOptions').resolves({ projectRoot: '/foo/bar' })89 cy.stub(this.ipc, 'updaterCheck').resolves(false)90 cy.stub(this.ipc, 'closeBrowser').resolves(null)91 this.config.projectId = null92 cy.stub(this.ipc, 'openProject').resolves(this.config)93 cy.stub(this.ipc, 'getSpecs').yields(null, this.specs)94 cy.stub(this.ipc, 'getRuns').resolves([])95 cy.stub(this.ipc, 'getRecordKeys').resolves(this.keys)96 cy.stub(this.ipc, 'pingApiServer').resolves()97 cy.stub(this.ipc, 'externalOpen')98 cy.stub(this.ipc, 'setProjectId').resolvesArg(0)99 this.getCurrentUser = this.util.deferred()100 cy.stub(this.ipc, 'getCurrentUser').resolves(this.getCurrentUser.promise)101 this.getOrgs = this.util.deferred()102 cy.stub(this.ipc, 'getOrgs').returns(this.getOrgs.promise)103 this.getProjectStatus = this.util.deferred()104 cy.stub(this.ipc, 'getProjectStatus').returns(this.getProjectStatus.promise)105 this.getDashboardProjects = this.util.deferred()106 cy.stub(this.ipc, 'getDashboardProjects').returns(this.getDashboardProjects.promise)107 this.setupDashboardProject = this.util.deferred()108 cy.stub(this.ipc, 'setupDashboardProject').returns(this.setupDashboardProject.promise)109 start()110 cy.get('.navbar-default a')111 .contains('Runs').click()112 })113 })114 it('displays "need to set up" message', function () {115 cy.contains('Connect to the Dashboard to see your recorded test results here')116 })117 describe('when there is a current user', function () {118 beforeEach(function () {119 this.getCurrentUser.resolve(this.user)120 })121 describe('general behavior', function () {122 beforeEach(function () {123 this.getOrgs.resolve(this.orgs)124 this.getDashboardProjects.resolve(this.dashboardProjects)125 cy.get('.btn').contains('Connect to Dashboard').click()126 })127 it('clicking link opens setup project window', function () {128 cy.get('.setup-project').should('be.visible')129 cy.percySnapshot()130 })131 it('closes when back is clicked', function () {132 cy.contains('Back').click()133 cy.contains('Connect to the Dashboard to see your recorded test results here')134 })135 it('org docs are linked', function () {136 cy.contains('label', 'Project owner')137 .find('a').click().then(function () {138 expect(this.ipc.externalOpen).to.be.calledWith('https://on.cypress.io/what-are-organizations')139 })140 })141 })142 describe('loading behavior', function () {143 beforeEach(function () {144 cy.get('.btn').contains('Connect to Dashboard').click()145 })146 it('calls getOrgs', function () {147 expect(this.ipc.getOrgs).to.be.calledOnce148 })149 it('calls getDashboardProjects', function () {150 expect(this.ipc.getDashboardProjects).to.be.calledOnce151 })152 it('displays loading view before both orgs and dashboard projects load', function () {153 cy.get('.loader').should('exist').then(function () {154 cy.percySnapshot()155 this.getOrgs.resolve(this.orgs)156 cy.get('.loader').should('exist').then(function () {157 this.getDashboardProjects.resolve(this.dashboardProjects)158 })159 })160 cy.get('.loader').should('not.exist')161 })162 it('logs user out when getOrgs 401s', function () {163 this.getOrgs.reject({ name: '', message: '', statusCode: 401 })164 cy.shouldBeLoggedOut()165 })166 it('logs user out when getDashboardProjects 401s', function () {167 this.getDashboardProjects.reject({ name: '', message: '', statusCode: 401 })168 cy.shouldBeLoggedOut()169 })170 it('displays "set up" message in background on log out', function () {171 this.getDashboardProjects.reject({ name: '', message: '', statusCode: 401 })172 cy.shouldBeLoggedOut()173 cy.contains('Connect to the Dashboard to see your recorded test results here')174 })175 })176 describe('selecting an org', function () {177 context('with orgs', function () {178 beforeEach(function () {179 this.getOrgs.resolve(this.orgs)180 this.getDashboardProjects.resolve(this.dashboardProjects)181 cy.get('.btn').contains('Connect to Dashboard').click()182 cy.get('.setup-project')183 })184 it('lists organizations to assign to project', function () {185 cy.get('.empty-select-orgs').should('not.exist')186 cy.get('.organizations-select__dropdown-indicator').click()187 cy.get('.organizations-select__menu').should('be.visible')188 cy.get('.organizations-select__option')189 .should('have.length', this.orgs.length)190 cy.percySnapshot()191 })192 it('selects personal org by default', function () {193 cy.get('.organizations-select').contains(194 'Your personal organization',195 )196 })197 it('opens external link on click of manage', () => {198 cy.contains('Manage organizations').click().then(function () {199 expect(this.ipc.externalOpen).to.be.calledWith('https://on.cypress.io/dashboard/organizations')200 })201 })202 })203 context('orgs with no default org', function () {204 beforeEach(function () {205 this.getOrgs.resolve(Cypress._.filter(this.orgs, { 'default': false }))206 this.getDashboardProjects.resolve(Cypress._.filter(this.dashboardProjects, { 'orgDefault': false }))207 cy.get('.btn').contains('Connect to Dashboard').click()208 })209 it('lists organizations to assign to project', function () {210 cy.get('.empty-select-orgs').should('not.exist')211 cy.get('.organizations-select__dropdown-indicator').click()212 cy.get('.organizations-select__menu').should('be.visible')213 cy.get('.organizations-select__option')214 // do not count the default org we removed215 .should('have.length', this.orgs.length - 1)216 })217 it('selects first org by default', function () {218 cy.get('.organizations-select').contains(this.orgs[1].name)219 })220 it('opens external link on click of manage', () => {221 cy.contains('Manage organizations').click().then(function () {222 expect(this.ipc.externalOpen).to.be.calledWith('https://on.cypress.io/dashboard/organizations')223 })224 })225 })226 context('without orgs', function () {227 beforeEach(function () {228 this.getOrgs.resolve([])229 this.getDashboardProjects.resolve([])230 cy.get('.btn').contains('Connect to Dashboard').click()231 })232 it('displays empty message', () => {233 cy.get('.empty-select-orgs').should('be.visible')234 cy.get('.organizations-select').should('not.exist')235 cy.get('.project-select').should('not.exist')236 cy.get('#projectName').should('not.exist')237 cy.get('.privacy-selector').should('not.exist')238 cy.contains('.btn', 'Set up project').should('be.disabled')239 cy.percySnapshot()240 })241 it('opens dashboard organizations when \'create org\' is clicked', () => {242 cy.contains('Create organization').click().then(function () {243 expect(this.ipc.externalOpen).to.be.calledWith('https://on.cypress.io/dashboard/organizations')244 })245 })246 })247 context('with only default org', function () {248 beforeEach(function () {249 this.getOrgs.resolve([{250 'id': '000',251 'name': 'Jane Lane',252 'default': true,253 }])254 this.getDashboardProjects.resolve(Cypress._.filter(this.dashboardProjects, { 'orgDefault': true }))255 cy.get('.btn').contains('Connect to Dashboard').click()256 cy.get('.setup-project')257 })258 it('displays in dropdown', () => {259 cy.get('.organizations-select__dropdown-indicator').click()260 cy.get('.organizations-select__menu').should('be.visible')261 cy.get('.organizations-select__option').should('have.length', 1)262 })263 })264 context('polls for updates to organizations', function () {265 beforeEach(function () {266 cy.clock()267 this.getOrgs.resolve(this.orgs)268 this.getDashboardProjects.resolve(this.dashboardProjects)269 cy.get('.btn').contains('Connect to Dashboard').click()270 })271 it('polls for orgs twice in 10+sec on click of org', function () {272 cy.tick(11000).then(() => {273 expect(this.ipc.getOrgs).to.be.calledTwice274 })275 })276 it('updates org name on list on successful poll', function () {277 this.name = 'Foo Bar Devs'278 this.orgs[1].name = this.name279 this.getOrgsAgain = this.ipc.getOrgs.onCall(2).resolves(this.orgs)280 cy.tick(11000)281 cy.get('.organizations-select__dropdown-indicator').click()282 cy.get('.organizations-select__menu').should('be.visible')283 cy.get('.organizations-select__option')284 .contains(this.name)285 })286 it('adds new org to list on successful poll', function () {287 this.orgs.push({288 'id': '333',289 'name': 'Ivory Developers',290 'default': false,291 })292 this.getOrgsAgain = this.ipc.getOrgs.onCall(2).resolves(this.orgs)293 cy.tick(11000)294 cy.get('.organizations-select__dropdown-indicator').click()295 cy.get('.organizations-select__menu').should('be.visible')296 cy.get('.organizations-select__option')297 .should('have.length', this.orgs.length)298 })299 })300 })301 describe('selecting or creating a project', function () {302 beforeEach(function () {303 this.getDashboardProjects.resolve(this.dashboardProjects)304 cy.get('.btn').contains('Connect to Dashboard').click()305 cy.get('.setup-project')306 })307 context('default behavior', function () {308 it('displays new project when preselected org has no projects', function () {309 this.getOrgs.resolve(Cypress._.filter(this.orgs, { id: '999' }))310 cy.get('#projectName').should('exist')311 cy.get('.privacy-selector').should('exist')312 cy.get('.project-select').should('not.exist')313 })314 it('displays project select when preselected org has existing projects', function () {315 this.getOrgs.resolve(Cypress._.filter(this.orgs, { id: '777' }))316 cy.get('.project-select').should('exist')317 cy.get('#projectName').should('not.exist')318 cy.get('.privacy-selector').should('not.exist')319 })320 })321 context('with org with existing projects', function () {322 beforeEach(function () {323 this.getOrgs.resolve(this.orgs)324 cy.get('.organizations-select__dropdown-indicator').click()325 cy.get('.organizations-select__menu').should('be.visible')326 cy.get('.organizations-select__option')327 .contains('Acme Developers').click()328 })329 it('defaults to selecting a project when not all projects have runs', function () {330 cy.contains('Select an existing project')331 cy.percySnapshot()332 })333 it('defaults to new project when all existing projects have runs', function () {334 cy.get('.organizations-select__dropdown-indicator').click()335 cy.get('.organizations-select__menu').should('be.visible')336 cy.get('.organizations-select__option')337 .contains('Your personal organization').click()338 cy.contains('New project name')339 })340 it('displays dropdown of existing projects with id for that org only', function () {341 const orgProjects = Cypress._.filter(this.dashboardProjects, { 'orgName': 'Acme Developers' })342 const otherProjects = Cypress._.reject(this.dashboardProjects, { 'orgName': 'Acme Developers' })343 cy.get('.project-select__dropdown-indicator').click()344 cy.get('.project-select__menu').should('be.visible')345 cy.wrap(orgProjects).each(function (project) {346 cy.get('.project-select__option').contains(`${project.name} (${project.id})`)347 })348 cy.wrap(otherProjects).each(function (project) {349 cy.get('.project-select__option').contains(project.name).should('not.exist')350 })351 })352 it('sorts existing projects, displaying those without existing runs first', function () {353 cy.get('.project-select__dropdown-indicator').click()354 cy.get('.project-select__menu').should('be.visible')355 cy.get('.project-select__option').eq(0).contains(this.dashboardProjects[1].name)356 cy.get('.project-select__option').eq(1).contains(this.dashboardProjects[3].name)357 cy.get('.project-select__option').eq(2).contains(this.dashboardProjects[2].name)358 cy.percySnapshot()359 })360 it('does not display name input or visibility selector', function () {361 cy.get('#projectName').should('not.exist')362 cy.get('.privacy-selector').should('not.exist')363 })364 it('disables submit button until project is selected', function () {365 cy.get('.setup-project')366 .contains('.btn', 'Set up project')367 .should('be.disabled')368 cy.get('.project-select__dropdown-indicator').click()369 cy.get('.project-select__menu').should('be.visible')370 cy.get('.project-select__option')371 .contains(this.dashboardProjects[1].name).click()372 cy.get('.setup-project')373 .contains('.btn', 'Set up project')374 .should('not.be.disabled')375 })376 it('switches to new project when org is changed to one without existing projects', function () {377 cy.get('.organizations-select__dropdown-indicator').click()378 cy.get('.organizations-select__menu').should('be.visible')379 cy.get('.organizations-select__option')380 .contains('Osato Devs').click()381 cy.get('#projectName').should('exist')382 cy.get('.privacy-selector').should('exist')383 cy.get('.project-select').should('not.exist')384 })385 context('on submit', function () {386 beforeEach(function () {387 cy.get('.project-select__dropdown-indicator').click()388 cy.get('.project-select__menu').should('be.visible')389 cy.get('.project-select__option').contains(this.dashboardProjects[1].name).click()390 })391 it('calls ipc setProjectId event with selected id', function () {392 cy.get('.setup-project')393 .contains('.btn', 'Set up project').click()394 .then(() => {395 expect(this.ipc.setProjectId).to.be.calledWith(this.dashboardProjects[1].id)396 })397 })398 it('does not call ipc setupDashboardProject event', function () {399 cy.get('.setup-project')400 .contains('.btn', 'Set up project').click()401 .then(() => {402 expect(this.ipc.setupDashboardProject).not.to.be.called403 })404 })405 it('updates localStorage projects cache', function () {406 cy.get('.setup-project')407 .contains('.btn', 'Set up project').click()408 .then(() => {409 const localProjects = JSON.parse(localStorage.projects || '[]')410 expect(localProjects[0].id).to.equal(this.dashboardProjects[1].id)411 expect(localProjects[0].name).to.equal(this.dashboardProjects[1].name)412 })413 })414 })415 context('creating a new project', function () {416 beforeEach(function () {417 cy.contains('Acme Developers')418 cy.get('.setup-project').contains('Create a new project').click()419 })420 it('displays name input and visibility selector with updated title', function () {421 cy.contains('New project name')422 cy.get('#projectName').should('exist')423 cy.get('.privacy-selector').should('exist')424 cy.percySnapshot()425 })426 it('does not display existing project selector', function () {427 cy.contains('Select a project').should('not.exist')428 cy.get('.project-select').should('not.exist')429 })430 it('allows user to go back to existing projects', function () {431 cy.get('.setup-project').contains('Choose an existing project').click()432 cy.contains('Select an existing project')433 cy.get('.project-select__dropdown-indicator').should('exist')434 })435 context('on submit', function () {436 onSubmitNewProject('777')437 })438 })439 })440 context('with org without existing projects', function () {441 beforeEach(function () {442 this.getOrgs.resolve(this.orgs)443 cy.get('.organizations-select__dropdown-indicator').click()444 cy.get('.organizations-select__menu').should('be.visible')445 cy.get('.organizations-select__option')446 .contains('Osato Devs').click()447 })448 it('prefills Project Name', function () {449 cy.get('#projectName').should('have.value', this.config.projectName)450 cy.percySnapshot()451 })452 it('allows me to change Project Name value', function () {453 cy.get('#projectName').clear().type('New Project Here')454 .should('have.value', 'New Project Here')455 })456 it('submit button is enabled by default', function () {457 cy.get('.setup-project').contains('.btn', 'Set up project')458 .should('not.be.disabled')459 })460 it('submit button is disabled when input is empty', function () {461 cy.get('#projectName').clear()462 cy.get('.setup-project').contains('.btn', 'Set up project')463 .should('be.disabled')464 })465 it('does not display link to choose existing project', function () {466 cy.get('.setup-project').contains('Create new project').should('not.exist')467 })468 it('switches to project dropdown when org is changed to one with existing projects', function () {469 cy.get('.organizations-select__dropdown-indicator').click()470 cy.get('.organizations-select__menu').should('be.visible')471 cy.get('.organizations-select__option')472 .contains('Acme Developers').click()473 cy.get('#projectName').should('not.exist')474 cy.get('.project-select').should('exist')475 })476 context('visibility', function () {477 it('is private by default', function () {478 cy.contains('Project visibility is set to Private.')479 })480 it('can be toggled on click', function () {481 cy.contains('Project visibility is set to Private.')482 cy.get('.privacy-selector').find('a').click()483 cy.contains('Project visibility is set to Public.')484 cy.get('.privacy-selector').find('a').click()485 cy.contains('Project visibility is set to Private.')486 })487 it('displays tooltip when set to private', function () {488 cy.get('.privacy-selector').children('span').trigger('mouseover')489 cy.get('.cy-tooltip').should('contain', 'Only invited users have access')490 })491 it('displays tooltip when set to public', function () {492 cy.get('.privacy-selector').find('a').click()493 cy.get('.privacy-selector').children('span').trigger('mouseover')494 cy.get('.cy-tooltip').should('contain', 'Anyone has access')495 })496 })497 context('on submit', function () {498 onSubmitNewProject('999')499 })500 })501 })502 describe('polls for updates to projects', function () {503 beforeEach(function () {504 cy.clock()505 this.getOrgs.resolve(this.orgs)506 this.getDashboardProjects.resolve(this.dashboardProjects)507 cy.get('.btn').contains('Connect to Dashboard').click()508 })509 it('polls for dashboard projects twice in 10+sec', function () {510 cy.tick(11000).then(() => {511 expect(this.ipc.getDashboardProjects).to.be.calledTwice512 })513 })514 it('updates project name on list on successful poll', function () {515 const name = 'My Project Name'516 this.dashboardProjects[1].name = name517 this.ipc.getDashboardProjects.onCall(2).resolves(this.dashboardProjects)518 cy.get('.organizations-select__dropdown-indicator').click()519 cy.get('.organizations-select__menu').should('be.visible')520 cy.get('.organizations-select__option')521 .contains('Acme Developers').click()522 cy.tick(11000)523 cy.get('.project-select__dropdown-indicator').click()524 cy.get('.project-select__menu').should('be.visible')525 cy.get('.project-select__option')526 .contains(name)527 })528 it('adds new project to list on successful poll', function () {529 this.dashboardProjects.push({530 ...this.dashboardProjects[0],531 'orgId': '777',532 'orgName': 'Acme Developers',533 'orgDefault': false,534 })535 this.ipc.getDashboardProjects.onCall(2).resolves(this.dashboardProjects)536 cy.get('.organizations-select__dropdown-indicator').click()537 cy.get('.organizations-select__menu').should('be.visible')538 cy.get('.organizations-select__option')539 .contains('Acme Developers').click()540 cy.tick(11000)541 cy.get('.project-select__dropdown-indicator').click()542 cy.get('.project-select__menu').should('be.visible')543 cy.get('.project-select__option')544 .contains(this.dashboardProjects[0].name)545 })546 it('stays on new project when additional project is added to org', function () {547 this.dashboardProjects.push({548 ...this.dashboardProjects[0],549 'orgId': '777',550 'orgName': 'Acme Developers',551 'orgDefault': false,552 })553 this.ipc.getDashboardProjects.onCall(2).resolves(this.dashboardProjects)554 cy.get('.organizations-select__dropdown-indicator').click()555 cy.get('.organizations-select__menu').should('be.visible')556 cy.get('.organizations-select__option')557 .contains('Acme Developers').click()558 cy.contains('Create a new project').click()559 cy.get('#projectName').should('exist').clear().type('Project Name')560 cy.tick(11000)561 cy.get('#projectName').should('have.value', 'Project Name')562 cy.contains('Choose an existing project')563 })564 it('stays on new project when first project is added to org', function () {565 this.dashboardProjects.push({566 ...this.dashboardProjects[0],567 'orgId': '999',568 'orgName': 'Osato Devs',569 'orgDefault': false,570 })571 this.ipc.getDashboardProjects.onCall(2).resolves(this.dashboardProjects)572 cy.get('.organizations-select__dropdown-indicator').click()573 cy.get('.organizations-select__menu').should('be.visible')574 cy.get('.organizations-select__option')575 .contains('Osato Devs').click()576 cy.get('#projectName').should('exist').clear().type('Project Name')577 cy.contains('Choose an existing project').should('not.exist')578 cy.tick(11000)579 cy.get('#projectName').should('have.value', 'Project Name')580 cy.contains('Choose an existing project')581 })582 })583 })584 describe('when there is no current user', function () {585 beforeEach(function () {586 this.getCurrentUser.resolve(null)587 cy.get('.btn').contains('Connect to Dashboard').click()588 })589 it('shows login', () => {590 cy.get('.modal').contains('Log In to Dashboard')591 })592 it('closes login modal', () => {593 cy.get('.modal').contains('Log In to Dashboard')594 cy.get('.close').click()595 cy.get('.btn').contains('Connect to Dashboard').click()596 })597 describe('when login succeeds', function () {598 beforeEach(function () {599 cy.stub(this.ipc, 'beginAuth').resolves(this.user)600 cy.contains('button', 'Log In to Dashboard').click()601 })602 it('shows setup', () => {603 cy.get('.login-content > .btn').click()604 cy.contains('h4', 'Set up project')605 })606 })607 })...
ReportDashboard.js
Source:ReportDashboard.js
...487 if (conversations && conversations.length) {488 projectIds = conversations.map((conversation) => conversation.project_id);489 supplierIds = conversations.map((conversation) => conversation.supplier_id);490 }491 const getDashboardProjects = await ProjectService.getDashboardProjects({492 projectIds,493 supplierIds494 });495 const project = {496 projectNetworkCount,497 projectNegotiationsStatus,498 projects: getDashboardProjects,499 };500 return {501 orders,502 orderAndQuantityCompare,503 orderBeDelivered,504 circleSupplierByOrderAndByQuantity,505 supplierByOrderAndByQuantity,506 countryByOrderAndByQuantity,507 productsGroup,508 samples,509 project,510 };511};512export const supplierReport = async ({ condition, context, ids }) => {513 const allDate = await date();514 const orders = await OrderService.getOrders({ condition });515 const circleSupplierByOrderAndByQuantity = await CircleSupplierByOrderAndByQuantity(516 { condition }517 );518 const orderAndQuantityCompare = await OrderAndQuantityCompare({519 condition,520 allDate,521 });522 const orderBeDelivered = await OrderBeDelivered({523 condition,524 allDate,525 });526 // show room527 const products = await ShowRoomProducts({ ids });528 const showRoomCountInfo = await ShowRoomAllCountInfo({ ids });529 const showRoom = {530 showRoomCountInfo: {531 ...showRoomCountInfo,532 total_items: `${products.length}`,533 },534 products,535 };536 // sample537 const samples = await SampleService.getSamples({ condition });538 // projects539 const projectNegotiationsStatus = await ProjectNegotiationsStatus({540 condition,541 ordersLength: orders.length,542 });543 const conditionGetProjects = {544 conversationCondition: {545 method: 'project conversation',546 supplier_id: {547 [Op.in]: ids,548 },549 },550 supplierCondition: {551 supplier_id: {552 [Op.in]: ids,553 }554 },555 required: true,556 };557 const getProjects = await ProjectService.getProjects({558 condition: conditionGetProjects,559 });560 const conversations = await GetLastFiveProjectConversation({ ids });561 let projectIds = [];562 let supplierIds = [];563 if (conversations && conversations.length) {564 projectIds = conversations.map((conversation) => conversation.project_id);565 supplierIds = conversations.map((conversation) => conversation.supplier_id);566 }567 const getDashboardProjects = await ProjectService.getDashboardProjects({568 projectIds,569 supplierIds570 });571 const projectNetworkCount = await GetProjectNetworkCount({572 user_id: context.authUser.id,573 projects: getProjects,574 organisation_id: context.authUser.organisation[0].id,575 });576 const project = {577 projectNetworkCount,578 projectNegotiationsStatus,579 projects: getDashboardProjects,580 };581 return {...
project_static.js
Source:project_static.js
...38 })));39 });40}41exports.getPathsAndIds = getPathsAndIds;42function getDashboardProjects() {43 return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {44 const authToken = yield user_1.default.ensureAuthToken();45 debug('got auth token: %o', { authToken: keys_1.default.hide(authToken) });46 return api_1.default.getProjects(authToken);47 });48}49exports.getDashboardProjects = getDashboardProjects;50function _mergeDetails(clientProject, project) {51 return lodash_1.default.extend({}, clientProject, project, { state: 'VALID' });52}53exports._mergeDetails = _mergeDetails;54function _mergeState(clientProject, state) {55 return lodash_1.default.extend({}, clientProject, { state });56}...
rightSection.js
Source:rightSection.js
...31 (state) => state.dashboard32 );33 useEffect(() => {34 if (my_profile_succeeded) {35 dispatch(getDashboardProjects());36 }37 }, [my_profile_succeeded]);38 const data = {};39 return (40 <Box className={styles.parent}>41 <Box className={styles.topItems}>42 <InfoCard43 icon={skillIco}44 icon2={skill2Ico}45 item={{46 name: 'Skills',47 placeholder: 'No Skills Summary',48 color: PALETTE_SUCCESS_MAIN,49 value: undefined,...
project.controller.js
Source:project.controller.js
1import { Project } from './project.model';2import { getProjectGraphQuery } from '../../utils/project';3import { User } from '../user/user.model';4const getDashboardProjects = async (req, res) => {5 const { skip, limit, orderBy, withGraph } = req.query;6 const { id: userId } = req.api_user;7 // Get projects where user is a manager or an engineer8 const query = Project.query()9 .whereIn(10 'id',11 User.relatedQuery('engineeredProjects').for(userId).select('Project.id')12 )13 .orWhere('manager_id', userId);14 query.offset(skip).limit(limit).orderBy(orderBy);15 if (withGraph) {16 getProjectGraphQuery(query, withGraph);17 }18 return res.status(200).json({ projects: await query });19};20const getProjects = async (req, res) => {21 const {22 skip,23 limit,24 orderBy,25 withGraph,26 search,27 engineer_id,28 manager_id,29 } = req.query;30 let query = Project.query();31 if (engineer_id) {32 query = User.relatedQuery('engineeredProjects').for(engineer_id);33 }34 query.offset(skip).limit(limit).where('archived_at', null).orderBy(orderBy);35 if (search) {36 query.modify('search', search);37 }38 if (manager_id) {39 query.where('manager_id', manager_id);40 }41 if (withGraph) {42 getProjectGraphQuery(query, withGraph);43 }44 return res.status(200).json({ projects: await query });45};46const createProject = async (req, res) => {47 const { id: createdById } = req.api_user;48 const projectData = { ...req.body, created_by: createdById };49 const project = await Project.query().insert(projectData).returning('*');50 return res.status(201).json({ project });51};52const getProject = async (req, res) => {53 const { id: projectId } = req.project;54 const { withGraph } = req.query;55 let project;56 if (withGraph) {57 const query = Project.query().findById(projectId);58 getProjectGraphQuery(query, withGraph);59 project = await query;60 } else {61 project = req.project;62 }63 return res.status(200).json({ project });64};65const updateProject = async (req, res) => {66 const { id: projectId } = req.project;67 const newProjectData = { ...req.body };68 const project = await Project.query()69 .findById(projectId)70 .patch(newProjectData)71 .returning('*');72 return res.status(200).json({ project });73};74const deleteProject = async (req, res) => {75 const { id: projectId } = req.project;76 const project = await Project.query()77 .findById(projectId)78 .delete()79 .returning('*');80 return res.status(200).json({ project });81};82export {83 getProjects,84 getDashboardProjects,85 getProject,86 createProject,87 updateProject,88 deleteProject,...
DashboardPage.js
Source:DashboardPage.js
...44}45const mapStateToProps = (state) => {46 return {47 projectsLoaded: state.project.projectsLoaded,48 projects: getDashboardProjects(state),49 usernameSet: state.auth.usernameSet,50 }51};52const mapDispatchToProps = (dispatch) => {53 return {54 actions: bindActionCreators(projectActions, dispatch),55 }56};57export default connect(58 mapStateToProps,59 mapDispatchToProps,...
dashboard-projects-api.js
Source:dashboard-projects-api.js
1import ipc from '../lib/ipc'2import dashboardProjectsStore from './dashboard-projects-store'3let pollId4const getDashboardProjects = () => {5 ipc.getDashboardProjects().then((projects = []) => {6 dashboardProjectsStore.setProjects(projects)7 return null8 }).catch(ipc.isUnauthed, ipc.handleUnauthed)9 .catch((err) => {10 dashboardProjectsStore.setError(err)11 return null12 })13 return null14}15const isPolling = () => {16 return !!pollId17}18const pollDashboardProjects = () => {19 if (pollId) return20 pollId = setInterval(() => {21 getDashboardProjects()22 }, 10000)23}24const stopPollingDashboardProjects = () => {25 clearInterval(pollId)26 pollId = null27}28const setupDashboardProject = (projectDetails) => {29 return ipc.setupDashboardProject(projectDetails)30 .then((project) => {31 dashboardProjectsStore.addProject(project)32 return project33 })34 .catch(ipc.isUnauthed, ipc.handleUnauthed)35}...
DataServices.js
Source:DataServices.js
...29 let result = await fetch(`http://localhost:5262/Project/getItemsByUserId/${userId}`);30 let data = await result.json();31 return data;32}33async function getDashboardProjects()34{35 let result = await fetch(`http://localhost:5262/Project/getPublishedItems`);36 let data = await result.json();37 return data;...
Using AI Code Generation
1const cypress = require('cypress-api')2cypress.getDashboardProjects().then((projects) => {3 console.log(projects)4})5const cypress = require('cypress-api')6cypress.getDashboardRuns().then((runs) => {7 console.log(runs)8})9const cypress = require('cypress-api')10cypress.getDashboardRun('run-id').then((run) => {11 console.log(run)12})13const cypress = require('cypress-api')14cypress.getDashboardRecord('record-id').then((record) => {15 console.log(record)16})17const cypress = require('cypress-api')18cypress.getDashboardRunTests('run-id').then((tests) => {19 console.log(tests)20})21const cypress = require('cypress-api')22cypress.getDashboardTest('test-id').then((test) => {23 console.log(test)24})25const cypress = require('cypress-api')26cypress.getDashboardRunArtifacts('run-id').then((artifacts) => {27 console.log(artifacts)28})29const cypress = require('cypress-api')30cypress.getDashboardArtifact('artifact-id').then((artifact) => {31 console.log(artifact)32})33const cypress = require('cypress-api')34cypress.getDashboardRunSpecs('run-id').then((specs) => {35 console.log(specs)36})37const cypress = require('cypress-api')38cypress.getDashboardSpec('spec-id').then((spec) => {39 console.log(spec)40})41const cypress = require('cypress-api')42cypress.getDashboardRunGroups('run-id').then((groups) => {43 console.log(groups)44})45const cypress = require('cypress-api')
Using AI Code Generation
1const cypress = require('cypress-api');2cypress.getDashboardProjects().then((res) => {3 console.log(res);4});5const cypress = require('cypress-api');6cypress.getDashboardRuns().then((res) => {7 console.log(res);8});9const cypress = require('cypress-api');10cypress.getDashboardRuns().then((res) => {11 console.log(res);12});13const cypress = require('cypress-api');14cypress.getDashboardRuns().then((res) => {15 console.log(res);16});17const cypress = require('cypress-api');18cypress.getDashboardRuns().then((res) => {19 console.log(res);20});21const cypress = require('cypress-api');22cypress.getDashboardRuns().then((res) => {23 console.log(res);24});25const cypress = require('cypress-api');26cypress.getDashboardRuns().then((res) => {27 console.log(res);28});29const cypress = require('cypress-api');30cypress.getDashboardRuns().then((res) => {31 console.log(res);32});33const cypress = require('cypress-api');34cypress.getDashboardRuns().then((res) => {35 console.log(res);36});37const cypress = require('cypress-api');38cypress.getDashboardRuns().then((res) => {39 console.log(res);40});41const cypress = require('cypress-api');42cypress.getDashboardRuns().then((res) => {43 console.log(res);44});
Using AI Code Generation
1var cypress = require('cypress-api');2var cypress = new Cypress('apiToken');3cypress.getDashboardProjects(function(err, projects){4 if(err){5 console.log(err);6 }7 else{8 console.log(projects);9 }10});11var cypress = require('cypress-api');12var cypress = new Cypress('apiToken');13cypress.getDashboardProjectRuns('projectId', function(err, runs){14 if(err){15 console.log(err);16 }17 else{18 console.log(runs);19 }20});21var cypress = require('cypress-api');22var cypress = new Cypress('apiToken');23cypress.getDashboardProjectRun('projectId', 'runId', function(err, run){24 if(err){25 console.log(err);26 }27 else{28 console.log(run);29 }30});31var cypress = require('cypress-api');32var cypress = new Cypress('apiToken');33cypress.getDashboardProjectRunSpecs('projectId', 'runId', function(err, specs){34 if(err){35 console.log(err);36 }37 else{38 console.log(specs);39 }40});41var cypress = require('cypress-api');42var cypress = new Cypress('apiToken');43cypress.getDashboardProjectRunSpec('projectId', 'runId', 'specId', function(err, spec){44 if(err){45 console.log(err);46 }47 else{48 console.log(spec);49 }50});51var cypress = require('cypress-api');52var cypress = new Cypress('apiToken');53cypress.getDashboardProjectRunSpecInstances('projectId', 'runId', 'specId', function(err, instances){54 if(err){55 console.log(err);56 }57 else{58 console.log(instances);59 }60});61var cypress = require('cypress-api');
Using AI Code Generation
1const cypress = require('cypress')2cypress.run({3}).then((results) => {4 console.log(results)5})6describe('Test Cypress.io', () => {7 it('should print project names', () => {8 cy.get('#navbar > .navbar-nav > :nth-child(2) > .nav-link').click()9 cy.get('#navbar > .navbar-nav > :nth-child(2) > .nav-dropdown > .dropdown-menu > :nth-child(1) > a').click()10 cy.get('.navbar-nav > :nth-child(2) > .nav-dropdown > .dropdown-menu > :nth-child(1) > a').click()11 cy.get('.navbar-nav > :nth-child(2) > .nav-dropdown > .dropdown-menu > :nth-child(1) > a').click()12 cy.get('.navbar-nav > :nth-child(2) > .nav-dropdown > .dropdown-menu > :nth-child(1) > a').click()13 cy.get('.navbar-nav > :nth-child(2) > .nav-dropdown > .dropdown-menu > :nth-child(1) > a
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!!