diff --git a/src/__tests__/home/TableRow.test.ts b/src/__tests__/home/TableRow.test.ts new file mode 100644 index 0000000..934b09d --- /dev/null +++ b/src/__tests__/home/TableRow.test.ts @@ -0,0 +1,53 @@ +import { describe, expect, test, afterEach } from 'vitest'; +import { render, screen, cleanup } from '@testing-library/svelte'; +import TableRow from '../../lib/home/TableRow.svelte'; + +describe('Unit:Home/TableRow', () => { + let data = { + id: '_1', + name: 'Test Medicine', + chemicalName: 'Test Medicine Chemical Name', + mrp: 50.0, + totalStock: 10, + index: 0, + }; + afterEach(() => { + cleanup() + }) + test('should render parsed data', () => { + render(TableRow, data); + + Object.keys(data).forEach((key) => { + if (key !== 'id' && key != 'totalStock' && key !== 'index') + expect(screen.getByText(data[key])).toBeTruthy(); + }); + }); + + test('should show Out of stock when totalStock == 0', () => { + data['totalStock'] = 0; + render(TableRow, data); + + expect(screen.getByTestId('availability').innerHTML).toBe('Out of stock'); + }) + + test('should show Limited Stocks when totalStock < 100', () => { + data['totalStock'] = 80; + render(TableRow, data); + + expect(screen.getByTestId('availability').innerHTML).toBe('Limited Stocks'); + }) + + test('should show Available when totalStock >= 100', () => { + data['totalStock'] = 110; + render(TableRow, data); + + expect(screen.getByTestId('availability').innerHTML).toBe('Available'); + }) + + test('snapshot test', () => { + render(TableRow, data); + + expect(screen).toMatchSnapshot(); + }) + +}); diff --git a/src/__tests__/home/__snapshots__/TableRow.test.ts.snap b/src/__tests__/home/__snapshots__/TableRow.test.ts.snap new file mode 100644 index 0000000..a815858 --- /dev/null +++ b/src/__tests__/home/__snapshots__/TableRow.test.ts.snap @@ -0,0 +1,56 @@ +// Vitest Snapshot v1 + +exports[`Unit:Home/TableRow > snapshot test 1`] = ` +{ + "debug": [Function], + "findAllByAltText": [Function], + "findAllByDisplayValue": [Function], + "findAllByLabelText": [Function], + "findAllByPlaceholderText": [Function], + "findAllByRole": [Function], + "findAllByTestId": [Function], + "findAllByText": [Function], + "findAllByTitle": [Function], + "findByAltText": [Function], + "findByDisplayValue": [Function], + "findByLabelText": [Function], + "findByPlaceholderText": [Function], + "findByRole": [Function], + "findByTestId": [Function], + "findByText": [Function], + "findByTitle": [Function], + "getAllByAltText": [Function], + "getAllByDisplayValue": [Function], + "getAllByLabelText": [Function], + "getAllByPlaceholderText": [Function], + "getAllByRole": [Function], + "getAllByTestId": [Function], + "getAllByText": [Function], + "getAllByTitle": [Function], + "getByAltText": [Function], + "getByDisplayValue": [Function], + "getByLabelText": [Function], + "getByPlaceholderText": [Function], + "getByRole": [Function], + "getByTestId": [Function], + "getByText": [Function], + "getByTitle": [Function], + "logTestingPlaygroundURL": [Function], + "queryAllByAltText": [Function], + "queryAllByDisplayValue": [Function], + "queryAllByLabelText": [Function], + "queryAllByPlaceholderText": [Function], + "queryAllByRole": [Function], + "queryAllByTestId": [Function], + "queryAllByText": [Function], + "queryAllByTitle": [Function], + "queryByAltText": [Function], + "queryByDisplayValue": [Function], + "queryByLabelText": [Function], + "queryByPlaceholderText": [Function], + "queryByRole": [Function], + "queryByTestId": [Function], + "queryByText": [Function], + "queryByTitle": [Function], +} +`;