Skip to content

Commit

Permalink
Corrected formatting in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Jaeger-Freeborn <[email protected]>
  • Loading branch information
Gavinok committed Dec 11, 2023
1 parent d9b5284 commit 868c4cb
Showing 1 changed file with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,52 @@ import { tryParseJson } from '@/helpers/jsonParsing';
import ToggleJson from '@/components/common/ToggleJson.vue';

const mountToggleJson = () =>
shallowMount(ToggleJson, {
props: {
toJson: () => {
return "{ 'testing': 1 }";
},
fromJson: (jsonRepresentation: string) => {
return tryParseJson<any>(jsonRepresentation);
},
},
slots: {
default: [CreateSchema, '<my-component />', 'text'],
},
global: {
plugins: [PrimeVue, VueToastificationPlugin],
},
});
shallowMount(ToggleJson, {
props: {
toJson: () => {
return "{ 'testing': 1 }";
},
fromJson: (jsonRepresentation: string) => {
return tryParseJson<any>(jsonRepresentation);
},
},
slots: {
default: [CreateSchema, '<my-component />', 'text'],
},
global: {
plugins: [PrimeVue, VueToastificationPlugin],
},
});

describe('Properly Toggle Json Input', () => {
test('reders properly', async () => {
const wrapper = mountToggleJson();
test('reders properly', async () => {
const wrapper = mountToggleJson();

expect(wrapper.exists()).toBe(true);
});
test('text area is only shown after input is toggled', async () => {
const wrapper = mountToggleJson();
const wrapperVm = wrapper.vm as unknown as typeof ToggleJson;
const toJson = vi.spyOn(wrapperVm.props, 'toJson');
const fromJson = vi.spyOn(wrapperVm.props, 'fromJson');
expect(wrapper.exists()).toBe(true);
});
test('text area is only shown after input is toggled', async () => {
const wrapper = mountToggleJson();
const wrapperVm = wrapper.vm as unknown as typeof ToggleJson;
const toJson = vi.spyOn(wrapperVm.props, 'toJson');
const fromJson = vi.spyOn(wrapperVm.props, 'fromJson');

expect(wrapper.findComponent({ name: 'Textarea' }).isVisible()).toBe(false);
// showRawJson;
expect(wrapper.findComponent({ name: 'InputSwitch' }).exists()).toBe(true);
expect(wrapper.findComponent({ name: 'Textarea' }).isVisible()).toBe(false);
// showRawJson;
expect(wrapper.findComponent({ name: 'InputSwitch' }).exists()).toBe(true);

expect(wrapper.findComponent({ name: 'CreateSchema' }).exists()).toBe(true);
wrapperVm.showRawJson = true;
await wrapperVm.toggleJson();
expect(wrapper.findComponent({ name: 'CreateSchema' }).exists()).toBe(true);
wrapperVm.showRawJson = true;
await wrapperVm.toggleJson();

await flushPromises();
await flushPromises();

wrapperVm.showRawJson = false;
await wrapperVm.toggleJson();
wrapperVm.showRawJson = false;
await wrapperVm.toggleJson();

await flushPromises();
await flushPromises();

expect(wrapper.findComponent({ name: 'Textarea' }).isVisible()).toBe(true);
expect(toJson).toHaveBeenCalled();
expect(fromJson).toHaveBeenCalled();
});
expect(wrapper.findComponent({ name: 'Textarea' }).isVisible()).toBe(true);
expect(toJson).toHaveBeenCalled();
expect(fromJson).toHaveBeenCalled();
});
});

0 comments on commit 868c4cb

Please sign in to comment.