Skip to content

Instantly share code, notes, and snippets.

View rezafikkri's full-sized avatar

Reza Sariful Fikri rezafikkri

View GitHub Profile
test('Should call asyncCreateThread function when save button clicked', async () => {
// Arrange
// create mock for asyncCreateThread module
vi.mock('@/lib/threads/action', async (importOriginal) => {
const mod = await importOriginal();
return {
...mod,
asyncCreateThread: vi.fn(),
};
});
@rezafikkri
rezafikkri / thread-input.jsx
Created April 11, 2024 00:50
Thread input component
'use client';
import { useRouter } from 'next/navigation';
import { useState } from 'react';
import Link from 'next/link';
import { useAppDispatch } from '@/hooks/redux-hooks';
import { asyncCreateThread } from '@/lib/threads/action';
import Alert from '@/components/alert';
import useInput from '@/hooks/use-input';
import Editor from './editor';
@rezafikkri
rezafikkri / thread-input.test.jsx
Created April 11, 2024 00:48
File test thread-input component
import {
describe,
test,
expect,
afterEach,
beforeAll,
vi,
} from 'vitest';
import { render, screen, cleanup } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
@rezafikkri
rezafikkri / romanToInt.php
Created June 8, 2022 23:18
Class for convert roman symbol to int and also validate roman symbol
<?php
class Solution
{
/** @var array SYMBOLS This is roman symbols cannot loop */
const SYMBOLS = ['V' => 5, 'L' => 50, 'D' => 500];
/** @var array LOOP_SYMBOLS This is roman symbols can loop */
const LOOP_SYMBOLS = ['I' => 1, 'X' => 10, 'C' => 100, 'M' => 1000];
@rezafikkri
rezafikkri / filterInputNumber2.js
Created September 6, 2020 02:35
Filter Input Number, menggunakan input type text
document.getElementById("floatTextBox").addEventListener('input', function (event) {
// jika value yang dimasukkan pertama adalah karakter (-), langsung keluar dari function
if(this.value === '-') return 0;
// selain dari itu, jika value input cocok dengan expression
if(/^-?\d+(,|\.)?\d*$/.test(this.value)) {
// set oldValue = value input dan keluar dari function
this.oldValue = this.value; return 0;
@rezafikkri
rezafikkri / filterInputNumber.js
Last active September 6, 2020 23:00
Filter Input Number, menggunakan input type number
document.getElementById("floatTextBox").addEventListener('keyup', function (event) {
// jika yang ditekan bukan backspace dan del
if(event.keyCode !== 8 && event.keyCode !== 46) {
// jika value cocok dengan expression
if(/^-?\d+(,|\.)?\d*$/.test(this.value)) {
// set oldValue = value dan keluar dari function;
this.oldValue = this.value; return 0;