-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
create-from-component.cy.ts
112 lines (86 loc) · 3.76 KB
/
create-from-component.cy.ts
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
import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'
import { getPathForPlatform } from '../../src/paths'
function validateCreateFromComponentCard (beforeEachFn: () => void, expectedSpecPath: string) {
beforeEach(beforeEachFn)
it('Shows create from component card for Vue projects with default spec patterns', () => {
cy.get('@ComponentCard')
.within(() => {
cy.findByRole('button', {
name: 'Create from component',
}).should('be.visible')
.and('not.be.disabled')
})
})
it('Can be closed with the x button', () => {
cy.get('@ComponentCard').click()
cy.findByRole('button', { name: 'Close' }).as('DialogCloseButton')
cy.get('@DialogCloseButton').click()
cy.findByRole('dialog', {
name: 'Choose a component',
}).should('not.exist')
})
it('Lists Vue components in the project', () => {
cy.get('@ComponentCard').click()
cy.findByText('2 matches').should('be.visible')
cy.findByText('App').should('be.visible')
cy.findByText('HelloWorld').should('be.visible')
})
it('Allows for the user to search through their components', () => {
cy.get('@ComponentCard').click()
cy.findByText('*.vue').should('be.visible')
cy.findByText('2 matches').should('be.visible')
cy.findByLabelText('file-name-input').type('HelloWorld')
cy.findByText('HelloWorld').should('be.visible')
cy.findByText('1 of 2 matches').should('be.visible')
cy.findByText('App').should('not.exist')
})
it('shows success modal when component spec is created', () => {
cy.get('@ComponentCard').click()
cy.findByText('HelloWorld').should('be.visible').click()
cy.findByRole('dialog', {
name: defaultMessages.createSpec.successPage.header,
}).as('SuccessDialog').within(() => {
cy.contains(getPathForPlatform(expectedSpecPath)).should('be.visible')
cy.findByRole('button', { name: 'Close' }).should('be.visible')
cy.findByRole('link', { name: 'Okay, run the spec' })
.should('have.attr', 'href', `#/specs/runner?file=${expectedSpecPath}`)
cy.findByRole('button', { name: 'Create another spec' }).click()
})
// 'Create from component' card appears again when the user selects "create another spec"
cy.findByText('Create from component').should('be.visible')
})
it('runs generated spec', () => {
cy.get('@ComponentCard').click()
cy.findByText('HelloWorld').should('be.visible').click()
cy.findByRole('dialog', {
name: defaultMessages.createSpec.successPage.header,
}).as('SuccessDialog').within(() => {
cy.contains(getPathForPlatform(expectedSpecPath)).should('be.visible')
cy.findByRole('button', { name: 'Close' }).should('be.visible')
cy.findByRole('link', { name: 'Okay, run the spec' })
.should('have.attr', 'href', `#/specs/runner?file=${expectedSpecPath}`).click()
})
cy.findByText('<HelloWorld ... />', { timeout: 10000 }).should('be.visible')
})
}
describe('Create from component card', () => {
context('project with default spec pattern', () => {
validateCreateFromComponentCard(() => {
cy.scaffoldProject('no-specs-vue-2')
cy.openProject('no-specs-vue-2')
cy.startAppServer('component')
cy.visitApp()
cy.findAllByTestId('card').eq(0).as('ComponentCard')
}, 'src/components/HelloWorld.cy.js')
})
context('project with custom spec pattern', () => {
validateCreateFromComponentCard(() => {
cy.scaffoldProject('no-specs-vue-2')
cy.openProject('no-specs-vue-2', ['--config-file', 'cypress-custom-spec-pattern.config.js'])
cy.startAppServer('component')
cy.visitApp()
cy.findByText('New spec').click()
cy.findAllByTestId('card').eq(0).as('ComponentCard')
}, 'src/specs-folder/HelloWorld.cy.js')
})
})