/
CloudConnectModals.spec.tsx
86 lines (72 loc) · 2.47 KB
/
CloudConnectModals.spec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { defaultMessages } from '@cy/i18n'
import { CloudUserStubs,
CloudOrganizationConnectionStubs,
} from '@packages/graphql/test/stubCloudTypes'
import { CloudConnectModalsFragmentDoc } from '../../generated/graphql-test'
import CloudConnectModals from './CloudConnectModals.vue'
import cloneDeep from 'lodash/cloneDeep'
type MountOptions = {
hasOrg: boolean
hasProjects: boolean
}
describe('<CloudConnectModals />', () => {
function mountDialog ({ hasOrg, hasProjects }: MountOptions) {
cy.mountFragment(CloudConnectModalsFragmentDoc, {
onResult: (result) => {
result.currentProject = {
__typename: 'CurrentProject' as const,
id: '1',
title: 'Test Project',
projectId: null,
}
result.cloudViewer = {
...CloudUserStubs.me,
organizations: hasOrg ? cloneDeep(CloudOrganizationConnectionStubs) : null,
}
if (!hasProjects) {
result.cloudViewer.organizations?.nodes.forEach((org) => {
org.projects = {
...org.projects,
nodes: [],
}
})
}
},
render (gql) {
return (<div class="h-screen">
<CloudConnectModals utmMedium="testing" gql={gql}/>
</div>)
},
})
}
context('has no organization', () => {
beforeEach(() => {
mountDialog({ hasOrg: false, hasProjects: false })
})
it('shows the create/select org modal when orgs are added', () => {
cy.contains(defaultMessages.runs.connect.modal.createOrg.button).should('be.visible')
cy.percySnapshot()
})
})
context('has organizations', () => {
context('with no projects', () => {
beforeEach(() => {
mountDialog({ hasOrg: true, hasProjects: false })
})
it('shows the select project modal with create new project action', () => {
cy.contains(defaultMessages.runs.connect.modal.selectProject.createProject).should('be.visible')
cy.contains('a', defaultMessages.links.needHelp).should('have.attr', 'href', 'https://on.cypress.io/adding-new-project')
cy.percySnapshot()
})
})
context('with projects', () => {
beforeEach(() => {
mountDialog({ hasOrg: true, hasProjects: true })
})
it('shows the select project modal with list of projects', () => {
cy.contains(defaultMessages.runs.connect.modal.selectProject.connectProject).should('be.visible')
cy.percySnapshot()
})
})
})
})