Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/__test__/unit/template-tag-filter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { describe, expect, it } from 'vitest'

/**
* Tests for the tag column filter logic used in the templates table.
* The filter checks if any of a template's tags contain the filter value (case-insensitive).
*/

function tagFilterFn(tags: string[], filterValue: string): boolean {
return tags.some((tag) =>
tag.toLowerCase().includes(filterValue.toLowerCase())
)
}

describe('Template Tag Filter', () => {
it('matches an exact tag name', () => {
expect(tagFilterFn(['production', 'latest'], 'production')).toBe(true)
})

it('matches a partial tag name', () => {
expect(tagFilterFn(['production', 'latest'], 'prod')).toBe(true)
})

it('is case-insensitive', () => {
expect(tagFilterFn(['Production', 'Latest'], 'production')).toBe(true)
expect(tagFilterFn(['production'], 'PROD')).toBe(true)
})

it('returns false when no tags match', () => {
expect(tagFilterFn(['staging', 'v1.0.0'], 'production')).toBe(false)
})

it('returns false for empty tags array', () => {
expect(tagFilterFn([], 'production')).toBe(false)
})

it('matches version-style tags', () => {
expect(tagFilterFn(['v1.0.0', 'v2.1.0'], 'v2')).toBe(true)
expect(tagFilterFn(['v1.0.0', 'v2.1.0'], '1.0')).toBe(true)
})

it('matches when filter is a single character', () => {
expect(tagFilterFn(['latest', 'stable'], 'l')).toBe(true)
expect(tagFilterFn(['latest', 'stable'], 'z')).toBe(false)
})
})
43 changes: 43 additions & 0 deletions src/configs/mock-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const DEFAULT_TEMPLATES: DefaultTemplate[] = [
diskSizeMB: 1024,
envdVersion: '0.1.0',
public: true,
tags: [],
templateID: 'code-interpreter-v1',
createdAt: '2024-01-01T00:00:00Z',
updatedAt: '2024-01-01T00:00:00Z',
Expand All @@ -44,6 +45,7 @@ const DEFAULT_TEMPLATES: DefaultTemplate[] = [
diskSizeMB: 1024,
envdVersion: '0.1.0',
public: true,
tags: [],
templateID: 'web-starter-v1',
createdAt: '2024-01-05T00:00:00Z',
updatedAt: '2024-01-05T00:00:00Z',
Expand All @@ -63,6 +65,7 @@ const DEFAULT_TEMPLATES: DefaultTemplate[] = [
diskSizeMB: 1024,
envdVersion: '0.1.0',
public: true,
tags: [],
templateID: 'data-science-v1',
createdAt: '2024-01-06T00:00:00Z',
updatedAt: '2024-01-06T00:00:00Z',
Expand All @@ -88,6 +91,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 2048,
envdVersion: '0.1.0',
public: true,
tags: ['latest', 'v1.0.0'],
templateID: 'node-typescript-v1',
createdAt: '2024-01-01T00:00:00Z',
updatedAt: '2024-01-01T00:00:00Z',
Expand All @@ -108,6 +112,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 1536,
envdVersion: '0.1.0',
public: true,
tags: ['production', 'stable'],
templateID: 'react-vite-v2',
createdAt: '2024-01-02T00:00:00Z',
updatedAt: '2024-01-02T00:00:00Z',
Expand All @@ -125,6 +130,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 10240,
envdVersion: '0.1.0',
public: false,
tags: ['staging'],
templateID: 'postgres-v15',
createdAt: '2024-01-03T00:00:00Z',
updatedAt: '2024-01-03T00:00:00Z',
Expand All @@ -142,6 +148,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 512,
envdVersion: '0.1.0',
public: true,
tags: [],
templateID: 'redis-v7',
createdAt: '2024-01-04T00:00:00Z',
updatedAt: '2024-01-04T00:00:00Z',
Expand All @@ -159,6 +166,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 5120,
envdVersion: '0.1.0',
public: false,
tags: ['latest', 'v2.1.0', 'gpu'],
templateID: 'python-ml-v1',
createdAt: '2024-01-05T00:00:00Z',
updatedAt: '2024-01-05T00:00:00Z',
Expand All @@ -176,6 +184,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 8192,
envdVersion: '0.1.0',
public: true,
tags: ['default'],
templateID: 'elastic-v8',
createdAt: '2024-01-06T00:00:00Z',
updatedAt: '2024-01-06T00:00:00Z',
Expand All @@ -193,6 +202,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 1024,
envdVersion: '0.1.0',
public: true,
tags: [],
templateID: 'grafana-v9',
createdAt: '2024-01-07T00:00:00Z',
updatedAt: '2024-01-07T00:00:00Z',
Expand All @@ -210,6 +220,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 512,
public: true,
envdVersion: '0.1.0',
tags: ['latest'],
templateID: 'nginx-v1',
createdAt: '2024-01-08T00:00:00Z',
updatedAt: '2024-01-08T00:00:00Z',
Expand All @@ -227,6 +238,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 10240,
envdVersion: '0.1.0',
public: true,
tags: [],
templateID: 'mongodb-v6',
createdAt: '2024-01-09T00:00:00Z',
updatedAt: '2024-01-09T00:00:00Z',
Expand All @@ -244,6 +256,7 @@ const TEMPLATES: Template[] = [
memoryMB: 4096,
diskSizeMB: 10240,
public: true,
tags: [],
templateID: 'mysql-v8',
createdAt: '2024-01-10T00:00:00Z',
updatedAt: '2024-01-10T00:00:00Z',
Expand All @@ -261,6 +274,7 @@ const TEMPLATES: Template[] = [
memoryMB: 2048,
diskSizeMB: 2048,
public: true,
tags: ['latest', 'production'],
templateID: 'nextjs-v14',
createdAt: '2024-01-11T00:00:00Z',
updatedAt: '2024-01-11T00:00:00Z',
Expand All @@ -281,6 +295,7 @@ const TEMPLATES: Template[] = [
memoryMB: 1024,
diskSizeMB: 1536,
public: true,
tags: [],
templateID: 'vue-v3',
createdAt: '2024-01-12T00:00:00Z',
updatedAt: '2024-01-12T00:00:00Z',
Expand All @@ -298,6 +313,7 @@ const TEMPLATES: Template[] = [
memoryMB: 3072,
diskSizeMB: 2048,
public: true,
tags: ['v4.2'],
templateID: 'django-v4',
createdAt: '2024-01-13T00:00:00Z',
updatedAt: '2024-01-13T00:00:00Z',
Expand All @@ -318,6 +334,7 @@ const TEMPLATES: Template[] = [
memoryMB: 1536,
diskSizeMB: 1024,
public: true,
tags: [],
templateID: 'flask-v2',
createdAt: '2024-01-14T00:00:00Z',
updatedAt: '2024-01-14T00:00:00Z',
Expand All @@ -335,6 +352,7 @@ const TEMPLATES: Template[] = [
memoryMB: 2048,
diskSizeMB: 2048,
public: true,
tags: ['latest'],
templateID: 'golang-v1.21',
createdAt: '2024-01-15T00:00:00Z',
updatedAt: '2024-01-15T00:00:00Z',
Expand All @@ -355,6 +373,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 2048,
public: true,
envdVersion: '0.1.0',
tags: [],
templateID: 'rust-v1.75',
createdAt: '2024-01-16T00:00:00Z',
updatedAt: '2024-01-16T00:00:00Z',
Expand All @@ -372,6 +391,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 3072,
public: true,
envdVersion: '0.1.0',
tags: ['staging', 'v3.2.0'],
templateID: 'java-spring-v3',
createdAt: '2024-01-17T00:00:00Z',
updatedAt: '2024-01-17T00:00:00Z',
Expand All @@ -392,6 +412,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 2048,
public: true,
envdVersion: '0.1.0',
tags: [],
templateID: 'dotnet-v8',
createdAt: '2024-01-18T00:00:00Z',
updatedAt: '2024-01-18T00:00:00Z',
Expand All @@ -409,6 +430,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 1536,
public: true,
envdVersion: '0.1.0',
tags: [],
templateID: 'php-laravel-v10',
createdAt: '2024-01-19T00:00:00Z',
updatedAt: '2024-01-19T00:00:00Z',
Expand All @@ -429,6 +451,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 1536,
public: true,
envdVersion: '0.1.0',
tags: [],
templateID: 'ruby-rails-v7',
createdAt: '2024-01-20T00:00:00Z',
updatedAt: '2024-01-20T00:00:00Z',
Expand All @@ -446,6 +469,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 4096,
public: true,
envdVersion: '0.1.0',
tags: [],
templateID: 'jupyter-v6',
createdAt: '2024-01-21T00:00:00Z',
updatedAt: '2024-01-21T00:00:00Z',
Expand All @@ -466,6 +490,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 10240,
public: false,
envdVersion: '0.1.0',
tags: [],
templateID: 'tensorflow-v2.15',
createdAt: '2024-01-22T00:00:00Z',
updatedAt: '2024-01-22T00:00:00Z',
Expand All @@ -486,6 +511,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 10240,
public: false,
envdVersion: '0.1.0',
tags: [],
templateID: 'pytorch-v2.1',
createdAt: '2024-01-23T00:00:00Z',
updatedAt: '2024-01-23T00:00:00Z',
Expand All @@ -506,6 +532,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 20480,
public: true,
envdVersion: '0.1.0',
tags: [],
templateID: 'cassandra-v4',
createdAt: '2024-01-24T00:00:00Z',
updatedAt: '2024-01-24T00:00:00Z',
Expand All @@ -523,6 +550,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 5120,
public: true,
envdVersion: '0.1.0',
tags: [],
templateID: 'docker-v24',
createdAt: '2024-01-25T00:00:00Z',
updatedAt: '2024-01-25T00:00:00Z',
Expand All @@ -543,6 +571,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 10240,
public: false,
envdVersion: '0.1.0',
tags: [],
templateID: 'kubernetes-v1.28',
createdAt: '2024-01-26T00:00:00Z',
updatedAt: '2024-01-26T00:00:00Z',
Expand All @@ -563,6 +592,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 1024,
public: true,
envdVersion: '0.1.0',
tags: [],
templateID: 'terraform-v1.6',
createdAt: '2024-01-27T00:00:00Z',
updatedAt: '2024-01-27T00:00:00Z',
Expand All @@ -579,6 +609,7 @@ const TEMPLATES: Template[] = [
memoryMB: 1536,
diskSizeMB: 1024,
public: true,
tags: [],
templateID: 'ansible-v2.16',
createdAt: '2024-01-28T00:00:00Z',
updatedAt: '2024-01-28T00:00:00Z',
Expand All @@ -599,6 +630,7 @@ const TEMPLATES: Template[] = [
memoryMB: 3072,
diskSizeMB: 5120,
public: true,
tags: [],
templateID: 'prometheus-v2.48',
envdVersion: '0.1.0',
createdAt: '2024-01-29T00:00:00Z',
Expand All @@ -617,6 +649,7 @@ const TEMPLATES: Template[] = [
memoryMB: 4096,
diskSizeMB: 3072,
public: true,
tags: [],
templateID: 'jenkins-v2.426',
createdAt: '2024-01-30T00:00:00Z',
updatedAt: '2024-01-30T00:00:00Z',
Expand All @@ -637,6 +670,7 @@ const TEMPLATES: Template[] = [
memoryMB: 3072,
diskSizeMB: 2048,
public: true,
tags: [],
templateID: 'gitlab-ci-v16',
createdAt: '2024-01-31T00:00:00Z',
updatedAt: '2024-01-31T00:00:00Z',
Expand All @@ -654,6 +688,7 @@ const TEMPLATES: Template[] = [
memoryMB: 12288,
diskSizeMB: 15360,
public: false,
tags: [],
templateID: 'apache-spark-v3.5',
createdAt: '2024-02-01T00:00:00Z',
updatedAt: '2024-02-01T00:00:00Z',
Expand All @@ -674,6 +709,7 @@ const TEMPLATES: Template[] = [
memoryMB: 6144,
diskSizeMB: 10240,
public: true,
tags: [],
templateID: 'kafka-v3.6',
createdAt: '2024-02-02T00:00:00Z',
updatedAt: '2024-02-02T00:00:00Z',
Expand All @@ -691,6 +727,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 2048,
public: true,
envdVersion: '0.1.0',
tags: [],
templateID: 'rabbitmq-v3.12',
createdAt: '2024-02-03T00:00:00Z',
updatedAt: '2024-02-03T00:00:00Z',
Expand All @@ -711,6 +748,7 @@ const TEMPLATES: Template[] = [
memoryMB: 2048,
diskSizeMB: 1024,
public: true,
tags: [],
templateID: 'zookeeper-v3.9',
createdAt: '2024-02-04T00:00:00Z',
updatedAt: '2024-02-04T00:00:00Z',
Expand All @@ -728,6 +766,7 @@ const TEMPLATES: Template[] = [
diskSizeMB: 5120,
public: true,
envdVersion: '0.1.0',
tags: [],
templateID: 'solr-v9.4',
createdAt: '2024-02-05T00:00:00Z',
updatedAt: '2024-02-05T00:00:00Z',
Expand All @@ -747,6 +786,7 @@ const TEMPLATES: Template[] = [
memoryMB: 3072,
diskSizeMB: 2048,
public: true,
tags: [],
templateID: 'logstash-v8.11',
createdAt: '2024-02-06T00:00:00Z',
envdVersion: '0.1.0',
Expand All @@ -764,6 +804,7 @@ const TEMPLATES: Template[] = [
memoryMB: 2048,
diskSizeMB: 1024,
public: true,
tags: [],
templateID: 'kibana-v8.11',
createdAt: '2024-02-07T00:00:00Z',
updatedAt: '2024-02-07T00:00:00Z',
Expand All @@ -781,6 +822,7 @@ const TEMPLATES: Template[] = [
memoryMB: 2048,
diskSizeMB: 5120,
public: true,
tags: [],
templateID: 'minio-v2024',
createdAt: '2024-02-08T00:00:00Z',
envdVersion: '0.1.0',
Expand All @@ -802,6 +844,7 @@ const TEMPLATES: Template[] = [
memoryMB: 1536,
diskSizeMB: 1024,
public: false,
tags: [],
templateID: 'vault-v1.15',
createdAt: '2024-02-09T00:00:00Z',
updatedAt: '2024-02-09T00:00:00Z',
Expand Down
Loading