Skip to content

Commit 026aa34

Browse files
committed
add tests
1 parent 7af5a52 commit 026aa34

File tree

4 files changed

+59
-23
lines changed

4 files changed

+59
-23
lines changed

packages/app/cypress/e2e/integration/settings.spec.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe('Settings', { viewportWidth: 1200 }, () => {
1+
describe('Settings', { viewportWidth: 600 }, () => {
22
beforeEach(() => {
33
cy.setupE2E('component-tests')
44

@@ -39,8 +39,17 @@ describe('Settings', { viewportWidth: 1200 }, () => {
3939
cy.wait('@ReconfigureProject')
4040
})
4141

42-
it.only('selects well known editor', () => {
42+
it('selects well known editor', () => {
4343
cy.visitApp()
4444
cy.get('[href="#/settings"]').click()
45+
cy.contains('Device Settings').click()
46+
cy.findByPlaceholderText('Custom path...').clear().type('/usr/local/bin/vim')
47+
48+
cy.intercept('POST', 'mutation-SetPreferredEditorBinary', (req) => {
49+
expect(req.body.variables).to.eql({ 'value': '/usr/local/bin/vim' })
50+
}).as('SetPreferred')
51+
52+
cy.get('[data-cy="use-custom-editor"]').click()
53+
cy.wait('@SetPreferred')
4554
})
4655
})

packages/app/src/settings/device/ExternalEditorSettings.spec.tsx

+28-3
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,34 @@ import { ExternalEditorSettingsFragmentDoc } from '../../generated/graphql-test'
55
const editorText = defaultMessages.settingsPage.editor
66

77
describe('<ExternalEditorSettings />', () => {
8-
beforeEach(() => {
8+
it('renders the placeholder by default', () => {
99
cy.mountFragment(ExternalEditorSettingsFragmentDoc, {
1010
render: (gqlVal) => {
1111
return <ExternalEditorSettings gql={gqlVal} />
1212
},
1313
})
14-
})
1514

16-
it('renders the placeholder by default', () => {
1715
cy.findByText(editorText.noEditorSelectedPlaceholder).should('be.visible')
1816
})
1917

2018
it('renders the title and description', () => {
19+
cy.mountFragment(ExternalEditorSettingsFragmentDoc, {
20+
render: (gqlVal) => {
21+
return <ExternalEditorSettings gql={gqlVal} />
22+
},
23+
})
24+
2125
cy.findByText(editorText.description).should('be.visible')
2226
cy.findByText(editorText.title).should('be.visible')
2327
})
2428

2529
it('can select an editor', () => {
30+
cy.mountFragment(ExternalEditorSettingsFragmentDoc, {
31+
render: (gqlVal) => {
32+
return <ExternalEditorSettings gql={gqlVal} />
33+
},
34+
})
35+
2636
const optionsSelector = '[role=option]'
2737
const inputSelector = '[aria-haspopup=true]'
2838

@@ -32,4 +42,19 @@ describe('<ExternalEditorSettings />', () => {
3242
cy.wrap($options.first()).click()
3343
})
3444
})
45+
46+
it('can input a custom binary', () => {
47+
cy.mountFragment(ExternalEditorSettingsFragmentDoc, {
48+
render: (gqlVal) => {
49+
return <ExternalEditorSettings gql={gqlVal} />
50+
},
51+
})
52+
53+
cy.findByPlaceholderText('Custom path...').type('/usr/bin')
54+
cy.get('[data-cy="use-custom-editor"]').as('custom')
55+
cy.get('@custom').click()
56+
57+
cy.get('@custom').should('be.focused')
58+
cy.get('[data-cy="use-well-known-editor"]').should('not.be.focused')
59+
})
3560
})

packages/app/src/settings/device/ExternalEditorSettings.vue

+19-18
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
</template>
99

1010
<div class="flex items-center">
11-
<input
12-
type="radio"
13-
v-model="editorToUse"
11+
<input
12+
v-model="editorToUse"
13+
type="radio"
1414
class="mr-5px"
15+
data-cy="use-well-known-editor"
1516
value="found"
16-
/>
17+
>
1718

1819
<Select
1920
:model-value="selectedWellKnownEditor"
@@ -46,17 +47,18 @@
4647
</div>
4748

4849
<div class="flex items-center py-2">
49-
<input
50-
type="radio"
50+
<input
51+
v-model="editorToUse"
52+
type="radio"
5153
class="mr-5px"
52-
v-model="editorToUse"
5354
value="custom"
54-
/>
55+
data-cy="use-custom-editor"
56+
>
5557

5658
<div class="w-400px">
57-
<Input
58-
v-model="customBinary"
59-
inputClasses="text-sm"
59+
<Input
60+
v-model="customBinary"
61+
input-classes="text-sm"
6062
placeholder="Custom path..."
6163
@blur="setCustomBinary"
6264
>
@@ -78,7 +80,6 @@ import Icon from '@cy/components/Icon.vue'
7880
import SettingsSection from '../SettingsSection.vue'
7981
import { useI18n } from '@cy/i18n'
8082
import Select from '@cy/components/Select.vue'
81-
import Button from '@cy/components/Button.vue'
8283
import Input from '@cy/components/Input.vue'
8384
import VSCode from '~icons/logos/visual-studio-code'
8485
import Atom from '~icons/logos/atom-icon'
@@ -141,13 +142,13 @@ const customBinary = ref<string>('')
141142
const selectedWellKnownEditor = ref<Editor>()
142143
const editorToUse = ref<'found' | 'custom'>('found')
143144
144-
145145
watch(
146-
() => props.gql.localSettings.preferences.preferredEditorBinary,
146+
() => props.gql.localSettings.preferences.preferredEditorBinary,
147147
(perferredEditorBinary) => {
148-
const isWellKnownEditor = props.gql.localSettings.availableEditors.find((x) =>
149-
x.binary === perferredEditorBinary
150-
)
148+
const isWellKnownEditor = props.gql.localSettings.availableEditors.find((x) => {
149+
return x.binary === perferredEditorBinary
150+
})
151+
151152
editorToUse.value = isWellKnownEditor ? 'found' : 'custom'
152153
153154
if (isWellKnownEditor) {
@@ -157,7 +158,7 @@ watch(
157158
if (editorToUse.value === 'custom' && perferredEditorBinary) {
158159
customBinary.value = perferredEditorBinary
159160
}
160-
}, { immediate: true }
161+
}, { immediate: true },
161162
)
162163
163164
watch(editorToUse, (val) => {

packages/data-context/src/util/urqlCacheKeys.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ export const urqlCacheKeys: Partial<CacheExchangeOpts> = {
1818
ProjectPreferences: (data) => data.__typename,
1919
VersionData: () => null,
2020
LocalSettings: (data) => data.__typename,
21+
LocalSettingsPreferences: () => null,
2122
},
2223
}

0 commit comments

Comments
 (0)