-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(editor): Fix workflows filter resetting (#8411)
- Loading branch information
Showing
15 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { Server } from 'miragejs'; | ||
import { Response } from 'miragejs'; | ||
import type { AppSchema } from '../types'; | ||
|
||
export function routesForTags(server: Server) { | ||
server.get('/rest/tags', (schema: AppSchema) => { | ||
const { models: data } = schema.all('tag'); | ||
|
||
return new Response(200, {}, { data }); | ||
}); | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/editor-ui/src/__tests__/server/endpoints/workflow.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { Server } from 'miragejs'; | ||
import { Response } from 'miragejs'; | ||
import type { AppSchema } from '../types'; | ||
|
||
export function routesForWorkflows(server: Server) { | ||
server.get('/rest/workflows', (schema: AppSchema) => { | ||
const { models: data } = schema.all('workflow'); | ||
|
||
return new Response(200, {}, { data }); | ||
}); | ||
server.get('/rest/active-workflows', (schema: AppSchema) => { | ||
const { models: data } = schema.all('workflow'); | ||
|
||
return new Response(200, {}, { data }); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Factory } from 'miragejs'; | ||
import type { ITag } from '@/Interface'; | ||
import { faker } from '@faker-js/faker'; | ||
|
||
export const tagFactory = Factory.extend<ITag>({ | ||
id(i: string) { | ||
return i; | ||
}, | ||
name() { | ||
return faker.lorem.word(); | ||
}, | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/editor-ui/src/__tests__/server/factories/workflow.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Factory } from 'miragejs'; | ||
import type { IWorkflowDb } from '@/Interface'; | ||
import { faker } from '@faker-js/faker'; | ||
|
||
export const workflowFactory = Factory.extend<IWorkflowDb>({ | ||
id(i: string) { | ||
return i; | ||
}, | ||
name() { | ||
return faker.lorem.word(); | ||
}, | ||
createdAt() { | ||
return faker.date.recent().toISOString(); | ||
}, | ||
tags() { | ||
return faker.lorem.words(2.5).split(' '); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { tags } from './tags'; | ||
import { workflows } from './workflows'; | ||
|
||
export const fixtures = { | ||
tags, | ||
workflows, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { ITag } from '@/Interface'; | ||
export const tags: ITag[] = [ | ||
{ | ||
id: '1', | ||
name: 'tag1', | ||
}, | ||
{ | ||
id: '2', | ||
name: 'tag2', | ||
}, | ||
{ | ||
id: '3', | ||
name: 'tag3', | ||
}, | ||
]; |
47 changes: 47 additions & 0 deletions
47
packages/editor-ui/src/__tests__/server/fixtures/workflows.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { IWorkflowDb } from '@/Interface'; | ||
import { faker } from '@faker-js/faker'; | ||
|
||
export const workflows = [ | ||
{ | ||
id: '1', | ||
name: 'workflow1', | ||
tags: [], | ||
}, | ||
{ | ||
id: '2', | ||
name: 'workflow2', | ||
tags: [ | ||
{ id: '1', name: 'tag1' }, | ||
{ id: '2', name: 'tag2' }, | ||
], | ||
}, | ||
{ | ||
id: '3', | ||
name: 'workflow3', | ||
tags: [ | ||
{ id: '1', name: 'tag1' }, | ||
{ id: '3', name: 'tag3' }, | ||
], | ||
}, | ||
{ | ||
id: '4', | ||
name: 'workflow4', | ||
tags: [ | ||
{ id: '2', name: 'tag2' }, | ||
{ id: '3', name: 'tag3' }, | ||
], | ||
}, | ||
{ | ||
id: '5', | ||
name: 'workflow5', | ||
tags: [ | ||
{ id: '1', name: 'tag1' }, | ||
{ id: '2', name: 'tag2' }, | ||
{ id: '3', name: 'tag3' }, | ||
], | ||
}, | ||
].map((wf, idx) => ({ | ||
...wf, | ||
createdAt: faker.date.recent().toISOString(), | ||
updatedAt: new Date(`2024-1-${idx + 1}`).toISOString(), | ||
})) as IWorkflowDb[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { ITag } from '@/Interface'; | ||
import { Model } from 'miragejs'; | ||
import type { ModelDefinition } from 'miragejs/-types'; | ||
|
||
export const TagModel: ModelDefinition<ITag> = Model.extend({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { IWorkflowDb } from '@/Interface'; | ||
import { Model } from 'miragejs'; | ||
import type { ModelDefinition } from 'miragejs/-types'; | ||
|
||
export const WorkflowModel: ModelDefinition<IWorkflowDb> = Model.extend({}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
packages/editor-ui/src/views/__tests__/WorkflowsView.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { afterAll, beforeAll } from 'vitest'; | ||
import { setActivePinia, createPinia } from 'pinia'; | ||
import { waitFor } from '@testing-library/vue'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { setupServer } from '@/__tests__/server'; | ||
import WorkflowsView from '@/views/WorkflowsView.vue'; | ||
import { useSettingsStore } from '@/stores/settings.store'; | ||
import { useUsersStore } from '@/stores/users.store'; | ||
import { createComponentRenderer } from '@/__tests__/render'; | ||
|
||
const originalOffsetHeight = Object.getOwnPropertyDescriptor( | ||
HTMLElement.prototype, | ||
'offsetHeight', | ||
) as PropertyDescriptor; | ||
|
||
describe('WorkflowsView', () => { | ||
let server: ReturnType<typeof setupServer>; | ||
let pinia: ReturnType<typeof createPinia>; | ||
let settingsStore: ReturnType<typeof useSettingsStore>; | ||
let usersStore: ReturnType<typeof useUsersStore>; | ||
|
||
const renderComponent = createComponentRenderer(WorkflowsView, { | ||
global: { | ||
mocks: { | ||
$route: { | ||
query: {}, | ||
}, | ||
$router: { | ||
replace: vi.fn(), | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
beforeAll(() => { | ||
Object.defineProperties(HTMLElement.prototype, { | ||
offsetHeight: { | ||
get() { | ||
return this.getAttribute('data-test-id') === 'resources-list' ? 1000 : 100; | ||
}, | ||
}, | ||
}); | ||
|
||
server = setupServer(); | ||
}); | ||
|
||
afterAll(() => { | ||
Object.defineProperty(HTMLElement.prototype, 'offsetHeight', originalOffsetHeight); | ||
}); | ||
|
||
beforeEach(async () => { | ||
pinia = createPinia(); | ||
setActivePinia(pinia); | ||
|
||
settingsStore = useSettingsStore(); | ||
usersStore = useUsersStore(); | ||
await settingsStore.getSettings(); | ||
await usersStore.fetchUsers(); | ||
await usersStore.loginWithCookie(); | ||
}); | ||
|
||
afterAll(() => { | ||
server.shutdown(); | ||
}); | ||
|
||
it('should filter workflows by tags', async () => { | ||
const { container, getByTestId, getAllByTestId, queryByTestId } = renderComponent({ | ||
pinia, | ||
}); | ||
|
||
expect(container.querySelectorAll('.n8n-loading')).toHaveLength(3); | ||
expect(queryByTestId('resources-list')).not.toBeInTheDocument(); | ||
|
||
await waitFor(() => { | ||
expect(container.querySelectorAll('.n8n-loading')).toHaveLength(0); | ||
// There are 5 workflows defined in server fixtures | ||
expect(getAllByTestId('resources-list-item')).toHaveLength(5); | ||
}); | ||
|
||
await userEvent.click( | ||
getAllByTestId('resources-list-item')[0].querySelector('.n8n-tag') as HTMLElement, | ||
); | ||
await waitFor(() => { | ||
expect(getAllByTestId('resources-list-item').length).toBeLessThan(5); | ||
}); | ||
|
||
await userEvent.click(getByTestId('workflows-filter-reset')); | ||
await waitFor(() => { | ||
expect(getAllByTestId('resources-list-item')).toHaveLength(5); | ||
}); | ||
|
||
await userEvent.click( | ||
getAllByTestId('resources-list-item')[3].querySelector('.n8n-tag') as HTMLElement, | ||
); | ||
await waitFor(() => { | ||
expect(getAllByTestId('resources-list-item').length).toBeLessThan(5); | ||
}); | ||
}); | ||
}); |