Best JavaScript code snippet using storybook-root
projectUpdateAccessService.spec.js
Source:projectUpdateAccessService.spec.js
1/* global describe, beforeEach, it, expect, spyOn, inject, _ */2'use strict';3describe('ProjectUpdateAccessService', function() {4 var ProjectUpdateAccessService;5 var Principal;6 var CurrentProjectService;7 var publisherName = 'publisher';8 var dataProviderName = 'dataProvider';9 var defaultProject;10 var trueOnDataProvider = function(role) {11 return role === 'ROLE_DATA_PROVIDER';12 };13 var trueOnPublisher = function(role) {14 return role === 'PUBLISHER';15 };16 beforeEach(module('metadatamanagementApp'));17 beforeEach(inject(function(_ProjectUpdateAccessService_, _Principal_,18 _CurrentProjectService_) {19 ProjectUpdateAccessService = _ProjectUpdateAccessService_;20 Principal = _Principal_;21 CurrentProjectService = _CurrentProjectService_;22 defaultProject = {23 assigneeGroup: 'DATA_PROVIDER',24 configuration: {25 publishers: ['publisher'],26 dataProviders: ['dataProvider'],27 surveysState: {28 publisherReady: false,29 dataProviderReady: false30 },31 requirements: {32 dataSetsRequired: true,33 surveysRequired: true,34 variablesRequired: true,35 dataPackagesRequired: true,36 instrumentsRequired: true,37 questionsRequired: true38 }39 }40 };41 }));42 it('should return false if no project is selected', function() {43 spyOn(CurrentProjectService, 'getCurrentProject')44 .and.returnValue(undefined);45 expect(ProjectUpdateAccessService.isUpdateAllowed(undefined,'')).toBe(false);46 });47 it('should return false since it is not the publishers turn', function() {48 spyOn(Principal, 'loginName').and.returnValue(publisherName);49 spyOn(Principal, 'hasAuthority').and.returnValue(true);50 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'dataPackages')).toBe(false);51 });52 it('should return true since it is the data providers turn', function() {53 spyOn(Principal, 'loginName').and.returnValue(dataProviderName);54 spyOn(Principal, 'hasAuthority').and.returnValue(true);55 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'dataPackages')).toBe(true);56 });57 it('should return true if the survey state is still false', function() {58 spyOn(Principal, 'loginName').and.returnValue(dataProviderName);59 spyOn(Principal, 'hasAuthority').and.callFake(trueOnDataProvider);60 _.set(defaultProject, 'configuration.surveysState.publisherReady', false);61 _.set(defaultProject, 'configuration.surveysState.dataProviderReady', false);62 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'surveys')).toBe(true);63 });64 it('should return false if survey state is marked as dataProviderReady', function() {65 spyOn(Principal, 'loginName').and.returnValue(dataProviderName);66 spyOn(Principal, 'hasAuthority').and.callFake(trueOnDataProvider);67 _.set(defaultProject, 'configuration.surveysState.publisherReady', false);68 _.set(defaultProject, 'configuration.surveysState.dataProviderReady', true);69 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'surveys')).toBe(false);70 });71 it('should return true if data packages state is still false', function() {72 spyOn(Principal, 'loginName').and.returnValue(dataProviderName);73 spyOn(Principal, 'hasAuthority').and.callFake(trueOnDataProvider);74 _.set(defaultProject, 'configuration.dataPackagesState.publisherReady', false);75 _.set(defaultProject, 'configuration.dataPackagesState.dataProviderReady', false);76 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'dataPackages')).toBe(true);77 });78 it('should return false if data packages state is marked as dataProviderReady', function() {79 spyOn(Principal, 'loginName').and.returnValue(dataProviderName);80 spyOn(Principal, 'hasAuthority').and.callFake(trueOnDataProvider);81 _.set(defaultProject, 'configuration.dataPackagesState.publisherReady', false);82 _.set(defaultProject, 'configuration.dataPackagesState.dataProviderReady', true);83 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'dataPackages')).toBe(false);84 });85 it('should return true if instruments state is still false', function() {86 spyOn(Principal, 'loginName').and.returnValue(dataProviderName);87 spyOn(Principal, 'hasAuthority').and.callFake(trueOnDataProvider);88 _.set(defaultProject, 'configuration.instrumentsState.publisherReady', false);89 _.set(defaultProject, 'configuration.instrumentsState.dataProviderReady', false);90 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'instruments')).toBe(true);91 });92 it('should return false if instruments state is marked as dataProviderReady', function() {93 spyOn(Principal, 'loginName').and.returnValue(dataProviderName);94 spyOn(Principal, 'hasAuthority').and.callFake(trueOnDataProvider);95 _.set(defaultProject, 'configuration.instrumentsState.publisherReady', false);96 _.set(defaultProject, 'configuration.instrumentsState.dataProviderReady', true);97 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'instruments')).toBe(false);98 });99 it('should return true if variables state is still false', function() {100 spyOn(Principal, 'loginName').and.returnValue(dataProviderName);101 spyOn(Principal, 'hasAuthority').and.callFake(trueOnDataProvider);102 _.set(defaultProject, 'configuration.variablesState.publisherReady', false);103 _.set(defaultProject, 'configuration.variablesState.dataProviderReady', false);104 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'variables')).toBe(true);105 });106 it('should return false if variables state is marked as dataProviderReady', function() {107 spyOn(Principal, 'loginName').and.returnValue(dataProviderName);108 spyOn(Principal, 'hasAuthority').and.callFake(trueOnDataProvider);109 _.set(defaultProject, 'configuration.variablesState.publisherReady', false);110 _.set(defaultProject, 'configuration.variablesState.dataProviderReady', true);111 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'variables')).toBe(false);112 });113 it('should return true if data_sets status is still false', function() {114 spyOn(Principal, 'loginName').and.returnValue(dataProviderName);115 spyOn(Principal, 'hasAuthority').and.callFake(trueOnDataProvider);116 _.set(defaultProject, 'configuration.dataSetsState.publisherReady', false);117 _.set(defaultProject, 'configuration.dataSetsState.dataProviderReady', false);118 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'data_sets')).toBe(true);119 });120 it('should return false if data_sets state is marked as publisherReady', function() {121 spyOn(Principal, 'loginName').and.returnValue(publisherName);122 spyOn(Principal, 'hasAuthority').and.callFake(trueOnPublisher);123 _.set(defaultProject, 'configuration.dataSetsState.publisherReady', true);124 _.set(defaultProject, 'configuration.dataSetsState.dataProviderReady', false);125 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'data_sets')).toBe(false);126 });127 it('should return true if questions state is still false', function() {128 spyOn(Principal, 'loginName').and.returnValue(dataProviderName);129 spyOn(Principal, 'hasAuthority').and.callFake(trueOnDataProvider);130 _.set(defaultProject, 'configuration.questionsState.publisherReady', false);131 _.set(defaultProject, 'configuration.questionsState.dataProviderReady', false);132 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'questions')).toBe(true);133 });134 it('should return false if questions state is marked as publisherReady', function() {135 spyOn(Principal, 'loginName').and.returnValue(dataProviderName);136 spyOn(Principal, 'hasAuthority').and.callFake(trueOnDataProvider);137 _.set(defaultProject, 'configuration.questionsState.publisherReady', true);138 _.set(defaultProject, 'configuration.questionsState.dataProviderReady', false);139 expect(ProjectUpdateAccessService.isUpdateAllowed(undefined, 'questions')).toBe(false);140 });141 it('should return false if a project has been released', function() {142 spyOn(Principal, 'loginName').and.returnValue(dataProviderName);143 spyOn(Principal, 'hasAuthority').and.callFake(trueOnDataProvider);144 defaultProject.release = {};145 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'dataPackages')).toBe(false);146 });147 it('should return false if the assigneeGroup doesn\'t match the current' +148 'user\'s role', function() {149 defaultProject.assigneeGroup = 'PUBLISHER';150 spyOn(Principal, 'loginName').and.returnValue(dataProviderName);151 spyOn(Principal, 'hasAuthority').and.callFake(trueOnDataProvider);152 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'dataPackages')).toBe(false);153 });154 it('should return false if assigneeGroup is unknown', function() {155 spyOn(Principal, 'loginName').and.returnValue(dataProviderName);156 spyOn(Principal, 'hasAuthority').and.callFake(trueOnDataProvider);157 defaultProject.assigneeGroup = '';158 expect(ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'dataPackages')).toBe(false);159 });160 it('should not call CurrentProjectService if the project was given as a ' +161 'parameter', function() {162 var spy = spyOn(CurrentProjectService, 'getCurrentProject').and163 .callThrough();164 ProjectUpdateAccessService.isUpdateAllowed(defaultProject, 'dataPackages');165 expect(spy).not.toHaveBeenCalled();166 });...
default-project.component.js
Source:default-project.component.js
1import * as React from "react";2import DefaultProjectList from "./default-project-list.component";3import {getDefaultProjectEnums} from "../enums/default-project.enum";4import {DefaultProject} from '../helpers/storageUserWorkspace';5class DefaultProjectComponent extends React.Component {6 constructor(props) {7 super(props);8 const { storage, defaultProject } = DefaultProject.getStorage();9 this.state = {10 defaultProjectEnabled: defaultProject ? defaultProject.enabled : false,11 selectedProject: defaultProject ? defaultProject.project : null12 };13 }14 componentDidMount() {15 this.onMountOrUpdate();16 }17 onMountOrUpdate() {18 const elem = document.getElementById('defaultProject');19 if (this.state.defaultProjectEnabled) {20 elem.style.padding = "10px 20px";21 elem.style.maxHeight = '360px';22 } 23 else {24 elem.style.padding = '0 20px';25 elem.style.maxHeight = "0";26 }27 }28 componentDidUpdate(prevProps, prevState) {29 if (prevState.defaultProjectEnabled !== this.state.defaultProjectEnabled) {30 const { storage, defaultProject } = DefaultProject.getStorage();31 this.setState({32 defaultProjectEnabled: defaultProject ? defaultProject.enabled : false,33 selectedProject: defaultProject ? defaultProject.project : null34 }, () => {35 this.onMountOrUpdate();36 });37 }38 }39 toggleDefaultProjectEnabled() {40 let { storage, defaultProject } = DefaultProject.getStorage();41 if (!defaultProject) {42 defaultProject = storage.setInitialDefaultProject();43 } 44 else {45 storage.toggleEnabledOfDefaultProject();46 }47 this.setState({48 defaultProjectEnabled: !this.state.defaultProjectEnabled,49 selectedProject: defaultProject ? defaultProject.project : null50 }, () => {51 this.projectList.closeOpened();52 this.props.changeSaved();53 });54 }55 setDefaultProject(project) {56 const { storage } = DefaultProject.getStorage();57 storage.setDefaultProject(project);58 this.setState({59 selectedProject: project60 }, () => {61 this.onMountOrUpdate();62 });63 this.props.changeSaved();64 }65 projectListOpened() {66 this.setState({67 defaultProjectEnabled: true68 });69 }70 render() {71 const { defaultProjectEnabled, selectedProject } = this.state;72 const {forceProjects, forceTasks} = this.props.workspaceSettings;73 const name = forceTasks ? 'Default project and task' : 'Default project';74 return (75 <div>76 <div className="default-project"77 onClick={this.toggleDefaultProjectEnabled.bind(this)}>78 <span className={defaultProjectEnabled ?79 "default-project-checkbox checked" : "default-project-checkbox"}>80 <img src="./assets/images/checked.png"81 className={defaultProjectEnabled ?82 "default-project-checkbox--img" :83 "default-project-checkbox--img_hidden"}/>84 </span>85 <span className="default-project-title">{name}</span>86 </div>87 <div id="defaultProject"88 className="default-project__project-list expandContainer">89 <DefaultProjectList90 ref={instance => {91 this.projectList = instance92 }}93 selectedProject={selectedProject}94 selectProject={this.setDefaultProject.bind(this)}95 workspaceSettings={this.props.workspaceSettings}96 projectListOpened={this.projectListOpened.bind(this)}97 isUserOwnerOrAdmin={this.props.isUserOwnerOrAdmin}98 noTask={false}99 isPomodoro={false}100 />101 </div>102 </div>103 )104 }105}...
Using AI Code Generation
1import {defaultProject} from 'storybook-root';2import {defaultProject} from 'storybook-root';3import {defaultProject} from 'storybook-root';4import {defaultProject} from 'storybook-root';5import {defaultProject} from 'storybook-root';6import {defaultProject} from 'storybook-root';7import {defaultProject} from 'storybook-root';8import {defaultProject} from 'storybook-root';9import {defaultProject} from 'storybook-root';10import {defaultProject} from 'storybook-root';11import {defaultProject} from 'storybook-root';12import {defaultProject} from 'storybook-root';13import {defaultProject} from 'storybook-root';14import {defaultProject} from 'storybook-root';15import {defaultProject} from 'storybook-root';16import {defaultProject} from 'storybook-root';17import {defaultProject} from 'storybook-root';18import {defaultProject} from 'storybook-root';19import {defaultProject} from 'storybook-root';20import {defaultProject} from 'storybook-root';21import {defaultProject} from 'storybook-root';
Using AI Code Generation
1import { defaultProject } from 'storybook-root-config';2import { configure } from '@storybook/react';3const req = require.context('../stories', true, /.stories.js$/);4function loadStories() {5 req.keys().forEach(filename => req(filename));6}7configure(loadStories, defaultProject('test'));8import React from 'react';9import { storiesOf } from '@storybook/react';10storiesOf('test', module)11 .add('test', () => <div>test</div>);
Using AI Code Generation
1import { defaultProject } from '@storybook/react';2import { render } from '@testing-library/react';3import React from 'react';4import { App } from '../App';5test('renders learn react link', () => {6 const { getByText } = render(<App />, { wrapper: defaultProject() });7 const linkElement = getByText(/learn react/i);8 expect(linkElement).toBeInTheDocument();9});10"scripts": {11 },12module.exports = {13 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],14 features: {15 },16};17import { addDecorator } from '@storybook/react';18import { withNextRouter } from 'storybook-addon-next-router';19import { withContexts } from '@storybook/addon-contexts/react';20import { contexts } from './contexts';21addDecorator(withNextRouter());22addDecorator(withContexts(contexts));23import { ThemeProvider } from 'styled-components';24 {
Using AI Code Generation
1import { defaultProject } from 'storybook-root';2import { storiesOf } from '@storybook/react';3const stories = storiesOf('defaultProject', module);4stories.add('defaultProject', () => {5 return defaultProject();6});7import { defaultProject } from 'storybook-root';8import { storiesOf } from '@storybook/react';9const stories = storiesOf('defaultProject', module);10stories.add('defaultProject', () => {11 return defaultProject();12});13import { defaultProject } from 'storybook-root';14import { storiesOf } from '@storybook/react';15const stories = storiesOf('defaultProject', module);16stories.add('defaultProject', () => {17 return defaultProject();18});19import { defaultProject } from 'storybook-root';20import { storiesOf } from '@storybook/react';21const stories = storiesOf('defaultProject', module);22stories.add('defaultProject', () => {23 return defaultProject();24});25import { defaultProject } from 'storybook-root';26import { storiesOf } from '@storybook/react';27const stories = storiesOf('defaultProject', module);28stories.add('defaultProject', () => {29 return defaultProject();30});31import { defaultProject } from 'storybook-root';32import { storiesOf } from '@storybook/react';33const stories = storiesOf('defaultProject', module);34stories.add('defaultProject', () => {35 return defaultProject();36});37import { defaultProject } from 'storybook-root';38import { storiesOf } from '@storybook/react';39const stories = storiesOf('defaultProject', module);40stories.add('defaultProject', () => {41 return defaultProject();42});43import { defaultProject } from 'storybook-root';44import { storiesOf } from '@storybook/react';45const stories = storiesOf('defaultProject', module);46stories.add('defaultProject', () => {47 return defaultProject();48});
Using AI Code Generation
1const { defaultProject } = require('storybook-root');2const project = defaultProject();3const { project } = require('storybook-root');4const project = project('project-name');5const { projects } = require('storybook-root');6const project = projects('project-name');7### defaultProject()8### project(projectName)9### projects(projectName)10module.exports = {11 projects: {12 'project-name': {13 },14 },15};
Using AI Code Generation
1import { defaultProject } from 'storybook-root';2const myProject = defaultProject();3myProject.addStory('MyStory', 'MyStory', () => {4 return <div>My Story</div>;5});6import { defaultProject } from 'storybook-root';7const myProject = defaultProject();8myProject.configure();9import { defaultProject } from 'storybook-root';10const myProject = defaultProject();11myProject.addStory('MyStory', 'MyStory', () => {12 return <div>My Story</div>;13});14import { defaultProject } from 'storybook-root';15const myProject = defaultProject();16myProject.addStory('MyStory', 'MyStory', () => {17 return <div>My Story</div>;18});19import { defaultProject } from 'storybook-root';20const myProject = defaultProject();21myProject.addStory('MyStory', 'MyStory', () => {22 return <div>My Story</div>;23});24import { defaultProject } from 'storybook-root';25const myProject = defaultProject();26myProject.addStory('MyStory', 'MyStory', () => {27 return <div>My Story</div>;28});29import { defaultProject } from 'storybook-root';30const myProject = defaultProject();31myProject.addStory('MyStory', 'MyStory', () => {32 return <div>My Story</div>;33});34import { defaultProject } from 'storybook-root';35const myProject = defaultProject();36myProject.addStory('MyStory', 'MyStory', () => {37 return <div>My Story</div>;38});
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!!