-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathDebugContainer.cy.tsx
154 lines (125 loc) · 4.86 KB
/
DebugContainer.cy.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import { DebugSpecsFragmentDoc } from '../generated/graphql-test'
import DebugContainer from './DebugContainer.vue'
import { defaultMessages } from '@cy/i18n'
import { useLoginConnectStore } from '@packages/frontend-shared/src/store/login-connect-store'
import { specsList } from './utils/DebugMapping'
import { CloudRunStubs } from '@packages/graphql/test/stubCloudTypes'
describe('<DebugContainer />', () => {
context('empty states', () => {
const validateEmptyState = (expectedMessage: string) => {
cy.mountFragment(DebugSpecsFragmentDoc, {
render: (gqlVal) => {
return (
<DebugContainer
gql={gqlVal}
/>
)
},
})
cy.findByTestId('debug-empty').contains(expectedMessage)
}
it('shows not logged in', () => {
validateEmptyState(defaultMessages.debugPage.notLoggedIn)
})
it('is logged in', () => {
const loginConnectStore = useLoginConnectStore()
loginConnectStore.setUserFlag('isLoggedIn', true)
validateEmptyState(defaultMessages.debugPage.notConnected)
})
it('has no runs', () => {
const loginConnectStore = useLoginConnectStore()
loginConnectStore.setUserFlag('isLoggedIn', true)
loginConnectStore.setProjectFlag('isProjectConnected', true)
cy.mountFragment(DebugSpecsFragmentDoc, {
render: (gqlVal) => {
return (
<DebugContainer
gql={gqlVal}
/>
)
},
})
cy.findByTestId('debug-empty').contains(defaultMessages.debugPage.noRuns)
})
})
describe('render specs and tests', () => {
it('renders data when logged in and connected', () => {
const loginConnectStore = useLoginConnectStore()
loginConnectStore.setUserFlag('isLoggedIn', true)
loginConnectStore.setProjectFlag('isProjectConnected', true)
cy.mountFragment(DebugSpecsFragmentDoc, {
onResult: (result) => {
if (result.currentProject?.cloudProject?.__typename === 'CloudProject') {
const test = result.currentProject.cloudProject.runByNumber
const other = CloudRunStubs.failingWithTests as typeof test
result.currentProject.cloudProject.runByNumber = other
}
},
render: (gqlVal) => {
return (
<DebugContainer
gql={gqlVal}
/>
)
},
})
// Only asserting that it is rendering the components for failed specs
cy.findByTestId('debug-header').should('be.visible')
cy.findByTestId('debug-spec-item').should('be.visible')
})
})
describe('testing util function: debugMapping', () => {
const createSpecs = (idArr: string[]) => {
const acc: {id: string}[] = []
idArr.forEach((val) => {
acc.push({ id: val })
})
return acc
}
it('maps correctly for a single spec', () => {
const spec = createSpecs(['a1c'])
const tests = [
{ specId: 'a1c', id: 'random1' },
{ specId: 'a1c', id: 'random2' },
]
const debugMappingArray = specsList(spec, tests)
expect(debugMappingArray).to.have.length(1)
expect(debugMappingArray[0]).to.deep.equal({ spec: { id: 'a1c' }, tests: [{ specId: 'a1c', id: 'random1' }, { specId: 'a1c', id: 'random2' }] })
})
it('maps correctly for multiple specs and test', () => {
const specs = createSpecs(['123', '456', '789'])
const tests = [
{ specId: '123', id: 'random1' },
{ specId: '456', id: 'random2' },
{ specId: '456', id: 'random3' },
{ specId: '789', id: 'random4' },
{ specId: '123', id: 'random6' },
]
const debugMappingArray = specsList(specs, tests)
const expected = [
{ spec: { id: '123' }, tests: [{ specId: '123', id: 'random1' }, { specId: '123', id: 'random6' }] },
{ spec: { id: '456' }, tests: [{ specId: '456', id: 'random2' }, { specId: '456', id: 'random3' }] },
{ spec: { id: '789' }, tests: [{ specId: '789', id: 'random4' }] },
]
expect(debugMappingArray).to.deep.equal(expected)
})
it('maps does not show specs that do not have tests', () => {
const specs = createSpecs(['123', '456', '789'])
const tests = [{ specId: '123', id: 'random1' }]
const debugMappingArray = specsList(specs, tests)
expect(debugMappingArray).to.have.length(1)
expect(debugMappingArray).to.deep.equal([{ spec: { id: '123' }, tests: [{ specId: '123', id: 'random1' }] }])
})
it('throws an error when a test does not map to a spec', () => {
const specs = createSpecs(['123'])
const tests = [
{ specId: '123', id: 'random1' },
{ specId: '456', id: 'random2' },
]
const specsListWrapper = () => {
return specsList(specs, tests)
}
expect(specsListWrapper).to.throw('Could not find spec for id 456')
})
})
})